feat: RBAC support for external argo/flux apps - #7014
feat: RBAC support for external argo/flux apps#7014vivekanandan-devtron wants to merge 19 commits into
Conversation
- add migration files - append flags in the /orchestrator/user/check/roles API to show/hide argo/flux tabs
- earlier filter was only applied with the cluster ID - add changes to filter based on cluster ID's and namespaces
|
Some linked issues are invalid. Please update the issue links:\nIssue # in is not found or invalid (HTTP }404).\n |
|
Bito Automatic Review Skipped - Draft PR |
| continue | ||
| } | ||
|
|
||
| if resourceActionFragment[0] == "argo-app" && (resourceActionFragment[1] == "admin" || resourceActionFragment[1] == "view") { |
There was a problem hiding this comment.
use const, this logic should be abstracted out
There was a problem hiding this comment.
- Abstracted the logic using a map
- Used the existing consts available
| } else if resourceRequestBean.ExternalArgoApplicationName != "" { | ||
| // RBAC enforcer applying For external Argo app | ||
| if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*"); !ok { | ||
| if request.ExternalArgoAppIdentifier == nil { |
There was a problem hiding this comment.
resourceRequestBean susing this right?
There was a problem hiding this comment.
Previously the ExternalArgoAppIdentifier was only available in the request, now the field is populated in the resourceRequestBean and code has been changed to refer resourceRequestBean
| @@ -0,0 +1,2 @@ | |||
| DELETE FROM "public"."rbac_policy_data" WHERE entity='apps' AND access_type IN ('argo-app','flux-app'); | |||
| DELETE FROM "public"."rbac_role_data" WHERE entity='apps' AND access_type IN ('argo-app','flux-app'); | |||
There was a problem hiding this comment.
update migration number with latest
There was a problem hiding this comment.
The previous number in the OSS is 36204600, The current migration number is 36304600. I think this is the latest, can you please confirm this once?
There was a problem hiding this comment.
Changed the migration number to maintain sync with enterprise
| "clusterName", clusterName, "namespace", namespace, "appName", appName) | ||
| return "" | ||
| } | ||
| return fmt.Sprintf("%s__%s/%s", clusterName, namespace, appName) |
There was a problem hiding this comment.
Even for external helm apps, the environment combination is clusterName__namespace. The same has been followed to maintain consistency
| //where the scope is environment(cluster__namespace) + app | ||
| query := "SELECT role.* FROM roles role WHERE coalesce(role.team,'') = ? AND role.entity_name=? AND role.environment=? AND role.action=?" | ||
| queryParams = append(queryParams, EMPTY_PLACEHOLDER_FOR_QUERY, app, env, act) | ||
| if oldValues { |
There was a problem hiding this comment.
old values handling should be removed here as these are new roles
There was a problem hiding this comment.
changed
| var queryParams []interface{} | ||
| //this is applicable for entities that have no project, e.g. external argo/flux apps, | ||
| //where the scope is environment(cluster__namespace) + app | ||
| query := "SELECT role.* FROM roles role WHERE coalesce(role.team,'') = ? AND role.entity_name=? AND role.environment=? AND role.action=?" |
There was a problem hiding this comment.
we should have specific queries for ago and flux entity type , should not be clubbed with other entity, as they are defined and specific
There was a problem hiding this comment.
changed
| func (impl *FluxApplicationServiceImpl) GetFluxApplicationList(ctx context.Context, clusterIds []int) ([]bean.FluxApplication, error) { | ||
| appStream, err := impl.listApplications(ctx, clusterIds) | ||
| if err != nil { |
There was a problem hiding this comment.
- This flux app list is used in both user permission dropdown and also flux app listing, In the former you would need to list all the apps and the later only apps the user has access to.
- The previous method combined too many logics like listing, RBAC, streaming/no-streaming etc. I have split the function into two to be used in two different places
| if _, ok := fluxInstalledApps[key][deployedApp.Name]; ok { | ||
| continue | ||
| } | ||
| if fluxAuth != nil && !fluxAuth(token, deployedApp.EnvironmentDetail.ClusterName, |
There was a problem hiding this comment.
Resp Transformers should be independent of auth check, auth check are different part after transformers
There was a problem hiding this comment.
This same pattern in being for external helm app listing, used the same to maintain consistency
| getUserResourceKindWithEntityAccessKey(bean.ClusterApiResources, bean.Alpha1Version, bean2.CLUSTER_ENTITIY, bean2.EmptyAccessType): (*UserResourceServiceImpl).enforceRbacForClusterApiResource, | ||
| getUserResourceKindWithEntityAccessKey(bean.ClusterNamespaces, bean.Alpha1Version, bean2.CLUSTER_ENTITIY, bean2.EmptyAccessType): (*UserResourceServiceImpl).enforceRbacForClusterNamespaces, | ||
| getUserResourceKindWithEntityAccessKey(bean.ClusterResources, bean.Alpha1Version, bean2.CLUSTER_ENTITIY, bean2.EmptyAccessType): (*UserResourceServiceImpl).enforceRbacForClusterResourceList, | ||
| getUserResourceKindWithEntityAccessKey(bean.KindArgoEnvironment, bean.Alpha1Version, bean2.ENTITY_APPS, bean2.APP_ACCESS_TYPE_ARGO): (*UserResourceServiceImpl).enforceRbacForEnvForHelmApp, |
There was a problem hiding this comment.
helm app enforcement here in case of argo and flux
There was a problem hiding this comment.
The function is same for helm, argo and flux. Renamed the function to avoid confusion
| getUserResourceKindWithEntityAccessKey(bean.KindChartGroup, bean.Alpha1Version, bean2.CHART_GROUP_ENTITY, bean2.EmptyAccessType): (*UserResourceExtendedServiceImpl).enforceRbacForChartGroup, | ||
| getUserResourceKindWithEntityAccessKey(bean.KindJobs, bean.Alpha1Version, bean2.EntityJobs, bean2.EmptyAccessType): (*UserResourceExtendedServiceImpl).enforceRbacForJobs, | ||
| getUserResourceKindWithEntityAccessKey(bean.KindWorkflow, bean.Alpha1Version, bean2.EntityJobs, bean2.EmptyAccessType): (*UserResourceExtendedServiceImpl).enforceRbacForJobsWfs, | ||
| getUserResourceKindWithEntityAccessKey(bean.KindArgoEnvironment, bean.Alpha1Version, bean2.ENTITY_APPS, bean2.APP_ACCESS_TYPE_ARGO): (*UserResourceExtendedServiceImpl).enforceRbacForEnvForHelmApp, |
There was a problem hiding this comment.
The function is same for helm, argo and flux. Renamed the function to avoid confusion
| clusterRepository repository.ClusterRepository) *EnforcerUtilGitOpsImpl { | ||
| return &EnforcerUtilGitOpsImpl{ | ||
| logger: logger, | ||
| clusterRepository: clusterRepository, |
There was a problem hiding this comment.
cluster read service, not repo dep
There was a problem hiding this comment.
Changed to cluster read service
…argo-flux-rbac-7007
|



Description
Fixes #7007
Checklist:
Does this PR introduce a user-facing change?