github.com/argoproj/argo-cd/v2@v2.10.9/docs/operator-manual/app-any-namespace.md (about) 1 # Applications 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.5, Argo CD supports managing `Application` 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 `Application` resources may be created, updated and reconciled in. However, applications in these additional namespaces will only be allowed to use certain `AppProjects`, as configured by the Argo CD administrators. This allows ordinary Argo CD users (e.g. application teams) to use patterns like declarative management of `Application` resources, implementing app-of-apps and others without the risk of a privilege escalation through usage of other `AppProjects` that would exceed the permissions granted to the application teams. 13 14 Some manual steps will need to be performed by the Argo CD administrator in order to enable this feature. 15 16 !!! note 17 This feature is considered beta as of now. Some of the implementation details may change over the course of time until it is promoted to a stable status. We will be happy if early adopters use this feature and provide us with bug reports and feedback. 18 19 20 One additional advantage of adopting applications in any namespace is to allow end-users to configure notifications for their Argo CD application in the namespace where Argo CD application is running in. See notifications [namespace based configuration](notifications/index.md#namespace-based-configuration) page for more information. 21 22 ## Prerequisites 23 24 ### Cluster-scoped Argo CD installation 25 26 This feature can only be enabled and used when your Argo CD 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 ### Switch resource tracking method 29 30 Also, while technically not necessary, it is strongly suggested that you switch the application tracking method from the default `label` setting to either `annotation` or `annotation+label`. The reasoning for this is, that application names will be a composite of the namespace's name and the name of the `Application`, and this can easily exceed the 63 characters length limit imposed on label values. Annotations have a notably greater length limit. 31 32 To enable annotation based resource tracking, refer to the documentation about [resource tracking methods](../../user-guide/resource_tracking/) 33 34 ## Implementation details 35 36 ### Overview 37 38 In order for an application to be managed and reconciled outside the Argo CD's control plane namespace, two prerequisites must match: 39 40 1. The `Application`'s namespace must be explicitly enabled using the `--application-namespaces` parameter for the `argocd-application-controller` and `argocd-server` workloads. This parameter controls the list of namespaces that Argo CD will be allowed to source `Application` resources from globally. Any namespace not configured here cannot be used from any `AppProject`. 41 1. The `AppProject` referenced by the `.spec.project` field of the `Application` must have the namespace listed in its `.spec.sourceNamespaces` field. This setting will determine whether an `Application` may use a certain `AppProject`. If an `Application` specifies an `AppProject` that is not allowed, Argo CD refuses to process this `Application`. As stated above, any namespace configured in the `.spec.sourceNamespaces` field must also be enabled globally. 42 43 `Applications` in different namespaces can be created and managed just like any other `Application` 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). 44 45 ### Reconfigure Argo CD to allow certain namespaces 46 47 #### Change workload startup parameters 48 49 In order to enable this feature, the Argo CD administrator must reconfigure the `argocd-server` and `argocd-application-controller` workloads to add the `--application-namespaces` parameter to the container's startup command. 50 51 The `--application-namespaces` parameter takes a comma-separated list of namespaces where `Applications` are to be allowed in. Each entry of the list supports shell-style wildcards such as `*`, so for example the entry `app-team-*` would match `app-team-one` and `app-team-two`. To enable all namespaces on the cluster where Argo CD is running on, you can just specify `*`, i.e. `--application-namespaces=*`. 52 53 The startup parameters for both, the `argocd-server` and the `argocd-application-controller` can also be conveniently set up and kept in sync by specifying the `application.namespaces` settings in the `argocd-cmd-params-cm` ConfigMap _instead_ of changing the manifests for the respective workloads. For example: 54 55 ```yaml 56 data: 57 application.namespaces: app-team-one, app-team-two 58 ``` 59 60 would allow the `app-team-one` and `app-team-two` namespaces for managing `Application` resources. After a change to the `argocd-cmd-params-cm` namespace, the appropriate workloads need to be restarted: 61 62 ```bash 63 kubectl rollout restart -n argocd deployment argocd-server 64 kubectl rollout restart -n argocd statefulset argocd-application-controller 65 ``` 66 67 #### Adapt Kubernetes RBAC 68 69 We decided to not extend the Kubernetes RBAC for the `argocd-server` workload by default for the time being. If you want `Applications` in other namespaces to be managed by the Argo CD API (i.e. the CLI and UI), you need to extend the Kubernetes permissions for the `argocd-server` ServiceAccount. 70 71 We supply a `ClusterRole` and `ClusterRoleBinding` suitable for this purpose in the `examples/k8s-rbac/argocd-server-applications` directory. For a default Argo CD installation (i.e. installed to the `argocd` namespace), you can just apply them as-is: 72 73 ```shell 74 kubectl apply -k examples/k8s-rbac/argocd-server-applications/ 75 ``` 76 77 `argocd-notifications-controller-rbac-clusterrole.yaml` and `argocd-notifications-controller-rbac-clusterrolebinding.yaml` are used to support notifications controller to notify apps in all namespaces. 78 79 !!! note 80 At some later point in time, we may make this cluster role part of the default installation manifests. 81 82 ### Allowing additional namespaces in an AppProject 83 84 Any user with Kubernetes access to the Argo CD control plane's namespace (`argocd`), especially those with permissions to create or update `Applications` in a declarative way, is to be considered an Argo CD admin. 85 86 This prevented unprivileged Argo CD users from declaratively creating or managing `Applications` in the past. Those users were constrained to using the API instead, subject to Argo CD RBAC which ensures only `Applications` in allowed `AppProjects` were created. 87 88 For an `Application` to be created outside the `argocd` namespace, the `AppProject` referred to in the `Application`'s `.spec.project` field must include the `Application`'s namespace in its `.spec.sourceNamespaces` field. 89 90 For example, consider the two following (incomplete) `AppProject` specs: 91 92 ```yaml 93 kind: AppProject 94 apiVersion: argoproj.io/v1alpha1 95 metadata: 96 name: project-one 97 namespace: argocd 98 spec: 99 sourceNamespaces: 100 - namespace-one 101 ``` 102 103 and 104 105 ```yaml 106 kind: AppProject 107 apiVersion: argoproj.io/v1alpha1 108 metadata: 109 name: project-two 110 namespace: argocd 111 spec: 112 sourceNamespaces: 113 - namespace-two 114 ``` 115 116 In order for an Application to set `.spec.project` to `project-one`, it would have to be created in either namespace `namespace-one` or `argocd`. Likewise, in order for an Application to set `.spec.project` to `project-two`, it would have to be created in either namespace `namespace-two` or `argocd`. 117 118 If an Application in `namespace-two` would set their `.spec.project` to `project-one` or an Application in `namespace-one` would set their `.spec.project` to `project-two`, Argo CD would consider this as a permission violation and refuse to reconcile the Application. 119 120 Also, the Argo CD API will enforce these constraints, regardless of the Argo CD RBAC permissions. 121 122 The `.spec.sourceNamespaces` field of the `AppProject` is a list that can contain an arbitrary amount of namespaces, and each entry supports shell-style wildcard, so that you can allow namespaces with patterns like `team-one-*`. 123 124 !!! warning 125 Do not add user controlled namespaces in the `.spec.sourceNamespaces` field of any privileged AppProject like the `default` project. Always make sure that the AppProject follows the principle of granting least required privileges. Never grant access to the `argocd` namespace within the AppProject. 126 127 !!! note 128 For backwards compatibility, Applications in the Argo CD control plane's namespace (`argocd`) are allowed to set their `.spec.project` field to reference any AppProject, regardless of the restrictions placed by the AppProject's `.spec.sourceNamespaces` field. 129 130 ### Application names 131 132 For the CLI and UI, applications are now referred to and displayed as in the format `<namespace>/<name>`. 133 134 For backwards compatibility, if the namespace of the Application is the control plane's namespace (i.e. `argocd`), the `<namespace>` can be omitted from the application name when referring to it. For example, the application names `argocd/someapp` and `someapp` are semantically the same and refer to the same application in the CLI and the UI. 135 136 ### Application RBAC 137 138 The RBAC syntax for Application objects has been changed from `<project>/<application>` to `<project>/<namespace>/<application>` to accommodate the need to restrict access based on the source namespace of the Application to be managed. 139 140 For backwards compatibility, Applications in the `argocd` namespace can still be refered to as `<project>/<application>` in the RBAC policy rules. 141 142 Wildcards do not make any distinction between project and application namespaces yet. For example, the following RBAC rule would match any application belonging to project `foo`, regardless of the namespace it is created in: 143 144 ``` 145 p, somerole, applications, get, foo/*, allow 146 ``` 147 148 If you want to restrict access to be granted only to `Applications` in project `foo` within namespace `bar`, the rule would need to be adapted as follows: 149 150 ``` 151 p, somerole, applications, get, foo/bar/*, allow 152 ``` 153 154 ## Managing applications in other namespaces 155 156 ### Declaratively 157 158 For declarative management of Applications, just create the Application from a YAML or JSON manifest in the desired namespace. Make sure that the `.spec.project` field refers to an AppProject that allows this namespace. For example, the following (incomplete) Application manifest creates an Application in the namespace `some-namespace`: 159 160 ```yaml 161 kind: Application 162 apiVersion: argoproj.io/v1alpha1 163 metadata: 164 name: some-app 165 namespace: some-namespace 166 spec: 167 project: some-project 168 # ... 169 ``` 170 171 The project `some-project` will then need to specify `some-namespace` in the list of allowed source namespaces, e.g. 172 173 ```yaml 174 kind: AppProject 175 apiVersion: argoproj.io/v1alpha1 176 metadata: 177 name: some-project 178 namespace: argocd 179 spec: 180 sourceNamespaces: 181 - some-namespace 182 ``` 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 `Application` named `foo` in the namespace `bar`, you can use the following CLI command: 189 190 ```shell 191 argocd app get foo/bar 192 ``` 193 194 Likewise, to manage this application, keep referring to it as `foo/bar`: 195 196 ```bash 197 # Create an application 198 argocd app create foo/bar ... 199 # Sync the application 200 argocd app sync foo/bar 201 # Delete the application 202 argocd app delete foo/bar 203 # Retrieve application's manifest 204 argocd app manifests foo/bar 205 ``` 206 207 As stated previously, for applications in the Argo CD's control plane namespace, you can omit the namespace from the application name. 208 209 ### Using the UI 210 211 Similar to the CLI, you can refer to the application in the UI as `foo/bar`. 212 213 For example, to create an application named `bar` in the namespace `foo` in the web UI, set the application name in the creation dialogue's _Application Name_ field to `foo/bar`. If the namespace is omitted, the control plane's namespace will be used. 214 215 ### Using the REST API 216 217 If you are using the REST API, the namespace for `Application` 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 `Application` resource named `foo` in the namespace `bar`, the request would look like follows: 218 219 ```bash 220 GET /api/v1/applications/foo?appNamespace=bar 221 ``` 222 223 For other operations such as `POST` and `PUT`, the `appNamespace` parameter must be part of the request's payload. 224 225 For `Application` resources in the control plane namespace, this parameter can be omitted.