Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IT-3559] Allow multiple bucket and prefix inputs #413

Merged
merged 2 commits into from
May 3, 2024

Conversation

zaro0508
Copy link
Member

@zaro0508 zaro0508 commented May 3, 2024

Add the ability to pass in multiple bucket Arn and Prefix to the snowflake access template.

  • Change to jinja template
  • Update to accept a matched set of bucket and prefix inputs

Add the ability to pass in multiple bucket Arn and Prefix to the
snowflake access template.

* Change to jinja template
* Update to accept a matched set of bucket and prefix inputs
@zaro0508 zaro0508 requested a review from a team as a code owner May 3, 2024 19:30
zaro0508 added a commit to zaro0508/organizations-infra that referenced this pull request May 3, 2024
switch to jinja template to accept multiple bucket Arn and Prefix

depends on Sage-Bionetworks/aws-infra#413
@zaro0508 zaro0508 requested a review from marcomarasca May 3, 2024 19:38
@zaro0508
Copy link
Member Author

zaro0508 commented May 3, 2024

example:

passing in these parameters from sceptre config..

sceptre_user_data:
  Buckets:
    - Arn: MyBucketArn1
      Prefix: MyPrefix1
    - Arn: MyBucketArn2
      Prefix: MyPrefix2

will generate this template..

---
Description: >
  Setup cross account IAM access to a bucket/prefix for Snowflake.
  See https://docs.snowflake.com/en/user-guide/data-load-s3-config-storage-integration
AWSTemplateFormatVersion: 2010-09-09
Parameters:
  SnowflakeAccountArn:
    Type: String
  SnowflakeAccountExternalId:
    Type: String
Resources:
  SnowflakeServicePolicy:
    Type: 'AWS::IAM::ManagedPolicy'
    Properties:
      PolicyDocument:
        Version: '2012-10-17'
        Statement:

          - Effect: Allow
            Action:
              - 's3:GetObject'
              - 's3:GetObjectVersion'
            Resource: "MyBucketArn1/MyPrefix1/*"
          - Effect: Allow
            Action:
              - 's3:ListBucket'
              - 's3:GetBucketLocation'
            Resource: "MyBucketArn1"
            Condition:
              StringLike:
                's3:prefix': "MyPrefix1/*"

          - Effect: Allow
            Action:
              - 's3:GetObject'
              - 's3:GetObjectVersion'
            Resource: "MyBucketArn2/MyPrefix2/*"
          - Effect: Allow
            Action:
              - 's3:ListBucket'
              - 's3:GetBucketLocation'
            Resource: "MyBucketArn2"
            Condition:
              StringLike:
                's3:prefix': "MyPrefix2/*"

  SnowflakeServiceRole:
    Type: "AWS::IAM::Role"
    Properties:
      Path: "/"
      ManagedPolicyArns:
        - !Ref SnowflakeServicePolicy
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              AWS: !Sub ${SnowflakeAccountArn}
            Action:
              - sts:AssumeRole
              - sts:TagSession
            Condition:
              StringEquals:
                sts:ExternalId: !Sub ${SnowflakeAccountExternalId}
Outputs:
  SnowflakeServiceRoleArn:
    Value: !GetAtt SnowflakeServiceRole.Arn
    Export:
      Name: !Sub '${AWS::StackName}-SnowflakeServiceRoleArn'

@zaro0508 zaro0508 merged commit 7666383 into Sage-Bionetworks:master May 3, 2024
3 checks passed
zaro0508 added a commit to Sage-Bionetworks-IT/organizations-infra that referenced this pull request May 3, 2024
switch to jinja template to accept multiple bucket Arn and Prefix

depends on Sage-Bionetworks/aws-infra#413
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants