If the system default policies provided by the platform cannot meet your needs, you can create custom policies based on the principle of least privilege. This enables fine-grained permission control and enhances secure access by IAM identities to resources under the root account. This topic shows examples of common custom policies related to ECS instances as a reference.
- When creating a custom policy, you need to follow the basic structure and syntax. For details of policy element configuration, refer to Policy syntax.
- In the following examples, the API operation names listed under Action can be obtained from the API list.
- For the TRN format of ECS-authorized resources, refer to Resources.
Allow access to resources under specified projects
This policy allows viewing instances belonging to the "default" project under Account 210005****. When you grant authorizations by project, you need to select a project scope in addition to the existing authorization policy, thereby restricting permissions to the specified project.
Deny ECS instance deletion
tip
Deny takes precedence over Allow. If an identity has Deny permissions for certain actions, the Allow permissions for those same actions will not take effect. To resolve this, remove the relevant Deny statements or modify them to Allow.
Deny all instance deletion
Deny ECS resource deletion for instances with IDs i-yczzpbpgqoqc6ilc**** and i-yczv4tg64gqc6iks**** under account 200000000X
Allow ECS instance creation
Deny ECS instance information change
Restrict ECS instance access
Allow actions on the ECS instance with the ID i-yczzpbpgqoqc6ilc**** under account 200000000X
Allow ECS resource viewing
Access ECS from a specific IP address
Only ECS resources with the tag key "ecs" and a condition value of "use" can be accessed
Allow access to tag feature
Deny key pair deletion
Only allow O&M orchestration tasks to apply for, query, and associate Elastic IPs (EIPs)
Restrict the use of target custom commands to the specified IAM users