The ack-pod-identity-webhook add-on simplifies the use of RAM Roles for Service Accounts (RRSA) in Container Compute Service. It automatically injects required configurations, such as OIDC token mounts and environment variables, into your application pods to eliminate manual configuration. This topic describes the features, usage, and changelog of the ack-pod-identity-webhook add-on.
How it works
The following figure shows the architecture of the ack-pod-identity-webhook add-on.
Example
In this example, you deploy an application that uses the RRSA feature to assume a specified role and retrieve a list of clusters. This example uses the following resources:
-
Namespace: rrsa-demo
-
Service account: demo-sa
-
RAM role: ack-pod-identity-webhook-demo
When you add the pod-identity.alibabacloud.com/injection: 'on' label to the namespace where your pod resides, the ack-pod-identity-webhook add-on automatically injects the necessary configurations into the pod based on the annotations of the pod's service account. Follow these steps to deploy the example.
-
Enable the RRSA feature for your cluster.
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Cluster Information.
-
On the cluster details page, click the Basic Information tab. In the Security and Auditing section, click Enable next to RRSA OIDC.
-
In the Enable RRSA dialog box, click OK.
Note-
Enabling the RRSA feature takes about 2 to 3 minutes. If the Cluster Status remains in the Updating state, click the
button in the upper-right corner of the page to refresh. -
When the cluster status changes from Updating to Running, the RRSA feature is enabled for the cluster. You can hover over Enabled next to RRSA OIDC to view the URL and ARN of the OIDC provider.
-
-
-
Install the ack-pod-identity-webhook add-on.
-
In the left-side navigation pane, choose .
-
Click the Security tab, find the ack-pod-identity-webhook add-on, and then click Install.
-
In the dialog box that appears, confirm the add-on information and click OK.
-
-
Create a RAM role named
ack-pod-identity-webhook-demo.-
Log on to the RAM console using your Alibaba Cloud account.
-
In the left-side navigation pane, choose . On the Role page, click Create Role.
-
In the Create Role panel, click Switch to Policy Editor to create the role.
-
This example uses the Visual Editor. Configure the role as described in the following table and click OK.
Parameter
Description
Effect
The default value is Allow.
Principal
Select Identity Provider and click Edit.
Select OIDC as the identity provider type, and then select the identity provider for your cluster, such as ack-rrsa-<cluster_id>. Replace <cluster_id> with your cluster ID.
Action
The sts:AssumeRole action is selected by default.
Condition
-
oidc:iss: This condition is automatically added after you select the identity provider. Keep the default value.
-
oidc:aud: This condition is automatically added after you select the identity provider. Keep the default value.
-
oidc:sub: Manually Add Condition.
-
Key:
oidc:sub -
Operator:
StringEquals -
Value: Use the format system:serviceaccount:<namespace>:<serviceAccountName>.
-
<namespace>: the namespace where the application resides.
-
<serviceAccountName>: the name of the service account.
Based on the information for the sample application, enter
system:serviceaccount:rrsa-demo:demo-sa. -
-
-
-
In the dialog box that appears, enter the role name
ack-pod-identity-webhook-demoand click OK.
-
-
Attach the AliyunCSReadOnlyAccess policy to the RAM role you created. For more information, see Manage permissions for a RAM role.
-
Deploy the sample application.
-
Connect to your cluster. For more information, see Connect to a cluster.
-
Create a file named demo.yaml with the following content.
In the following YAML manifest, the
pod-identity.alibabacloud.com/injection: 'on'label is added to therrsa-demonamespace, and thepod-identity.alibabacloud.com/role-name: ack-pod-identity-webhook-demoannotation is added to thedemo-saservice account. This enables the automatic injection feature of the ack-pod-identity-webhook add-on. For more information about the RRSA demo implementation, see the source code.NoteThe
registry.cn-hangzhou.aliyuncs.com/acs/ack-ram-tool:1.0.0image used in the following example is pulled over the internet. Make sure your cluster has internet access enabled. For more information, see Enable internet access for a cluster.--- apiVersion: v1 kind: Namespace metadata: name: rrsa-demo labels: pod-identity.alibabacloud.com/injection: 'on' --- apiVersion: v1 kind: ServiceAccount metadata: name: demo-sa namespace: rrsa-demo annotations: pod-identity.alibabacloud.com/role-name: ack-pod-identity-webhook-demo --- apiVersion: v1 kind: Pod metadata: name: demo namespace: rrsa-demo spec: serviceAccountName: demo-sa containers: - image: registry.cn-hangzhou.aliyuncs.com/acs/ack-ram-tool:1.0.0 imagePullPolicy: "Always" args: - rrsa - demo name: demo restartPolicy: OnFailure -
Run the following command to deploy the sample application:
kubectl apply -f demo.yaml
-
-
Verify that the ack-pod-identity-webhook add-on automatically injected the required configurations into the application pod.
kubectl -n rrsa-demo get pod demo -o yamlThe output shows that the add-on automatically injected the following configurations into the pod.
Field
Parameter
Description
envALIBABA_CLOUD_ROLE_ARNThe ARN of the RAM role to be assumed.
ALIBABA_CLOUD_OIDC_PROVIDER_ARNThe ARN of the OIDC identity provider.
ALIBABA_CLOUD_OIDC_TOKEN_FILEThe file path that contains the OIDC token.
VolumeMountsrrsa-oidc-tokenMounts the rrsa-oidc-token volume into the container.
Volumesrrsa-oidc-tokenDefines the rrsa-oidc-token volume using a projected service account token.
-
View the application logs.
kubectl -n rrsa-demo logs demoExpected output:
cluster id: c66e40b731ab24f96b36bec5b1a******, cluster name: test-**** cluster id: cbec9a1f7b433470ebe4c900552******, cluster name: test-****
Custom configurations
You can customize the ack-pod-identity-webhook add-on at the namespace, service account, and pod levels.
Namespace configuration
|
Parameter |
Type |
Description |
Code sample |
|
pod-identity.alibabacloud.com/injection |
Label |
Specifies whether to enable automatic configuration injection for pods in this namespace.
|
|
Service account configuration
|
Parameter |
Type |
Description |
Code sample |
|
pod-identity.alibabacloud.com/role-name |
Annotation |
The name of the RAM role associated with this service account. If this annotation is not configured or its value is not a valid RAM role name, configurations are not injected into pods using this service account. |
|
|
pod-identity.alibabacloud.com/service-account-token-expiration |
Annotation |
Specifies the validity period of the OIDC token mounted in pods using this service account.
Note
If this annotation is specified on both a service account and a pod, the pod-level configuration takes precedence and the service account-level configuration is ignored. |
|
Pod configuration
|
Parameter |
Type |
Description |
Code sample |
|
pod-identity.alibabacloud.com/service-account-token-expiration |
Annotation |
Specifies the validity period of the OIDC token that is mounted in this pod.
Note
If this annotation is specified on both a service account and a pod, the pod-level configuration takes precedence and the service account-level configuration is ignored. |
|
|
pod-identity.alibabacloud.com/only-containers |
Annotation |
Injects configurations only into the specified containers within the pod. Use commas (,) to separate multiple container names. Note
If a container name is specified in both the |
|
|
pod-identity.alibabacloud.com/skip-containers |
Annotation |
Injects configurations into all containers within the pod except for the specified ones. Use commas (,) to separate multiple container names. Note
If a container name is specified in both the |
|
RRSA SDK reference
|
Language |
Supported SDK version |
Example |
|
Go |
Alibaba Cloud Credentials for Go 1.2.6 or later |
|
|
Java |
Alibaba Cloud Credentials for Java 0.2.10 or later |
|
|
Python 3 |
Alibaba Cloud Credentials for Python 0.3.1 or later |
|
|
Node.js and TypeScript |
Alibaba Cloud Credentials for TypeScript/Node.js 2.2.6 or later |
Changelog
June 2024
|
Version |
Image address |
Description |
Release date |
Impact |
|
0.1.1 |
registry.cn-hangzhou.aliyuncs.com/acs/ack-pod-identity-webhook:v0.1.1.0-gbddcb74-aliyun |
|
June 30, 2024 |
An exception during the add-on upgrade may cause pod creation to fail. We recommend performing the upgrade during off-peak hours. |