Skip to content

Commit ef11462

Browse files
mayank-devtronvikramdevtronprkhrkatSATYAsasinisystemsdt
authored
feat: app filters enhancement (#6939)
* vendor files * feat: auto assign permission group (#6923) * feat: auto-assign role groups * fix: sync claims with casbin policy * feat: file re-structuring for ent oss sync * feat: global auth apis * sync file name with oss * fix: global auth apis wire register for ea mode (#6929) * fix: global auth apis wire register for ea mode * fix: linting * release: PR for v2.1.0 (#6928) * Updated release-notes files * Updated release notes * Updated release notes * Updated release notes * Updated release notes * Updated release notes * Updated release notes * Updated release notes * Updated release notes * Updated devtron to 59238e8-434-38692 tag in values file * Updated kubelink to 6b408df4-564-38694 tag in values file * Updated dashboard to d87d9a07-690-38693 tag in values file * Updated release notes * Updated release notes * Updated release notes * Updated release notes * Updated kubewatch to fbde4d5e-419-38744 tag in values file * Updated hyperion to 37b07f1-280-38743 tag in values file * Updated devtron to 37b07f1-434-38746 tag in values file * Updated kubelink to fbde4d5e-564-38749 tag in values file * Updated git-sensor to fbde4d5e-200-38750 tag in values file * Updated lens to fbde4d5e-333-38752 tag in values file * Updated dashboard to d4a16ea7-690-38751 tag in values file * Updated ci-runner to fbde4d5e-138-38754 tag in values file * Updated image-scanner to fbde4d5e-141-38756 tag in values file * Updated notifier to 580d409b-372-38755 tag in values file * Updated chart-sync to fbde4d5e-836-38757 tag in values file * Updated the version in scripts * Update TimescaleDB password secret reference * Bump version from 0.22.99 to 0.23.1 * Add CLUSTER_OVERVIEW_MAX_STALE_DATA_SECONDS variable * Update releasenotes.md * Update release-notes-v2.1.0.md * Updated devtron to 634eb59-434-38762 tag in values file * Updated hyperion to 634eb59-280-38763 tag in values file --------- Co-authored-by: akshatsinha007 <156403098+akshatsinha007@users.noreply.github.com> * add support of container name in cronjob * fix: clusterId check for modifying triggers for cluster level notification (#6932) * fix: auto assign permission group related fixes (#6934) * fix: sync auto-assigned groups with casbin_rule user→group policies * fix: support token for rbac check for clusters * fix: support token for checkUser roles * fix: support token based authentication for policy rest handlers * fix: check for user isGroupClaims active in all rbac related functions * fix: add email in case of devtron system managed * fix: ea mode dependency updates * feat: update app listing tag filter payload and operators (cherry picked from commit a2866a1b5f54f7a5e6f94d73c6e3011ffabd789d) * feat: refine tag negative operators behavior (cherry picked from commit 5a5d201c1072b3e147287967ff99666d3fd35122) * jsontag (cherry picked from commit 81341fccad519cabd5b94c9b26e4f19b8a832c2c) * migration renaming (cherry picked from commit c2e625e2ea0aa1feb3d655dd8f28fbf28c96c43a) * refactor app list tag-filter validation (cherry picked from commit 60ef7488f49db9b56e2f55323066cc8ea8ba2c55) * feat: add tag filter support in app listing (cherry picked from commit 57e4fd6b65185e2f3f6add7d7010f4c1ebdcf1fc) * chore: add logs for app listing query builder errors (cherry picked from commit 4e682d12255bc748eb18325cbeda662771cdf60b) * fix: correct app label filter migration sequence * rename migration no * release: PR for v2.1.1 (#6940) * Updated release-notes files * Updated release notes * Updated release notes * Updated devtron to 1188d0b-434-38818 tag in values file * Updated hyperion to 1188d0b-280-38819 tag in values file * Updated release notes * Updated dashboard to 8a175cbd-690-38843 tag in values file * Updated the version in scripts * Update release notes for version 2.1.1 * Update release notes for version 2.1.1 Removed the Enhancements and Others sections from the release notes. --------- Co-authored-by: akshatsinha007 <156403098+akshatsinha007@users.noreply.github.com> * sync: migration seq (#6942) * sync: migration files * sync: migration files * renamed migration no --------- Co-authored-by: Vikram <73224103+vikramdevtron@users.noreply.github.com> Co-authored-by: prakhar katiyar <prkhrkat@gmail.com> Co-authored-by: prakhar katiyar <39842461+prkhrkat@users.noreply.github.com> Co-authored-by: satya_prakash <155617493+SATYAsasini@users.noreply.github.com> Co-authored-by: systemsdt <129372406+systemsdt@users.noreply.github.com> Co-authored-by: akshatsinha007 <156403098+akshatsinha007@users.noreply.github.com> Co-authored-by: Neha Sharma <nehasharma@Nehas-MacBook-Pro.local> Co-authored-by: AJAY KUMAR <99399155+ajaydevtron@users.noreply.github.com>
1 parent 0a1ee95 commit ef11462

67 files changed

Lines changed: 2198 additions & 528 deletions

File tree

Some content is hidden

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

CHANGELOG/release-notes-v2.1.0.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## v2.1.0
2+
3+
## Enhancements
4+
- feat: auto assign permission group ( https://github.com/devtron-labs/devtron/issues/6911 )
5+
## Bugs
6+
- fix: prevent exposure of internal-only attributes in API responses and requests (#6917)
7+
- fix: append filtered cluster details to the cluster detail list in capacity handler (#6915)
8+
- fix: enhance cluster overview response with raw cluster capacity details and caching support (#6914)
9+
- fix: Handle cluster capacity fetch errors by returning detailed connection failure status (#6912)
10+
## Others
11+
- sync: main (#6920)
12+
- chore: Adds scarf pixel (#6918)
13+
- misc: add clientIP in audit log (#6908)
14+
- misc: Refactor vulnerability query implementation and cleanup unused code (#6907)

CHANGELOG/release-notes-v2.1.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## v2.1.1
2+
3+
## Bugs
4+
- fix: auto assign permission group related fixes (#6934)
5+
- fix: clusterId check for modifying triggers for cluster level notific… (#6932)

Wire.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
appStoreDiscover "github.com/devtron-labs/devtron/api/appStore/discover"
3434
appStoreValues "github.com/devtron-labs/devtron/api/appStore/values"
3535
"github.com/devtron-labs/devtron/api/argoApplication"
36+
"github.com/devtron-labs/devtron/api/auth/authorisation/globalConfig"
3637
"github.com/devtron-labs/devtron/api/auth/sso"
3738
"github.com/devtron-labs/devtron/api/auth/user"
3839
chartRepo "github.com/devtron-labs/devtron/api/chartRepo"
@@ -192,6 +193,7 @@ func InitializeApp() (*App, error) {
192193
externalLink.ExternalLinkWireSet,
193194
team.TeamsWireSet,
194195
AuthWireSet,
196+
globalConfig.GlobalConfigWireSet,
195197
util4.GetRuntimeConfig,
196198
util4.NewK8sUtil,
197199
wire.Bind(new(util4.K8sService), new(*util4.K8sServiceImpl)),
@@ -993,7 +995,7 @@ func InitializeApp() (*App, error) {
993995

994996
router.NewOverviewRouterImpl,
995997
wire.Bind(new(router.OverviewRouter), new(*router.OverviewRouterImpl)),
996-
998+
997999
restHandler.NewInfraOverviewRestHandlerImpl,
9981000
wire.Bind(new(restHandler.InfraOverviewRestHandler), new(*restHandler.InfraOverviewRestHandlerImpl)),
9991001

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package globalConfig
18+
19+
import "github.com/gorilla/mux"
20+
21+
type AuthorisationConfigRouter interface {
22+
InitAuthorisationConfigRouter(router *mux.Router)
23+
}
24+
25+
type AuthorisationConfigRouterImpl struct {
26+
handler AuthorisationConfigRestHandler
27+
}
28+
29+
func NewGlobalConfigAuthorisationRouterImpl(handler AuthorisationConfigRestHandler) *AuthorisationConfigRouterImpl {
30+
return &AuthorisationConfigRouterImpl{handler: handler}
31+
}
32+
33+
func (router *AuthorisationConfigRouterImpl) InitAuthorisationConfigRouter(authorisationConfigRouter *mux.Router) {
34+
authorisationConfigRouter.Path("/global-config").
35+
HandlerFunc(router.handler.CreateOrUpdateAuthorisationConfig).Methods("POST")
36+
authorisationConfigRouter.Path("/global-config").
37+
HandlerFunc(router.handler.GetAllActiveAuthorisationConfig).Methods("GET")
38+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright (c) 2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package globalConfig
18+
19+
import (
20+
"encoding/json"
21+
"errors"
22+
"net/http"
23+
24+
"github.com/devtron-labs/devtron/api/restHandler/common"
25+
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
26+
auth "github.com/devtron-labs/devtron/pkg/auth/authorisation/globalConfig"
27+
"github.com/devtron-labs/devtron/pkg/auth/authorisation/globalConfig/bean"
28+
"github.com/devtron-labs/devtron/pkg/auth/user"
29+
"github.com/devtron-labs/devtron/util/commonEnforcementFunctionsUtil"
30+
"go.uber.org/zap"
31+
"gopkg.in/go-playground/validator.v9"
32+
)
33+
34+
type AuthorisationConfigRestHandler interface {
35+
CreateOrUpdateAuthorisationConfig(w http.ResponseWriter, r *http.Request)
36+
GetAllActiveAuthorisationConfig(w http.ResponseWriter, r *http.Request)
37+
}
38+
39+
type AuthorisationConfigRestHandlerImpl struct {
40+
validator *validator.Validate
41+
logger *zap.SugaredLogger
42+
enforcer casbin.Enforcer
43+
userService user.UserService
44+
userCommonService user.UserCommonService
45+
globalAuthorisationConfigService auth.GlobalAuthorisationConfigService
46+
rbacEnforcementUtil commonEnforcementFunctionsUtil.CommonEnforcementUtil
47+
}
48+
49+
func NewGlobalAuthorisationConfigRestHandlerImpl(validator *validator.Validate,
50+
logger *zap.SugaredLogger, enforcer casbin.Enforcer,
51+
userService user.UserService,
52+
globalAuthorisationConfigService auth.GlobalAuthorisationConfigService,
53+
userCommonService user.UserCommonService,
54+
rbacEnforcementUtil commonEnforcementFunctionsUtil.CommonEnforcementUtil,
55+
) *AuthorisationConfigRestHandlerImpl {
56+
return &AuthorisationConfigRestHandlerImpl{
57+
validator: validator,
58+
logger: logger,
59+
enforcer: enforcer,
60+
userService: userService,
61+
globalAuthorisationConfigService: globalAuthorisationConfigService,
62+
userCommonService: userCommonService,
63+
rbacEnforcementUtil: rbacEnforcementUtil,
64+
}
65+
}
66+
67+
func (handler *AuthorisationConfigRestHandlerImpl) CreateOrUpdateAuthorisationConfig(w http.ResponseWriter, r *http.Request) {
68+
userId, err := handler.userService.GetLoggedInUser(r)
69+
if userId == 0 || err != nil {
70+
common.HandleUnauthorized(w, r)
71+
return
72+
}
73+
decoder := json.NewDecoder(r.Body)
74+
var globalConfigPayload bean.GlobalAuthorisationConfig
75+
err = decoder.Decode(&globalConfigPayload)
76+
if err != nil {
77+
handler.logger.Errorw("request err, CreateOrUpdateAuthorisationConfig", "err", err, "payload", globalConfigPayload)
78+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
79+
return
80+
}
81+
token := r.Header.Get("token")
82+
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*"); !ok {
83+
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
84+
return
85+
}
86+
isValidationError, err := handler.validateGlobalAuthorisationConfigPayload(globalConfigPayload)
87+
if err != nil {
88+
handler.logger.Errorw("error, validateGlobalAuthorisationConfigPayload", "payload", globalConfigPayload, "err", err)
89+
if isValidationError {
90+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
91+
return
92+
}
93+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
94+
return
95+
}
96+
globalConfigPayload.UserId = userId
97+
resp, err := handler.globalAuthorisationConfigService.CreateOrUpdateGlobalAuthConfig(globalConfigPayload, nil)
98+
if err != nil {
99+
handler.logger.Errorw("service error, CreateOrUpdateAuthorisationConfig", "err", err, "payload", globalConfigPayload)
100+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
101+
return
102+
}
103+
common.WriteJsonResp(w, nil, resp, http.StatusOK)
104+
}
105+
106+
func (handler *AuthorisationConfigRestHandlerImpl) GetAllActiveAuthorisationConfig(w http.ResponseWriter, r *http.Request) {
107+
userId, err := handler.userService.GetLoggedInUser(r)
108+
if userId == 0 || err != nil {
109+
common.HandleUnauthorized(w, r)
110+
return
111+
}
112+
token := r.Header.Get("token")
113+
isAuthorised, err := handler.rbacEnforcementUtil.CheckRbacForMangerAndAboveAccess(token, userId)
114+
if err != nil {
115+
handler.logger.Errorw("error, GetAllActiveAuthorisationConfig", "err", err)
116+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
117+
return
118+
}
119+
if !isAuthorised {
120+
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
121+
return
122+
}
123+
resp, err := handler.globalAuthorisationConfigService.GetAllActiveAuthorisationConfig()
124+
if err != nil {
125+
handler.logger.Errorw("service error, GetAllActiveAuthorisationConfig", "err", err)
126+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
127+
return
128+
}
129+
common.WriteJsonResp(w, nil, resp, http.StatusOK)
130+
}
131+
132+
func (handler *AuthorisationConfigRestHandlerImpl) validateGlobalAuthorisationConfigPayload(globalConfigPayload bean.GlobalAuthorisationConfig) (bool, error) {
133+
err := handler.validator.Struct(globalConfigPayload)
134+
if err != nil {
135+
handler.logger.Errorw("err, validateGlobalAuthorisationConfigPayload", "payload", globalConfigPayload, "err", err)
136+
return true, err
137+
}
138+
if len(globalConfigPayload.ConfigTypes) == 0 {
139+
handler.logger.Errorw("err, validation failed on validateGlobalAuthorisationConfigPayload due to no configType provided", "payload", globalConfigPayload)
140+
return true, errors.New("no configTypes provided in request")
141+
}
142+
return false, nil
143+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package globalConfig
18+
19+
import "github.com/google/wire"
20+
21+
// GlobalConfigWireSet wires the REST handler and router for the authorisation global-config API.
22+
// NOTE: GlobalAuthorisationConfigRepository and GlobalAuthorisationConfigService are already
23+
// provided by UserWireSet (api/auth/user/wire_user.go) and must not be re-declared here.
24+
var GlobalConfigWireSet = wire.NewSet(
25+
NewGlobalAuthorisationConfigRestHandlerImpl,
26+
wire.Bind(new(AuthorisationConfigRestHandler), new(*AuthorisationConfigRestHandlerImpl)),
27+
NewGlobalConfigAuthorisationRouterImpl,
28+
wire.Bind(new(AuthorisationConfigRouter), new(*AuthorisationConfigRouterImpl)),
29+
)

api/auth/user/UserRestHandler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ func (handler UserRestHandlerImpl) CheckUserRoles(w http.ResponseWriter, r *http
749749
common.HandleUnauthorized(w, r)
750750
return
751751
}
752-
roles, err := handler.userService.CheckUserRoles(userId, "")
752+
token := r.Header.Get("token")
753+
roles, err := handler.userService.CheckUserRoles(userId, token)
753754
if err != nil {
754755
handler.logger.Errorw("service err, CheckUserRoles", "err", err, "userId", userId)
755756
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

api/auth/user/wire_selfRegistration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
//depends on sql,
2626
//TODO integrate user auth module
2727

28+
// SelfRegistrationWireSet depends on GlobalAuthorisationConfigService which is provided by UserWireSet
2829
var SelfRegistrationWireSet = wire.NewSet(
2930
repository.NewSelfRegistrationRolesRepositoryImpl,
3031
wire.Bind(new(repository.SelfRegistrationRolesRepository), new(*repository.SelfRegistrationRolesRepositoryImpl)),

api/auth/user/wire_user.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package user
1919
import (
2020
"github.com/devtron-labs/devtron/pkg/auth/authentication"
2121
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
22+
globalConfig "github.com/devtron-labs/devtron/pkg/auth/authorisation/globalConfig"
23+
globalConfigRepo "github.com/devtron-labs/devtron/pkg/auth/authorisation/globalConfig/repository"
2224
user2 "github.com/devtron-labs/devtron/pkg/auth/user"
2325
repository2 "github.com/devtron-labs/devtron/pkg/auth/user/repository"
2426
"github.com/google/wire"
@@ -77,4 +79,13 @@ var UserWireSet = wire.NewSet(
7779
wire.Bind(new(RbacRoleRestHandler), new(*RbacRoleRestHandlerImpl)),
7880
user2.NewRbacRoleServiceImpl,
7981
wire.Bind(new(user2.RbacRoleService), new(*user2.RbacRoleServiceImpl)),
82+
83+
repository2.NewUserAutoAssignGroupMapRepositoryImpl,
84+
wire.Bind(new(repository2.UserAutoAssignGroupMapRepository), new(*repository2.UserAutoAssignGroupMapRepositoryImpl)),
85+
86+
globalConfigRepo.NewGlobalAuthorisationConfigRepositoryImpl,
87+
wire.Bind(new(globalConfigRepo.GlobalAuthorisationConfigRepository), new(*globalConfigRepo.GlobalAuthorisationConfigRepositoryImpl)),
88+
89+
globalConfig.NewGlobalAuthorisationConfigServiceImpl,
90+
wire.Bind(new(globalConfig.GlobalAuthorisationConfigService), new(*globalConfig.GlobalAuthorisationConfigServiceImpl)),
8091
)

api/cluster/ClusterRestHandler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ func (impl ClusterRestHandlerImpl) HandleRbacForClusterNamespace(userId int32, t
686686
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); ok {
687687
return clusterNamespaces, nil
688688
}
689-
roles, err := impl.clusterService.FetchRolesFromGroup(userId)
689+
roles, err := impl.clusterService.FetchRolesFromGroup(userId, token)
690690
if err != nil {
691691
impl.logger.Errorw("error on fetching user roles for cluster list", "err", err)
692692
return nil, err
@@ -740,7 +740,7 @@ func (impl ClusterRestHandlerImpl) GetClusterNamespaces(w http.ResponseWriter, r
740740
return
741741
}
742742

743-
allClusterNamespaces, err := impl.clusterService.FindAllNamespacesByUserIdAndClusterId(userId, clusterId, isActionUserSuperAdmin)
743+
allClusterNamespaces, err := impl.clusterService.FindAllNamespacesByUserIdAndClusterId(userId, clusterId, isActionUserSuperAdmin, token)
744744
if err != nil {
745745
// Check if it's a cluster connectivity error and return appropriate status code
746746
if err.Error() == cluster.ErrClusterNotReachable {
@@ -767,7 +767,7 @@ func (impl ClusterRestHandlerImpl) FindAllForClusterPermission(w http.ResponseWr
767767
if ok := impl.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); ok {
768768
isActionUserSuperAdmin = true
769769
}
770-
clusterList, err := impl.clusterService.FindAllForClusterByUserId(userId, isActionUserSuperAdmin)
770+
clusterList, err := impl.clusterService.FindAllForClusterByUserId(userId, isActionUserSuperAdmin, token)
771771
if err != nil {
772772
impl.logger.Errorw("error in deleting cluster", "err", err)
773773
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

0 commit comments

Comments
 (0)