Prohibit RAM users from creating Linux instances with root as the initial user
Use RAM access policies to enforce ecs-user as the initial logon user for Linux ECS instances instead of root.
Limitations
Windows instances do not support creating non-administrator users during instance creation. Do not apply these access policies to Windows instances.
Some Linux images do not support ecs-user creation. See Public image release notes for unsupported image versions.
Procedure
This example prohibits a RAM user named Alice from creating Linux instances with root as the initial logon user.
Create a RAM user named Alice in the RAM console.
See Create a RAM user.
Create an access policy named ecs-root-user-control in the RAM console. Add the following policy content in the script editor.
NoteThis policy denies setting the logon username to root when creating an ECS instance and denies resetting root logon credentials by replacing the system disk.
{ "Version": "1", "Statement": [ { "Action": [ "ecs:RunInstances", "ecs:CreateInstance", "ecs:CreateOrder", "ecs:ReplaceSystemDisk", "ecs:AttachDisk", "ecs:InvokeCommand" ], "Resource": "*", "Condition": { "Bool": { "ecs:LoginAsNonRoot": [ "false" ] } }, "Effect": "Deny" } ] }Create another access policy named ecs-admin. Add the following policy content in the script editor.
NoteThis policy grants permissions to purchase, manage, and view ECS instances, simulating an ECS administrator. Modify the policy as needed.
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "ecs:*", "ecs-workbench:*", "vpc:CheckCanAllocateVpcPrivateIpAddress", "vpc:DescribeVpcs", "vpc:DescribeVSwitches", "bss:ModifyAgreementRecord", "bss:DescribeOrderList", "bss:DescribeOrderDetail", "bss:PayOrder", "bss:CancelOrder" ], "Resource": "*" } ] }Grant permissions to the RAM user Alice in the RAM console.
Set Authorization Scope to Account. Select the RAM user Alice as the principal. Select the custom policies ecs-root-user-control and ecs-admin. See Grant permissions to a RAM user.
Verify the results
Log on to the Alibaba Cloud Management Console as the RAM user Alice.
See Log on to the Alibaba Cloud console as a RAM user.
, the precheck succeeded.
, the precheck failed. Fix the issue as instructed and retry.