Access secrets from multi-cloud workloads
For virtual machines and Kubernetes workloads deployed on AWS, GCP, and Azure, reading secrets from KMS typically requires storing an Alibaba Cloud AccessKey on the application side, which raises concerns about distribution, rotation, and leakage. Multi-cloud access allows a workload to use the identity that it already has on its cloud platform (the AWS EC2 instance identity document, or the OIDC tokens issued by Kubernetes clusters and virtual machines on each cloud) directly as the authentication method of an application access point (AAP). A workload that carries the identity token issued by its cloud platform can pass KMS identity verification, and no long-term credentials need to be stored in the application.
Multi-cloud access overview
How it works
KMS multi-cloud access uses a three-layer identity authentication mechanism to achieve fine-grained access control. Authentication is based on temporary identity tokens throughout the process. Applications do not need to embed or manage long-term AccessKeys, which eliminates the risk of key leakage from the root.
-
Authentication adaptation layer: After you specify the cloud provider and workload type in the console, KMS automatically matches the corresponding underlying authentication protocol.
-
Identity binding layer: Configure identity binding rules (Principal) in the application access point (AAP) to explicitly define the principal identities that are allowed to access.
-
Dynamic verification layer: KMS verifies each request in real time, validates the identity token issued by the cloud platform, and compares the token claims with the binding rules item by item. Access is allowed only when all items match.
Benefits
-
AccessKey-free access: Workloads access KMS in a zero-trust manner by using native identity authentication, which eliminates the risk of AccessKey leakage.
-
Zero cryptographic configuration: Administrators only need to configure the access rules between workloads and KMS resources. No complex cryptographic configuration is required.
-
Automatic rotation: Secrets stored in KMS can be automatically rotated. The credentials used to access KMS are dynamically updated, and no permanent credentials exist across the entire business link.
-
Unified multi-cloud access: A single integration solution provides unified application access for Alibaba Cloud, AWS, GCP, Azure, and self-managed Kubernetes environments.
Configuration process
-
Enable Multi-Cloud Identity Management: When you go to the Multi-cloud Access page of the KMS console for the first time, create a managed identity authentication instance.
-
Create an application access point: Select the cloud provider, workload type, and authentication method, enter the identity binding fields, and then configure the permission policy.
-
Application access: At runtime, the workload obtains an identity token from its cloud platform and calls KMS with the token. After the verification succeeds, the workload can access secrets based on the permission policy.
Supported scope
|
Cloud provider |
Workload Type |
Authentication method |
Token type |
|
AWS |
EC2 instance |
|
PKCS7 signature of the instance identity document. |
|
EKS cluster |
|
ServiceAccount OIDC token. |
|
|
GCP |
VM instance |
|
Instance identity OIDC token. |
|
GKE cluster |
|
ServiceAccount OIDC token. |
|
|
Azure |
VM instance |
|
Managed identity OIDC token. |
|
AKS cluster |
|
ServiceAccount OIDC token. |
|
|
IDC |
Kubernetes cluster in a self-managed or IDC environment |
|
ServiceAccount OIDC token. |
GCP workloads (VM instances and GKE clusters) are currently supported only in KMS regions outside the Chinese mainland. The IDaaS service in Chinese mainland regions cannot be reached due to GCP network restrictions. Therefore, you cannot create access points of the GCP type in Chinese mainland regions.
Step 1: Enable multi-cloud access
-
Log on to the Key Management Service console. In the left-side navigation pane, choose .
-
Click Enable Now on the guide page. In the Enable Multi-Cloud Identity Management dialog box, confirm the information and click Confirm Enable. The managed identity authentication instance is deployed and billed as follows:
-
Deployment location: determined by the selected region. The instance is deployed in China (Hangzhou) (cn-hangzhou) for Chinese mainland regions, and in Singapore (ap-southeast-1) for regions outside the Chinese mainland.
-
Fees: The managed identity authentication instance itself is free of charge.
-
-
While the enablement is in progress, the system completes Create Identity Authentication Managed Instance and Initialize Authentication Service Configuration.
NoteThe process is expected to take about 3 minutes. Please wait patiently.
Step 2: Create an access point
Multi-cloud workloads cannot access Alibaba Cloud KMS by default. After public network access is enabled, non-Alibaba Cloud environments (AWS/GCP/Azure/IDC) can connect to KMS through the public endpoint. Make sure that security group and network ACL rules are configured.
Select resources and configure authentication information
-
Log on to the Key Management Service console. In the left-side navigation pane, choose .
-
On the Multi-cloud Access page, click Add Multi-Cloud Access and select Cloud Provider. Currently, only AWS, GCP, Azure, or IDC (self-managed Kubernetes cluster) can be selected.
-
Configure the authentication information: Different cloud providers and workload types require different authentication information. For field descriptions, see the tab of each cloud provider below.
AWS
-
EC2 Instance
-
AWS Account ID: The AWS account ID.
-
Region: The region where the server resides.
-
Instance ID List: The server instance ID. Click Add to add multiple servers.
-
-
EKS Cluster
-
AWS Account ID: The AWS account ID.
-
Region: The region where the cluster resides.
-
Cluster Name: The name of the EKS cluster.
-
Namespace: The Namespace in the cluster.
-
Service Account: The name of the ServiceAccount used by the workload in the cluster.
-
Pod Name Prefix: The Pod name prefix, which is used to further restrict the workloads that can access.
-
IssuerURL: You can obtain it by running aws eks describe-cluster --name <cluster> --query "cluster.identity.oidc.issuer".
-
GCP
NoteGCP workloads (VM instances and GKE clusters) are currently supported only in KMS regions outside the Chinese mainland. You cannot create access points of the GCP type in Chinese mainland regions.
-
VM Instance
-
GCP Account ID: The numeric GCP account ID.
-
Project ID: The GCP Project ID.
-
Instances: The instance information, including Zone, Instance ID, and Instance Name. Click Add to configure multiple instances.
-
IssuerURL (optional): The OIDC Issuer URL. The default value is
https://accounts.google.com.
-
-
GKE Cluster
-
GCP Account ID: The numeric GCP account ID.
-
Project ID: The GCP Project ID.
-
Region: The location of the cluster.
-
Cluster Name: The name of the GKE cluster.
-
Namespace: The Namespace in the cluster.
-
Service Account: The name of the ServiceAccount used by the workload in the cluster.
-
Pod Name Prefix: The Pod name prefix, which is used to further restrict the workloads that can access.
-
IssuerURL: The OIDC Issuer URL, which can be obtained from the GKE cluster details. The default value is automatically filled in as
https://container.googleapis.com/v1/projects/<project>/locations/<location>/clusters/<clusterName>
-
Azure
-
VM Instance
-
Azure Tenant ID: The Azure tenant ID.
-
Subscription ID: The Azure subscription ID.
-
Resource Group Name: The name of the resource group to which the virtual machine belongs.
-
VM Name List: The virtual machine name. Click Add to configure multiple virtual machines.
-
Issuer URL (optional): The managed identity OIDC Issuer URL. If you leave it blank, the value is automatically derived as
https://sts.windows.net/<tenant ID>/after you enter the Azure Tenant ID.
-
-
AKS Cluster
-
Azure Tenant ID: The Azure tenant ID.
-
Subscription ID: The Azure subscription ID.
-
Resource Group Name: The name of the resource group to which the AKS cluster belongs.
-
Cluster Name: The name of the AKS cluster.
-
Namespace: The Namespace in the cluster.
-
Service Account: The name of the ServiceAccount used by the workload in the cluster.
-
Pod Name Prefix: The Pod name prefix, which is used to further restrict the workloads that can access.
-
Issuer URL: The OIDC Issuer URL. You can obtain it by running az aks show -n <cluster> -g <rg> --query oidcIssuerProfile.issuerUrl -o tsv.
-
IDC
-
Cluster Name: The name of the self-managed Kubernetes cluster.
-
Namespace: The Namespace in the cluster.
-
Service Account: The name of the ServiceAccount used by the workload in the cluster.
-
Pod Name Prefix: The Pod name prefix, which is used to further restrict the workloads that can access.
-
IssuerURL: The OIDC Issuer URL of the cluster, which must be able to issue OIDC tokens for the cluster ServiceAccount.
-
Permission configuration
After you select resources and click Next, you go to the Permission Configuration page. On this page, you define the scope, name, permissions, and accessible resources of the application access point. The following describes the configuration items:
-
Scope: Select the method used to access KMS. Valid values:
-
Specified KMS instance (KMS dedicated gateway): Access secrets in the specified instance through the KMS instance endpoint.
-
Shared KMS Gateway: Access secrets through the KMS service endpoint.
-
-
Application Access Point Name: The custom name of the application access point (access credential), which facilitates subsequent identification and management.
-
Accessible Resources: Configure the accessible secrets.
ImportantIn KMS dedicated gateway mode, to obtain encrypted secrets, you must have both the secret read permission and the key decrypt permission. Therefore, when you configure an access policy, you must add the secrets and the corresponding encryption keys at the same time.
Default configuration
-
If the scope is set to Specified KMS instance (KMS dedicated gateway):
key/*andsecret/*. All keys and secrets within the current account can be used. -
If the scope is set to Shared KMS Gateway:
secret/*. All secrets within the current account can be used.
Custom access resources
To restrict the Agent to access only specific secrets or keys, configure the resources in one of the following ways:
-
Method 1: Specify specific secrets
-
Clear the default rule: In the Resource Type area on the left, click Selected Resources. In the Accessible Resources list on the right, find
secret/*, and in the Operation column, click Delete. -
Add specified secrets: In the Resource Type area on the left, click Credential. In the Credential list on the right, select the Credential that you want to access.
-
Add the Encryption Key corresponding to the secrets (KMS dedicated gateway):
-
Get the key information: Go to the details page of the selected secret and view the associated encryption key ID. For more information, see Manage and use generic secrets.
-
Grant key permissions: In the Resource Type area on the left, click Key. In the Key list on the right, select the Encryption Key corresponding to the secrets above.
NoteIf you want to simplify the operation and the security policy allows, you can also directly use the default key rule
key/*.
-
-
-
Method 2: Add resources with wildcards.
-
Add specified secrets:
-
In the Resource Type area on the left, click Selected Resources. Above the Accessible Resources list on the right, click Add Custom Resource.
-
In the Add Resource dialog box, enter the Resource Name (with the wildcard /*). For example, if you set it to
secret/rds-ibm*, access is allowed to secrets whose names have the rds-ibm prefix.
-
-
Configure the Encryption Key corresponding to the secrets (KMS dedicated gateway): If these secrets are encrypted by different keys and there are many of them, we recommend that you use the default key rule
key/*.
-
-
Confirm the information
After you complete the permission configuration, click Submit. Before the submission, the console displays the Confirm information dialog box, which summarizes the following content:
-
Resource information
-
Cloud provider: The selected cloud provider, such as AWS, GCP, Azure, or IDC.
-
Workload type: The selected workload type, such as EC2 instance or EKS cluster.
-
Identity binding fields: All identity binding fields that have been entered, listed item by item based on the authentication method, such as AWS account ID, region, and IssuerURL.
-
-
Permission configuration
-
Scope: Displays Shared KMS when the shared gateway is selected; otherwise, displays the specified KMS instance ID.
-
Application access point name: The name of the application access point (access credential) that you create this time.
-
Description: The description of the application access point.
-
RBAC permissions: Automatically set based on the scope.
-
Shared KMS :
SecretUser -
Specified KMS instance (KMS dedicated gateway) :
CryptoServiceKeyUserandCryptoServiceSecretUser.
-
-
Allowed access resources: The configured resource access scope, such as
key/*andsecret/*.
-
After you verify the items one by one, click Submit. The console starts to create the access point and the access policy. After the creation succeeds, the message Access point configured. appears.
Step 3: Application access
After you create an access point, the console provides two access guides: SDK integration and KMS Agent integration.
-
Log on to the Key Management Service console. In the left-side navigation pane, choose .
-
On the resource list page, find the target resource. In the Actions column, click Access Guide and complete the access by following the instructions in the access guide panel. The following two access methods are supported:
-
SDK Integration: The workload directly accesses KMS secrets through Go SDK integration without managing an AccessKey pair. Two configuration methods are supported: inline configuration and configuration file.
-
Agent Access: Access KMS secret resources through request forwarding by KMS Agent. The Agent automatically completes AAP identity authentication and token refresh without managing an AccessKey pair. This method is suitable for non-intrusive integration in multiple languages.
SDK integration
The following two configuration methods are supported:
-
Inline Configuration: Build the IDaaSClientConfig object directly in Go code and enter fields such as ClientId and InstanceId. This method is suitable for scenarios that require programmatic configuration.
-
Configuration File: When the workload starts, the SDK automatically obtains the local identity credential (OIDC Token / PKCS7 signature / Instance Identity), completes identity authentication through the AAP, and then accesses KMS secret resources without managing an AccessKey pair.
Inline configuration
-
Install the dependencies:
go mod init demo go get -u github.com/aliyun/alibabacloud-secretsmanager-client-go-v2 -
Write the code. This topic uses an AWS EC2 instance as an example.
Important-
Replace <SecretName> with the actual secret name.
-
For other configurations such as <ClientId>, <InstanceId>, <IssuerEndpoint>, <TokenEndpoint>, and the application access point ARN, the system automatically fills them in based on the authentication information generated in Step 2: Create an access point. Keep the defaults unless you have special requirements.
package main import ( "fmt" "github.com/aliyun/alibabacloud-secretsmanager-client-go-v2/sdk" "github.com/aliyun/alibabacloud-secretsmanager-client-go-v2/sdk/service" idaasconfig "github.com/cloud-idaas/idaas-go-core-sdk/config" ) func main() { cfg := &idaasconfig.IDaaSClientConfig{ ClientId: "app_nj2x5w****l3lkihnbi", InstanceId: "idaas_jzeao****rn5xkyratw4", IssuerEndpoint: "https://fd***acn.aliyunidaas.com/api/v2/iauths_system/oauth2", TokenEndpoint: "https://fd***acn.aliyunidaas.com/api/v2/iauths_system/oauth2/token", Scope: "urn:alibabacloud:kms|kms:default", AuthnConfiguration: &idaasconfig.IdentityAuthenticationConfiguration{ AuthnMethod: "PKCS7", IdentityType: "CLIENT", ApplicationFederatedCredentialName: "shared--o6vd27c2", ClientDeployEnvironment: "AWS_EC2", }, } client, err := sdk.NewSecretCacheClientBuilder( service.NewDefaultSecretManagerClientBuilder().Standard(). WithAwsEc2PKCS7( cfg, // IDaaS client configuration object "acs:kms:cn-hangzhou:119*****18460:applicationaccesspoint/shared--o6vd27c2", // Application access point ARN ). WithRegion("cn-hangzhou"). // Region of the target KMS service Build(), ).Build() if err != nil { panic(err) } secretInfo, err := client.GetSecretInfo("<SecretName>") // Secret name if err != nil { panic(err) } fmt.Printf("SecretValue: %s\n", secretInfo.SecretValue) } -
-
Run the code. Expected output:
SecretValue: xxxxxxxx.go mod tidy go build -o demo main.go ./demo
Configuration file
-
Download and save the identity file:
-
On the Configuration File tab, click Download Identity File.
-
Save the downloaded file as idaasconfig.json and place it in the workload environment, so that the SDK can load it through the configuration file path and complete KMS identity authentication.
ImportantDo not modify the content of the identity file. Otherwise, the identity file becomes unavailable.
-
-
Install the dependencies:
go mod init demo go get -u github.com/aliyun/alibabacloud-secretsmanager-client-go-v2 -
Write the code. This topic uses an AWS EC2 instance as an example.
NoteReplace <IdaasConfigPath> with the actual save path of the downloaded identity file, and <SecretName> with the actual secret name.
package main import ( "fmt" "github.com/aliyun/alibabacloud-secretsmanager-client-go-v2/sdk" "github.com/aliyun/alibabacloud-secretsmanager-client-go-v2/sdk/service" ) func main() { client, err := sdk.NewSecretCacheClientBuilder( service.NewDefaultSecretManagerClientBuilder().Standard(). WithAwsEc2PKCS7Path( "<IdaasConfigPath>", // Path of the identity file "acs:kms:cn-hangzhou:119*****18460:applicationaccesspoint/shared--o6vd27c2", // Application access point ARN ). WithRegion("cn-hangzhou"). // Region of the target KMS service Build(), ).Build() if err != nil { panic(err) } secretInfo, err := client.GetSecretInfo("<SecretName>") // Secret name if err != nil { panic(err) } fmt.Printf("SecretValue: %s\n", secretInfo.SecretValue) } -
Run the code. Expected output:
SecretValue: xxxxxxxx.go mod tidy go build -o demo main.go ./demo
Agent integration
-
Select the deployment environment for KMS Agent: Linux or Windows.
-
Download and save the identity file:
-
On the Linux or Windows tab, click Download Identity File.
-
Save the downloaded file as idaasconfig.json and place it in the workload environment, so that the SDK can load it through the configuration file path and complete KMS identity authentication.
ImportantDo not modify the content of the identity file. Otherwise, the identity file becomes unavailable.
-
-
Get the secret:
Linux
-
Install KMS Agent
mkdir -p /home/ec2-user/kms && cd /home/ec2-user/kms # Download the installation script # amd64 curl -fsSL -o install_alibabacloud_kms_agent "https://alibabacloud-kms-agent-cn.oss-cn-hangzhou.aliyuncs.com/1.3.0/install_alibabacloud_kms_agent" # arm64 #curl -fsSL -o install_alibabacloud_kms_agent "https://alibabacloud-kms-agent-cn.oss-cn-hangzhou.aliyuncs.com/1.3.0/install_alibabacloud_kms_agent_arm64"chmod +x install_alibabacloud_kms_agent # Run the installation (replace the parameters with the actual values) sudo ./install_alibabacloud_kms_agent --install \ --AuthMethod AwsEc2PKCS7 \ --AapArn "acs:kms:cn-hangzhou:119*****18460:applicationaccesspoint/shared--o6vd27c2" \ --IdaasConfigPath "<IdaasConfigPath>" # Path of the identity file # --Endpoint is optional. You can specify the instance domain name. The public domain name is used by default. -
Verify the KMS Agent installation
curl http://127.0.0.1:2025/ping # Expected: healthy -
Get Secret: Before you run the following command, replace <SecretName> with the secret name.
TOKEN=$(sudo cat /var/run/kmstoken) curl -H "X-KMS-Token: $TOKEN" \ "http://127.0.0.1:2025/secretsmanager/get?secretId=<SecretName>" # Secret name -
Uninstall (optional): If KMS Agent is no longer needed, you can uninstall it with the following command.
sudo ./install_alibabacloud_kms_agent --uninstall
Windows
-
Download Executable File
curl.exe -fsSL -o install_alibabacloud_kms_agent.exe "https://alibabacloud-kms-agent-cn.oss-cn-hangzhou.aliyuncs.com/1.3.0/install_alibabacloud_kms_agent.exe" -
Install KMS Agent: Before you run the following command, replace <IdaasConfigPath> with the path of the downloaded identity file.
# Run the installation in PowerShell as an administrator .\install_alibabacloud_kms_agent.exe --install ` --AuthMethod AwsEc2PKCS7 ` --AapArn "acs:kms:cn-hangzhou:119*****18460:applicationaccesspoint/shared--o6vd27c2" ` --IdaasConfigPath "<IdaasConfigPath>" # Path of the identity file # --Endpoint is optional. You can specify the instance domain name. The public domain name is used by default. -
Verify the KMS Agent installation
curl.exe http://127.0.0.1:2025/ping # Expected: healthy -
Get Secret: Before you run the following command, replace <SecretName> with the secret name.
$TOKEN = Get-Content $env:ProgramData\AlibabaCloud\KMSAgent\token curl.exe -H "X-KMS-Token: $TOKEN" ` "http://127.0.0.1:2025/secretsmanager/get?secretId=<SecretName>" # Secret name -
Uninstall (optional): If KMS Agent is no longer needed, you can uninstall it with the following command.
.\install_alibabacloud_kms_agent.exe --uninstall
-
-
More information
-
Overview of AAPs introduces the authentication and authorization model of AAP, as well as the applicable scenarios of each authentication method.
-
For the AccessKey-free access methods of Alibaba Cloud ECS instances and ACK clusters, see Quick access from ECS and Quick access from ACK.
-
To choose an integration method such as SDK, secret SDK, or KMS Agent, see Integrate KMS with self-managed applications.