Skip to content

Commit 58f8dab

Browse files
somtochiamahiddeco
andcommitted
docs: document Azure Workload Identity in specs
Co-authored-by: Hidde Beydals <[email protected]> Signed-off-by: Somtochi Onyekwere <[email protected]>
1 parent 37e113a commit 58f8dab

File tree

3 files changed

+203
-15
lines changed

3 files changed

+203
-15
lines changed

docs/spec/v1beta2/buckets.md

+102-15
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ Without a [Secret reference](#secret-reference), authentication using a chain
280280
with:
281281

282282
- [Environment credentials](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#EnvironmentCredential)
283+
- [Workload Identity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/[email protected]#WorkloadIdentityCredential)
283284
- [Managed Identity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#ManagedIdentityCredential)
284285
with the `AZURE_CLIENT_ID`
285286
- Managed Identity with a system-assigned identity
@@ -436,22 +437,103 @@ data:
436437
accountKey: <BASE64>
437438
```
438439

439-
#### Managed Identity with AAD Pod Identity
440+
##### Workload Identity
440441

441-
If you are using [aad pod identity](https://azure.github.io/aad-pod-identity/docs), you can create an identity that has access to Azure Storage.
442+
If you have [Workload Identity mutating webhook](https://azure.github.io/azure-workload-identity/docs/installation/managed-clusters.html)
443+
installed on your cluster. You need to create an Azure Identity and give it
444+
access to Azure Blob Storage.
445+
446+
```shell
447+
export IDENTITY_NAME="blob-access"
448+
449+
az role assignment create --role "Storage Blob Data Reader" \
450+
--assignee-object-id "$(az identity show -n $IDENTITY_NAME -o tsv --query principalId -g $RESOURCE_GROUP)" \
451+
--scope "/subscriptions/<SUBSCRIPTION-ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Storage/storageAccounts/<account-name>/blobServices/default/containers/<container-name>"
452+
```
453+
454+
Establish a federated identity between the Identity and the source-controller
455+
ServiceAccount.
456+
457+
```shell
458+
export SERVICE_ACCOUNT_ISSUER="$(az aks show --resource-group <RESOURCE_GROUP> --name <CLUSTER-NAME> --query "oidcIssuerProfile.issuerUrl" -otsv)"
459+
460+
az identity federated-credential create \
461+
--name "kubernetes-federated-credential" \
462+
--identity-name "${IDENTITY_NAME}" \
463+
--resource-group "${RESOURCE_GROUP}" \
464+
--issuer "${SERVICE_ACCOUNT_ISSUER}" \
465+
--subject "system:serviceaccount:flux-system:source-controller"
466+
```
467+
468+
Add a patch to label and annotate the source-controller Pods and ServiceAccount
469+
correctly so that it can match an identity binding:
470+
471+
```yaml
472+
apiVersion: kustomize.config.k8s.io/v1beta1
473+
kind: Kustomization
474+
resources:
475+
- gotk-components.yaml
476+
- gotk-sync.yaml
477+
patches:
478+
- patch: |-
479+
apiVersion: v1
480+
kind: ServiceAccount
481+
metadata:
482+
name: source-controller
483+
namespace: flux-system
484+
annotations:
485+
azure.workload.identity/client-id: <AZURE_CLIENT_ID>
486+
labels:
487+
azure.workload.identity/use: "true"
488+
- patch: |-
489+
apiVersion: apps/v1
490+
kind: Deployment
491+
metadata:
492+
name: source-controller
493+
namespace: flux-system
494+
labels:
495+
azure.workload.identity/use: "true"
496+
spec:
497+
template:
498+
metadata:
499+
labels:
500+
azure.workload.identity/use: "true"
501+
```
502+
503+
If you have set up Workload Identity correctly and labeled the source-controller
504+
Pod and ServiceAccount, then you don't need to reference a Secret. For more information,
505+
please see [documentation](https://azure.github.io/azure-workload-identity/docs/quick-start.html).
506+
507+
```yaml
508+
apiVersion: source.toolkit.fluxcd.io/v1beta2
509+
kind: Bucket
510+
metadata:
511+
name: azure-bucket
512+
namespace: flux-system
513+
spec:
514+
interval: 5m0s
515+
provider: azure
516+
bucketName: testsas
517+
endpoint: https://testfluxsas.blob.core.windows.net
518+
```
519+
520+
##### Managed Identity with AAD Pod Identity
521+
522+
If you are using [aad pod identity](https://azure.github.io/aad-pod-identity/docs),
523+
You need to create an Azure Identity and give it access to Azure Blob Storage.
442524

443525
```sh
444526
export IDENTITY_NAME="blob-access"
445527
446-
az role assignment create --role "Storage Blob Data Contributor" \
447-
--assignee-object-id "$(az identity show -n blob-access -o tsv --query principalId -g $RESOURCE_GROUP)" \
448-
--scope "/subscriptions/<SUBSCRIPTION-ID>/resourceGroups/aks-somto/providers/Microsoft.Storage/storageAccounts/<account-name>/blobServices/default/containers/<container-name>"
528+
az role assignment create --role "Storage Blob Data Reader" \
529+
--assignee-object-id "$(az identity show -n $IDENTITY_NAME -o tsv --query principalId -g $RESOURCE_GROUP)" \
530+
--scope "/subscriptions/<SUBSCRIPTION-ID>/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Storage/storageAccounts/<account-name>/blobServices/default/containers/<container-name>"
449531
450532
export IDENTITY_CLIENT_ID="$(az identity show -n ${IDENTITY_NAME} -g ${RESOURCE_GROUP} -otsv --query clientId)"
451533
export IDENTITY_RESOURCE_ID="$(az identity show -n ${IDENTITY_NAME} -otsv --query id)"
452534
```
453535

454-
Create an `AzureIdentity` object that references the identity created above:
536+
Create an AzureIdentity object that references the identity created above:
455537

456538
```yaml
457539
---
@@ -466,7 +548,8 @@ spec:
466548
type: 0 # user-managed identity
467549
```
468550

469-
Create an `AzureIdentityBinding` object that binds pods with a specific selector with the `AzureIdentity` created:
551+
Create an AzureIdentityBinding object that binds Pods with a specific selector
552+
with the AzureIdentity created:
470553

471554
```yaml
472555
apiVersion: "aadpodidentity.k8s.io/v1"
@@ -493,7 +576,8 @@ spec:
493576
aadpodidbinding: ${IDENTITY_NAME} # match the AzureIdentity name
494577
```
495578

496-
If you have set aad-pod-identity up correctly and labeled the source-controller pod, then you don't need to reference a secret.
579+
If you have set up aad-pod-identity correctly and labeled the source-controller
580+
Pod, then you don't need to reference a Secret.
497581

498582
```yaml
499583
apiVersion: source.toolkit.fluxcd.io/v1beta2
@@ -535,13 +619,16 @@ data:
535619
sasKey: <base64>
536620
```
537621

538-
The sasKey only contains the SAS token e.g `?sv=2020-08-0&ss=bfqt&srt=co&sp=rwdlacupitfx&se=2022-05-26T21:55:35Z&st=2022-05...`.
539-
The leading question mark is optional.
540-
The query values from the `sasKey` data field in the Secrets gets merged with the ones in the `spec.endpoint` of the `Bucket`.
541-
If the same key is present in the both of them, the value in the `sasKey` takes precedence.
622+
The `sasKey` only contains the SAS token e.g
623+
`?sv=2020-08-0&ss=bfqt&srt=co&sp=rwdlacupitfx&se=2022-05-26T21:55:35Z&st=2022-05...`.
624+
The leading question mark (`?`) is optional. The query values from the `sasKey`
625+
data field in the Secrets gets merged with the ones in the `.spec.endpoint` of
626+
the Bucket. If the same key is present in the both of them, the value in the
627+
`sasKey` takes precedence.
542628

543-
**Note:** The SAS token has an expiry date and it must be updated before it expires to allow Flux to
544-
continue to access Azure Storage. It is allowed to use an account-level or container-level SAS token.
629+
**Note:** The SAS token has an expiry date, and it must be updated before it
630+
expires to allow Flux to continue to access Azure Storage. It is allowed to use
631+
an account-level or container-level SAS token.
545632

546633
The minimum permissions for an account-level SAS token are:
547634

@@ -756,7 +843,7 @@ spec:
756843

757844
### Triggering a reconcile
758845

759-
To manually tell the source-controller to reconcile a Bucket outside of the
846+
To manually tell the source-controller to reconcile a Bucket outside the
760847
[specified interval window](#interval), a Bucket can be annotated with
761848
`reconcile.fluxcd.io/requestedAt: <arbitrary value>`. Annotating the resource
762849
queues the Bucket for reconciliation if the `<arbitrary-value>` differs from

docs/spec/v1beta2/helmrepositories.md

+55
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,13 @@ The `aws` provider can be used to authenticate automatically using the EKS worke
190190
node IAM role or IAM Role for Service Accounts (IRSA), and by extension gain access
191191
to ECR.
192192

193+
##### EKS Worker Node IAM Role
194+
193195
When the worker node IAM role has access to ECR, source-controller running on it
194196
will also have access to ECR.
195197

198+
##### IAM Role for Service Accounts (IRSA)
199+
196200
When using IRSA to enable access to ECR, add the following patch to your bootstrap
197201
repository, in the `flux-system/kustomization.yaml` file:
198202

@@ -224,9 +228,56 @@ The `azure` provider can be used to authenticate automatically using kubelet man
224228
identity or Azure Active Directory pod-managed identity (aad-pod-identity), and
225229
by extension gain access to ACR.
226230

231+
##### Kubelet Managed Identity
232+
227233
When the kubelet managed identity has access to ACR, source-controller running on
228234
it will also have access to ACR.
229235

236+
##### Azure Workload Identity
237+
238+
When using Workload Identity to enable access to ACR, add the following patch to
239+
your bootstrap repository, in the `flux-system/kustomization.yaml` file:
240+
241+
```yaml
242+
apiVersion: kustomize.config.k8s.io/v1beta1
243+
kind: Kustomization
244+
resources:
245+
- gotk-components.yaml
246+
- gotk-sync.yaml
247+
patches:
248+
- patch: |-
249+
apiVersion: v1
250+
kind: ServiceAccount
251+
metadata:
252+
name: source-controller
253+
namespace: flux-system
254+
annotations:
255+
azure.workload.identity/client-id: <AZURE_CLIENT_ID>
256+
labels:
257+
azure.workload.identity/use: "true"
258+
- patch: |-
259+
apiVersion: apps/v1
260+
kind: Deployment
261+
metadata:
262+
name: source-controller
263+
namespace: flux-system
264+
labels:
265+
azure.workload.identity/use: "true"
266+
spec:
267+
template:
268+
metadata:
269+
labels:
270+
azure.workload.identity/use: "true"
271+
```
272+
273+
To use Workload Identity, you have to install the Workload Identity
274+
mutating webhook and create an identity that has access to ACR. Next, establish
275+
a federated identity between the source-controller ServiceAccount and the
276+
identity. Patch the source-controller Pod and ServiceAccount as shown in the patch
277+
above. Please take a look at this [guide](https://azure.github.io/azure-workload-identity/docs/quick-start.html#6-establish-federated-identity-credential-between-the-identity-and-the-service-account-issuer--subject).
278+
279+
##### AAD Pod Identity
280+
230281
When using aad-pod-identity to enable access to ACR, add the following patch to
231282
your bootstrap repository, in the `flux-system/kustomization.yaml` file:
232283

@@ -261,9 +312,13 @@ if you want to use AKS pod-managed identities add-on that is in preview.
261312
The `gcp` provider can be used to authenticate automatically using OAuth scopes or
262313
Workload Identity, and by extension gain access to GCR or Artifact Registry.
263314

315+
#### Access Scopes
316+
264317
When the GKE nodes have the appropriate OAuth scope for accessing GCR and Artifact Registry,
265318
source-controller running on it will also have access to them.
266319

320+
#### GKE Workload Identity
321+
267322
When using Workload Identity to enable access to GCR or Artifact Registry, add the
268323
following patch to your bootstrap repository, in the `flux-system/kustomization.yaml`
269324
file:

docs/spec/v1beta2/ocirepositories.md

+46
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,55 @@ The `azure` provider can be used to authenticate automatically using kubelet
161161
managed identity or Azure Active Directory pod-managed identity (aad-pod-identity),
162162
and by extension gain access to ACR.
163163

164+
##### Kubelet Managed Identity
165+
164166
When the kubelet managed identity has access to ACR, source-controller running
165167
on it will also have access to ACR.
166168

169+
##### Workload Identity
170+
171+
When using Workload Identity to enable access to ACR, add the following patch to
172+
your bootstrap repository, in the `flux-system/kustomization.yaml` file:
173+
174+
```yaml
175+
apiVersion: kustomize.config.k8s.io/v1beta1
176+
kind: Kustomization
177+
resources:
178+
- gotk-components.yaml
179+
- gotk-sync.yaml
180+
patches:
181+
- patch: |-
182+
apiVersion: v1
183+
kind: ServiceAccount
184+
metadata:
185+
name: source-controller
186+
namespace: flux-system
187+
annotations:
188+
azure.workload.identity/client-id: <AZURE_CLIENT_ID>
189+
labels:
190+
azure.workload.identity/use: "true"
191+
- patch: |-
192+
apiVersion: apps/v1
193+
kind: Deployment
194+
metadata:
195+
name: source-controller
196+
namespace: flux-system
197+
labels:
198+
azure.workload.identity/use: "true"
199+
spec:
200+
template:
201+
metadata:
202+
labels:
203+
azure.workload.identity/use: "true"
204+
```
205+
206+
To use Workload Identity, you have to install the Workload Identity
207+
mutating webhook and create an identity that has access to ACR. Next, establish
208+
a federated identity between the source-controller ServiceAccount and the
209+
identity. Patch the source-controller Pod and ServiceAccount as shown in the patch
210+
above. Please take a look at this [guide](https://azure.github.io/azure-workload-identity/docs/quick-start.html#6-establish-federated-identity-credential-between-the-identity-and-the-service-account-issuer--subject).
211+
212+
##### AAD Pod Identity
167213
When using aad-pod-identity to enable access to ACR, add the following patch to
168214
your bootstrap repository, in the `flux-system/kustomization.yaml` file:
169215

0 commit comments

Comments
 (0)