aws-notebook

My AWS Notebook

View the Project on GitHub kyhau/aws-notebook

Identity and Access Management

Topics


IAM

IAM Policies

  1. Identity policies (users, groups, roles) allow those identities to be ALLOWED or DENIED access to resources.
  2. Resource policies control who has access to that specific resource from its perspective (specify “Principal”). E.g. S3 Bucket Policy.
  3. Roles
    App --- (sts:AssumeRole)   --> Role
    App <-- (Temp credentials) <-- Role
    

Policy Evaluation


Cross-account access to S3 bucket and objects

There are 3 ways to provide access to a S3 bucket (Account A) from another AWS account (Account B).

  1. Bucket Policy and IAM Policy
    • For programmatic-only access to S3.
    • Account B users are the owner of any objects created. Bucket policies can require Account A be the owner for objects as they are put in the bucket.
    • Bucket Policy at account A
         "Effect": "Allow",
         "Principal": {"AWS": "arn:aws:iam::AccountB:user/AccountBUserName"},
         "Action": ["s3:GetObject", "s3:PutObject", "s3:PutObjectAcl"],
         "Resource": "arn:aws:s3:::AccountABucketName/*"
      
    • IAM role or user in Account B with IAM policy
         "Effect": "Allow",
         "Action": ["s3:GetObject", "s3:PutObject", "s3:PutObjectAcl"],
         "Resource": "arn:aws:s3:::AccountABucketName/*"
      
  2. ACL and IAM Policy
    • For programmatic-only access to S3.
    • Account A: Bucket ACL WRITE permission for Account B to upload objects.
    • Account B: IAM role or user with IAM policy (the same as (1) above).
    • Objects are owned by the identity who PUTs them.
    • ACLs can apply to objects.
  3. Cross-account IAM Role
    • For programmatic and console access to S3.
    • Permissions are managed by IAM, not S3.
    • Objects are owned by that role of Account A.
    • In Account A, create an IAM Role with trust policy, grant a role or user from Account B permissions to assume the role in Account A.
         "Effect": "Allow",
         "Principal": {"AWS": "arn:aws:iam::AccountB:user/AccountBUserName"},
         "Action": "sts:AssumeRole"
      
    • And access policy for : If only programmatic access is required, the first two statements in the following policy can be removed:
         "Statement": [
             {
                 "Action": ["s3:ListAllMyBuckets"],
                 "Effect": "Allow",
                 "Resource": "arn:aws:s3:::*"
             },
             {
                 "Action": ["s3:ListBucket", "s3:GetBucketLocation"],
                 "Effect": "Allow",
                 "Resource": "arn:aws:s3:::AccountABucketName"
             },
             {
                 "Effect": "Allow",
                 "Action": ["s3:GetObject", "s3:PutObject"],
                 "Resource": "arn:aws:s3:::AccountABucketName/*"
             }
         ]
      
    • Grant an IAM role or user in Account B permissions to assume the IAM role created in A.
         "Effect": "Allow",
         "Action": "sts:AssumeRole",
         "Resource": "arn:aws:iam::AccountA:role/AccountARole"
      

Cross-account access to Lambda

You can also grant cross-account permissions using the Lambda function policy. aws lambda add-permission \ --region region \ --function-name helloworld \ --principal 111111111111 \ --action lambda_InvokeFunction

Identity Federation

alt text


Cognito

Cognito with API Gateway

alt text

IdP        (token) -> Cognito IP (AWS credentials) -> APIG (IAM or Cognito UP Authorizer)
Cognito UP (token) -> Cognito IP (AWS credentials) -> APIG (IAM or Cognito UP Authorizer)
Cognito UP (JWT)  ----------------------------------> APIG (IAM or Cognito UP Authorizer)

STS


IAM Use Cases