Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Using CSMS to Prevent AK and SK Leakage

Updated on 2024-08-30 GMT+08:00

CSMS is a secure, reliable, and easy-to-use credential hosting service. Users or applications can use CSMS to create, retrieve, update, and delete credentials in a unified manner throughout the credential lifecycle. CSMS can help you eliminate risks incurred by hardcoding, plaintext configuration, and permission abuse.

Scenario

Application secrets are stored and can be accessed temporarily to prevent AK and SK leakage.

How It Works

You can use Identity and Access Management (IAM) to obtain temporary access keys for Elastic Cloud Server (ECS) to protect AKs and SKs.

Access secrets can be classified into permanent secrets and temporary secrets based on their validity periods. Permanent access secrets include usernames and passwords. Temporary access keys have a shorter validity period, are updated frequently, thus are more secure. You can assign an IAM agency to an ECS instance, so that applications in the ECS instance can use the temporary AK, SK, and security token to access CSMS. The temporary access keys are dynamically obtained every time they are required. They can also be cached in the memory and updated periodically.

Process Flow

Figure 1 ECS agency configuration process

Constraint

Only the administrator or an IAM user with the ECS permission can configure an agency for an ECS instance.

Procedure

  1. Create an ECS agency on IAM.

    1. Log in to the management console.
    2. Click on the left of the page and choose Management & Governance > Identity and Access Management. The Users page is displayed.
    3. In the navigation pane, choose Agencies.
    4. Click Create Agency in the upper right corner.
    5. Configure parameters in the Create Agency dialog box. For more information, see Agency parameters.
      Figure 2 Creating an agency
      Table 1 Agency parameters

      Parameter Name

      Description

      Agency Name

      Enter an agency name. Example: ECS_TO_CSMS

      Agency Type

      Select Cloud service.

      Cloud Service

      Select Elastic Cloud Server (ECS) and Bare Metal Server (BMS).

      Validity Period

      Select a duration. The value can be Unlimited, 1 day, or Custom.

      Description

      (Optional) Enter agency description.

    6. Click Next to go to the authorization page.
    7. Click Create Policy in the upper right corner. If you already have a policy, skip this step.
      1. Configure policy parameters. For more information, see Policy parameters.
        Figure 3 Creating a policy
        Table 2 Policy parameters

        Parameter Name

        Description

        Policy Name

        Enter a policy name.

        Policy View

        Select Visual editor.

        Policy Content

        • Allow: Select Allow.
        • Select service: Select Cloud Secret Management Service (CSMS).
        • Select action: Select read and write permissions as required.
        • (Optional) Select resource: Select the scope of resources.
          • Specific: Access specific secrets.
            NOTE:

            You can select Specify resource path, and then click Add Resource Path to specify an accessible secret.

          • All: Access all secrets.
        • (Optional) Add request condition: Click Add Request Condition, select a condition key and an operator, and enter values as required.

        Description

        (Optional) Enter policy description.

    8. Select a policy for the agency. Click Next.
    9. Select a scope and click OK.
      • All resources: IAM users will be able to use all resources, including those in enterprise projects, region-specific projects, and global services under your account based on assigned permissions.
      • Enterprise projects: The selected permissions will be applied to resources in the enterprise projects you select.
      • Region-specific projects: The selected permissions will be applied to resources in the region-specific projects you select.

  2. Assign an agency (for example, ECS_TO_CSMS) to an ECS instance.

    • To create an ECS instance, perform the operations described in Creating an ECS. In Step 3: Configure Advanced Settings, select the new agency (for example, ECS_TO_CSMS).
    • To use an existing ECS instance, perform the following steps:
      1. Click on the left of the page and choose Management & Governance > Identity and Access Management. Go to the ECS page.
      2. Click the name of an ECS instance to go to the Summary page.
      3. In the Management Information area, click and select an agency (for example, ECS_TO_CSMS).
        Figure 4 Selecting an agency

  3. In an application running on the ECS instance, call an API to obtain the temporary agency secrets, including the temporary AK, SK, and security token, to access CSMS.

    1. Obtain the temporary AK and SK (in the Security Key directory). For details, see Obtaining Metadata.
      • URI

        /openstack/latest/securitykey

      • Method

        GET request

      • The following data is returned:
        {
              "credential":{
                  "access": "LDHZK30XXXXXXXXXXXXV",
                  "secret":"gyqcdzVXXXXXXXXXXXXXXXXXXXXXXXMl6",
                  "securitytoken": "El9FI2C65qXXXXXXXXXXXXXXXXXXXXXnkcaoV",
                  "expires_at": "2022-07-14T12:09:24.147000Z"
                          }
        }
        NOTE:
        • Extract the values of access, secret, and securitytoken to access CSMS.
        • ECS automatically rotates temporary secrets to ensure that they are secure and valid.
    2. Use the temporary AK, SK, and security token to access CSMS.
      • An example of the secret list is as follows. For details, see Secret Management APIs.
      • Prepare basic authentication information.
        • ACCESS_KEY: Access key of the Huawei account. For details, see How Do I Obtain an Access Key (AK/SK)?
        • SECRET_ACCESS_KEY: Secret access key of the Huawei account. For details, see How Do I Obtain an Access Key (AK/SK)?
        • There will be security risks if the AK/SK used for authentication is directly written into code. Encrypt the AK/SK in the configuration file or environment variables for storage.
        • In this example, the AK/SK stored in the environment variables are used for identity authentication. Configure the environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK in the local environment first.
        package com.huaweicloud.sdk.test;
        
        import com.huaweicloud.sdk.core.auth.ICredential;
        import com.huaweicloud.sdk.core.auth.BasicCredentials;
        import com.huaweicloud.sdk.core.exception.ConnectionException;
        import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
        import com.huaweicloud.sdk.core.exception.ServiceResponseException;
        import com.huaweicloud.sdk.csms.v1.region.CsmsRegion;
        import com.huaweicloud.sdk.csms.v1.*;
        import com.huaweicloud.sdk.csms.v1.model.*;
        
        public class ListSecretsSolution {
            public static void main(String[] args) { 
             * Basic authentication information:
             * - ACCESS_KEY: Access key of the Huawei account
             * - SECRET_ACCESS_KEY: Secret access key of the Huawei account
             * - PROJECT_ID: Huawei Cloud project ID. For details, see https://support.huaweicloud.com/intl/en-us/productdesc-iam/iam_01_0023.html
        * - CSMS_ENDPOINT: endpoint address for accessing CSMS. For details, see https://support.huaweicloud.com/intl/en-us/api-dew/dew_02_0052.html.
             * - There will be security risks if the AK/SK used for authentication is directly written into code. Encrypt the AK/SK in the configuration file or environment variables for storage.
             * - In this example, the AK/SK stored in the environment variables are used for identity authentication. Configure the environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK in the local environment first.
             */
            private static final String ACCESS_KEY = System.getenv("HUAWEICLOUD_SDK_AK");
            private static final String SECRET_ACCESS_KEY = System.getenv("HUAWEICLOUD_SDK_SK");
            String securitytoken = "<YOUR SecurityToken>";
                     
                String ak = System.getenv("CLOUD_SDK_AK");        
                String sk = System.getenv("CLOUD_SDK_SK");
        
                ICredential auth = new BasicCredentials()
                        .withAk(ak)
                        .withSk(sk)
                        .withSecurityToken(securitytoken);
        
                 CsmsClient client = CsmsClient.newBuilder()
                         .withCredential(auth)
                         .withRegion(CsmsRegion.valueOf("cn-north-1"))
                         .build();
                 ListSecretsRequest request = new ListSecretsRequest();
                 try {
                     ListSecretsResponse response = client.listSecrets(request);
                     System.out.println(response.toString());
                 } catch (ConnectionException e) {
                     e.getMessage();
                 } catch (RequestTimeoutException e) {
                     e.getMessage();
                 } catch (ServiceResponseException e) {
                     e.getMessage();
                     System.out.println(e.getHttpStatusCode());
                     System.out.println(e.getErrorCode());
                     System.out.println(e.getErrorMsg());
                 }
             }
        }

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback