AWSTemplateFormatVersion: "2010-09-09"
Description: >
  Broken Labs - IAM Lab 02.
  An IAM role's policy was recently updated, and now the role's S3 read requests are denied.
  Licensed under CC BY-NC-SA 4.0: https://creativecommons.org/licenses/by-nc-sa/4.0/
  Developed by: Mark Schoonover <mark.schoonover@gmail.com>

Resources:

  LabBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub "brokenlabs-iam-lab-02-${AWS::Region}-${AWS::AccountId}"

  LabRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub "brokenlabs-iam-lab-02-role-${AWS::Region}-${AWS::AccountId}"
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service: ec2.amazonaws.com
            Action: sts:AssumeRole
      Policies:
        - PolicyName: LabRolePolicy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Sid: AllowGetObject
                Effect: Allow
                Action: s3:GetObject
                Resource: !Sub "${LabBucket.Arn}/*"
              - Sid: DenyGetObject
                Effect: Deny
                Action: s3:GetObject
                Resource: !Sub "${LabBucket.Arn}/*"

Outputs:

  RoleName:
    Description: Name of the IAM role to test in the Policy Simulator
    Value: !Ref LabRole

  TestResourceArn:
    Description: Resource ARN to simulate s3:GetObject against
    Value: !Sub "${LabBucket.Arn}/*"

  BucketName:
    Description: Name of the S3 bucket
    Value: !Ref LabBucket
