Skip to content

Commit bcd3366

Browse files
authored
Merge branch 'main' into user-flow-security-fix
2 parents ff08608 + 0fc6d64 commit bcd3366

File tree

176 files changed

+16602
-6547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+16602
-6547
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ RUN apt clean autoclean
1717
RUN apt autoremove -y && rm -rf /var/lib/apt/lists/*
1818
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/devtron .
1919
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/auth_model.conf .
20-
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets/ /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets
20+
#COPY --from=build-env /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets/ /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets
21+
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/argocd-assets/ /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets
2122
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/scripts/devtron-reference-helm-charts scripts/devtron-reference-helm-charts
2223
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/scripts/sql scripts/sql
2324
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/scripts/casbin scripts/casbin

DockerfileEA

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ RUN apt autoremove -y && rm -rf /var/lib/apt/lists/*
1717
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/auth_model.conf .
1818
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/cmd/external-app/devtron-ea .
1919

20-
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets/ /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets
20+
#COPY --from=build-env /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets/ /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets
21+
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/argocd-assets/ /go/src/github.com/devtron-labs/devtron/vendor/github.com/argoproj/argo-cd/assets
2122
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/scripts/devtron-reference-helm-charts scripts/devtron-reference-helm-charts
2223
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/scripts/sql scripts/sql
2324
COPY --from=build-env /go/src/github.com/devtron-labs/devtron/scripts/casbin scripts/casbin

api/argoApplication/ArgoApplicationRestHandler.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"errors"
2121
"github.com/devtron-labs/devtron/api/restHandler/common"
2222
"github.com/devtron-labs/devtron/pkg/argoApplication"
23+
"github.com/devtron-labs/devtron/pkg/argoApplication/read"
2324
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
2425
"go.uber.org/zap"
2526
"net/http"
@@ -34,14 +35,16 @@ type ArgoApplicationRestHandler interface {
3435

3536
type ArgoApplicationRestHandlerImpl struct {
3637
argoApplicationService argoApplication.ArgoApplicationService
38+
readService read.ArgoApplicationReadService
3739
logger *zap.SugaredLogger
3840
enforcer casbin.Enforcer
3941
}
4042

4143
func NewArgoApplicationRestHandlerImpl(argoApplicationService argoApplication.ArgoApplicationService,
42-
logger *zap.SugaredLogger, enforcer casbin.Enforcer) *ArgoApplicationRestHandlerImpl {
44+
readService read.ArgoApplicationReadService, logger *zap.SugaredLogger, enforcer casbin.Enforcer) *ArgoApplicationRestHandlerImpl {
4345
return &ArgoApplicationRestHandlerImpl{
4446
argoApplicationService: argoApplicationService,
47+
readService: readService,
4548
logger: logger,
4649
enforcer: enforcer,
4750
}
@@ -101,9 +104,9 @@ func (handler *ArgoApplicationRestHandlerImpl) GetApplicationDetail(w http.Respo
101104
return
102105
}
103106
}
104-
resp, err := handler.argoApplicationService.GetAppDetail(resourceName, namespace, clusterId)
107+
resp, err := handler.readService.GetAppDetail(resourceName, namespace, clusterId)
105108
if err != nil {
106-
handler.logger.Errorw("error in listing all argo applications", "err", err, "resourceName", resourceName, "clusterId", clusterId)
109+
handler.logger.Errorw("error in getting argo application app detail", "err", err, "resourceName", resourceName, "clusterId", clusterId)
107110
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
108111
return
109112
}

api/argoApplication/wire_argoApplication.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ package argoApplication
1818

1919
import (
2020
"github.com/devtron-labs/devtron/pkg/argoApplication"
21+
"github.com/devtron-labs/devtron/pkg/argoApplication/read"
2122
"github.com/google/wire"
2223
)
2324

2425
var ArgoApplicationWireSet = wire.NewSet(
26+
read.NewArgoApplicationReadServiceImpl,
27+
wire.Bind(new(read.ArgoApplicationReadService), new(*read.ArgoApplicationReadServiceImpl)),
28+
2529
argoApplication.NewArgoApplicationServiceImpl,
2630
wire.Bind(new(argoApplication.ArgoApplicationService), new(*argoApplication.ArgoApplicationServiceImpl)),
2731

api/helm-app/HelmAppRestHandler.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import (
2525
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service"
2626
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/EAMode"
2727
"github.com/devtron-labs/devtron/pkg/argoApplication"
28+
"github.com/devtron-labs/devtron/pkg/argoApplication/helper"
2829
clientErrors "github.com/devtron-labs/devtron/pkg/errors"
2930
"github.com/devtron-labs/devtron/pkg/fluxApplication"
3031
bean2 "github.com/devtron-labs/devtron/pkg/k8s/application/bean"
32+
"github.com/devtron-labs/devtron/pkg/pipeline"
3133
"net/http"
3234
"strconv"
3335
"strings"
@@ -144,6 +146,11 @@ func (handler *HelmAppRestHandlerImpl) GetApplicationDetail(w http.ResponseWrite
144146
//RBAC enforcer Ends
145147
appdetail, err := handler.helmAppService.GetApplicationDetail(context.Background(), appIdentifier)
146148
if err != nil {
149+
150+
if pipeline.CheckAppReleaseNotExist(err) {
151+
common.WriteJsonResp(w, err, nil, http.StatusNotFound)
152+
return
153+
}
147154
apiError := clientErrors.ConvertToApiError(err)
148155
if apiError != nil {
149156
err = apiError
@@ -226,7 +233,7 @@ func (handler *HelmAppRestHandlerImpl) handleFluxApplicationHibernate(r *http.Re
226233
return handler.fluxApplication.HibernateFluxApplication(r.Context(), appIdentifier, hibernateRequest)
227234
}
228235
func (handler *HelmAppRestHandlerImpl) handleArgoApplicationHibernate(r *http.Request, token string, hibernateRequest *openapi.HibernateRequest) ([]*openapi.HibernateStatus, error) {
229-
appIdentifier, err := argoApplication.DecodeExternalArgoAppId(*hibernateRequest.AppId)
236+
appIdentifier, err := helper.DecodeExternalArgoAppId(*hibernateRequest.AppId)
230237
if err != nil {
231238
return nil, err
232239
}
@@ -310,7 +317,7 @@ func (handler *HelmAppRestHandlerImpl) handleFluxApplicationUnHibernate(r *http.
310317
return handler.fluxApplication.UnHibernateFluxApplication(r.Context(), appIdentifier, hibernateRequest)
311318
}
312319
func (handler *HelmAppRestHandlerImpl) handleArgoApplicationUnHibernate(r *http.Request, token string, hibernateRequest *openapi.HibernateRequest) ([]*openapi.HibernateStatus, error) {
313-
appIdentifier, err := argoApplication.DecodeExternalArgoAppId(*hibernateRequest.AppId)
320+
appIdentifier, err := helper.DecodeExternalArgoAppId(*hibernateRequest.AppId)
314321
if err != nil {
315322
return nil, err
316323
}

api/helm-app/service/HelmAppService.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type HelmAppService interface {
8686
UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *helmBean.AppIdentifier, chartRepository *gRPC.ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error)
8787
TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error)
8888
GetNotes(ctx context.Context, request *gRPC.InstallReleaseRequest) (string, error)
89-
ValidateOCIRegistry(ctx context.Context, OCIRegistryRequest *gRPC.RegistryCredential) bool
89+
ValidateOCIRegistry(ctx context.Context, OCIRegistryRequest *gRPC.RegistryCredential) (bool, error)
9090
GetRevisionHistoryMaxValue(appType bean.SourceAppType) int32
9191
GetResourceTreeForExternalResources(ctx context.Context, clusterId int, clusterConfig *gRPC.ClusterConfig, resources []*gRPC.ExternalResourceDetail) (*gRPC.ResourceTreeResponse, error)
9292
CheckIfNsExistsForClusterIds(clusterIdToNsMap map[int]string) error
@@ -1022,13 +1022,13 @@ func (impl *HelmAppServiceImpl) GetNotes(ctx context.Context, request *gRPC.Inst
10221022
return notesTxt, err
10231023
}
10241024

1025-
func (impl *HelmAppServiceImpl) ValidateOCIRegistry(ctx context.Context, OCIRegistryRequest *gRPC.RegistryCredential) bool {
1025+
func (impl *HelmAppServiceImpl) ValidateOCIRegistry(ctx context.Context, OCIRegistryRequest *gRPC.RegistryCredential) (bool, error) {
10261026
response, err := impl.helmAppClient.ValidateOCIRegistry(ctx, OCIRegistryRequest)
10271027
if err != nil {
10281028
impl.logger.Errorw("error in fetching chart", "err", err)
1029-
return false
1029+
return false, err
10301030
}
1031-
return response.IsLoggedIn
1031+
return response.IsLoggedIn, nil
10321032
}
10331033

10341034
func (impl *HelmAppServiceImpl) DecodeAppId(appId string) (*helmBean.AppIdentifier, error) {

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import (
3333
client "github.com/devtron-labs/devtron/api/helm-app/service"
3434
"github.com/devtron-labs/devtron/api/restHandler/common"
3535
util2 "github.com/devtron-labs/devtron/internal/util"
36-
"github.com/devtron-labs/devtron/pkg/argoApplication"
36+
"github.com/devtron-labs/devtron/pkg/argoApplication/helper"
37+
"github.com/devtron-labs/devtron/pkg/argoApplication/read"
3738
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
3839
"github.com/devtron-labs/devtron/pkg/auth/user"
3940
"github.com/devtron-labs/devtron/pkg/cluster"
@@ -81,39 +82,39 @@ type K8sApplicationRestHandler interface {
8182
}
8283

8384
type K8sApplicationRestHandlerImpl struct {
84-
logger *zap.SugaredLogger
85-
k8sApplicationService application2.K8sApplicationService
86-
pump connector.Pump
87-
terminalSessionHandler terminal.TerminalSessionHandler
88-
enforcer casbin.Enforcer
89-
validator *validator.Validate
90-
enforcerUtil rbac.EnforcerUtil
91-
enforcerUtilHelm rbac.EnforcerUtilHelm
92-
helmAppService client.HelmAppService
93-
userService user.UserService
94-
k8sCommonService k8s.K8sCommonService
95-
terminalEnvVariables *util.TerminalEnvVariables
96-
fluxAppService fluxApplication.FluxApplicationService
97-
argoApplication argoApplication.ArgoApplicationService
85+
logger *zap.SugaredLogger
86+
k8sApplicationService application2.K8sApplicationService
87+
pump connector.Pump
88+
terminalSessionHandler terminal.TerminalSessionHandler
89+
enforcer casbin.Enforcer
90+
validator *validator.Validate
91+
enforcerUtil rbac.EnforcerUtil
92+
enforcerUtilHelm rbac.EnforcerUtilHelm
93+
helmAppService client.HelmAppService
94+
userService user.UserService
95+
k8sCommonService k8s.K8sCommonService
96+
terminalEnvVariables *util.TerminalEnvVariables
97+
fluxAppService fluxApplication.FluxApplicationService
98+
argoApplicationReadService read.ArgoApplicationReadService
9899
}
99100

100-
func NewK8sApplicationRestHandlerImpl(logger *zap.SugaredLogger, k8sApplicationService application2.K8sApplicationService, pump connector.Pump, terminalSessionHandler terminal.TerminalSessionHandler, enforcer casbin.Enforcer, enforcerUtilHelm rbac.EnforcerUtilHelm, enforcerUtil rbac.EnforcerUtil, helmAppService client.HelmAppService, userService user.UserService, k8sCommonService k8s.K8sCommonService, validator *validator.Validate, envVariables *util.EnvironmentVariables, fluxAppService fluxApplication.FluxApplicationService, argoApplication argoApplication.ArgoApplicationService,
101+
func NewK8sApplicationRestHandlerImpl(logger *zap.SugaredLogger, k8sApplicationService application2.K8sApplicationService, pump connector.Pump, terminalSessionHandler terminal.TerminalSessionHandler, enforcer casbin.Enforcer, enforcerUtilHelm rbac.EnforcerUtilHelm, enforcerUtil rbac.EnforcerUtil, helmAppService client.HelmAppService, userService user.UserService, k8sCommonService k8s.K8sCommonService, validator *validator.Validate, envVariables *util.EnvironmentVariables, fluxAppService fluxApplication.FluxApplicationService, argoApplicationReadService read.ArgoApplicationReadService,
101102
) *K8sApplicationRestHandlerImpl {
102103
return &K8sApplicationRestHandlerImpl{
103-
logger: logger,
104-
k8sApplicationService: k8sApplicationService,
105-
pump: pump,
106-
terminalSessionHandler: terminalSessionHandler,
107-
enforcer: enforcer,
108-
validator: validator,
109-
enforcerUtilHelm: enforcerUtilHelm,
110-
enforcerUtil: enforcerUtil,
111-
helmAppService: helmAppService,
112-
userService: userService,
113-
k8sCommonService: k8sCommonService,
114-
terminalEnvVariables: envVariables.TerminalEnvVariables,
115-
fluxAppService: fluxAppService,
116-
argoApplication: argoApplication,
104+
logger: logger,
105+
k8sApplicationService: k8sApplicationService,
106+
pump: pump,
107+
terminalSessionHandler: terminalSessionHandler,
108+
enforcer: enforcer,
109+
validator: validator,
110+
enforcerUtilHelm: enforcerUtilHelm,
111+
enforcerUtil: enforcerUtil,
112+
helmAppService: helmAppService,
113+
userService: userService,
114+
k8sCommonService: k8sCommonService,
115+
terminalEnvVariables: envVariables.TerminalEnvVariables,
116+
fluxAppService: fluxAppService,
117+
argoApplicationReadService: argoApplicationReadService,
117118
}
118119
}
119120

@@ -289,7 +290,7 @@ func (handler *K8sApplicationRestHandlerImpl) GetHostUrlsByBatch(w http.Response
289290
resourceTreeResponse = appDetail.ResourceTreeResponse
290291

291292
} else if appType == bean2.ArgoAppType {
292-
appIdentifier, err := argoApplication.DecodeExternalArgoAppId(appIdString)
293+
appIdentifier, err := helper.DecodeExternalArgoAppId(appIdString)
293294
if err != nil {
294295
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
295296
return
@@ -301,7 +302,7 @@ func (handler *K8sApplicationRestHandlerImpl) GetHostUrlsByBatch(w http.Response
301302
}
302303
//RBAC enforcer Ends
303304

304-
appDetail, err := handler.argoApplication.GetAppDetail(appIdentifier.AppName, appIdentifier.Namespace, appIdentifier.ClusterId)
305+
appDetail, err := handler.argoApplicationReadService.GetAppDetail(appIdentifier.AppName, appIdentifier.Namespace, appIdentifier.ClusterId)
305306
if err != nil {
306307
apiError := clientErrors.ConvertToApiError(err)
307308
if apiError != nil {
@@ -721,12 +722,12 @@ func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.Re
721722
}
722723
//RBAC enforcer ends here
723724
} else if request.AppType == bean2.ArgoAppType && request.ExternalArgoApplicationName != "" {
724-
appIdentifier, err := argoApplication.DecodeExternalArgoAppId(request.AppId)
725+
appIdentifier, err := helper.DecodeExternalArgoAppId(request.AppId)
725726
if err != nil {
726727
handler.logger.Errorw(bean2.AppIdDecodingError, "err", err, "appIdentifier", request.AppIdentifier)
727728
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
728729
}
729-
valid, err := handler.k8sApplicationService.ValidateArgoResourceRequest(r.Context(), appIdentifier, request.K8sRequest)
730+
valid, err := handler.argoApplicationReadService.ValidateArgoResourceRequest(r.Context(), appIdentifier, request.K8sRequest)
730731
if err != nil || !valid {
731732
handler.logger.Errorw("error in validating resource request", "err", err)
732733
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
@@ -1145,14 +1146,14 @@ func (handler *K8sApplicationRestHandlerImpl) verifyRbacForAppRequests(token str
11451146
envObject := ""
11461147
switch request.AppType {
11471148
case bean2.ArgoAppType:
1148-
argoAppIdentifier, err := argoApplication.DecodeExternalArgoAppId(request.AppId)
1149+
argoAppIdentifier, err := helper.DecodeExternalArgoAppId(request.AppId)
11491150
if err != nil {
11501151
handler.logger.Errorw("error in decoding appId", "err", err, "appId", request.AppId)
11511152
return false, err
11521153
}
11531154
request.ClusterId = argoAppIdentifier.ClusterId
11541155
request.ExternalArgoApplicationName = argoAppIdentifier.AppName
1155-
valid, err := handler.k8sApplicationService.ValidateArgoResourceRequest(r.Context(), argoAppIdentifier, request.K8sRequest)
1156+
valid, err := handler.argoApplicationReadService.ValidateArgoResourceRequest(r.Context(), argoAppIdentifier, request.K8sRequest)
11561157
if err != nil || !valid {
11571158
handler.logger.Errorw("error in validating resource request", "err", err)
11581159
return false, err

api/restHandler/DockerRegRestHandler.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/devtron-labs/devtron/api/restHandler/common"
2626
repository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
27-
"github.com/devtron-labs/devtron/internal/util"
2827
chartProviderService "github.com/devtron-labs/devtron/pkg/appStore/chartProvider"
2928
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
3029
"github.com/devtron-labs/devtron/pkg/auth/user"
@@ -233,13 +232,8 @@ func (impl DockerRegRestHandlerImpl) SaveDockerRegistryConfig(w http.ResponseWri
233232
//RBAC enforcer Ends
234233

235234
// valid registry credentials from kubelink
236-
if isValid := impl.dockerRegistryConfig.ValidateRegistryCredentials(&bean); !isValid {
237-
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err, "payload", bean)
238-
err = &util.ApiError{
239-
HttpStatusCode: http.StatusBadRequest,
240-
InternalMessage: "Invalid authentication credentials. Please verify.",
241-
UserMessage: "Invalid authentication credentials. Please verify.",
242-
}
235+
if err = impl.dockerRegistryConfig.ValidateRegistryCredentials(&bean); err != nil {
236+
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err)
243237
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
244238
return
245239
}
@@ -349,13 +343,8 @@ func (impl DockerRegRestHandlerImpl) ValidateDockerRegistryConfig(w http.Respons
349343
bean.Cert = existingStore.Cert
350344
}
351345
// valid registry credentials from kubelink
352-
if isValid := impl.dockerRegistryConfig.ValidateRegistryCredentials(&bean); !isValid {
353-
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err, "payload", bean)
354-
err = &util.ApiError{
355-
HttpStatusCode: http.StatusBadRequest,
356-
InternalMessage: "Invalid authentication credentials. Please verify.",
357-
UserMessage: "Invalid authentication credentials. Please verify.",
358-
}
346+
if err = impl.dockerRegistryConfig.ValidateRegistryCredentials(&bean); err != nil {
347+
impl.logger.Errorw("registry credentials validation err, SaveDockerRegistryConfig", "err", err)
359348
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
360349
return
361350
}

0 commit comments

Comments
 (0)