github.com/argoproj/argo-cd/v3@v3.2.1/docs/operator-manual/rbac.md (about)

     1  # RBAC Configuration
     2  
     3  The RBAC feature enables restrictions of access to Argo CD resources. Argo CD does not have its own
     4  user management system and has only one built-in user, `admin`. The `admin` user is a superuser and
     5  it has unrestricted access to the system. RBAC requires [SSO configuration](user-management/index.md) or [one or more local users setup](user-management/index.md).
     6  Once SSO or local users are configured, additional RBAC roles can be defined, and SSO groups or local users can then be mapped to roles.
     7  
     8  There are two main components where RBAC configuration can be defined:
     9  
    10  - The global RBAC config map (see [argo-rbac-cm.yaml](argocd-rbac-cm-yaml.md))
    11  - The [AppProject's roles](../user-guide/projects.md#project-roles)
    12  
    13  ## Basic Built-in Roles
    14  
    15  Argo CD has two pre-defined roles but RBAC configuration allows defining roles and groups (see below).
    16  
    17  - `role:readonly`: read-only access to all resources
    18  - `role:admin`: unrestricted access to all resources
    19  
    20  These default built-in role definitions can be seen in [builtin-policy.csv](https://github.com/argoproj/argo-cd/blob/master/assets/builtin-policy.csv)
    21  
    22  ## Default Policy for Authenticated Users
    23  
    24  When a user is authenticated in Argo CD, it will be granted the role specified in `policy.default`.
    25  
    26  !!! warning "Restricting Default Permissions"
    27  
    28      **All authenticated users get _at least_ the permissions granted by the default policies. This access cannot be blocked
    29      by a `deny` rule.** It is recommended to create a new `role:authenticated` with the minimum set of permissions possible,
    30      then grant permissions to individual roles as needed.
    31  
    32  ## Anonymous Access
    33  
    34  Enabling anonymous access to the Argo CD instance allows users to assume the default role permissions specified by `policy.default` **without being authenticated**.
    35  
    36  The anonymous access to Argo CD can be enabled using the `users.anonymous.enabled` field in `argocd-cm` (see [argocd-cm.yaml](argocd-cm-yaml.md)).
    37  
    38  !!! warning
    39  
    40      When enabling anonymous access, consider creating a new default role and assigning it to the default policies
    41      with `policy.default: role:unauthenticated`.
    42  
    43  ## RBAC Model Structure
    44  
    45  The model syntax is based on [Casbin](https://casbin.org/docs/overview) (an open source ACL/ACLs). There are two different types of syntax: one for assigning policies, and another one for assigning users to internal roles.
    46  
    47  **Group**: Allows to assign authenticated users/groups to internal roles.
    48  
    49  Syntax: `g, <user/group>, <role>`
    50  
    51  - `<user/group>`: The entity to whom the role will be assigned. It can be a local user or a user authenticated with SSO.
    52    When SSO is used, the `user` will be based on the `sub` claims, while the group is one of the values returned by the `scopes` configuration.
    53  - `<role>`: The internal role to which the entity will be assigned.
    54  
    55  **Policy**: Allows to assign permissions to an entity.
    56  
    57  Syntax: `p, <role/user/group>, <resource>, <action>, <object>, <effect>`
    58  
    59  - `<role/user/group>`: The entity to whom the policy will be assigned
    60  - `<resource>`: The type of resource on which the action is performed.
    61  - `<action>`: The operation that is being performed on the resource.
    62  - `<object>`: The object identifier representing the resource on which the action is performed. Depending on the resource, the object's format will vary.
    63  - `<effect>`: Whether this policy should grant or restrict the operation on the target object. One of `allow` or `deny`.
    64  
    65  Below is a table that summarizes all possible resources and which actions are valid for each of them.
    66  
    67  | Resource\Action     | get | create | update | delete | sync | action | override | invoke |
    68  | :------------------ | :-: | :----: | :----: | :----: | :--: | :----: | :------: | :----: |
    69  | **applications**    | ✅  |   ✅   |   ✅   |   ✅   |  ✅  |   ✅   |    ✅    |   ❌   |
    70  | **applicationsets** | ✅  |   ✅   |   ✅   |   ✅   |  ❌  |   ❌   |    ❌    |   ❌   |
    71  | **clusters**        | ✅  |   ✅   |   ✅   |   ✅   |  ❌  |   ❌   |    ❌    |   ❌   |
    72  | **projects**        | ✅  |   ✅   |   ✅   |   ✅   |  ❌  |   ❌   |    ❌    |   ❌   |
    73  | **repositories**    | ✅  |   ✅   |   ✅   |   ✅   |  ❌  |   ❌   |    ❌    |   ❌   |
    74  | **accounts**        | ✅  |   ❌   |   ✅   |   ❌   |  ❌  |   ❌   |    ❌    |   ❌   |
    75  | **certificates**    | ✅  |   ✅   |   ❌   |   ✅   |  ❌  |   ❌   |    ❌    |   ❌   |
    76  | **gpgkeys**         | ✅  |   ✅   |   ❌   |   ✅   |  ❌  |   ❌   |    ❌    |   ❌   |
    77  | **logs**            | ✅  |   ❌   |   ❌   |   ❌   |  ❌  |   ❌   |    ❌    |   ❌   |
    78  | **exec**            | ❌  |   ✅   |   ❌   |   ❌   |  ❌  |   ❌   |    ❌    |   ❌   |
    79  | **extensions**      | ❌  |   ❌   |   ❌   |   ❌   |  ❌  |   ❌   |    ❌    |   ✅   |
    80  
    81  ### Application-Specific Policy
    82  
    83  Some policy only have meaning within an application. It is the case with the following resources:
    84  
    85  - `applications`
    86  - `applicationsets`
    87  - `logs`
    88  - `exec`
    89  
    90  While they can be set in the global configuration, they can also be configured in [AppProject's roles](../user-guide/projects.md#project-roles).
    91  The expected `<object>` value in the policy structure is replaced by `<app-project>/<app-name>`.
    92  
    93  For instance, these policies would grant `example-user` access to get any applications,
    94  but only be able to see logs in `my-app` application part of the `example-project` project.
    95  
    96  ```csv
    97  p, example-user, applications, get, *, allow
    98  p, example-user, logs, get, example-project/my-app, allow
    99  ```
   100  
   101  #### Application in Any Namespaces
   102  
   103  When [application in any namespace](app-any-namespace.md) is enabled, the expected `<object>` value in the policy structure is replaced by `<app-project>/<app-ns>/<app-name>`.
   104  Since multiple applications could have the same name in the same project, the policy below makes sure to restrict access only to `app-namespace`.
   105  
   106  ```csv
   107  p, example-user, applications, get, */app-namespace/*, allow
   108  p, example-user, logs, get, example-project/app-namespace/my-app, allow
   109  ```
   110  
   111  ### The `applications` resource
   112  
   113  The `applications` resource is an [Application-Specific Policy](#application-specific-policy).
   114  
   115  #### Fine-grained Permissions for `update`/`delete` action
   116  
   117  The `update` and `delete` actions, when granted on an application, will allow the user to perform the operation on the application itself,
   118  but not on its resources.
   119  
   120  To allow an action on the application's resources, specify the action as `<action>/<group>/<kind>/<ns>/<name>`.
   121  
   122  For instance, to grant access to `example-user` to only delete Pods in the `prod-app` Application, the policy could be:
   123  
   124  ```csv
   125  p, example-user, applications, delete/*/Pod/*/*, default/prod-app, allow
   126  ```
   127  
   128  !!!warning "Understand glob pattern behavior"
   129  
   130      Argo CD RBAC does not use `/` as a separator when evaluating glob patterns. So the pattern `delete/*/kind/*`
   131      will match `delete/<group>/kind/<namespace>/<name>` but also `delete/<group>/<kind>/kind/<name>`.
   132  
   133      The fact that both of these match will generally not be a problem, because resource kinds generally contain capital
   134      letters, and namespaces cannot contain capital letters. However, it is possible for a resource kind to be lowercase.
   135      So it is better to just always include all the parts of the resource in the pattern (in other words, always use four
   136      slashes).
   137  
   138  If we want to grant access to the user to update all resources of an application, but not the application itself:
   139  
   140  ```csv
   141  p, example-user, applications, update/*, default/prod-app, allow
   142  ```
   143  
   144  If we want to explicitly deny delete of the application, but allow the user to delete Pods:
   145  
   146  ```csv
   147  p, example-user, applications, delete, default/prod-app, deny
   148  p, example-user, applications, delete/*/Pod/*/*, default/prod-app, allow
   149  ```
   150  
   151  If we want to explicitly allow updates to the application, but deny updates to any sub-resources:
   152  
   153  ```csv
   154  p, example-user, applications, update, default/prod-app, allow
   155  p, example-user, applications, update/*, default/prod-app, deny
   156  ```
   157  
   158  !!! note "Preserve Application permission Inheritance (Since v3.0.0)"
   159  
   160      Prior to v3, `update` and `delete` actions (without a `/*`) were also evaluated
   161      on sub-resources.
   162  
   163      To preserve this behavior, you can set the config value
   164      `server.rbac.disableApplicationFineGrainedRBACInheritance` to `false` in
   165      the Argo CD ConfigMap `argocd-cm`.
   166  
   167      When disabled, it is not possible to deny fine-grained permissions for a sub-resource
   168      if the action was **explicitly allowed on the application**.
   169      For instance, the following policies will **allow** a user to delete the Pod and any
   170      other resources in the application:
   171  
   172      ```csv
   173      p, example-user, applications, delete, default/prod-app, allow
   174      p, example-user, applications, delete/*/Pod/*, default/prod-app, deny
   175      ```
   176  
   177  #### The `action` action
   178  
   179  The `action` action corresponds to either built-in resource customizations defined
   180  [in the Argo CD repository](https://github.com/argoproj/argo-cd/tree/master/resource_customizations),
   181  or to [custom resource actions](resource_actions.md#custom-resource-actions) defined by you.
   182  
   183  See the [resource actions documentation](resource_actions.md#built-in-actions) for a list of built-in actions.
   184  
   185  The `<action>` has the `action/<group>/<kind>/<action-name>` format.
   186  
   187  For example, a resource customization path `resource_customizations/extensions/DaemonSet/actions/restart/action.lua`
   188  corresponds to the `action` path `action/extensions/DaemonSet/restart`. If the resource is not under a group (for example, Pods or ConfigMaps),
   189  then the path will be `action//Pod/action-name`.
   190  
   191  The following policies allows the user to perform any action on the DaemonSet resources, as well as the `maintenance-off` action on a Pod:
   192  
   193  ```csv
   194  p, example-user, applications, action//Pod/maintenance-off, default/*, allow
   195  p, example-user, applications, action/extensions/DaemonSet/*, default/*, allow
   196  ```
   197  
   198  To allow the user to perform any actions:
   199  
   200  ```csv
   201  p, example-user, applications, action/*, default/*, allow
   202  ```
   203  
   204  #### The `override` action
   205  
   206  When granted along with the `sync` action, the override action will allow a user to synchronize local manifests to the Application.
   207  These manifests will be used instead of the configured source, until the next sync is performed.
   208  
   209  ### The `applicationsets` resource
   210  
   211  The `applicationsets` resource is an [Application-Specific policy](#application-specific-policy).
   212  
   213  [ApplicationSets](applicationset/index.md) provide a declarative way to automatically create/update/delete Applications.
   214  
   215  Allowing the `create` action on the resource effectively grants the ability to create Applications. While it doesn't allow the
   216  user to create Applications directly, they can create Applications via an ApplicationSet.
   217  
   218  !!! note
   219  
   220      In v2.5, it is not possible to create an ApplicationSet with a templated Project field (e.g. `project: {{path.basename}}`)
   221      via the API (or, by extension, the CLI). Disallowing templated projects makes project restrictions via RBAC safe:
   222  
   223  With the resource being application-specific, the `<object>` of the applicationsets policy will have the format `<app-project>/<app-name>`.
   224  However, since an ApplicationSet does belong to any project, the `<app-project>` value represents the projects in which the ApplicationSet will be able to create Applications.
   225  
   226  With the following policy, a `dev-group` user will be unable to create an ApplicationSet capable of creating Applications
   227  outside the `dev-project` project.
   228  
   229  ```csv
   230  p, dev-group, applicationsets, *, dev-project/*, allow
   231  ```
   232  
   233  ### The `logs` resource
   234  
   235  The `logs` resource is an [Application-Specific Policy](#application-specific-policy).
   236  
   237  When granted with the `get` action, this policy allows a user to see Pod's logs of an application via
   238  the Argo CD UI. The functionality is similar to `kubectl logs`.
   239  
   240  ### The `exec` resource
   241  
   242  The `exec` resource is an [Application-Specific Policy](#application-specific-policy).
   243  
   244  When granted with the `create` action, this policy allows a user to `exec` into Pods of an application via
   245  the Argo CD UI. The functionality is similar to `kubectl exec`.
   246  
   247  See [Web-based Terminal](web_based_terminal.md) for more info.
   248  
   249  ### The `extensions` resource
   250  
   251  With the `extensions` resource, it is possible to configure permissions to invoke [proxy extensions](../developer-guide/extensions/proxy-extensions.md).
   252  The `extensions` RBAC validation works in conjunction with the `applications` resource.
   253  A user **needs to have read permission on the application** where the request is originated from.
   254  
   255  Consider the example below, it will allow the `example-user` to invoke the `httpbin` extensions in all
   256  applications under the `default` project.
   257  
   258  ```csv
   259  p, example-user, applications, get, default/*, allow
   260  p, example-user, extensions, invoke, httpbin, allow
   261  ```
   262  
   263  ### The `deny` effect
   264  
   265  When `deny` is used as an effect in a policy, it will be effective if the policy matches.
   266  Even if more specific policies with the `allow` effect match as well, the `deny` will have priority.
   267  
   268  The order in which the policies appears in the policy file configuration has no impact, and the result is deterministic.
   269  
   270  ## Policies Evaluation and Matching
   271  
   272  The evaluation of access is done in two parts: validating against the default policy configuration, then validating against the policies for the current user.
   273  
   274  **If an action is allowed or denied by the default policies, then this effect will be effective without further evaluation**.
   275  When the effect is undefined, the evaluation will continue with subject-specific policies.
   276  
   277  The access will be evaluated for the user, then for each configured group that the user is part of.
   278  
   279  The matching engine, configured in `policy.matchMode`, can use two different match modes to compare the values of tokens:
   280  
   281  - `glob`: based on the [`glob` package](https://pkg.go.dev/github.com/gobwas/glob).
   282  - `regex`: based on the [`regexp` package](https://pkg.go.dev/regexp).
   283  
   284  When all tokens match during the evaluation, the effect will be returned. The evaluation will continue until all matching policies are evaluated, or until a policy with the `deny` effect matches.
   285  After all policies are evaluated, if there was at least one `allow` effect and no `deny`, access will be granted.
   286  
   287  ### Glob matching
   288  
   289  When `glob` is used, the policy tokens are treated as single terms, without separators.
   290  
   291  Consider the following policy:
   292  
   293  ```
   294  p, example-user, applications, action/extensions/*, default/*, allow
   295  ```
   296  
   297  When the `example-user` executes the `extensions/DaemonSet/test` action, the following `glob` matches will happen:
   298  
   299  1. The current user `example-user` matches the token `example-user`.
   300  2. The value `applications` matches the token `applications`.
   301  3. The value `action/extensions/DaemonSet/test` matches `action/extensions/*`. Note that `/` is not treated as a separator and the use of `**` is not necessary.
   302  4. The value `default/my-app` matches `default/*`.
   303  
   304  ## Using SSO Users/Groups
   305  
   306  The `scopes` field controls which OIDC scopes to examine during RBAC enforcement (in addition to `sub` scope).
   307  If omitted, it defaults to `'[groups]'`. The scope value can be a string, or a list of strings.
   308  
   309  For more information on `scopes` please review the [User Management Documentation](user-management/index.md).
   310  
   311  The following example shows targeting `email` as well as `groups` from your OIDC provider, and also demonstrates explicit role assignments and role-to-role inheritance:
   312  
   313  ```yaml
   314  apiVersion: v1
   315  kind: ConfigMap
   316  metadata:
   317    name: argocd-rbac-cm
   318    namespace: argocd
   319    labels:
   320      app.kubernetes.io/name: argocd-rbac-cm
   321      app.kubernetes.io/part-of: argocd
   322  data:
   323    policy.csv: |
   324      p, my-org:team-alpha, applications, sync, my-project/*, allow
   325      g, my-org:team-beta, role:admin
   326      g, user@example.org, role:admin
   327      g, admin, role:admin
   328      g, role:admin, role:readonly
   329    policy.default: role:readonly
   330    scopes: '[groups, email]'
   331  ```
   332  
   333  Here:
   334  1. `g, admin, role:admin` explicitly binds the built-in admin user to the admin role.
   335  2. `g, role:admin, role:readonly` shows role inheritance, so anyone granted `role:admin` also automatically has all the permissions of      
   336     `role:readonly`.
   337  
   338  This approach can be combined with AppProjects to associate users' emails and groups directly at the project level:
   339  ```yaml
   340  apiVersion: argoproj.io/v1alpha1
   341  kind: AppProject
   342  metadata:
   343    name: team-beta-project
   344    namespace: argocd
   345  spec:
   346    roles:
   347      - name: admin
   348        description: Admin privileges to team-beta
   349        policies:
   350          - p, proj:team-beta-project:admin, applications, *, team-beta-project/*, allow
   351        groups:
   352          - user@example.org # Value from the email scope
   353          - my-org:team-beta # Value from the groups scope
   354  ```
   355  
   356  ## Local Users/Accounts
   357  
   358  [Local users](user-management/index.md#local-usersaccounts) are assigned access by either grouping them with a role or by assigning policies directly
   359  to them.
   360  
   361  The example below shows how to assign a policy directly to a local user.
   362  
   363  ```yaml
   364  p, my-local-user, applications, sync, my-project/*, allow
   365  ```
   366  
   367  This example shows how to assign a role to a local user.
   368  
   369  ```yaml
   370  g, my-local-user, role:admin
   371  ```
   372  
   373  !!! warning "Ambiguous Group Assignments"
   374  
   375      If you have [enabled SSO](user-management/index.md#sso), any SSO user with a scope that matches a local user will be
   376      added to the same roles as the local user. For example, if local user `sally` is assigned to `role:admin`, and if an
   377      SSO user has a scope which happens to be named `sally`, that SSO user will also be assigned to `role:admin`.
   378  
   379      An example of where this may be a problem is if your SSO provider is an SCM, and org members are automatically
   380      granted scopes named after the orgs. If a user can create or add themselves to an org in the SCM, they can gain the
   381      permissions of the local user with the same name.
   382  
   383      To avoid ambiguity, if you are using local users and SSO, it is recommended to assign policies directly to local
   384      users, and not to assign roles to local users. In other words, instead of using `g, my-local-user, role:admin`, you
   385      should explicitly assign policies to `my-local-user`:
   386  
   387      ```yaml
   388      p, my-local-user, *, *, *, allow
   389      ```
   390  
   391  ## Policy CSV Composition
   392  
   393  It is possible to provide additional entries in the `argocd-rbac-cm` configmap to compose the final policy csv.
   394  In this case, the key must follow the pattern `policy.<any string>.csv`.
   395  Argo CD will concatenate all additional policies it finds with this pattern below the main one ('policy.csv').
   396  The order of additional provided policies are determined by the key string.
   397  
   398  Example: if two additional policies are provided with keys `policy.A.csv` and `policy.B.csv`,
   399  it will first concatenate `policy.A.csv` and then `policy.B.csv`.
   400  
   401  This is useful to allow composing policies in config management tools like Kustomize, Helm, etc.
   402  
   403  The example below shows how a Kustomize patch can be provided in an overlay to add additional configuration to an existing RBAC ConfigMap.
   404  
   405  ```yaml
   406  apiVersion: v1
   407  kind: ConfigMap
   408  metadata:
   409    name: argocd-rbac-cm
   410    namespace: argocd
   411  data:
   412    policy.tester-overlay.csv: |
   413      p, role:tester, applications, *, */*, allow
   414      p, role:tester, projects, *, *, allow
   415      g, my-org:team-qa, role:tester
   416  ```
   417  
   418  ## Validating and testing your RBAC policies
   419  
   420  If you want to ensure that your RBAC policies are working as expected, you can
   421  use the [`argocd admin settings rbac` command](../user-guide/commands/argocd_admin_settings_rbac.md) to validate them.
   422  This tool allows you to test whether a certain role or subject can perform the requested action with a policy
   423  that's not live yet in the system, i.e. from a local file or config map.
   424  Additionally, it can be used against the live RBAC configuration in the cluster your Argo CD is running in.
   425  
   426  ### Validating a policy
   427  
   428  To check whether your new policy configuration is valid and understood by Argo CD's RBAC implementation,
   429  you can use the [`argocd admin settings rbac validate` command](../user-guide/commands/argocd_admin_settings_rbac_validate.md).
   430  
   431  ### Testing a policy
   432  
   433  To test whether a role or subject (group or local user) has sufficient
   434  permissions to execute certain actions on certain resources, you can
   435  use the [`argocd admin settings rbac can` command](../user-guide/commands/argocd_admin_settings_rbac_can.md).