Realtime Compute for Apache Flink supports referencing RAM roles in namespaces. By assuming a RAM role, jobs use temporary STS tokens instead of plaintext AccessKey pairs to access Alibaba Cloud resources. This enables credential-free access, fine-grained permission control, and maintenance-free credential management.
Overview
By referencing a RAM role, you can use the role to access other Alibaba Cloud services, such as OSS and KMS, from Flink jobs, without exposing plaintext AccessKey pairs in the job code.
Key benefits:
-
Sensitive information protection: No AccessKey pairs are exposed in jobs. The RAM role STS token replaces static credentials.
-
Fine-grained permission control: RAM role permission policies are customizable. Different connectors can use different roles to enforce the principle of least privilege.
-
Maintenance-free credentials: STS tokens are automatically obtained and renewed by the system, with no need to manage credential rotation.
For details, see Appendix: STS invocation flow.
Notes
Incorrectly deleting or modifying the permissions and trust policy of a RAM role in RAM may cause Flink jobs to fail because they cannot access cloud resources. According to the Service Level Agreement for Realtime Compute for Apache Flink, unavailability caused by incorrect resource usage by customers is not covered by the SLA.
Limits
-
Only VVR 11.8 and later engines are supported. The OSS Connector and Postgres CDC Connector support accessing cloud resources with RAM roles.
-
Up to 10 RAM roles can be referenced per workspace.
-
A single add operation supports selecting up to 5 roles.
-
Only regular service roles (SR) can be referenced. Service-linked roles (SLR) are not supported.
-
STS tokens are not supported for local debugging of PyFlink and Flink JAR jobs. The jobs must be deployed to a cluster before use.
-
Only RAM identity authentication for Alibaba Cloud services is supported.
Permission preparation
-
Step 1 and Step 2: The operator must be granted the
AliyunRAMFullAccesspolicy, or separately granted RAM role management and permission management permissions. For more information, see Create a custom policy and API overview for RAM role management and permission management. -
Step 3: The operator must have editor permissions or higher on the Flink namespace, or be granted fine-grained permissions to reference RAM roles and develop jobs. For details, see Grant permissions to access the development console.
Step 1: Create and configure a RAM role
This role is the identity credential that the Flink service uses to access other cloud resources. Flink assumes this role to obtain temporary credentials and access cloud resources as the role.
1. Create a RAM role
-
Log on to the RAM console - Roles page and click Create Role. Keep the default options (the trusted entity is the current Alibaba Cloud account) and click OK.
-
Enter a recognizable role name, for example,
FlinkRoleForOSSRead, and click OK.
2. Add a trust policy
Flink assumes the RAM role to obtain temporary credentials. The RAM role must trust Flink to assume it.
After the role is created, on the role details page, click the Trust Policy tab and click Edit Trust Policy. Add "Service": ["stream.aliyuncs.com"] to Principal to trust Flink to assume the role. For more information, see Modify the trust policy of a RAM role.
{
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": [
"stream.aliyuncs.com"
]
}
}
],
"Version": "1"
}
3. Grant permissions to access cloud resources
Flink uses the RAM role identity to access cloud resources. Grant the required permissions to the RAM role in advance to prevent access errors.
On the role details page, click the Permissions tab and click Grant Permission to grant the role permissions to access target cloud resources.
For example, to access OSS, grant AliyunOSSReadOnlyAccess (read-only) or AliyunOSSFullAccess (full) permissions. For more information, see Grant permissions to a RAM role.
Step 2: Grant permissions to a RAM user
Create a permission policy and grant it to the RAM user. This allows the user to pass the RAM role created in Step 1 to the Flink service for assumption.
If the RAM user in Step 3 is already associated with the AliyunRAMFullAccess or AliyunStreamFullAccess policy, the user already has the PassRole permission. You can skip this step.
Create a permission policy
Log on to the RAM console - Policies page and click Create Policy. Switch to Script mode and edit the policy content.
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ram:ListRoles"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "ram:PassRole",
"Resource": "acs:ram::<account-id>:role/<role-name>",
"Condition": {
"StringEquals": {
"acs:Service": "stream.aliyuncs.com"
}
}
}
]
}
|
Permission |
Description |
|
|
Allows the user to view the role list under the account, so that the role can be selected in the Flink console. |
|
|
Allows the user to pass the specified role to the Flink cloud service. Replace
Add a |
Click OK to save the policy, for example, as FlinkPassRolePolicy. For more information, see Create a custom policy.
Grant permissions to the RAM user
-
Log on to the RAM console - Users page. Find the RAM user to authorize and click Add Permissions in the Actions column.
-
In the Add Permissions panel, search for and select the policy created in Step 2 (for example,
FlinkPassRolePolicy), then click Confirm. For more information, see Grant permissions to a RAM user.
Step 3: Reference the RAM role in Flink
Users authorized in Step 2 can pass the RAM role from Step 1 to Flink. Flink assumes the role to obtain temporary credentials and access cloud resources as the role.
Add a RAM role reference
-
Log on to the Realtime Compute console and enter the target workspace.
-
In the left-side navigation pane, choose .
-
Click the RAM Roles tab.
-
Click Reference RAM Role.
-
In the dialog box, configure the following:
Item
Required
Description
RAM role
Yes
Select the role from the drop-down list. Fuzzy search by role name and multi-select (up to 5 per operation) are supported. Referenced roles cannot be selected again.
Note-
The role list contains regular service roles under the Alibaba Cloud account that owns the current namespace.
-
The operator must belong to the same Alibaba Cloud account as the current namespace and have the
ListRolespermission to view the roles.
Description
No
Role description. Up to 256 characters.
-
-
Click Test. The system automatically checks the following two items:
-
PassRole permission check: The current user has the
ram:PassRolepermission on the selected RAM role. -
Trust policy check: The selected RAM role trusts the current Flink namespace to assume it.
-
-
After the checks pass, click OK.
Use the RAM role in jobs
After the RAM role is referenced, specify the role name using the akless.assume-role.role-name parameter in the job code. Flink assumes the role to obtain the temporary STS token and accesses cloud resources as the role.
Only the OSS Connector and Postgres CDC Connector of VVR 11.8 and later engines support this feature.
Parameter description
|
Parameter |
Type |
Required |
Description |
|
akless.assume-role.role-name |
String |
No |
The name of the RAM role, for example, |
Priority rules
-
If an AccessKey pair (accessKeyId + accessKeySecret) is explicitly specified, the AccessKey pair takes the highest priority.
-
If no AccessKey pair is specified but
akless.assume-role.role-nameis, the STS token of the role is used. -
Different connectors in a job can use different roles by specifying different
akless.assume-role.role-namevalues.
OSS example
Add the following configuration in Other Configuration under Runtime Parameters on the Deployment Details tab:
# OSS
fs.oss.bucket.<bucketName>.akless.assume-role.role-name: <your-role-name>
fs.oss.inner.bucket: <workspace-associated-bucket-name>
# OSS-HDFS
fs.oss.jindo.akless.assume-role.role-name: <your-role-name>
|
Parameter |
Description |
|
|
The bucket name in the target file system path parameter ( |
|
|
Check the Storage Type field on the workspace list page to determine whether the workspace uses a self-managed OSS bucket or fully managed storage, and obtain the bucket name accordingly:
|
|
|
The name of the RAM role used to access OSS. |
Manage RAM role references
Editing or removing a RAM role in Flink affects only the Flink reference to the RAM role. It does not directly modify the RAM role.
Edit a RAM role
-
Under Security Services > Access Security > RAM Roles, find the target role and click Edit in the Actions column.
-
In the dialog box, modify the description. The role name cannot be modified.
-
Click Test. After the checks pass, click OK.
Remove a RAM role
After you remove a RAM role, all jobs in the current namespace that reference the role will fail. Proceed with caution.
-
Under Security Services > Access Security > RAM Roles, find the target role and click Remove in the Actions column.
-
In the confirmation dialog box, enter the role name and click Confirm Removal.
Refresh role status
Click Refresh in the upper-right corner of the RAM Roles list to check the status of all referenced roles in bulk.
|
Status |
Description |
|
Normal |
The role exists in RAM and the STS token is valid. |
|
Abnormal |
The role has been deleted from RAM, or the trust policy no longer allows Flink to assume it. Jobs referencing this role may run abnormally. |
Appendix: STS invocation flow
Alibaba Cloud RAM provides two core role-related authorization models: direct assumption (AssumeRole) and delegated authorization (PassRole).
Model 1: Direct assumption (sts:AssumeRole)
-
Core action: A trusted entity (such as a RAM user or an application) actively calls the STS
AssumeRoleAPI to obtain temporary credentials for a RAM role, effectively "transforming" into that role. -
Authorization chain:
Entity A→Calls sts:AssumeRole→Assumes Role R→Obtains Role R permissions. -
Permission requirement: Entity A must be granted the
sts:AssumeRolepermission. -
Typical scenario: An application running on ECS or a local server needs to temporarily access OSS. The application uses its own AccessKey pair to call
AssumeRole, obtains temporary credentials, and then uses them to access OSS. In this scenario, Entity A is the active executor.
Model 2: Delegated authorization (ram:PassRole)
-
Core action: An entity (such as a RAM user) "passes" a RAM role to a cloud service (such as Flink), authorizing the service to assume the role. The user does not assume the role.
-
Authorization chain: User_B → Passes Role_A → To the cloud service → The cloud service calls
sts:AssumeRoleto assume Role_A → The cloud service obtains Role_A permissions. -
Permission requirement: User B must be granted the
ram:PassRolepermission, and Role A must trust the cloud service to assume it. -
Typical scenario: A developer (User_B) develops a job in the Flink console and specifies a role (Role_A). To allow the Flink service to access cloud resources on behalf of the user, the user must have the permission to pass Role_A to the Flink service. In this scenario, the user is the authorizer, and the cloud service is the executor.
Example: Flink accessing OSS
The interaction flow of the delegated authorization (PassRole) model consists of a configuration phase and a runtime phase:
-
Configuration phase:
-
The RAM administrator completes basic setup, including creating the role, configuring its permissions and trust relationship, and granting the
PassRolepermission to the user. -
The user adds a RAM role reference in Flink. The Flink platform verifies that the user is authorized to "pass" the role and that the role trusts Flink to assume it.
-
-
Runtime phase:
-
Service assumes the role: The Flink service (
stream.aliyuncs.com), as the actual role assumer, sends anAssumeRolerequest to STS. -
STS authorization and service execution: STS confirms that Flink is trusted by Role A, then issues temporary credentials. The Flink service uses these credentials to access OSS and complete the task delegated by the user.
-