Elastic Container Instance (ECI) can pull images from Container Registry (ACR) without secrets, improving efficiency and security. This topic describes how to enable this secret-free access.
Background information
Alibaba Cloud Container Registry (ACR) is available in Personal and Enterprise editions. The Enterprise Edition is an enterprise-grade platform for managing cloud-native application artifacts. It provides lifecycle management for container images, Helm Chart, and OCI-compliant artifacts. It is suitable for large-scale business deployments and helps enterprises reduce delivery complexity. For more information, see Introduction to Container Registry (ACR).
When you create an ECI instance or an image cache using an ACR image, you can configure secret-free access. This simplifies the process, improves efficiency, and enhances security by avoiding credential leaks.
Note
Secret-free pulling is not supported for non-ACR images, such as Docker images.
Prerequisites
Before you can pull ACR images without secrets, complete the following tasks:
-
Create an ACR instance and configure its image repositories and images.
-
If you use an ACR Enterprise Edition instance, you must configure network access controls.
By default, new ACR Enterprise Edition instances are disconnected from all networks. You must configure an access control list (ACL) to allow access from the internet or a Virtual Private Cloud (VPC).
Configuration
Secret-free image pulling is supported differently depending on the ACR instance type and whether the instance and ECI resource are in the same Alibaba Cloud account.
|
Account scenario
|
ACR type
|
Support
|
|
Same-account
|
|
Enabled by default. You can configure a RAM role to restrict the scope of secret-free access.
|
|
Same-account
|
Enterprise Edition (custom domain name)
|
Not enabled by default. You must specify the ACR instance to enable secret-free access.
|
|
Cross-account
|
-
Personal Edition
-
Enterprise Edition
|
Not enabled by default. You must configure a RAM role to enable secret-free access.
|
Choose the configuration that matches your account and ACR instance setup.
Restrict access with a RAM role
When an ACR instance and an ECI resource are in the same Alibaba Cloud account, secret-free access is enabled by default for Personal Edition instances and for Enterprise Edition instances that use a default domain name. You can optionally configure a Resource Access Management (RAM) role to restrict this access, for example, to allow pulls from only a specific ACR instance.
Note
By default, ECI uses the service-linked role AliyunServiceRoleForECI to access other cloud services when creating ECI resources. This role includes permissions to pull images from all Personal Edition ACR instances and Enterprise Edition ACR instances that use a default domain name within the same account, and does not allow for fine-grained control.
This configuration consists of two steps.
Step 1: Create and authorize a RAM role
-
Create a RAM role for a trusted Alibaba Cloud service. For more information, see Create a RAM role for a trusted Alibaba Cloud service.
Note the following parameters:
-
Principal type: Cloud Service
-
Principal name: Elastic Container Instance
-
Role name: acr-test (example)
-
Create a custom permission policy. For more information, see Create a custom permission policy.
The following policy allows image pulls only from the specified ACR instance. For more information about how to write a permission policy, see Policy elements.
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cr:Get*",
"cr:List*"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"cr:Pull*"
],
"Resource": [
"acs:cr:cn-hangzhou:1609982529******:instance/cri-nwj395hgf6f3****"
]
}
]
}
-
Attach the custom permission policy to the RAM role. For more information, see Grant permissions to a RAM role.
-
Find the new acr-test role and click its name to open the details page. Verify the permissions and get the ARN.
In the Basic Information section, find the ARN field (formatted as acs:ram::<AccountID>:role/acr-test) and click the copy button next to it. On the Permissions tab, verify that the custom policy acr is attached.
Step 2: Specify the RAM role
When calling the CreateContainerGroup operation to create an ECI instance or the CreateImageCache operation to create an image cache, set the AcrRegistryInfo.N.ArnService parameter to specify the RAM role to use for creating the resource. The parameter is described in the following table. For more information, see CreateContainerGroup and CreateImageCache.
|
Parameter
|
Type
|
Example
|
Description
|
|
AcrRegistryInfo.N.ArnService
|
string
|
acs:ram::1609982529******:role/acr-test
|
The ARN of the RAM role in the Alibaba Cloud account that owns the ECI resource.
|
The following example shows how to pass parameters via the OpenAPI to create an ECI instance:
ContainerGroupName=test-acr
#Container
Container.1.Name=test
Container.1.Image=test****-registry.cn-hangzhou.cr.aliyuncs.com/eci_test/nginx:1.0
#AcrRegistryInfo
AcrRegistryInfo.1.ArnService=acs:ram::1609982529******:role/acr-test
Specify an ACR Enterprise instance
If an ACR Enterprise Edition instance uses a custom domain name and belongs to the same Alibaba Cloud account as the ECI resource, you must specify the ACR instance to enable secret-free access.
API
When you call the CreateContainerGroup API to create an ECI instance or the CreateImageCache API to create an image cache, you can set AcrRegistryInfo-related parameters to specify an ACR instance. The following table describes these parameters. For more information, see CreateContainerGroup and CreateImageCache.
|
Parameter
|
Type
|
Example
|
Description
|
|
AcrRegistryInfo.N.RegionId
|
string
|
cn-beijing
|
The region of the ACR Enterprise Edition instance.
This parameter is required if the ACR Enterprise Edition instance and the ECI resource are in different regions.
|
|
AcrRegistryInfo.N.InstanceId
|
string
|
cri-nwj395hgf6f3****
|
The ID of the ACR Enterprise Edition instance.
This parameter is required if the ACR Enterprise Edition instance uses a custom domain name.
|
The following examples show how to pass parameters via the OpenAPI to create an ECI instance:
-
Example 1: Specify only the ACR instance ID
ContainerGroupName=test
#Container
Container.1.Name=c1
Container.1.Image=test****-registry.example.com/eci_test/nginx:1.0
#AcrRegistryInfo
AcrRegistryInfo.1.InstanceId=cri-nwj395hg********
-
Example 2: Specify the region and ACR instance ID
ContainerGroupName=test
#Container
Container.1.Name=c1
Container.1.Image=test****-registry.example.com/eci_test/nginx:1.0
Container.2.Name=c2
Container.2.Image=test****-registry.example.com/eci_test/busybox:1.0
Container.2.Command=sleep
Container.2.Arg=3600
#AcrRegistryInfo
AcrRegistryInfo.1.RegionId=cn-beijing
AcrRegistryInfo.1.InstanceId=cri-nwj395hg********
Console
When creating an ECI instance from the ECI buy page, navigate to the Container Configuration section. From there, select an image for a container and use the Enterprise Image tab to specify an image from an ACR Enterprise Edition instance.
In the Enterprise Image dialog box, configure the Container Registry instance (CRI) information, including the Region and Instance Name. Then, select the Image Repository and Domain Name, and click OK.
Note
You cannot specify an image from an ACR Enterprise Edition instance when you create an image cache in the console.
Cross-account access with RAM roles
If the ACR instance and the ECI resource belong to different Alibaba Cloud accounts, you must configure and authorize RAM roles in both accounts to enable secret-free access.
Step 1: Create and authorize RAM roles
-
In Account A, which owns the ECI resource, create and authorize a RAM role.
-
Create a RAM role for a trusted Alibaba Cloud service. For more information, see Create a RAM role for a trusted Alibaba Cloud service.
Note the following parameters:
-
Principal type: Cloud Service
-
Principal name: Elastic Container Instance
-
Role name: role-assume (example)
-
Grant the role-assume role permissions to call the AssumeRole operation of Security Token Service (STS). For more information, see Grant permissions to a RAM role.
Attach the AliyunSTSAssumeRoleAccess system policy.
-
Find the newly created role-assume role, click its name to go to the details page, and then verify the permissions and trust policy and obtain the ARN.
-
Permissions and ARN
The ARN of the RAM role is acs:ram::<AccountID>:role/role-assume. The role is granted the AliyunSTSAssumeRoleAccess system policy, which allows it to call the STS AssumeRole operation.
-
Trust policy
{
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": [
"eci.aliyuncs.com"
]
}
}
],
"Version": "1"
}
-
In Account B, which owns the ACR instance, create and authorize a RAM role.
-
Create a RAM role for a trusted Alibaba Cloud account. For more information, see Create a RAM role for a trusted Alibaba Cloud account.
Note the following parameters:
-
Principal type: Alibaba Cloud Account
-
Principal name: Other Alibaba Cloud Account. Enter the ID of Account A, which owns the ECI resource.
-
Role name: role-acr (example)
-
Grant the role-acr role permissions to pull ACR images. For more information, see Grant permissions to a RAM role.
Attach the AliyunContainerRegistryFullAccess system policy.
-
Modify the trust policy to allow the role-assume role to assume the role-acr role. For more information, see Modify the trust policy of a RAM role.
By default, the role-acr role can be assumed by any authorized RAM user or RAM role in Account A. We recommend that you modify the trust policy for precise authorization.
In the Principal section, change the value of the RAM field to the ARN of the role-assume role. This ensures that only the role-assume role can assume the role-acr role. Example:
"Principal": {
"RAM": [
"acs:ram::1609982529******:role/role-assume"
]
}
-
Verify the permissions and trust policy, and obtain the ARN.
-
Permissions and ARN
The ARN of the role-acr role is acs:ram::<AccountID>:role/role-acr. You can click the copy button to copy the value. On the Permissions tab, verify that the AliyunContainerRegistryFullAccess system policy is attached and the resource scope is at the account level.
-
Trust policy
{
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"RAM": ["acs:ram::10051309xxxx:role/role-assume"]
}
}
],
"Version": "1"
}
Step 2: Specify the RAM roles
When you call the CreateContainerGroup or CreateImageCache operation, you can set AcrRegistryInfo parameters to specify an ACR instance from another Alibaba Cloud account. Note the following:
-
If the ACR instance belongs to another Alibaba Cloud account, you must set the ArnService and ArnUser parameters to specify the RAM roles for permission configuration.
-
If the ACR Enterprise Edition instance uses a custom domain name, you must also set the InstanceId parameter.
For more information, see CreateContainerGroup and CreateImageCache.
|
Parameter
|
Type
|
Example
|
Description
|
|
AcrRegistryInfo.N.ArnService
|
string
|
acs:ram::1609982529******:role/role-assume
|
The ARN of the RAM role in the account that owns the ECI resource.
|
|
AcrRegistryInfo.N.ArnUser
|
string
|
acs:ram::1298452580******:role/role-acr
|
The ARN of the RAM role in the account that owns the ACR instance.
|
|
AcrRegistryInfo.N.RegionId
|
string
|
cn-beijing
|
The region of the ACR Enterprise Edition instance.
This parameter is required if the ACR Enterprise Edition instance and the ECI resource are in different regions.
|
|
AcrRegistryInfo.N.InstanceId
|
string
|
cri-nwj395hgf6f3****
|
The ID of the ACR Enterprise Edition instance.
This parameter is required if the ACR Enterprise Edition instance uses a custom domain name.
|
The following example shows how to pass parameters via the OpenAPI to create an ECI instance:
ContainerGroupName=test-acr
#Container
Container.1.Name=test
Container.1.Image=test****-registry.cn-hangzhou.cr.aliyuncs.com/eci_test/nginx:1.0
#AcrRegistryInfo
AcrRegistryInfo.1.ArnService=acs:ram::1609982529******:role/role-assume
AcrRegistryInfo.1.ArnUser=acs:ram::1298452580******:role/role-acr