This document summarizes a talk on building AWS partner applications using IAM roles. It discusses using the AssumeRole API to access AWS resources across accounts with temporary credentials instead of long-term access keys. It also covers using an external ID parameter to prevent confused deputy attacks by verifying the account being accessed belongs to the user. The document provides code samples and recommends architectures that use least privilege and isolate privileged instances.
3. Use cases
•Cloud management platform
•Log analysis
•Cloud spend analysis
•Operating across more than one AWS account
•Generalized: AWS applications that access other AWS accounts
4. Anti-patterns
•Ask for access key IDand secret access key
•Asking users to trust you more than they should
–“Create an admin user and send us the creds”
•Eager IAM policies
–action: *
5. Requirements
•Act within another AWS account
•Take on subset of permissions to act within AWS
•Cannot be required to persist a secret(s)
6. AssumeRole API call
“Returns a set of temporary security credentials that you can use to access AWS resources that you might not normally have access to.Typically, you use AssumeRolefor cross-account access or federation.”
http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html
7. DescribeInstances example
•Given account IDand region
•Print instance names and status
•Setup required:
–IAM role in customer account
–Role trust in customer account
10. Easy ones
•Duration: validity period for creds, 900-3600sec
–Go shorter with IAM policy variables
•RoleArn: The ARN of the role you’re assuming
•SerialNumber:For an MFA device
–Hardware serial number for gemalto
–ARN for virtual
•arn:aws:iam::<account id>:mfa/<iamuser>
•TokenCode: Code from MFA device
11. Policy
•JSON string with valid IAM policy up to 2048 bytes
•Use this to further restrict permissions by scoping down the policy
•Imagine a logical and of the role’s policies with this new policy.
–i.e. May only be used to restrict access of the role being assumed
13. RoleSessionName
•Between 2 and 32 characters long
•Fairly restrictive character set:
–^[w+=,.@-]{2,32}$
•Useful for auditing
•Shows up in AWS CloudTraillogs (i.e. name wisely)…
session_name= “Hi-Mom”
sts_conn.assume_role(role_arn, session_name)
14. CloudTrail in your account
'requestParameters': {
‘durationSeconds': 2011,
'roleArn': ‘arn:…role/role-name’,
'roleSessionName': ‘Hi-Mom’},
18. ExternalId
•A pre-shared secret between you and your customer
•String from 2-1224 bytes long
•Used to prevent “confused deputy” problem
“A confused deputy is a computer program that is innocently fooled by some other party into misusing its authority.”
http://en.wikipedia.org/wiki/Confused_deputy_problem
19. Let’s confuse the deputy
•Assume a cloud management platform
•Customers bring their own AWS account
23. We’ve been owned
•Attacker has obtained a login to our platform
•Attacker has given a legitimate customer’s AWS ID(the victim’s) instead of his own
•Attacker can now use our platform to view and act within the victim’s AWS account.
•Oops.
24. What went wrong?
•We never verified that our user owned the AWS account in question
•AWS provides the External IDparameters,which lets us do that
26. Prevent that attack
•Customer brings 12-digit IDon signup
•You generate an external IDand hand to customer
•Customer sets up roles and trust, including the external IDyou specified
•Attack mitigated
–Attacker can only leverage your platform to takeover customer account if they have already compromised the customer account and can modify the trust policy
27. Are you vulnerable?
•Do you allow customers to bring their own account?
•Are you using external IDas described here?
•If not, your customers are at risk.
•It’s your fault.
29. Notch it up
•Let’s build our cloud management platform on AWS
•Use Amazon EC2 instance profiles to seed access
•Instance profile should reference an access policy that is again least privilege
•The more privileged an instance, the further from users/attackers it should be