Skip to content

Commit

Permalink
Merge pull request #286 from zaro0508/it-2360_5
Browse files Browse the repository at this point in the history
[IT-2360] Setup IAM roles for tower
  • Loading branch information
thomasyu888 authored Feb 8, 2024
2 parents 1fd5eb4 + da3843d commit 1a2158b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 34 deletions.
6 changes: 6 additions & 0 deletions config/common/nextflow-ecs-service-shared.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
template:
path: nextflow-ecs-service-shared.yaml
stack_name: nextflow-ecs-service-shared

stack_tags:
{{stack_group_config.default_stack_tags}}
1 change: 1 addition & 0 deletions src/tower/resources/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ TOWER_OIDC_TOKEN_IMPORT: "!If [ HasTowerOidcClient, !Ref TowerOidcTokenImport, !
TOWER_ROOT_USERS: "!If [ HasTowerRootUsers, !Join [',', !Ref TowerRootUsers], !Ref AWS::NoValue]"
TOWER_USER_WORKSPACE_ENABLED: "!Ref 'TowerUserWorkspace'"
TOWER_CONFIG_FILE: "!Sub '${EfsVolumeMountPath}/${TowerConfigFileName}'"
TOWER_ALLOW_INSTANCE_CREDENTIALS: "true"
36 changes: 36 additions & 0 deletions templates/nextflow-ecs-service-shared.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: Shared resources Nextflow Tower ECS Service

Resources:
EcsServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ecs.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: ecs-service
PolicyDocument:
Statement:
- Effect: Allow
Action:
- elasticloadbalancing:DeregisterInstancesFromLoadBalancer
- elasticloadbalancing:DeregisterTargets
- elasticloadbalancing:Describe*
- elasticloadbalancing:RegisterInstancesWithLoadBalancer
- elasticloadbalancing:RegisterTargets
- ec2:Describe*
- ec2:AuthorizeSecurityGroupIngress
Resource: '*'

Outputs:
EcsServiceRoleArn:
Value: !GetAtt EcsServiceRole.Arn
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-EcsServiceRoleArn'
36 changes: 2 additions & 34 deletions templates/nextflow-ecs-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,6 @@ Parameters:

Resources:

EcsServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ecs.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: ecs-service
PolicyDocument:
Statement:
- Effect: Allow
Action:
- elasticloadbalancing:DeregisterInstancesFromLoadBalancer
- elasticloadbalancing:DeregisterTargets
- elasticloadbalancing:Describe*
- elasticloadbalancing:RegisterInstancesWithLoadBalancer
- elasticloadbalancing:RegisterTargets
- ec2:Describe*
- ec2:AuthorizeSecurityGroupIngress
Resource: '*'

EcsAlbSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
Expand Down Expand Up @@ -125,7 +98,6 @@ Resources:

EcsAlbListener:
Type: AWS::ElasticLoadBalancingV2::Listener
DependsOn: EcsServiceRole
Properties:
DefaultActions:
- Type: forward
Expand All @@ -148,7 +120,8 @@ Resources:
CapacityProviderStrategy:
- CapacityProvider: !Ref TowerCapacityProviderName
Weight: 1
Role: !Ref EcsServiceRole
Role:
'Fn::ImportValue': !Sub ${AWS::Region}-nextflow-ecs-service-shared-EcsServiceRoleArn
LoadBalancers:
- ContainerName: !Ref TowerUIContainerName
ContainerPort: !Ref TowerUIContainerPort
Expand Down Expand Up @@ -214,8 +187,3 @@ Outputs:
Value: !GetAtt EcsApplicationLoadBalancer.CanonicalHostedZoneID
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-LoadBalancerCanonicalHostedZoneID'

EcsServiceRoleArn:
Value: !GetAtt EcsServiceRole.Arn
Export:
Name: !Sub '${AWS::Region}-${AWS::StackName}-EcsServiceRoleArn'
38 changes: 38 additions & 0 deletions templates/tower-project.j2
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,39 @@ Resources:
Service:
- ecs-tasks.amazonaws.com

TowerRole:
Type: "AWS::IAM::Role"
Properties:
ManagedPolicyArns:
- 'Fn::ImportValue': !Sub ${AWS::Region}-nextflow-forge-iam-policy-NextFlowForgePolicyArn
- 'Fn::ImportValue': !Sub ${AWS::Region}-nextflow-launch-iam-policy-NextFlowLaunchPolicyArn
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: sts:AssumeRole
- Effect: Allow
Principal:
Service: eks.amazonaws.com
Action: sts:AssumeRole
- Sid: AllowEc2AssumeRole
Effect: Allow
Principal:
AWS: !Ref AccountAdminArns
Action: sts:AssumeRole
- Sid: AllowEcsServiceRole2AssumeRole
Effect: Allow
Principal:
AWS:
- 'Fn::ImportValue': !Sub ${AWS::Region}-nextflow-ecs-service-shared-EcsServiceRoleArn
Action: sts:AssumeRole

TowerForgeBatchHeadJobPolicy:
Type: AWS::IAM::Policy
Properties:
Expand Down Expand Up @@ -586,6 +619,11 @@ Outputs:
Export:
Name: !Sub "${AWS::Region}-${AWS::StackName}-TowerForgeServiceRoleArn"

TowerRoleArn:
Value: !GetAtt TowerRole.Arn
Export:
Name: !Sub "${AWS::Region}-${AWS::StackName}-TowerRoleArn"

TowerForgeBatchHeadJobRole:
Value: !Ref TowerForgeBatchHeadJobRole
Export:
Expand Down

0 comments on commit 1a2158b

Please sign in to comment.