Skip to content

Commit d4b9060

Browse files
authored
Merge pull request #3320 from davidblum/multi-tenancy-docs
update multi-tenacy docs
2 parents b1ac1ea + 4048a8d commit d4b9060

File tree

1 file changed

+78
-6
lines changed

1 file changed

+78
-6
lines changed

docs/book/src/topics/multitenancy.md

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Starting from v0.6.5, single controller multi-tenancy is supported that allows u
44
For details, see the [multi-tenancy proposal](https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/docs/proposal/20200506-single-controller-multitenancy.md).
55

66

7-
For multi-tenancy support, a reference field (`identityRef`) is added to `AWSCluster`, which describes the identity to be used when reconciling the cluster.
7+
For multi-tenancy support, a reference field (`identityRef`) is added to `AWSCluster`, which informs the controller of which identity to be used when reconciling the cluster.
8+
If the identity provided exists in a different AWS account, this is the mechanism which informs the controller to provision a cluster in a different account.
9+
810

911
```yaml
1012
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
@@ -112,10 +114,13 @@ stringData:
112114
The assumed role could be used by the AWSClusters that is in the `allowedNamespaces`.
113115

114116
Example:
115-
Below, an `AWSClusterRoleIdentity` instance, which will be used by AWSCluster "test", is created.
117+
Below, an `AWSClusterRoleIdentity` instance, which will be used by `AWSCluster` "test", is created.
116118
This role will be assumed by the source identity at runtime. Source identity can be of any identity type.
117119
Role is assumed in the beginning once and after, whenever the assumed role's credentials are expired.
118120

121+
This snippet illustrates the connection between `AWSCluster`and the `AWSClusterRoleIdentity`, however this is not a working example.
122+
Please view a full example below.
123+
119124
```yaml
120125
---
121126
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
@@ -135,12 +140,11 @@ metadata:
135140
name: "test-account-role"
136141
spec:
137142
allowedNamespaces:
138-
list: # allows only "test" namespace to use this identity
139-
"test"
143+
- "test" # allows only "test" namespace to use this identity
140144
roleARN: "arn:aws:iam::123456789:role/CAPARole"
141145
sourceIdentityRef:
142-
kind: AWSClusterStaticIdentity
143-
name: test-account-creds
146+
kind: AWSClusterControllerIdentity # use the singleton for root auth
147+
name: default
144148
```
145149

146150
Nested role assumption is also supported.
@@ -175,6 +179,74 @@ spec:
175179
name: multi-tenancy-role
176180
```
177181

182+
### Examples
183+
184+
This is a deployable example which uses the `AWSClusterRoleIdentity` "test-account-role" to assume into the `arn:aws:iam::123456789:role/CAPARole` role in the target account.
185+
This example assumes that the `CAPARole` has already been configured in the target account.
186+
187+
Finally, we inform the `Cluster` to use our `AWSCluster`type to provision a cluster in the target account specified by the `identityRef` section.
188+
189+
**Note**
190+
191+
By default the `AutoControllerIdentityCreator=true` feature gate is set to `true` [here](https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/412d310654c6b05f1b4bc3d319f6957a07c009c2/feature/feature.go?rgh-link-date=2022-03-23T14%3A57%3A46Z#L81).
192+
If this is not enabled for your cluster, you will need to enable the flag, or create your own default `AWSClusterControllerIdentity`.
193+
194+
```yaml
195+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
196+
kind: AWSClusterControllerIdentity
197+
metadata:
198+
name: "default"
199+
spec:
200+
allowedNamespaces:{} # matches all namespaces
201+
```
202+
203+
```yaml
204+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
205+
kind: AWSClusterRoleIdentity
206+
metadata:
207+
name: "test-account-role"
208+
spec:
209+
allowedNamespaces: {} # matches all namespaces
210+
roleARN: "arn:aws:iam::123456789:role/CAPARole"
211+
sourceIdentityRef:
212+
kind: AWSClusterControllerIdentity # use the singleton for root auth
213+
name: default
214+
---
215+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
216+
kind: AWSCluster
217+
metadata:
218+
name: "test-multi-tenant-workload"
219+
spec:
220+
region: "eu-west-1"
221+
identityRef:
222+
kind: AWSClusterRoleIdentity
223+
name: test-account-role
224+
---
225+
apiVersion: cluster.x-k8s.io/v1beta1
226+
kind: Cluster
227+
metadata:
228+
name: "test-multi-tenant-workload"
229+
spec:
230+
infrastructureRef:
231+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
232+
kind: AWSCluster
233+
name: "test-multi-tenant-workload"
234+
```
235+
236+
More specific examples can be referenced from the existing [templates](../../../../templates/) directory.
237+
238+
In order to use the [EC2 template](../../../../templates/cluster-template.yaml) with identity type, you can add the `identityRef` section to `kind: AWSCluster` spec section in the template. If you do not, CAPA will automatically add the default identity provider (which is usually your local account credentials).
239+
240+
Similarly, to use the [EKS template](../../../../templates/cluster-template-eks.yaml) with identity type, you can add the `identityRef` section to `kind: AWSManagedControlPlane` spec section in the template. If you do not, CAPA will automatically add the default identity provider (which is usually your local account credentials).
241+
242+
#### Permissions
243+
244+
There are multiple AWS assume role permissions that need to be configured in order for the assume role to work
245+
- The Primary role in the management account must be allowed to assume role into the target role account
246+
- This is traditionally the controller role, but the operator can configure it to be any role
247+
- The target account role must be configured to allow the management role to assume into it
248+
- The target account role must have adequate permissions for cluster-api to build both EC2 and EKS based clusters
249+
178250
## Secure Access to Identities
179251
`allowedNamespaces` field is used to grant access to the namespaces to use Identities.
180252
Only AWSClusters that are created in one of the Identity's allowed namespaces can use that Identity.

0 commit comments

Comments
 (0)