If the origin for your accelerated domain name is a private Alibaba Cloud Object Storage (OSS) bucket, we recommend enabling the Alibaba Cloud OSS Private Bucket Access feature. This provides access control to prevent traffic theft and allows CDN to accelerate resources from your private bucket.
How it works and benefits
-
How it works: After you enable this feature, when CDN or DCDN sends an origin fetch request to your private OSS bucket, they automatically add an
Authorizationfield to the request header. The value of this field is a valid signature generated from the authorized identity information, such as an STS temporary token or an AccessKey. OSS uses this signature to authenticate the request. -
Secure access: By granting CDN or DCDN limited, read-only permissions, you ensure the legitimacy of origin fetch requests and avoid the security risks of making a private bucket public.
-
Cost optimization: End-user requests are served from the CDN cache, which is more cost-effective than serving them directly from OSS. Origin fetch traffic from CDN or DCDN to OSS is billed as lower-priced CDN origin fetch traffic, not as more expensive outbound Internet traffic from OSS. This reduces your overall costs. For more information, see Billing of CDN-accelerated OSS resources.
Procedure
The configuration involves two steps: first, grant one-time authorization for your account, and then enable the feature for a specific accelerated domain name.
-
Authorize CDN or DCDN to access OSS. Before you can enable this feature for any domain name in your account, you must grant CDN or DCDN permission to access OSS. This is a one-time, account-level operation. If you are not prompted to grant authorization, skip to the next step.
(Recommended) One-click authorization
-
Log on to the CDN console.
-
In the left-side navigation pane, click Domain Names.
-
On the Domain Names page, find the domain name that you want to manage and click Manage in the Actions column.
-
In the left-side navigation pane of the domain name's configuration page, click Origin Fetch.
-
In the Alibaba Cloud OSS Private Bucket Access section, click Authorize. In the confirmation dialog box that appears, click Authorize.
The Role Authorization row indicates that the CDN service is not authorized to access your OSS buckets. The Status switch is off by default.
(Alternative) Manual authorization with RAM
-
Log on to the RAM console.
-
In the left-side navigation pane, choose Permissions> Policies.
-
On the Policies page, click Create Policy.
-
On the Script Editor tab, enter the following policy content:
-
Click OK. On the Create Policy page, enter the following information and click OK.
-
Policy Name: AliyunCDNAccessingPrivateOSSRolePolicy
-
Remarks: An authorization policy for the role that allows CDN or DCDN to perform origin fetch from a private OSS bucket. This policy grants read-only permissions to OSS.
{ "Version": "1", "Statement": [ { "Action": [ "oss:List*", "oss:Get*" ], "Resource": "*", "Effect": "Allow" } ] }In the left-side navigation pane, choose Identities> Roles.
-
On the Roles page, click Create Role.
-
Set Trusted Principal Type to Cloud Account, select Current Cloud Account as the Trusted Principal Name, and click OK.
-
In the Create Role step, enter the following information.
-
Role Name: AliyunCDNAccessingPrivateOSSRole
After the role is created, find and click AliyunCDNAccessingPrivateOSSRole in the list on the Roles page to open the role details page.
-
On the Trust Policy tab, click Edit Trust Policy, enter the following content, and then click OK.
-
Switch to the Permissions tab. On the Authorize tab, click Add Authorization.
-
Resource Scope: Account Level
-
Principal: Select the AliyunCDNAccessingPrivateOSSRole role that you created.
-
Policy: Select Custom Policy, select the AliyunCDNAccessingPrivateOSSRolePolicy policy that you created, and then click Confirm New Authorization.
{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "cdn.aliyuncs.com" ] } } ], "Version": "1" }After you click Confirm New Authorization, return to the Origin Fetch page in the CDN console. You can see that the Alibaba Cloud OSS Private Bucket Access feature is now authorized.
-
-
Enable Alibaba Cloud OSS Private Bucket Access and configure the origin type.
-
In the Alibaba Cloud OSS Private Bucket Access section, turn on the switch.
-
In the Alibaba Cloud OSS Private Bucket Access dialog box that appears, select an origin type and click OK.
Origin type
Description
Bucket in the Same Account
(Recommended) Use this option when the CDN or DCDN service and the OSS bucket belong to the same Alibaba Cloud account. The system uses an STS temporary token for authentication, which simplifies configuration, eliminates key management, and improves security.
You can also use an STS temporary token for cross-account origin fetch. For more information, see Use STS to access a private OSS bucket in a different account.
Bucket Across Accounts or in the Same Account
Use this option when the CDN or DCDN service and the OSS bucket belong to different Alibaba Cloud accounts. This option also supports same-account scenarios. You must provide the AccessKey ID and AccessKey Secret of the account that owns the private OSS bucket. For more information, see Create an AccessKey.
Note-
Scope of access: After you enable this feature, the accelerated domain name can access all resources in its origin private bucket. You cannot use CDN or DCDN to restrict access to specific resources within the bucket.
-
Signature conflicts: To prevent OSS authentication failures, ensure that an origin fetch request does not contain signatures in both the request header and URL parameters.
-
Feature conflicts: This feature conflicts with the default index page setting of the static website hosting feature in OSS. If you need to use both features at the same time, see the related documentation.
-
-
Security recommendations
After you enable origin fetch from a private bucket, your origin data is secure. However, resources cached on CDN POPs are publicly accessible by default. To prevent traffic theft, use additional security features from CDN or DCDN:
-
Configure a Referer blacklist or whitelist: Restrict access to your CDN resources to requests from specific websites.
-
Configure URL signing: Set a dynamic signature and an expiration time for your resource URLs to effectively prevent malicious downloads.
Disable private OSS bucket origin fetch
If you no longer want an accelerated domain name to access resources in a private bucket, you can go to the Resource Access Management (RAM) console to revoke the authorization for the corresponding role. This revokes the permissions that allow CDN to access the private OSS bucket.
-
Disable the feature in the CDN console.
-
Log on to the CDN console.
-
In the left-side navigation pane, click Domain Names.
-
On the Domain Names page, find the domain name that you want to manage and click Manage in the Actions column.
-
In the left-side navigation pane, click Origin Fetch.
-
In the Alibaba Cloud OSS Private Bucket Access section, turn off the Alibaba Cloud OSS Private Bucket Access switch.
-
-
Permanently delete the authorization in the RAM console.
-
Log on to the RAM console.
-
In the left-side navigation pane, choose .
-
In the Role Name list, click the AliyunCDNAccessingPrivateOSSRole role.
On the role details page, go to the Permissions tab. You can view the authorized system policy, which has the remark "An authorization policy for the role that allows CDN/DCDN to perform origin fetch from a private OSS bucket and grants read-only permissions to OSS". The resource scope is Account Level. The Actions column provides a Revoke Authorization link, and there is a Delete Role button in the upper-right corner of the page.
-
Remove all permissions from the AliyunCDNAccessingPrivateOSSRole role.
-
Click Revoke Authorization for the policy.
-
In the confirmation dialog box that appears, click Revoke Authorization.
-
-
Return to the page and delete the AliyunCDNAccessingPrivateOSSRole role.
-
Find the AliyunCDNAccessingPrivateOSSRole role and click Delete Role in the Actions column.
-
In the Delete Role confirmation dialog box, click Delete Role.
-
-
Return to the page and delete the AliyunCDNAccessingPrivateOSSRolePolicy policy.
-
Find the AliyunCDNAccessingPrivateOSSRolePolicy policy and click Delete Policy in the Actions column.
-
In the Delete Policy confirmation dialog box, enter the policy name and click Delete Policy.
-
-
FAQ
How do I resolve the This request is forbidden by kms. error when CDN or DCDN accesses OSS resources?
If your OSS bucket is encrypted with Key Management Service (KMS), you must grant the AliyunCDNAccessingPrivateOSSRole role the permission to use the KMS key. Otherwise, CDN or DCDN cannot decrypt and access the files, resulting in a This request is forbidden by kms. error. To resolve this issue, grant the required KMS permissions to the role.
-
Log on to the RAM console.
-
In the left-side navigation pane, choose .
-
In the Role Name list, find and click the AliyunCDNAccessingPrivateOSSRole role.
-
Click Add Authorization. The Principal is automatically populated.
-
Under Policies, select System Policies, search for and click AliyunKMSCryptoUserAccess to add it to the Selected Policies box.
-
Click Confirm New Authorization. A message indicates that the operation is Completed.
-
Click Disable.
-
Use the refresh and prefetch feature to clear the cache. After the refresh task is complete, try to access the resource again.
Related documentation
Best practices for using CDN to accelerate access to OSS resources