Sub topic 4
The IAM service role AWS Backup assumes
This chapter assumes you know how IAM roles, trust policies and permission policies work, and that you have used the AWS CLI. You should also have read the earlier chapters on vaults and backup plans. Here you will learn which role AWS Backup uses, what it needs to be allowed to do, and how to diagnose failures caused by it.
Why AWS Backup needs a role
AWS Backup does not run with your permissions. When a scheduled rule fires, no user is signed in. The service must read the protected resource, write a recovery point into a vault, and later create a new resource during a restore. It does this by assuming an IAM role in your account. That role is the service role.
Two separate permission checks are involved, and mixing them up causes most confusion:
- The role's trust policy decides who may assume the role. For AWS Backup, the trusted principal is
backup.amazonaws.com. - The role's permission policies decide what AWS Backup may do once it has assumed the role.
A third check applies to you, the person or automation calling the API. To hand a role to AWS Backup, you need the iam:PassRole permission on that role.
The default role
When you use AWS Backup in the console for the first time, it can create a role named AWSBackupDefaultServiceRole. Its path is service-role/, so the ARN looks like this:
arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRoleThis is the role used in the selection file and the start-backup-job example in this tutorial. If you work only with the CLI, the role may not exist yet. In that case, create it yourself or let the console create it.
The default role has two AWS managed policies attached:
| Managed policy | Purpose |
|---|---|
| `AWSBackupServiceRolePolicyForBackup` | Lets AWS Backup create backups of supported resource types. |
| `AWSBackupServiceRolePolicyForRestores` | Lets AWS Backup restore from recovery points. |
Amazon S3 uses its own pair of managed policies, AWSBackupServiceRolePolicyForS3Backup and AWSBackupServiceRolePolicyForS3Restore. Attach those too if the role will protect S3 buckets.
The split between the backup and restore policies matters. You can give a role backup permissions only, for example when a restore must go through a separate, more tightly controlled role.
Creating a custom role
You may want your own role instead of the default. Common reasons are naming standards, one role per team, or a permissions boundary. The trust policy is the same in every case:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "backup.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}Save it as trust.json, then create the role and attach the managed policies:
aws iam create-role \
--role-name TeamABackupRole \
--path /service-role/ \
--assume-role-policy-document file://trust.json
aws iam attach-role-policy \
--role-name TeamABackupRole \
--policy-arn arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup
aws iam attach-role-policy \
--role-name TeamABackupRole \
--policy-arn arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestoresCheck the result:
aws iam list-attached-role-policies --role-name TeamABackupRoleYou then use the new role's ARN in the IAMRoleArn field of a resource selection, or in --iam-role-arn for an on-demand job.
Where the role is chosen
The role is not part of the backup plan. It is supplied each time resources are tied to AWS Backup:
- In a resource assignment (the selection file), through
IAMRoleArn. - In an on-demand backup, through
--iam-role-arn. - In a restore, through the role used for the restore job.
This has a practical consequence. One plan can protect resources through several selections, each with a different role. A plan for the data team and a plan for the web team can share one set of rules while using different roles with different reach.
The caller needs iam:PassRole
Creating a selection or starting a job names a role. IAM requires the caller to be allowed to pass that role to AWS Backup. If your own identity lacks the permission, the call fails immediately, before any backup runs.
A minimal policy for the caller looks like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "arn:aws:iam::123456789012:role/service-role/TeamABackupRole",
"Condition": {
"StringEquals": { "iam:PassedToService": "backup.amazonaws.com" }
}
}
]
}Scoping Resource to specific roles prevents a user from handing AWS Backup a more powerful role than they should be able to use.
Permissions beyond the managed policies
The managed policies cover the usual cases. Several situations need extra permissions.
Encrypted resources and vaults
If a source volume or database is encrypted with a customer managed KMS key, the role must be allowed to use that key. The vault's own key matters too, as the encryption chapter explained. Check the key policy as well as the role. A key policy that does not trust the account's IAM policies, or does not name the role, blocks the job even when the role's identity policy looks correct.
Tag-based selections
A selection by tag requires AWS Backup to find resources by tag. The managed backup policy includes the needed tagging read permissions. If you build a custom role without the managed policy, include them yourself, or the selection will silently match nothing.
Restores that attach other resources
A restore sometimes creates a resource that references other IAM objects. Restoring an EC2 instance can involve an instance profile, for example. The role then needs iam:PassRole for that profile. When a restore fails and a backup of the same resource worked, look here first.
Restricting the role
Limiting the role is possible. You can attach a permissions boundary, or use a custom policy with fewer resource types than the managed one. Do this deliberately and test both backup and restore, because a role that is too narrow produces failed jobs only when the schedule fires, which may be hours later.
Service-linked role versus service role
AWS Backup also has a service-linked role, AWSServiceRoleForBackup. AWS creates and manages it for service-internal operations. You cannot edit its permissions. It does not replace the service role. You still supply a service role for backup and restore jobs.
Diagnosing role failures
Most role problems show up as a failed backup job with a message about permissions. Work through these checks in order:
- Does the role exist, and does its trust policy name
backup.amazonaws.com? - Are the backup and restore policies attached? List them with
list-attached-role-policies. - Does the role's ARN in the selection match exactly, including the
service-role/path? - If the resource is encrypted, does the KMS key policy allow the role?
- Is a permissions boundary, a service control policy or a resource policy denying an action? An explicit deny always wins.
- For a failed restore, does the role have
iam:PassRolefor the roles or profiles the new resource uses?
Inspect the failed job's status message first, with the job ID from the console or from list-backup-jobs:
aws backup describe-backup-job --backup-job-id <backup-job-id>The StatusMessage field usually names the missing permission or the failing step.
Exercise
A backup plan runs nightly and has worked for weeks. After a security cleanup, every job starts failing with a permissions error, although the plan, the vault and the selection are unchanged. Name two role-related causes you would check, and the command you would run first.
Show answer
Likely causes: the role's trust policy or attached managed policies were removed or changed, or the KMS key policy for an encrypted resource no longer allows the role. A permissions boundary or service control policy added during the cleanup could also deny an action. First run aws backup describe-backup-job --backup-job-id <backup-job-id> to read the status message. Then run aws iam list-attached-role-policies --role-name <role> to confirm that the policies are still attached.
Exercise
A developer can create backup plans but gets an access error when creating a selection that names TeamABackupRole. The role has the correct trust policy. What permission is probably missing, and how should it be scoped?
Show answer
The developer lacks iam:PassRole on TeamABackupRole. Scope it to that role's ARN, and add the condition iam:PassedToService equal to backup.amazonaws.com.