-
Notifications
You must be signed in to change notification settings - Fork 356
[IB] doc: add identity binding example setup #5430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bcho
wants to merge
19
commits into
master
Choose a base branch
from
hbc/ib-demo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
670e223
doc: add identity binding example setup
bcho f590ebd
fix: typo
bcho 0e030a4
chore: bump image
bcho 4903f75
Update examples/identity-binding/pod.yaml
bcho 9f58ebc
Update examples/identity-binding/README.md
bcho b90957d
Update examples/identity-binding/README.md
bcho d043410
Update examples/identity-binding/README.md
bcho 7ec2a7b
Update examples/identity-binding/README.md
bcho 12973b5
Update examples/identity-binding/README.md
bcho 42ea31a
Update examples/identity-binding/README.md
bcho 37a3710
Update examples/identity-binding/README.md
bcho 754e310
Update examples/identity-binding/README.md
bcho 5eb2e1f
Update examples/identity-binding/pod.yaml
bcho 2ab6f53
Update examples/identity-binding/README.md
bcho 9422a33
Update examples/identity-binding/README.md
bcho 96ca0e0
Update examples/identity-binding/README.md
bcho 9479a11
Update examples/identity-binding/README.md
bcho 91a7ac1
Update examples/identity-binding/README.md
bcho 2598eec
Update examples/identity-binding/README.md
bcho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Identity Binding Example | ||
|
|
||
| This example demonstrates how to use the Identity Binding feature in an AKS cluster. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Please ensure you have the latest preview version of Azure CLI installed. You can follow the instructions [here](https://learn.microsoft.com/cli/azure/aks/extension?view=azure-cli-latest). | ||
| - Ensure your subscription has the `Microsoft.ContainerService/IdentityBinding` feature flag enabled. | ||
| - Ensure your cluster is enabled with [AKS Workload Identity](https://learn.microsoft.com/azure/aks/workload-identity-deploy-cluster) feature. | ||
|
|
||
|
|
||
| > [!NOTE] | ||
| > Identity Binding requires preview version of AKS workload identity webhook. Please confirm the following output from the command: | ||
| > | ||
| > ```bash | ||
| > kubectl -n kube-system get pods -l azure-workload-identity.io/system=true -o yaml | grep v1.6.0 | ||
| > image: mcr.microsoft.com/oss/v2/azure/workload-identity/webhook:v1.6.0-alpha.1 | ||
| > ``` | ||
| > | ||
| > Seeing `v1.6.0-alpha.1` in the image tag confirms that the preview version of webhook is installed. | ||
|
|
||
| ## Steps | ||
|
|
||
| The following steps assume you have already created an AKS cluster `<cluster-name>` and managed identity `<mi-name>` under resource group `<rg-name>` and subscription `<subscription-id>`. | ||
|
|
||
| We will reference the client id of the managed identity with `<mi-client-id>` in the following steps. | ||
|
|
||
| ### 1. Create identity binding resource | ||
|
|
||
|
|
||
| ```bash | ||
| az aks identity-binding create \ | ||
| --resource-group <rg-name> \ | ||
| --cluster-name <cluster-name> \ | ||
| --name my-first-ib \ | ||
| --managed-identity-resource-id /subscriptions/<subscription-id>/resourceGroups/<rg-name>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<mi-name> | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > Successful creation of identity binding resource will result in a federated managed identity credential being created in the managed identity with name `aks-identity-binding`. This federated managed identity credential is required by identity binding feature to work. | ||
|
||
|
|
||
| ### 2. Configure in-cluster access via ClusterRole and ClusterRoleBinding | ||
|
|
||
| The identity binding feature uses Kubernetes RBAC to control which pods can access which managed identities via a cluster role with the verb `use-managed-identity`. In this step, we will create a cluster role and cluster role binding to grant the `default` service account in the `default` namespace permission to access the managed identity created in the previous step. | ||
|
|
||
| Before deploying the `cluster-role-and-cluster-role-binding.yaml`, please make sure to replace the `<mi-client-id>` placeholder in the file with the actual client ID of the managed identity. | ||
|
|
||
| ```bash | ||
| kubectl apply -f cluster-role-and-cluster-role-binding.yaml | ||
| clusterrole.rbac.authorization.k8s.io/my-first-ib-cr created | ||
| clusterrolebinding.rbac.authorization.k8s.io/my-first-ib-crb created | ||
| ``` | ||
|
|
||
| ### 3. Deploy sample application Pod | ||
|
|
||
| Following the same step from the [Azure workload identity documentation](https://learn.microsoft.com/azure/aks/workload-identity-deploy-cluster#grant-permissions-to-access-azure-key-vault), we will deploy a sample pod that uses the managed identity to access a secret from an Azure Key Vault. | ||
| Please make sure to replace the `<your-keyvault-name>` and `REPLACE_WITH_SECRET_NAME` placeholders in the `pod.yaml` file with your actual Key Vault name and secret name. | ||
|
|
||
| ```bash | ||
| kubectl apply -f pod.yaml | ||
| pod/my-first-ib-pod created | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > Compared with the original workload identity example, the following highlights the differences when using the identity binding feature: | ||
| > ```diff | ||
| > kind: Pod | ||
| > metadata: | ||
| > labels: | ||
| > azure.workload.identity/use: "true" | ||
| > + annotations: | ||
| > + azure.workload.identity/use-identity-binding: "true" | ||
| > ``` | ||
|
|
||
| ### 4. Verify the sample application Pod | ||
|
|
||
| ```bash | ||
| kubectl logs my-first-ib-pod | ||
| I1107 20:03:42.865180 1 main.go:77] "successfully got secret" secret="Hello!" | ||
| ``` | ||
22 changes: 22 additions & 0 deletions
22
examples/identity-binding/cluster-role-and-cluster-role-binding.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: my-first-ib-cr | ||
| rules: | ||
| - verbs: ["use-managed-identity"] | ||
| apiGroups: ["cid.wi.aks.azure.com"] | ||
bcho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resources: ["<mi-client-id>"] | ||
bcho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: my-first-ib-crb | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: my-first-ib-cr | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: default | ||
| namespace: default | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: my-first-ib-pod | ||
| namespace: default | ||
| labels: | ||
| azure.workload.identity/use: "true" | ||
| annotations: | ||
| azure.workload.identity/use-identity-binding: "true" | ||
| spec: | ||
| serviceAccount: default | ||
| containers: | ||
| - name: azure-sdk | ||
| # source code: https://github.com/Azure/azure-workload-identity/blob/feature/custom-token-endpoint/examples/identitybinding-msal-go/main.go | ||
| image: ghcr.io/bahe-msft/azure-workload-identity/identitybinding-msal-go@sha256:d8a262e2aed015790335650f1d1221cbf9270ee209993337e4c6055b39dd00ae | ||
| env: | ||
| - name: KEYVAULT_URL | ||
| # Replace YOUR_KEYVAULT_NAME with your actual Azure Key Vault name | ||
| value: https://YOUR_KEYVAULT_NAME.vault.azure.net/ | ||
| - name: SECRET_NAME | ||
| # Replace with the name of your Key Vault secret | ||
| value: REPLACE_WITH_SECRET_NAME | ||
bcho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| restartPolicy: Never | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.