Mount an OSS bucket across Alibaba Cloud accounts
PAI DSW, DLC, and EAS instances can access OSS buckets owned by a different Alibaba Cloud account through either a bucket policy (OSS-side authorization) or a RAM role (RAM-side authorization). This topic describes both approaches and compares when to use each.
This topic uses DSW as an example. The procedure is similar for DLC and EAS. For EAS, the trusted cloud service is eas.pai.aliyuncs.com.
Solution overview
Scenario: Account A owns an OSS bucket. A PAI DSW instance under Account B needs to mount this bucket.
How it works: Cross-account mounting grants the DSW instance in Account B permission to access the OSS bucket in Account A. Both approaches use a RAM role. When you create a DSW instance, you specify a role that the DSW service assumes to access OSS. The key difference is who creates the role and how permissions are granted:
-
Approach 1: Bucket policy (recommended) — Account B creates the role. Account A grants access through a bucket policy on the OSS side.
-
Approach 2: RAM role authorization — Account A creates the role, grants it OSS permissions, and trusts the PAI service in Account B to assume it.
The following table compares the two approaches:
|
Approach 1: Bucket policy (recommended) |
Approach 2: RAM role authorization |
|
|
Role creation |
Created by Account B |
Created by Account A |
|
Permission configuration |
Account A configures a bucket policy in the OSS console |
Account A attaches an OSS access policy to the role in the RAM console |
|
Authorization granularity |
Per bucket — configure each bucket separately |
Per role — a single policy can cover multiple buckets |
|
Use case |
Few buckets; Account A wants to manage access directly on the OSS side |
Many buckets, or multiple accounts share the same role for centralized access management |
Procedure
Step 1: Create a RAM role and grant permissions
Approach 1: Bucket policy (recommended)
1. Account B creates a RAM role
Account B creates a RAM role with a cloud service as the trusted entity:
-
Log on to the RAM console. In the left-side navigation pane, choose .
-
Click Create Role:
-
Principal Type: Select Cloud Service.
-
Principal Name: Select Machine Learning Platform for AI / PAI pai.aliyuncs.com. (For EAS, select eas.pai.aliyuncs.com instead.)
-
-
Click OK, enter a role name such as
oss-access, and then click OK again.
The resulting trust policy allows the PAI service to assume this role:
{
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": ["pai.aliyuncs.com"]
}
}
],
"Version": "1"
}
2. Account A configures a bucket policy
For detailed steps, see the OSS documentation: Bucket Policy:
-
Log on to the OSS console as Account A. In the Buckets, click the target bucket.
-
In the left-side navigation pane, choose .
-
Select Add in GUI, and then click Authorize. Configure an authorization rule as needed:
-
Authorized User: Select Other Accounts.
-
In the text box, enter the temporary identity ARN that the PAI service obtains by assuming the RAM role. Format:
arn:sts::<UID of Account B>:assumed-role/<Role name of Account B>/*
-
Approach 2: RAM role authorization
1. Account A creates a RAM role
Account A creates a RAM role that trusts the PAI service under Account B:
-
Log on to the RAM console. In the left-side navigation pane, choose .
-
Click Create Role. In the upper-right corner of the page, select Switch to Policy Editor.
-
In the visual editor, set Principal to Cloud Service, and then click Edit to add a principal:
-
For Cloud Account, select Other Cloud Account and enter the UID of Account B.
-
For Cloud Service, select Machine Learning Platform for AI / PAI pai.aliyuncs.com. (For EAS, select eas.pai.aliyuncs.com instead.)
-
-
Click OK, enter a role name such as
oss-access-for-B, and then click OK again. -
After the role is created, copy the ARN from the role details page and share it with Account B. Account B uses this ARN to mount the OSS bucket. Format:
acs:ram::<UID of Account A>:role/<Role name>
The resulting trust policy is equivalent to:
{
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": "<UID of Account B>@pai.aliyuncs.com"
}
}
]
}
Add other principals as needed.
2. Account A grants OSS permissions to the role
Attach the following access policy to the role oss-access-for-B that you just created:
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"oss:GetObject",
"oss:ListObjects",
"oss:PutObject",
"oss:DeleteObject"
],
"Resource": [
"acs:oss:*:<UID of Account A>:<bucket-name>",
"acs:oss:*:<UID of Account A>:<bucket-name>/*"
]
}
]
}
Adjust the Action scope as needed. For read-only scenarios, keep onlyGetObjectandListObjects.
Step 2: Create a DSW instance and mount the OSS bucket
-
Grant permissions (RAM users only)
If you use a RAM user (sub-account) to create a DSW instance, ask the primary Alibaba Cloud account to grant the required permissions. By default, RAM users do not have permission to pass a role to a cloud service.
For more information, see Manage RAM user permissions. The following example shows a custom policy that grants the required permissions:
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": "ram:PassRole", "Resource": "acs:ram::<UID of the account that owns the role>:role/<Role name>" } ] }Replace
<UID of the account that owns the role>and<Role name>with the UID and role name of the RAM role you created in the previous step. -
Create a DSW instance and mount the OSS bucket.
Method 1: PAI console (recommended)
-
Log on to the PAI console. In the left-side navigation pane, choose Model Training > Data Science Workshop (DSW).
If you have multiple workspaces, select the target workspace.
-
Click Create an instance.. In the Environment Information section, set Storage Mount to OSS.
-
Select OSS Mount and enter the Account A bucket path:
-
Uri: Enter the Account A bucket path in the following format:
oss://{bucket-name}.oss-{region}-internal.aliyuncs.com/{path}/. -
Mount Path: For example,
/mnt/data. -
RAM Role: Select the role that Account A has authorized.
If the drop-down list is empty, enter the ARN manually.
-
Method 2: API / CLI
Call the
CreateInstanceAPI and specifyRoleArnin theDatasetsparameter:aliyun pai-dsw create-instance \ --region cn-hangzhou \ --workspace-id {Workspace ID of Account B} \ --instance-name cross-account-oss-demo \ --ecs-spec ecs.gn6v-c8g1.2xlarge \ --image-url registry.cn-hangzhou.aliyuncs.com/pai-dlc/pytorch-training:2.0-gpu-py310-cu118-ubuntu20.04 \ --accessibility PRIVATE \ --datasets '[{ "Uri": "oss://{Bucket name of Account A}.oss-cn-hangzhou-internal.aliyuncs.com/data/", "MountPath": "/mnt/data", "MountAccess": "RO", "RoleArn": "<RAM role with OSS access>" }]'Key parameters:
Parameter
Description
UriThe OSS bucket path of Account A. Use the internal endpoint (
oss-{region}-internal.aliyuncs.com) to avoid data transfer fees.MountPathThe mount path inside the container, such as
/mnt/data.MountAccessRO= read-only.RW= read-write.RoleArnThe ARN of the RAM role that the DSW service assumes.
-
Approach 1: The ARN of the RAM role under Account B, such as
acs:ram::<UID of Account B>:role/<Role name> -
Approach 2: The ARN of the RAM role under Account A, such as
acs:ram::<UID of Account A>:role/<Role name>
-
Step 3: Verify the mount
After the DSW instance starts, open the terminal and check whether the mount succeeded:
ls /mnt/data
If the files from the Account A OSS bucket are listed, the cross-account mount succeeded.
Usage notes
-
Least privilege: Grant only the bucket and action permissions required. For read-only scenarios, grant only
GetObjectandListObjects. -
Use internal endpoints: Include
-internalin the URI domain to avoid data transfer fees. -
RoleArn can be added later: For existing instances, call
UpdateInstanceto modify the Datasets configuration and add a RoleArn. -
Works with Options: To configure JindoFuse parameters such as caching policies, use the
Optionsfield. You can useOptionstogether withRoleArn. -
Regular audit: Review role access logs in the RAM console to detect unusual activity.
FAQ
|
Issue |
Cause |
Solution |
|
|
The bucket policy is misconfigured or the Principal is incorrect |
Check that the Principal in the bucket policy exactly matches the ARN of the role under Account B |
|
DSW instance fails to start with a RoleArn error |
The trust policy of the role under Account B does not include |
Add the PAI service to the trust policy of the role |
|
Can read but cannot write |
OSS permissions only include GetObject |
Add write actions such as PutObject and DeleteObject |
|
Mount path is empty |
The URI path does not exist or has no objects under that prefix |
Verify that files exist under the specified path in OSS and that the path ends with |