Accessing Huawei Cloud Open APIs Using Access Credentials
Applications must be authenticated to access cloud service open APIs. The common method is to maintain an access key in your application to sign requests for calling the open APIs of cloud services. Once generated, an access key is valid unless you disable or delete it. This means that attackers can use the key for a long time and access all cloud resources that the access key has permissions to operate. To prevent access key leakage, you need to take measures such as narrowing down the access key usage scope, encrypting the access key for storage, and periodically rotating the access key. These steps reduce the risk of leaks but also increase complexity and costs.
Access Credential Type
Access credentials include access keys and temporary security credentials.
- An access key ID/secret access key (AK/SK) pair is a permanent identity credential that you can use to access Huawei Cloud. It cannot be used to log in to the console. An AK is a unique identifier used in conjunction with an SK to sign requests cryptographically, ensuring that the requests are secret, complete, and correct. For details, see Access Keys.
- Temporary security credentials include temporary access keys (AK/SK) and security token. In addition to the access key feature, a temporary security credential has a validity period that can be customized. If it expires, the temporary security credential becomes invalid and you have to obtain a new one. Temporary security credentials are more secure than permanent credentials since they expire after a set time and allow stricter control over access rights. For details, see Temporary Security Credentials.
Typical Access Credential Leakage Scenarios
- Access credentials in plaintext are available in public documents.
- The code containing access credentials is uploaded to public code repositories, such as GitHub.
- Hardcoded access credentials in plaintext are stored in service code and are provided to third-party employees.
Secure Use of Access Credentials
The following table lists the solutions to reduce access credential leakage in typical scenarios.
| Solution | Scenario |
|---|---|
| Configuring access credentials in KooCLI profiles | When you use KooCLI to call a cloud service, you can configure temporary security credentials and ecsAgency (used to obtain temporary authentication information on an ECS) in KooCLI profiles. You can also use SSO login to set identity credentials instead of using access keys. For details, see Setting System Parameters in a Profile. |
| Accessing other cloud services through temporary access keys of an agency | Your applications running on an ECS need to call open APIs to access cloud service resources. You need to configure access credentials for the applications to pass identity authentication. You can create an ECS agency to allow the ECS service for obtaining temporary security credentials from IAM. Your applications do not need to manage and maintain access credentials. Instead, they can obtain temporary security credentials from the ECS metadata service, sign the requests, and call cloud service open APIs. ECS automatically rotates temporary security credentials to ensure that they are secure and valid. For details, see Accessing Other Cloud Services from ECS Using Temporary Access Keys of an Agency. |
| Security settings for using workload identity in CCE clusters | Your applications running on a Cloud Container Engine (CCE) instance need to call open APIs to access cloud service resources. You need to configure access credentials for the applications to pass identity authentication. You can create an OpenID Connect (OIDC) identity provider to map the ServiceAccount of your application to the IAM user group, and obtain the OIDC ID token to access cloud services like an IAM user. CCE automatically rotates the OIDC ID tokens to ensure that they are secure and valid. For details, see Using OIDC to Authenticate Workloads in a CCE Cluster. |
| Obtaining temporary security credentials for an agency of a FunctionGraph function | Your FunctionGraph function needs to access other cloud service resources. You need to configure an agency for the function and then this function can obtain temporary security credentials through environment variables. This method avoids the need to configure plaintext access keys in the function. |
| Others | If none of the preceding solutions fit your scenario, you are advised to configure and save access credentials properly and rotate them periodically. |
Configuring Access Credentials in KooCLI Profiles
- Scenarios
To call a cloud service on KooCLI, add a profile to set access credentials. If multiple profiles are used, you can use --cli-profile to specify the name of the profile you want to operate or use and --cli-mode to specify the authentication mode.
Available authentication modes:- AK/SK: Access keys or temporary security credentials. Access keys are permanent AK/SK pairs. Temporary security credentials include temporary AKs/SKs and security tokens.
- ecsAgency: The agency will obtain temporary authentication information when you use the KooCLI to call a cloud service on the ECS. You are advised to use this method to prevent plaintext access credentials from being queried in the CLI history.
- SSO: After you enable IAM Identity Center and complete configurations, your users can log in to the unified portal with their username and password and access allocated resources under multiple accounts. They do not need to pass the authentication again before the authentication information expires.
- Setting access credentials
- To set the authentication mode to AK/SK, set the authentication parameters to temporary security credentials. Specify the temporary AK for cli-access-key, the SK for cli-secret-key, and the security token for cli-security-token. Temporary security credentials are exposed in a shorter period than access keys.
hcloud configure set --cli-profile=testAKSKST --cli-mode=AKSK --cli-region=cn-north-4 --cli-access-key=******** --cli-secret-key=******** --cli-security-token=******** --cli-project-id=068119468****************af89d2e --cli-domain-id=094518e46****************cfbc4c0 --cli-read-timeout=10 --cli-connect-timeout=5
- For a profile in AK/SK authentication mode, if the cli-security-token parameter is configured in the profile, cli-access-key and cli-secret-key are temporary AK/SK. Otherwise, they are permanent AK/SK.
- Configure a profile in ecsAgency authentication mode. No authentication parameters are required.
hcloud configure set --cli-profile=testEcsAgency --cli-mode=ecsAgency --cli-region=cn-north-4 --cli-read-timeout=10 --cli-connect-timeout=5
- When you use the KooCLI to call a cloud service on an ECS, the KooCLI automatically obtains temporary authentication information based on the ECS agency.
- To configure a profile in SSO authentication mode, set the following authentication parameters: user portal URL (cli-sso-start-url), region of an IAM Identity Center instance (cli-sso-region), account name (cli-sso-account-name), and permission set name (cli-sso-permission-set-name). cli-sso-account-name and cli-sso-permission-set-name are optional.
- Create a profile that uses SSO authentication.
hcloud configure set --cli-profile=testSSO --cli-mode=SSO --cli-region=cn-north-4 --cli-sso-start-url=https://idcenter.huaweicloud.com/d-3********6/portal --cli-sso-region=cn-north-4 --cli-sso-account-name=ACCOUNT_01 --cli-sso-permission-set-name=PERMISSION_01
- Log in with SSO. You will be prompted to enter an account name and permission set name if cli-sso-account-name and cli-sso-permission-set-name are not set.
hcloud configure sso --cli-profile=testSSO
- Create a profile that uses SSO authentication.
- To set the authentication mode to AK/SK, set the authentication parameters to temporary security credentials. Specify the temporary AK for cli-access-key, the SK for cli-secret-key, and the security token for cli-security-token. Temporary security credentials are exposed in a shorter period than access keys.
Accessing Other Cloud Services Through Temporary Access Keys of an Agency
- Scenarios Assume that you are a developer working on an application that runs on an ECS instance. The code in the application needs to call open APIs to access Huawei Cloud services. Your application can obtain temporary access credentials through a cloud service agency created for the ECS instance on the IAM console to access cloud services in a more secure way.Figure 1 Obtaining a temporary access key through an ECS agency
- Procedure The following figure shows how to obtain a temporary access key through an ECS agency. For details, see Accessing Other Cloud Services from ECS Using Temporary Access Keys of an Agency.Figure 2 Obtaining a temporary access key through an ECS agency
Security Settings for Using Workload Identity in CCE Clusters
- Scenarios Assume that you are a developer of an application that runs in a CCE cluster. The application can access cloud services like an IAM user so there is no need to use the AK/SK of the IAM account.Figure 3 Workload identity security settings in CCE clusters
- Procedure
For detailed steps, see Using OIDC to Authenticate Workloads in a CCE Cluster.
Obtaining Temporary Security Credentials for an Agency of a FunctionGraph Function
- Scenarios
Applications deployed on FunctionGraph functions need access credentials to access other cloud services. A typical practice is to specify access keys in function code or configuration files. This approach can expose credentials and requires periodical key rotation. You can associate an IAM agency with a FunctionGraph function and use temporary security credentials to access cloud resources. This approach is more secure than using permanent credentials.
- Procedure
- Configure agency permissions. Figure 4 Entering the basic information of the agency
- Create a FunctionGraph function and associate it with the IAM agency created in step 1. (FunctionGraph can then use the agency to obtain temporary security credentials of the account to call open APIs.) Figure 5 Creating a FunctionGraph function
- In the function code, use the context.getSecurityAccessKey(), context.getSecuritySecretKey(), and context.getSecurityToken() methods of the context class to obtain the temporary AK/SK and security token. The following shows a Python example:
#- * -coding: utf - 8 - * - import json import os from huaweicloudsdkcore.auth.credentials import GlobalCredentials from huaweicloudsdkiam.v3.region.iam_region import IamRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkiam.v3 import * def handler(event, context): credentials = GlobalCredentials( ak = context.getSecurityAccessKey(), sk = context.getSecuritySecretKey() ).with_security_token(context.getSecurityToken()) client = IamClient.new_builder()\ .with_credentials(credentials)\ .with_region(IamRegion.value_of("cn-north-4"))\ .build() ...
- Configure agency permissions.
Other scenarios
If the preceding scenarios do not fit your scenario and you need access keys, follow these suggestions to manage them securely:
- Do not create access keys for HUAWEI IDs.
- Do not create access keys for IAM users who only need to access the console.
- Do not embed access keys in plaintext into code.
- Keep access keys secure. Do not share them or record them in public documents.
- Grant only the minimum permissions required to IAM users.
- Disable and delete access keys after they are no longer used.
- Regularly rotate access keys. When you enable a key pair for an IAM user, keep the second pair only for rotation purposes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot