Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2f2c82f
secret masking initial commit,all flow complete except prepare payloa…
prakash100198 Nov 22, 2024
0204f3c
prepare final response with index in CompareCategoryWiseConfigData se…
prakash100198 Nov 22, 2024
acef3fe
Merge branch 'develop' into secret-masking-fix
prakash100198 Nov 25, 2024
30dc494
DeploymentConfigurationService_ent.go new file created for ent logic
prakash100198 Nov 26, 2024
1394a97
validation fixes
prakash100198 Nov 26, 2024
75926be
prepareKeyValMapForSingleSecretAndMaskValue-> prepareSecretNameWithKe…
prakash100198 Nov 26, 2024
9ad0636
minor refactor
prakash100198 Nov 26, 2024
a0ccf0c
send secret in config-data api only if user has admin access
prakash100198 Nov 26, 2024
7f2ae8a
rename var names for better clarity
prakash100198 Nov 26, 2024
b391b00
add omitempty with json key Index in DeploymentAndCmCsConfigDto
prakash100198 Nov 28, 2024
bcfd4e7
some refact after code review -1
prakash100198 Nov 28, 2024
a940803
Merge branch 'develop' into secret-masking-fix
prakash100198 Nov 28, 2024
be86fd0
take in query param ComparisonRequestDto instead of payload in get req
prakash100198 Nov 29, 2024
7a2ca72
Merge branch 'develop' into secret-masking-fix
prakash100198 Nov 29, 2024
740c3ae
envName and appName in comparisonItems
prakash100198 Nov 29, 2024
b5008f3
support wfrid in case of previous deployments as config type
prakash100198 Nov 29, 2024
e5a6a00
bug fix
prakash100198 Dec 1, 2024
9778130
Merge branch 'develop' into secret-masking-fix
prakash100198 Dec 2, 2024
22cd18a
dev test fix:- instead of checking on global field in secret config d…
prakash100198 Dec 2, 2024
e3ae3a0
first depl fix
prakash100198 Dec 3, 2024
457febe
mask secret in case of view only when request is for only one secret
prakash100198 Dec 4, 2024
d3ad04a
code review
prakash100198 Dec 5, 2024
7aaa013
Merge branch 'develop' into secret-masking-fix
prakash100198 Dec 9, 2024
8ef9681
comment
prakash100198 Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/devtron-labs/devtron/api/restHandler"
"github.com/devtron-labs/devtron/api/restHandler/app/appInfo"
appList2 "github.com/devtron-labs/devtron/api/restHandler/app/appList"
configDiff2 "github.com/devtron-labs/devtron/api/restHandler/app/configDiff"
pipeline3 "github.com/devtron-labs/devtron/api/restHandler/app/pipeline"
pipeline2 "github.com/devtron-labs/devtron/api/restHandler/app/pipeline/configure"
"github.com/devtron-labs/devtron/api/restHandler/app/pipeline/history"
Expand All @@ -61,6 +62,7 @@ import (
app3 "github.com/devtron-labs/devtron/api/router/app"
appInfo2 "github.com/devtron-labs/devtron/api/router/app/appInfo"
"github.com/devtron-labs/devtron/api/router/app/appList"
configDiff3 "github.com/devtron-labs/devtron/api/router/app/configDiff"
pipeline5 "github.com/devtron-labs/devtron/api/router/app/pipeline"
pipeline4 "github.com/devtron-labs/devtron/api/router/app/pipeline/configure"
history2 "github.com/devtron-labs/devtron/api/router/app/pipeline/history"
Expand Down Expand Up @@ -702,10 +704,10 @@ func InitializeApp() (*App, error) {
scopedVariable.NewScopedVariableRestHandlerImpl,
wire.Bind(new(scopedVariable.ScopedVariableRestHandler), new(*scopedVariable.ScopedVariableRestHandlerImpl)),

router.NewDeploymentConfigurationRouter,
wire.Bind(new(router.DeploymentConfigurationRouter), new(*router.DeploymentConfigurationRouterImpl)),
restHandler.NewDeploymentConfigurationRestHandlerImpl,
wire.Bind(new(restHandler.DeploymentConfigurationRestHandler), new(*restHandler.DeploymentConfigurationRestHandlerImpl)),
configDiff3.NewDeploymentConfigurationRouter,
wire.Bind(new(configDiff3.DeploymentConfigurationRouter), new(*configDiff3.DeploymentConfigurationRouterImpl)),
configDiff2.NewDeploymentConfigurationRestHandlerImpl,
wire.Bind(new(configDiff2.DeploymentConfigurationRestHandler), new(*configDiff2.DeploymentConfigurationRestHandlerImpl)),
configDiff.NewDeploymentConfigurationServiceImpl,
wire.Bind(new(configDiff.DeploymentConfigurationService), new(*configDiff.DeploymentConfigurationServiceImpl)),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package restHandler
package configDiff

import (
"context"
"encoding/json"
"fmt"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/devtron-labs/devtron/pkg/configDiff/bean"
util2 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/gorilla/mux"
"github.com/gorilla/schema"
"go.uber.org/zap"
"gopkg.in/go-playground/validator.v9"
Expand All @@ -20,6 +22,7 @@ import (
type DeploymentConfigurationRestHandler interface {
ConfigAutoComplete(w http.ResponseWriter, r *http.Request)
GetConfigData(w http.ResponseWriter, r *http.Request)
CompareCategoryWiseConfigData(w http.ResponseWriter, r *http.Request)
}
type DeploymentConfigurationRestHandlerImpl struct {
logger *zap.SugaredLogger
Expand Down Expand Up @@ -143,3 +146,69 @@ func getConfigDataQueryParams(r *http.Request) (*bean.ConfigDataQueryParams, err

return &queryParams, nil
}

func (handler *DeploymentConfigurationRestHandlerImpl) CompareCategoryWiseConfigData(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
vars := mux.Vars(r)
configCategory := vars["resource"]

v := r.URL.Query()
comparisonReqString := v.Get("compareConfig")
var comparisonRequestDto bean.ComparisonRequestDto
err = json.Unmarshal([]byte(comparisonReqString), &comparisonRequestDto)
if err != nil {
handler.logger.Errorw("error in unmarshalling stringified json query param", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
err = validateComparisonRequest(configCategory, comparisonRequestDto)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

comparisonRequestDto.UpdateUserIdInComparisonItems(userId)
appName := comparisonRequestDto.GetAppName()

//RBAC START
token := r.Header.Get(common.TokenHeaderKey)
object := handler.enforcerUtil.GetAppRBACName(appName)

ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, object, casbin.ActionGet)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
//RBAC END
//isSuperAdmin is required to make decision if a sensitive data(as defined by super admin) needs to be redacted
//or not while resolving scope variable.
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*")
//userHasAdminAccess is required to mask secrets in the response after scope resolution.
userHasAdminAccess := handler.checkIfUserHasAdminAccessForLeastPrivilegeEnv(token, comparisonRequestDto)

ctx := util2.SetSuperAdminInContext(r.Context(), isSuperAdmin)
res, err := handler.deploymentConfigurationService.CompareCategoryWiseConfigData(ctx, comparisonRequestDto, userHasAdminAccess)
if err != nil {
handler.logger.Errorw("service err, CompareCategoryWiseConfigData ", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

common.WriteJsonResp(w, nil, res, http.StatusOK)
}

// checkIfUserHasAdminAccessForLeastPrivilegeEnv computes if a user has admin access or not for all env,
// if a user is non admin for at least one env then return false.
func (handler *DeploymentConfigurationRestHandlerImpl) checkIfUserHasAdminAccessForLeastPrivilegeEnv(token string, comparisonRequestDto bean.ComparisonRequestDto) bool {
for _, item := range comparisonRequestDto.ComparisonItems {
userHadAdminAccess := handler.enforcer.Enforce(token, casbin.ResourceEnvironment, casbin.ActionGet, item.EnvName)
if !userHadAdminAccess {
return false
}
}
return true
}
26 changes: 26 additions & 0 deletions api/restHandler/app/configDiff/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package configDiff

import (
"errors"
"github.com/devtron-labs/devtron/pkg/configDiff/bean"
)

var validConfigCategories = map[string]bool{bean.Secret.ToString(): true, bean.ConfigMap.ToString(): true, bean.DeploymentTemplate.ToString(): true, bean.PipelineStrategy.ToString(): true}
var ErrInvalidConfigCategory = errors.New("invalid config category provided")
var ErrInvalidComparisonItems = errors.New("invalid comparison items, only 2 items are supported for comparison")
var ErrInvalidIndexValInComparisonItems = errors.New("invalid index values in comparison items")

func validateComparisonRequest(configCategory string, comparisonRequestDto bean.ComparisonRequestDto) error {
if ok := validConfigCategories[configCategory]; !ok {
return ErrInvalidConfigCategory
}
// comparison items expects exactly two items
if len(comparisonRequestDto.ComparisonItems) != 2 {
return ErrInvalidComparisonItems
}
// if index value is other than 0 or 1 then throw invalid index error
if len(comparisonRequestDto.ComparisonItems) > 1 && (comparisonRequestDto.ComparisonItems[0].Index != 0 && comparisonRequestDto.ComparisonItems[1].Index != 1) {
return ErrInvalidIndexValInComparisonItems
}
return nil
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
package router
package configDiff

import (
"github.com/devtron-labs/devtron/api/restHandler"
"github.com/devtron-labs/devtron/api/restHandler/app/configDiff"
"github.com/gorilla/mux"
)

type DeploymentConfigurationRouter interface {
initDeploymentConfigurationRouter(configRouter *mux.Router)
InitDeploymentConfigurationRouter(configRouter *mux.Router)
}

type DeploymentConfigurationRouterImpl struct {
deploymentGroupRestHandler restHandler.DeploymentConfigurationRestHandler
deploymentGroupRestHandler configDiff.DeploymentConfigurationRestHandler
}

func NewDeploymentConfigurationRouter(deploymentGroupRestHandler restHandler.DeploymentConfigurationRestHandler) *DeploymentConfigurationRouterImpl {
func NewDeploymentConfigurationRouter(deploymentGroupRestHandler configDiff.DeploymentConfigurationRestHandler) *DeploymentConfigurationRouterImpl {
router := &DeploymentConfigurationRouterImpl{
deploymentGroupRestHandler: deploymentGroupRestHandler,
}
return router
}

func (router DeploymentConfigurationRouterImpl) initDeploymentConfigurationRouter(configRouter *mux.Router) {
func (router DeploymentConfigurationRouterImpl) InitDeploymentConfigurationRouter(configRouter *mux.Router) {
configRouter.Path("/autocomplete").
HandlerFunc(router.deploymentGroupRestHandler.ConfigAutoComplete).
Methods("GET")
configRouter.Path("/data").
HandlerFunc(router.deploymentGroupRestHandler.GetConfigData).
Methods("GET")
configRouter.Path("/compare/{resource}").
HandlerFunc(router.deploymentGroupRestHandler.CompareCategoryWiseConfigData).
Methods("GET")

}
9 changes: 5 additions & 4 deletions api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/devtron-labs/devtron/api/module"
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/api/router/app"
"github.com/devtron-labs/devtron/api/router/app/configDiff"
"github.com/devtron-labs/devtron/api/server"
"github.com/devtron-labs/devtron/api/team"
terminal2 "github.com/devtron-labs/devtron/api/terminal"
Expand Down Expand Up @@ -114,7 +115,7 @@ type MuxRouter struct {
rbacRoleRouter user.RbacRoleRouter
scopedVariableRouter ScopedVariableRouter
ciTriggerCron cron.CiTriggerCron
deploymentConfigurationRouter DeploymentConfigurationRouter
deploymentConfigurationRouter configDiff.DeploymentConfigurationRouter
infraConfigRouter infraConfig.InfraConfigRouter
argoApplicationRouter argoApplication.ArgoApplicationRouter
fluxApplicationRouter fluxApplication2.FluxApplicationRouter
Expand Down Expand Up @@ -147,12 +148,12 @@ func NewMuxRouter(logger *zap.SugaredLogger,
scopedVariableRouter ScopedVariableRouter,
ciTriggerCron cron.CiTriggerCron,
proxyRouter proxy.ProxyRouter,
deploymentConfigurationRouter DeploymentConfigurationRouter,
deploymentConfigurationRouter configDiff.DeploymentConfigurationRouter,
infraConfigRouter infraConfig.InfraConfigRouter,
argoApplicationRouter argoApplication.ArgoApplicationRouter,
devtronResourceRouter devtronResource.DevtronResourceRouter,
fluxApplicationRouter fluxApplication2.FluxApplicationRouter,
) *MuxRouter {
) *MuxRouter {
r := &MuxRouter{
Router: mux.NewRouter(),
EnvironmentClusterMappingsRouter: EnvironmentClusterMappingsRouter,
Expand Down Expand Up @@ -298,7 +299,7 @@ func (r MuxRouter) Init() {

configRouter := r.Router.PathPrefix("/orchestrator/config").Subrouter()
r.ConfigMapRouter.initConfigMapRouter(configRouter)
r.deploymentConfigurationRouter.initDeploymentConfigurationRouter(configRouter)
r.deploymentConfigurationRouter.InitDeploymentConfigurationRouter(configRouter)

appStoreRouter := r.Router.PathPrefix("/orchestrator/app-store").Subrouter()
r.AppStoreRouter.Init(appStoreRouter)
Expand Down
17 changes: 17 additions & 0 deletions internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type CdWorkflowRepository interface {

MigrateIsArtifactUploaded(wfrId int, isArtifactUploaded bool)
MigrateCdArtifactLocation(wfrId int, cdArtifactLocation string)
FindDeployedCdWorkflowRunnersByPipelineId(pipelineId int) ([]*CdWorkflowRunner, error)
}

type CdWorkflowRepositoryImpl struct {
Expand Down Expand Up @@ -761,3 +762,19 @@ func (impl *CdWorkflowRepositoryImpl) MigrateCdArtifactLocation(wfrId int, cdArt
impl.logger.Errorw("error in updating cd artifact location", "wfrId", wfrId, "err", err)
}
}

func (impl *CdWorkflowRepositoryImpl) FindDeployedCdWorkflowRunnersByPipelineId(pipelineId int) ([]*CdWorkflowRunner, error) {
var runners []*CdWorkflowRunner
err := impl.dbConnection.
Model(&runners).
Column("cd_workflow_runner.*", "CdWorkflow").
Where("cd_workflow.pipeline_id = ?", pipelineId).
Where("workflow_type = ? ", apiBean.CD_WORKFLOW_TYPE_DEPLOY).
Order("cd_workflow_runner.id").
Select()
if err != nil {
impl.logger.Errorw("error in finding previous co workflow runners by pipeline id ", "pipelineId", pipelineId, "err", err)
return nil, err
}
return runners, nil
}
Loading
Loading