Sub topic 4
The IAM service role AWS Backup assumes
This chapter assumes you know how IAM roles, trust policies and managed policies work, and that you can run AWS CLI commands. Here you will see why AWS Backup needs a role, what the role contains, and how to fix the errors that come from a wrong or missing one.
Why a service role is needed
AWS Backup does not use your own credentials to read an EBS volume or write a recovery point. It assumes an IAM role that you supply, and it acts with that role's permissions. The role is called a service role. It appears in three places:
- A resource assignment, in the
IAMRoleArnfield. - An on-demand backup, in
--iam-role-arn. - A restore request, in
iamRoleArn.
If the role lacks a permission, the job fails even when you have full access yourself.
The two parts of the role
Every service role has a trust policy and one or more permissions policies.
- The trust policy lets the
backup.amazonaws.comservice principal assume the role. - The permissions policies say what AWS Backup may do after it assumes the role.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "backup.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}AWS provides two managed policies for the permissions:
| Managed policy | Purpose |
|---|---|
| `AWSBackupServiceRolePolicyForBackup` | Create backups of supported resources |
| `AWSBackupServiceRolePolicyForRestores` | Restore recovery points into new resources |
The default role
When you create a plan in the console, AWS Backup can create AWSBackupDefaultServiceRole for you. It carries both managed policies. With the CLI, nothing creates it, so you create it yourself. The ARN used in this tutorial is:
arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRoleCreate it and attach both policies:
aws iam create-role \
--role-name AWSBackupDefaultServiceRole \
--path /service-role/ \
--assume-role-policy-document file://trust.json
aws iam attach-role-policy \
--role-name AWSBackupDefaultServiceRole \
--policy-arn arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup
aws iam attach-role-policy \
--role-name AWSBackupDefaultServiceRole \
--policy-arn arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestoresCommon errors
- Access denied when assuming the role. The trust policy is missing
backup.amazonaws.com. - Job fails for one resource type only. The managed policy may not cover that service. Add a policy for the missing actions.
- KMS errors. If the resource or the vault uses a customer managed key, the role also needs permission to use that key. Grant it in the key policy or an IAM policy.
- Restore fails while backups succeed. The role has the backup policy but not the restore policy.
iam:PassRoledenied. The identity that creates the assignment, backup or restore must be allowed to pass the role to AWS Backup.
Exercise
A scheduled backup of an RDS database works, but a restore from its recovery point fails with an access error. The role has AWSBackupServiceRolePolicyForBackup attached. What is the likely cause and fix?
Show answer
The role lacks restore permissions. Attach AWSBackupServiceRolePolicyForRestores to the role, then retry the restore. Also check that the role can use the KMS key if the recovery point is encrypted with a customer managed key.