Skip to content

Commit ff7c25b

Browse files
authored
Merge pull request #924 from cvvz/workload_identity
feat: support workload identity
2 parents 185f1fc + 70a1c2d commit ff7c25b

File tree

8 files changed

+192
-0
lines changed

8 files changed

+192
-0
lines changed

charts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ The following table lists the configurable parameters of the latest Azure Blob S
146146
| `node.tolerations` | node pod tolerations | [] |
147147
| `linux.kubelet` | configure kubelet directory path on Linux agent node node | `/var/lib/kubelet` |
148148
| `linux.distro` | configure ssl certificates for different Linux distribution(available values: `debian`, `fedora`) | `debian`
149+
| `workloadIdentity.clientID` | client ID of workload identity | ''
150+
| `workloadIdentity.tenantID` | [optional] If the AAD application or user-assigned managed identity is not in the same tenant as the cluster then set tenantID with the AAD application or user-assigned managed identity tenant ID | ''
149151

150152
## troubleshooting
151153
- Add `--wait -v=5 --debug` in `helm install` command to get detailed error
163 Bytes
Binary file not shown.

charts/latest/blob-csi-driver/templates/csi-blob-controller.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ spec:
1717
labels:
1818
app: {{ .Values.controller.name }}
1919
{{- include "blob.labels" . | nindent 8 }}
20+
{{- if .Values.workloadIdentity.clientID }}
21+
azure.workload.identity/use: "true"
22+
{{- end }}
2023
{{- if .Values.podLabels }}
2124
{{- toYaml .Values.podLabels | nindent 8 }}
2225
{{- end }}

charts/latest/blob-csi-driver/templates/csi-blob-node.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ spec:
2020
labels:
2121
app: {{ .Values.node.name }}
2222
{{- include "blob.labels" . | nindent 8 }}
23+
{{- if .Values.workloadIdentity.clientID }}
24+
azure.workload.identity/use: "true"
25+
{{- end }}
2326
{{- if .Values.podLabels }}
2427
{{- toYaml .Values.podLabels | nindent 8 }}
2528
{{- end }}

charts/latest/blob-csi-driver/templates/serviceaccount-csi-blob-controller.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ metadata:
66
namespace: {{ .Release.Namespace }}
77
labels:
88
{{- include "blob.labels" . | nindent 4 }}
9+
{{- if .Values.workloadIdentity.clientID }}
10+
azure.workload.identity/use: "true"
11+
annotations:
12+
azure.workload.identity/client-id: {{ .Values.workloadIdentity.clientID }}
13+
{{- if .Values.workloadIdentity.tenantID }}
14+
azure.workload.identity/tenant-id: {{ .Values.workloadIdentity.tenantID }}
15+
{{- end }}
16+
{{- end }}
917
{{- end -}}

charts/latest/blob-csi-driver/templates/serviceaccount-csi-blob-node.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ metadata:
66
namespace: {{ .Release.Namespace }}
77
labels:
88
{{- include "blob.labels" . | nindent 4 }}
9+
{{- if .Values.workloadIdentity.clientID }}
10+
azure.workload.identity/use: "true"
11+
annotations:
12+
azure.workload.identity/client-id: {{ .Values.workloadIdentity.clientID }}
13+
{{- if .Values.workloadIdentity.tenantID }}
14+
azure.workload.identity/tenant-id: {{ .Values.workloadIdentity.tenantID }}
15+
{{- end }}
16+
{{- end }}
917
{{- end -}}

charts/latest/blob-csi-driver/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,9 @@ driver:
165165
linux:
166166
kubelet: /var/lib/kubelet
167167
distro: debian
168+
169+
workloadIdentity:
170+
clientID: ""
171+
# [optional] If the AAD application or user-assigned managed identity is not in the same tenant as the cluster
172+
# then set tenantID with the application or user-assigned managed identity tenant ID
173+
tenantID: ""

docs/workload-identity.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# How to Use workload identity with Blob CSI driver
2+
3+
## Prerequisites
4+
5+
This document is mainly refer to [Azure AD Workload Identity Quick Start](https://azure.github.io/azure-workload-identity/docs/quick-start.html). Please Complete the [Installation guide](https://azure.github.io/azure-workload-identity/docs/installation.html) before the following steps.
6+
7+
After you finish the Installation guide, you should have already:
8+
9+
* installed the mutating admission webhook
10+
* obtained your cluster’s OIDC issuer URL
11+
12+
## 1. Export environment variables
13+
14+
```shell
15+
export CLUSTER_NAME="<your cluster name>"
16+
export CLUSTER_RESOURCE_GROUP="<cluster resource group name>"
17+
export LOCATION="<location>"
18+
export OIDC_ISSUER="<your cluster’s OIDC issuer URL>"
19+
20+
# [OPTIONAL] resource group where Blob storage account reside
21+
export AZURE_BLOB_RESOURCE_GROUP="<resource group where Blob storage account reside>"
22+
23+
# environment variables for the AAD application
24+
# [OPTIONAL] Only set this if you're using a Azure AD Application as part of this tutorial
25+
export APPLICATION_NAME="<your application name>"
26+
27+
# environment variables for the user-assigned managed identity
28+
# [OPTIONAL] Only set this if you're using a user-assigned managed identity as part of this tutorial
29+
export USER_ASSIGNED_IDENTITY_NAME="<your user-assigned managed identity name>"
30+
export IDENTITY_RESOURCE_GROUP="<resource group where your user-assigned managed identity reside>"
31+
32+
# Blob CSI Driver Service Account and namespace
33+
export SA_LIST=( "csi-blob-controller-sa" "csi-blob-node-sa" )
34+
export NAMESPACE="kube-system"
35+
```
36+
37+
## 2. Create Blob resource group
38+
39+
If you are using AKS, you can get the resource group where Blob storage class reside by running:
40+
41+
```shell
42+
export AZURE_BLOB_RESOURCE_GROUP="$(az aks show --name $CLUSTER_NAME --resource-group $CLUSTER_RESOURCE_GROUP --query "nodeResourceGroup" -o tsv)"
43+
```
44+
45+
You can also create resource group by yourself, but you must [specify the resource group](https://github.com/cvvz/blob-csi-driver/blob/workload_identity/docs/driver-parameters.md) in the storage class while using Blob CSI driver:
46+
47+
```shell
48+
az group create -n $AZURE_BLOB_RESOURCE_GROUP -l $LOCATION
49+
```
50+
51+
## 3. Create an AAD application or user-assigned managed identity and grant required permissions
52+
53+
```shell
54+
# create an AAD application if using Azure AD Application for this tutorial
55+
az ad sp create-for-rbac --name "${APPLICATION_NAME}"
56+
```
57+
58+
```shell
59+
# create a user-assigned managed identity if using user-assigned managed identity for this tutorial
60+
az group create -n ${IDENTITY_RESOURCE_GROUP} -l $LOCATION
61+
az identity create --name "${USER_ASSIGNED_IDENTITY_NAME}" --resource-group "${IDENTITY_RESOURCE_GROUP}"
62+
```
63+
64+
Grant required permission to the AAD application or user-assigned managed identity, for simplicity, we just assign Contributor role to the resource group where Blob storage class reside:
65+
66+
If using Azure AD Application:
67+
68+
```shell
69+
export APPLICATION_CLIENT_ID="$(az ad sp list --display-name "${APPLICATION_NAME}" --query '[0].appId' -otsv)"
70+
export AZURE_BLOB_RESOURCE_GROUP_ID="$(az group show -n $AZURE_BLOB_RESOURCE_GROUP --query 'id' -otsv)"
71+
az role assignment create --assignee $APPLICATION_CLIENT_ID --role Contributor --scope $AZURE_BLOB_RESOURCE_GROUP_ID
72+
```
73+
74+
if using user-assigned managed identity:
75+
76+
```shell
77+
export USER_ASSIGNED_IDENTITY_OBJECT_ID="$(az identity show --name "${USER_ASSIGNED_IDENTITY_NAME}" --resource-group "${IDENTITY_RESOURCE_GROUP}" --query 'principalId' -otsv)"
78+
export AZURE_BLOB_RESOURCE_GROUP_ID="$(az group show -n $AZURE_BLOB_RESOURCE_GROUP --query 'id' -otsv)"
79+
az role assignment create --assignee $USER_ASSIGNED_IDENTITY_OBJECT_ID --role Contributor --scope $AZURE_BLOB_RESOURCE_GROUP_ID
80+
```
81+
82+
## 4. Establish federated identity credential between the identity and the Blob service account issuer & subject
83+
84+
If using Azure AD Application:
85+
86+
```shell
87+
# Get the object ID of the AAD application
88+
export APPLICATION_OBJECT_ID="$(az ad app show --id ${APPLICATION_CLIENT_ID} --query id -otsv)"
89+
90+
# Add the federated identity credential:
91+
for SERVICE_ACCOUNT_NAME in "${SA_LIST[@]}"
92+
do
93+
cat <<EOF > params.json
94+
{
95+
"name": "${SERVICE_ACCOUNT_NAME}",
96+
"issuer": "${OIDC_ISSUER}",
97+
"subject": "system:serviceaccount:${NAMESPACE}:${SERVICE_ACCOUNT_NAME}",
98+
"description": "Kubernetes service account federated credential",
99+
"audiences": [
100+
"api://AzureADTokenExchange"
101+
]
102+
}
103+
EOF
104+
az ad app federated-credential create --id ${APPLICATION_OBJECT_ID} --parameters @params.json
105+
done
106+
```
107+
108+
If using user-assigned managed identity:
109+
110+
```shell
111+
for SERVICE_ACCOUNT_NAME in "${SA_LIST[@]}"
112+
do
113+
az identity federated-credential create \
114+
--name "${SERVICE_ACCOUNT_NAME}" \
115+
--identity-name "${USER_ASSIGNED_IDENTITY_NAME}" \
116+
--resource-group "${IDENTITY_RESOURCE_GROUP}" \
117+
--issuer "${OIDC_ISSUER}" \
118+
--subject system:serviceaccount:"${NAMESPACE}":"${SERVICE_ACCOUNT_NAME}"
119+
done
120+
```
121+
122+
## 5. Deploy Blob CSI Driver
123+
124+
Deploy storageclass:
125+
126+
```shell
127+
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/blob-csi-driver/master/deploy/example/storageclass-blobfuse.yaml
128+
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/blob-csi-driver/master/deploy/example/storageclass-blob-nfs.yaml
129+
```
130+
131+
Deploy Blob CSI Driver
132+
133+
If using Azure AD Application:
134+
135+
```shell
136+
export CLIENT_ID="$(az ad sp list --display-name "${APPLICATION_NAME}" --query '[0].appId' -otsv)"
137+
export TENANT_ID="$(az ad sp list --display-name "${APPLICATION_NAME}" --query '[0].appOwnerOrganizationId' -otsv)"
138+
helm install blob-csi-driver charts/latest/blob-csi-driver \
139+
--namespace $NAMESPACE \
140+
--set workloadIdentity.clientID=$CLIENT_ID \
141+
--set workloadIdentity.tenantID=$TENANT_ID
142+
```
143+
144+
If using user-assigned managed identity:
145+
146+
```shell
147+
export CLIENT_ID="$(az identity show --name "${USER_ASSIGNED_IDENTITY_NAME}" --resource-group "${IDENTITY_RESOURCE_GROUP}" --query 'clientId' -otsv)"
148+
export TENANT_ID="$(az identity show --name "${USER_ASSIGNED_IDENTITY_NAME}" --resource-group "${IDENTITY_RESOURCE_GROUP}" --query 'tenantId' -otsv)"
149+
helm install blob-csi-driver charts/latest/blob-csi-driver \
150+
--namespace $NAMESPACE \
151+
--set workloadIdentity.clientID=$CLIENT_ID \
152+
--set workloadIdentity.tenantID=$TENANT_ID
153+
```
154+
155+
## 6. Deploy application using Blob CSI driver
156+
157+
```shell
158+
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/blob-csi-driver/master/deploy/example/nfs/statefulset.yaml
159+
kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/blob-csi-driver/master/deploy/example/deployment.yaml
160+
```
161+
162+
Please make sure all the Pods are running.

0 commit comments

Comments
 (0)