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
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
Help Center/ Ubiquitous Cloud Native Service/ Best Practices/ On-Premises Clusters/ Using Workload Identities to Securely Access Cloud Services

Using Workload Identities to Securely Access Cloud Services

Updated on 2024-11-01 GMT+08:00

Application Scenarios

With workload identities, your workloads in a cluster can access cloud services like IAM users without using the AK/SK, reducing security risks.

This section describes how to use workload identities in UCS.

Solution Process

Figure 1 shows the process of using workload identities.

  1. Assign authorization in advance.

    1. Obtain the JSON Web Key Set (JWKS) issued by the private key of an on-premises cluster from UCS. The JWKS is used to verify the token issued by this cluster for a ServiceAccount.
    2. Create an identity provider (IdP) for the on-premises cluster in IAM.
    3. Add the public key of this cluster for the IdP. When a workload uses a token to send requests, IAM will use this public key to verify the token.
    4. Add a rule to map the ServiceAccount to the IAM account. After the configuration, the ServiceAccount has the permissions of the IAM account.

  2. Configure the token.

    1. Deploy a workload and configure a ServiceAccount.
    2. Mount the token of the ServiceAccount to the workload.

  3. Verify the token.

    1. Call the IAM API to obtain the IAM token.
    2. Use the IAM token to access cloud services.

Figure 1 Process of using workload identities

Obtaining the JWKS of an On-Premises Cluster

  1. Use kubectl to access the on-premises cluster.
  2. Run the following command to obtain the public key:

    kubectl get --raw /openid/v1/jwks

    A json string is returned, containing the public key of the on-premises cluster for accessing the IdP.

    {
        "keys": [
            {
                "kty": "RSA",
                "e": "AQAB",
                "use": "sig",
                "kid": "Ew29q....",
                "alg": "RS256",
                "n": "peJdm...."
            }
        ]
    }

Creating an IdP

  1. Log in to the IAM console, create an IdP, and select OpenID Connect for Protocol.

    Figure 2 Creating an IdP

  2. Click OK. Then, modify the IdP information as described in Table 1. If you need an identity conversion rule, click Create Rule.

    Figure 3 Modifying IdP information
    Figure 4 Creating an identity conversion rule
    Table 1 IdP parameters

    Parameter

    Description

    Access Type

    Select Programmatic access.

    Configuration Information

    • Identity Provider URL: Enter https://kubernetes.default.svc.cluster.local.
    • Client ID: Enter ucs-cluster-identity.
    • Signing Key: Enter the JWKS of the on-premises cluster obtained in Obtaining the JWKS of an On-Premises Cluster.

    Identity Conversion Rules

    An identity conversion rule maps the ServiceAccount of a workload to an IAM user group.

    For example, create a ServiceAccount named xxx in namespace default of the cluster and map it to user group demo. If you use the IdP ID to access cloud services, you have the permissions of the demo user group.

    Value format: system:serviceaccount:Namespace:ServiceAccountName.

  3. Click OK.

Obtaining an IAM Token

  1. Create a ServiceAccount, whose name must be the value of ServiceAccountName set in 2.

    apiVersion: v1 
    kind: ServiceAccount 
    metadata: 
     name: test_sa_name # The value must be the same as that in the identity conversion rule.

  2. Add the ServiceAccount and volume configurations to the workload.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
          version: v1
      template:
        metadata:
          labels:
            app: nginx
            version: v1
        spec:
          containers:
          - name: container-1
            image: nginx:latest
            volumeMounts
            - mountPath: "/var/run/secrets/tokens" # Mount the ServiceAccountToken generated by Kubernetes to /var/run/secrets/tokens/token_path.
              name: token-volume
          imagePullSecrets:
          - name: default-secret
          serviceAccountName: test_sa_name    # Name of the ServiceAccount created in the previous step
          volumes:
          - name: token-volume
            projected:
              defaultMode: 420
              sources:
              - serviceAccountToken:
                  audience: ucs-cluster-identity   # The value must be the client ID of the IdP.
                  expirationSeconds: 7200     # Expiration time
                  path: token_path     # Path name, which can be customized

  3. After the creation, log in to the container to obtain the token.

  4. Construct request body data. For details, see Obtaining a Project ID.

    {
        "auth" : { 
          "id_token" : { 
            "id" : "eyJhbGciOiJSUzIXXXXX"   // Token obtained in the previous step
          },
          "scope": {
            "project" : {
              "id" : "05495693df80d3c92fa1c01795c2be02",  // Project ID
              "name" : "cn-north-7"  
            }
          }
        }
      }

  5. Call the IAM API to obtain the IAM token. For details about the IAM endpoint, see Regions and Endpoints.

    curl -i --location --request POST 'https://{{iam endpoint}}/v3.0/OS-AUTH/id-token/tokens'  --header 'X-Idp-Id: {{workload_identity}}'  --header 'Content-Type: application/json'  --data @token_body.json
    • Replace {workload_identity} with the name of the IdP registered in 1. In this example, the name is ucs-cluster-identity.
    • token_body.json is the constructed request body data file.

  6. Obtain the IAM token from the response body. The value of X-Subject-Token in the response header is the IAM token.

Using an IAM Token to Access Cloud Services

This section uses LTS as an example.

  1. Before using an IAM token to access LTS, you need to configure permissions for the user group.
  2. To call LTS, you need to add the LTS FullAccess permissions to the user group.

  3. Run the following command to call the service API:

    curl --location --request GET 'https://ltsperform.cn-north-7.myhuaweicloud.com/v2/{{Project ID}}/groups/{{Log group ID}}/streams' \--header 'Content-Type: application/json;charset=utf-8' \--header 'X-Auth-Token: {{IAM token obtained in the previous step}}' \--data-raw ''

    The value of {Log group ID} can be obtained in LTS.

    The following figure shows the expected result.

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