Updated on 2024-03-15 GMT+08:00

Granting IAM Users Under an Account the Access to a Bucket and the Resources in It

Scenario

This topic describes how to grant IAM users the permissions to access OBS buckets and resources in them.

The following describes how to grant the permissions to upload and download objects in a bucket. If you need to configure other specified permissions, configure the corresponding permissions in the bucket policy and IAM permissions.

Recommended Configuration

To grant permissions to IAM users under an account, you need to configure both bucket policies and IAM permissions.

For example, to allow IAM user A of account A to access bucket B of account B, you need to:

  1. Configure a bucket policy that allows IAM user A to access bucket B.
  2. Configure IAM permissions for account A to allow IAM user A to access bucket B.

Configuration Precautions

After the configuration is complete, the authorized IAM user can upload and download objects through APIs or SDKs. In addition, the user can upload and download objects by mounting external buckets on OBS Browser+. To add external buckets, the ListBucket permission is also required. Currently, access to buckets of other accounts is not allowed on OBS Console.

Procedure 1: The Bucket Owner Configures a Bucket Policy.

The bucket owner or a user who has the permission to configure bucket policies needs to configure a bucket policy that allows IAM users under an account to perform specified operations on the bucket.

In this example, account B (owner of bucket B) configures a bucket policy that allows IAM user A of account A to upload objects to and download objects from bucket B of account B.

  1. In the navigation pane of OBS Console, choose Buckets.
  2. In the bucket list, click the bucket name you want to go to the Objects page.
  3. In the navigation pane, choose Permissions > Bucket Policies.
  4. On the Bucket Policies page, click Create.
  5. Choose a policy configuration method you like. Visual Editor is used here.
  6. Configure parameters for a bucket policy.

    Figure 1 Configuring a bucket policy
    Table 1 Parameters for configuring a bucket policy

    Parameter

    Description

    Policy Name

    Enter a policy name.

    Policy content

    Effect

    Select Allow.

    Principals

    • Select Other accounts.
      In this example, you can enter ID of account A/ID of IAM user A.
      NOTE:
      1. You can obtain the account ID and IAM user ID from the My Credentials page.
      2. Accounts should be configured in the Account ID/IAM user ID format, with each one on a separate line.
      3. Account ID/* indicates that permission is granted to all IAM users under the account.

    Resources

    • Select Current bucket and Specified objects.
    • Enter an object name prefix for the resource path.
      NOTE:
      1. You can click Add to specify multiple resource paths.
      2. You can specify a specific object, an object set, or a directory. * indicates all objects in the bucket.

        To specify a specific object, enter the object name.

        To specify a set of objects, enter Object name prefix*, *Object name suffix, or *.

    Actions

    • Choose Customize.
    • Select the following actions:
      • GetObject (to obtain object content and metadata)
      • GetObjectVersion (to obtain the content and metadata of a specified object version)
      • PutObject (to upload objects using PUT and POST, upload parts, initiate multipart uploads, and assemble parts)
      • (Optional) ListBucket (to list objects in the bucket and obtain the bucket metadata)
      NOTE:
      1. After the ListBucket permission is configured, the authorized account can access the bucket from OBS Browser+ by adding an external bucket.
      2. To configure other permissions, select the corresponding actions. For details about the actions supported by OBS, see Action/NotAction.

  7. Ensure all the configurations are correct and click Create.

Procedure 2: The Account Grants Permissions to IAM Users Under It.

The account (not the bucket owner) need to grant permissions to its IAM users to allow them perform specified operations on the bucket. (The allowed operations must be the same as those allowed in the bucket policy.)

In this example, account A needs to grant IAM user A the permissions to upload objects to and download objects from bucket B of account B.

  1. Log in to Huawei Cloud and click Console in the upper right corner.
  2. On the console, hover your cursor over the username in the upper right corner, and choose Identity and Access Management from the drop-down list.
  3. In the navigation pane, choose Permissions > Policies/Roles > Create Custom Policy.
  4. Configure parameters for a custom policy.

    Figure 2 Configuring a custom policy
    Table 2 Parameters for configuring a custom policy

    Parameter

    Description

    Policy Name

    Name of the custom policy

    Policy View

    Set this parameter based on your own habits. Visual editor is used here.

    Policy Content

    • Select Allow.
    • Select Object Storage Service (OBS).
    • Select the actions to be authorized.
      • ReadOnly > obs:bucket:ListBucketVersions and obs:object:GetObjectVersion
      • ReadWrite > obs:object:PutObject
      • ListOnly > obs:bucket:ListBucket (Select this operation if you need to use OBS Browser+ to add external buckets.)

      If you need to configure permissions on other actions, select the corresponding actions. For details, see Bucket-Related Actions and Object-Related Actions.

    • Choose Specific > object to specify an object resource. The specified object or object set must be consistent with the bucket policy.
      • Select Any if the resource set in the bucket policy is *.
      • If the resource specified in the bucket policy is a specified object or a set of objects, you need to specify the object or the set of objects the same as that in the bucket policy through the resource path.

        [Format]

        obs:*:*:object:bucket name/object name

      Select Any as the bucket policy in this example is set to *.

    • Choose Specific > bucket > Specify resource path to specify bucket resources.

      Click Add Resource Path and enter the name of the authorized bucket in the Path text box, for example, example-bucket.

      The complete path of the resource is as follows: OBS:*:*:bucket:example-bucket.

    Scope

    The default value is Global services.

  5. Click OK. The custom policy is created.
  6. Create a user group and assign permissions.

    Add the created custom policy to the user group by following the instructions in the IAM document.

  7. Add the IAM user you want to authorize to the created user group by referring to Adding Users to or Removing Users from a User Group.

    Due to data caching, it takes about 10 to 15 minutes for a custom policy to take effect after the authorization.