El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

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/ Object Storage Service/ Best Practices/ Uploading Data to OBS/ Uploading Data from Mobile Apps to OBS/ Using a Temporary Security Credential to Upload Data to OBS

Using a Temporary Security Credential to Upload Data to OBS

Updated on 2024-10-17 GMT+08:00

Solution Architecture

Upload data from your apps to OBS or download your data from OBS. Figure 1 describes the process.

OBS allows you to use a temporary security credential (temporary AK/SK pair and security token) for access. In addition, you can configure permissions for the credential to specify what actions are allowed during the access with the credential used. To learn more, see What Are Temporary Access Keys?

Mobile apps can use temporary security credentials with specific permissions configured to directly upload data to OBS. This process does not expose users' permanent access keys, reducing security risks in the case of account leakage.

Figure 1 Process of using temporary security credentials to directly upload data to OBS

Role Analysis

  • App client: End user's mobile app. It requests a temporary security credential from the server, and uploads data to or downloads data from OBS.
  • App server: A backend provided by developers of Android or iOS apps. It manages user accounts and authorization.
  • OBS: Huawei Cloud's object storage service. It processes requests from mobile apps.
  • IAM: Huawei Cloud's Identity and Access Management. It generates temporary security credentials.

Workflow

  1. An app client requests a temporary security credential from the app server.
  2. The app server requests the temporary security credential from IAM.
  3. IAM returns the credential to the app server.
  4. The app server sends the credential to the app client.
  5. The app client uses the security credential to upload data to and download data from OBS.

Prerequisites

You have created a bucket and set its access control to private read/write or public read and private write.

For details, see Creating a Bucket and Creating a Custom Bucket Policy.

Resource and Cost Planning

The table below describes the resources that you need in this practice.

Table 1 Resource description

Resource

Description

App client

End user's mobile app. It requests a temporary security credential from the server, and uploads data to or downloads data from OBS.

App server

A backend provided by developers of Android or iOS apps. It manages user accounts and authorization.

OBS

Huawei Cloud's object storage service that processes requests from mobile apps.

IAM

Huawei Cloud's identity and access management service that generates temporary security credentials.

Procedure

  1. Obtain the OBS SDK and IAM SDK.

    To obtain the OBS SDK, visit SDK Developer Guide.

    To obtain the IAM SDK, visit IAM SDK.

  2. Simulate the app server to request a temporary security credential from IAM.

    The process is as follows:

    1. Obtain the user's IAM token.

      For details, see Obtaining a User Token Through Password Authentication or SDKs.

    2. Use a token to obtain a temporary security credential (temporary AK/SK pair and security token). You need to use the Policy field to specify what actions are allowed by the security credential.

      For details, see Obtaining Temporary Access Keys and SecurityToken Through a Token or SDKs.

    Example: Obtain a temporary security credential whose validity period is 900 seconds. This credential allows you to upload data to only the APPClient/APP-1/ directory of bucket hi-company.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    {
        "auth":{
            "identity":{
                "policy":{
                    "Version":"1.1",
                    "Statement":[
                        {
                            "Action":[
                                "obs:object:PutObject"
                            ],
                            "Resource":[
                                "obs:*:*:object:hi-company/APPClient/APP-1/*"
                            ],
                            "Effect":"Allow"
                        }
                    ]
                },
                "token":{
                    "duration-seconds":900,
                    "id":"MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALMEXXXXX..."
                },
                "methods":[
                    "token"
                ]
            }
        }
    }
    

  3. Initialize the ObsClient.

    Initialization examples:

    • Android
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      String endPoint = "https://your-endpoint";
      // Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID.
      // Obtain an AK and SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
      String ak = System.getenv("ACCESS_KEY_ID");
      String sk = System.getenv("SECRET_ACCESS_KEY_ID");
      String token = System.getenv("Security_Token");
      
      // Create an ObsConfiguration instance.
      ObsConfiguration config = new ObsConfiguration();
      config.setEndPoint(endPoint);
      config.setSocketTimeout(30000);
      config.setConnectionTimeout(10000);
      
      // Create an ObsClient instance.
      ObsClient obsClient = new ObsClient(ak, sk,token,config); 
      
      // Use the instance to access OBS.
      
      // Close ObsClient.
      obsClient.close();
      
      NOTE:
      • endPoint indicates an endpoint, which can be queried from Regions and Endpoints.
      • ak and sk indicate the temporary AK and SK, and token indicates the security token. For details about how to obtain them, see Access Keys (AK/SK).
    • iOS
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      NSString *endPoint = @"your-endpoint";
      // Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables for identity authentication. Before running the code in this example, configure environment variables AccessKeyID and SecretAccessKey.
      // Obtain an AK and SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
      NSString *SK = getenv("AccessKeyID");
      NSString *AK = getenv("SecretAccessKey");
      // Initialize identity authentication.
      OBSStaticCredentialProvider *credentailProvider = [[OBSStaticCredentialProvider alloc] initWithAccessKey:AK secretKey:SK];
      securityTokencredentailProvider.securityToken = @"*** Provide your Security Token ***";
      // Initialize service configuration.
      OBSServiceConfiguration *conf = [[OBSServiceConfiguration alloc] initWithURLString:endPoint credentialProvider:credentialProvider];
      // Perform initialization.
      clientOBSClient *client  = [[OBSClient alloc] initWithConfiguration:conf];
      
      NOTE:
      • endPoint indicates an endpoint, which can be queried from Regions and Endpoints.
      • ak and sk indicate the temporary AK and SK, and token indicates the security token. For details about how to obtain them, see Access Keys (AK/SK).
    • web js
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      // AMD is not imported. Use the constructor to create an ObsClient instance.
      var obsClient = new ObsClient({
             // Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables for identity authentication. Before running the code in this example, configure environment variables AccessKeyID and SecretAccessKey.
             // Obtain an AK and SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
             access_key_id: process.env.AccessKeyID,
             secret_access_key: process.env.SecretAccessKey,
             security_token: process.env.SecurityToken,
             server : 'https://your-endpoint'
      });
      // Use the instance to access OBS.
      
      // AMD is imported. Use the injected constructor to create an ObsClient instance.
      var obsClient;
      define(['ObsClient'], function(ObsClient){
          obsClient = new ObsClient({
             // Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables for identity authentication. Before running the code in this example, configure environment variables AccessKeyID and SecretAccessKey.
             // Obtain an AK and SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
              access_key_id: process.env.AccessKeyID,
              secret_access_key: process.env.SecretAccessKey,
              security_token: process.env.SecurityToken,
              server : 'https://your-endpoint'
          });    
          // Use the instance to access OBS.
      });
      
      NOTE:
      • endPoint indicates an endpoint, which can be queried from Regions and Endpoints.
      • ak and sk indicate the temporary AK and SK, and token indicates the security token. For details about how to obtain them, see Access Keys (AK/SK).

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback