Create a role
Create a role, attach the policies it carries, and assign it to IAM users or let a workload assume it.
A role is a set of policies. Assigned to an IAM user, it gives the user every policy attached to the role. With a trust policy, a workload such as a GitHub Actions job can assume it with an OIDC token instead of a stored key. Replace ci-deployer with the role's name, and role-id, user-id and policy-id with ids.
Prerequisites
- Permission for
iam:CreateRoleandiam:AttachRolePolicy. - To assign the role to a user,
iam:AssignUserRoleon that user; to take it away,iam:RemoveUserRole. - To delete the role,
iam:DeleteRole. - In the console, also
iam:ListRolesto see Roles andiam:GetRoleon the role to open its page (without it the page is not found). To assign the role from a user's page, alsoiam:GetUseron the user.
Create the role
- Open Identity, then choose Roles.
- Choose Create role. Enter the name ci-deployer and, optionally, a description.
- Choose Create role. The role's page opens.
- Choose Permissions, pick a policy from the list, then choose Attach. Repeat for each policy.
- To assign the role to a user, open the user, choose Permissions, pick the role from the list under Roles, then choose Add.
dcloud iam roles create --name ci-deployer --description "Deploys from CI"
dcloud iam roles attach-policy role-id --policy-id policy-id
dcloud iam users assign-role user-id --role-id role-idPOST /iam/api/roles
{ "name": "ci-deployer", "description": "Deploys from CI" }Then POST /iam/api/roles/{id}/policies with {"policyId": …}, and
POST /iam/api/users/{id}/roles with {"roleId": …}.
resource "dcloud_iam_role" "ci_deployer" {
name = "ci-deployer"
}
resource "dcloud_iam_role_policy_attachment" "ci_deployer_deploy" {
role_id = dcloud_iam_role.ci_deployer.id
policy_id = dcloud_iam_policy.deploy.id
}
resource "dcloud_iam_user_role_assignment" "alice_ci_deployer" {
user_id = dcloud_iam_user.alice.id
role_id = dcloud_iam_role.ci_deployer.id
}Result
Everyone assigned the role holds every policy attached to it. Detaching a policy, or removing the role from a user, takes those permissions away at once.
For a workload to assume the role, give it a trust policy; see Set a trust policy.
To delete the role, open it and choose Danger zone, then Delete role, and type its name
(dcloud iam roles delete).
A preset role that ships with Deutsche Cloud is shown as managed: in the console its policies cannot be changed and it cannot be deleted.
If a change is refused
- 404
Role not found,IAM user not found, orRole or policy not foundfor an id that is not in your organization. - 400
Cannot delete a managed rolefor a preset role. - 409
Quota exceeded: …when the organization has as many roles as its quota allows; see Quotas.