The credential-free add-on automates authentication for pulling images, eliminating the need to repeatedly configure imagePullSecrets. This topic describes how to install, configure, and use it, along with important usage notes.
How it works
When you use Container Registry (ACR) as an image source without enabling anonymous image pulling, your ACK cluster must provide a username and password to authenticate each image pull. The common solution is to store these credentials in a Secret, but this approach has several drawbacks:
-
Secrets are Base64-encoded plaintext, which poses a security risk if exposed.
-
You must manually specify
imagePullSecretsfor each workload. -
Secrets cannot be shared across namespaces.
The credential-free add-on works as follows:
-
The add-on obtains temporary credentials from the ACR instance.
-
The add-on saves the temporary credentials to a Secret.
-
The add-on associates the Secret with the ServiceAccounts specified in its configuration.
-
Workloads that use these ServiceAccounts can then automatically pull images by using the temporary credentials stored in the Secret.
The credential-free add-on can manage ServiceAccounts across multiple namespaces and periodically refresh the temporary credentials. This reduces security risks and eliminates the need to manually addimagePullSecrets to your workloads. The credential-free add-on is free of charge.
Add-on comparison
ACK provides the aliyun-acr-credential-helper add-on in two editions: managed and self-managed. You can install only one edition at a time. The following table compares the two editions.
|
Item |
aliyun-acr-credential-helper (managed) |
aliyun-acr-credential-helper (self-managed) |
|
Supported cluster versions |
Version 1.22 or later of ACK managed clusters, ACK serverless clusters, or ACK Edge clusters |
Version 1.20 or later of ACK managed clusters or ACK dedicated clusters |
|
Features |
|
|
To upgrade a cluster, see Manually upgrade a cluster.
Prerequisites
-
Your cluster runs a version supported by the credential-free add-on. For more information, see the preceding table.
-
You have an ACR Enterprise Edition instance.
Important-
The credential-free add-on supports only ACR Enterprise Edition instances and ACR Personal Edition instances created on or before September 8, 2024. If you cannot use the credential-free add-on, see How do I use imagePullSecrets?.
-
-
Permissions are granted to the RAM role used by the credential-free add-on. For more information, see Grant permissions.
-
Network connectivity is established between the ACR Enterprise Edition instance and the ACK cluster.
Use the managed credential-free add-on
Step 1: Install the add-on
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click Add-ons .
-
On the Add-ons page, click the Security tab, find the aliyun-acr-credential-helper (managed) card, and then click Install.
-
On the Install add-on aliyun-acr-credential-helper page, view the AcrInstanceInfo settings and other options. AcrInstanceInfo contains the settings for each ACR instance that is associated with the add-on. The other options are add-on settings. If you do not need to change the namespaces or ServiceAccounts that the add-on monitors, you can keep the default settings.
After the add-on is installed, you can change its settings by clicking Configurations on the aliyun-acr-credential-helper (managed) card on the Add-ons page.
ACR instance association settings:
AcrInstanceInfo
Description
InstanceId
The ID of the ACR instance. You can obtain the ID from the Container Registry console.
ImportantLeave this field blank for ACR Personal Edition instances. This field is required for ACR Enterprise Edition instances.
regionId
The ID of the region where the ACR instance is deployed. You can obtain the ID from the Container Registry console.
ImportantThis parameter is required for cross-region image pulls.
domains
The domain names used by the credential-free add-on to access the ACR instance. By default, this includes all domain names (internet and VPC) of the specified ACR instance. To specify multiple domain names, separate them with commas (,).
Settings for cross-account image pulls
These settings apply to cross-account image pulls. If you do not need this feature, leave the fields blank.
assumeRoleARN
No configuration is required for same-account pulls. For cross-account pulls, see Pull images across accounts.
expireDuration
rrsaRoleARN
rrsaOIDCProviderRoleARN
Step 2: Pull an image
After you install and configure the credential-free add-on, specify a ServiceAccount associated with the add-on when you create a workload. This enables credential-free image pulling.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
serviceAccountName: my-service-account # Specify a ServiceAccount that is associated with the credential-free add-on.
containers:
- name: nginx
image: "******.cn-hangzhou.cr.aliyuncs.com/nginx/nginx:latest" # Specify the ACR image address.
ports:
- containerPort: 80
Use the self-managed credential-free add-on
Step 1: Install the add-on
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click Add-ons .
-
On the Add-ons page, click the Security tab, find the aliyun-acr-credential-helper card, and then click Install.
-
On the Parameters page, select a permission mode from the tokenMode drop-down list and click OK. After the add-on is installed, you need to configure it before you can pull images. For more information, see Step 2: Update the add-on configuration (add an ACR instance).
tokenMode
Description
auto
(Recommended) The add-on detects the cluster creation time and automatically chooses a permission mode. Clusters created before April 3, 2023 use the workerRole mode. Clusters created on or after April 3, 2023 use the managedRole mode.
ImportantVersions of aliyun-acr-credential-helper released on or after April 3, 2023 provide a parameter that allows you to customize the RAM role that the add-on depends on. For more information, see [Product Change] Announcement on changing the permissions required by the aliyun-acr-credential-helper add-on.
managedRole
The add-on uses the AliyunCSManagedAcrRole role authorized in Prerequisites to obtain permissions.
workerRole
The add-on uses the cluster worker RAM role to obtain permissions. You need to grant specific permissions to the worker RAM role.
ImportantSelect this mode if you need to pull images across accounts by assuming a role.
Step 2: Update the add-on configuration
After the credential-free add-on is installed, you need to configure theacr-configuration ConfigMap to add an ACR instance before you can pull images. You can do this by using the console or kubectl.
Console
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the ConfigMaps page, select kube-system from the Namespace drop-down list. Then, click the acr-configuration ConfigMap and modify the settings as described in the following table.
Parameter
Description
watch-namespace
The namespaces where you want to enable credential-free image pulls. The default value isdefault. Set the value toall to enable this feature for all namespaces. To specify multiple namespaces, separate them with commas (,). We recommend that you specify only your business namespaces and avoid using
allor namespaces for cluster system components to prevent disruptions to system image pulls.acr-api-version
Keep the default value.
expiring-threshold
The expiration threshold for credentials in the add-on. The default value is
15m(15 minutes).acr-registry-info
An array of ACR instance information in multi-line YAML string format. Each instance is configured with a set of three parameters.
-
instanceId: The ID of the ACR instance. You can obtain the ID from the Container Registry console.ImportantLeave this field blank for ACR Personal Edition instances. This field is required for ACR Enterprise Edition instances.
-
regionId: The ID of the region where the ACR instance is deployed. You can obtain the ID from the Container Registry console.ImportantThis parameter is required for cross-region image pulls. For an example configuration, see the section below.
-
domains: The domain names used by the credential-free add-on to access the ACR instance. By default, this includes all domain names of the ACR instance specified byinstanceId. To specify multiple domain names, separate them with commas (,).
service-account
The ServiceAccounts associated with the credential-free add-on. To specify multiple ServiceAccounts, separate them with commas (,). If you set the value todefault, the add-on associates with the default ServiceAccount in each specified namespace. If you set the value to
"*", the add-on associates with all ServiceAccounts in the specified namespaces. -
kubectl
-
Run the following command to edit the
acr-configurationConfigMap. Refer to the following table for configuration details.kubectl edit cm acr-configuration -n kube-systemParameter key
Description
Value
service-account
The ServiceAccounts that the credential-free add-on targets.
The default value isdefault.
NoteTo specify multiple ServiceAccounts, separate them with commas (,). If you set the value to
"*", it applies to all ServiceAccounts in the specified namespaces.acr-registry-info
An array of ACR instance information in multi-line YAML string format. Each instance is configured with a set of three parameters.
NoteInstance information parameters:
-
instanceId: The ID of the instance. This is required for Enterprise Edition instances.
-
regionId: Optional. Defaults to the local region.
-
domains: Optional. Defaults to all domain names of the corresponding instance. To specify multiple domain names, separate them with commas (,).
Example configuration for an ACR Enterprise Edition instance:
- instanceId: <cri-instanceId> regionId: "cn-hangzhou" domains: "xxx.com,yyy.com"watch-namespace
The namespaces where you want to enable credential-free image pulls.
The default value isdefault. Set the value toall to enable this feature for all namespaces. To specify multiple namespaces, separate them with commas (,).
NoteWe recommend that you specify only your business namespaces and avoid usingall or namespaces for cluster system components to prevent disruptions to system image pulls.
expiring-threshold
The expiration threshold for locally cached credentials.
The default value is
15m(15 minutes). -
Step 3: Pull an image
After you install and configure the credential-free add-on, specify a ServiceAccount associated with the add-on when you create a workload. This enables credential-free image pulling.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
serviceAccountName: my-service-account # Specify a ServiceAccount that is associated with the credential-free add-on.
containers:
- name: nginx
image: "******.cn-hangzhou.cr.aliyuncs.com/nginx/nginx:latest" # Specify the ACR image address.
ports:
- containerPort: 80
FAQ
Enable immediate use of ServiceAccounts
This feature requires aliyun-acr-credential-helper v23.02.06.1-74e2172-aliyun or later.
When enabled, the credential-free add-on uses a Webhook to monitor ServiceAccount changes in the cluster. When a new ServiceAccount is created, the add-on immediately injects the credential-free Secret. This is useful for scenarios where a ServiceAccount is used immediately after creation, such as when a Helm Chart creates both a ServiceAccount and a Deployment simultaneously. This feature may affect add-on performance and is not recommended for general use.
Managed add-on
To enable this feature, install the acr-credential-helper-webhook add-on in your cluster:
-
On the ACK Clusters page, click the name of your cluster. In the left navigation pane, click Add-ons .
-
On the Add-ons page, click the Security tab, find the acr-credential-helper-webhook (managed) card, and then click Install.
Self-managed add-on
To enable this feature, add the following fields to the acr-configuration ConfigMap:
data:
webhook-configuration: |
enable: true
failure-policy: Ignore
timeout-seconds: 10
|
Parameter |
Description |
|
|
Specifies whether to enable the Webhook feature.
|
|
|
The policy for handling exceptions during ServiceAccount creation.
Important
Due to a limitation of the cluster API Server, if |
|
|
The timeout period for a single ServiceAccount creation request. If the timeout is exceeded, the system responds according to the |
Troubleshoot image pull failures
One possible cause is an incorrect credential-free add-on configuration, for example:
-
The instance information configured in the credential-free add-on does not match the ACR instance.
-
The image address used for pulling does not match the domain name specified in the add-on's instance information.
Follow the steps in this topic to troubleshoot the issue.
If the add-on is configured correctly but image pulling still fails, it may be due to a conflict between a manually specifiedimagePullSecrets field in the workload YAML and the credential-free add-on. To resolve this, manually remove theimagePullSecrets field and recreate the Pod.
How do I use imagePullSecrets?
ACR Personal Edition instances created on or after September 9, 2024 do not support the credential-free add-on. For these instances, we recommend that you store the username and password in a Secret and reference it in theimagePullSecrets field.
-
The credential-free add-on is incompatible with a manually specified
imagePullSecretsfield. -
The Secret must be in the same namespace as the workload.
Related topics
-
To pull images across accounts by using the credential-free add-on, see Pull images across accounts.
-
For the change history of the credential-free add-on, see aliyun-acr-credential-helper.