Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Commit 9235b52

Browse files
authored
Remove sensitive info (#544)
* use gh secrets * use gh secrets also for prod * infra bucket dynamic lookup and documentation update * temporary trigger deploy from remove-sensitive-info branch to test actions * adding additional required policy * allow correct resource for description * fix cf stack update params handling * Revert "temporary trigger deploy from remove-sensitive-info branch to test actions" This reverts commit d97a32e. * typo fix
1 parent 5c5a276 commit 9235b52

9 files changed

+47
-23
lines changed

.github/workflows/demo_deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
uses: aws-actions/configure-aws-credentials@v1
7575
with:
7676
aws-region: eu-west-1
77-
role-to-assume: arn:aws:iam::***REMOVED***:role/pcluster-manager-github-PrivateInfrastructureUpdat-1HXHHPQ292PNI
77+
role-to-assume: ${{ secrets.ACTION_DEMO_DEPLOY_JOB_UPDATE_INFRASTRUCTURE_ROLE }}
7878

7979
- name: Update staging infrastructure
8080
run: ./infrastructure/update-environment-infra.sh demo
@@ -92,7 +92,7 @@ jobs:
9292
uses: aws-actions/configure-aws-credentials@v1
9393
with:
9494
aws-region: eu-west-1
95-
role-to-assume: arn:aws:iam::***REMOVED***:role/pcluster-manager-github-PrivateDeployRole-8D5K5C4RM02U
95+
role-to-assume: ${{ secrets.ACTION_DEMO_DEPLOY_JOB_BUILD_AND_DEPLOY_ROLE }}
9696

9797
- name: Update staging environment
9898
run: ./scripts/build_and_update_lambda.sh --stack-name "parallelcluster-ui-demo" --region eu-west-1

.github/workflows/e2e_tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
uses: aws-actions/configure-aws-credentials@v1
2525
with:
2626
aws-region: eu-west-1
27-
role-to-assume: arn:aws:iam::***REMOVED***:role/pcluster-manager-github-E2ETestExecution-Z7IMRUIJAZAO
27+
role-to-assume: ${{ secrets.ACTION_E2E_TESTS_ROLE }}
2828

2929
- name: Retrieve test user email and password
3030
uses: aws-actions/aws-secretsmanager-get-secrets@v1

.github/workflows/production_release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
uses: aws-actions/configure-aws-credentials@v1
7272
with:
7373
aws-region: us-east-1
74-
role-to-assume: arn:aws:iam::***REMOVED***:role/pcluster-manager-github-prod-ProductionDeploy-1I1HYDA5DH7T3
74+
role-to-assume: ${{ secrets.ACTION_PRODUCTION_RELEASE_ROLE }}
7575

7676
- name: Build and upload Docker image
7777
run: ./scripts/build_and_release_image.sh

infrastructure/readme.md renamed to infrastructure/README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ To access AWS resources inside a Github workflow you need to create new IAM role
44
To create the resources needed by the workflow action you can deploy the `./github-env-setup.yml` to [CloudFormation](https://aws.amazon.com/cloudformation/).
55
- Go under `CloudFormation > Stacks > Create stack`
66
- Upload a template file using `github-env-setup.yml`
7-
- Give the stack a name (it doesn't matter which one)
7+
- Give the stack a name (it should match the `INFRA_BUCKET_STACK_NAME` for env deploy, i.e. `INFRA_BUCKET_STACK_NAME=pcluster-manager-github` for the demo env)
88
- Create the stack
9-
- Go to the IAM console, find the role name `*PrivateDeploy*`, copy the ARN and use it with the [AWS credentials action](https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions) to authenticate
10-
- Same needs to be done for the `*PrivateInfrastructureUpdateRole*` role
9+
- Go to the IAM console, find the roles created (see list below), copy the ARN and use it with the [AWS credentials action](https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions) to authenticate using those in the matching GitHub Secrets
1110

12-
The stack will create two new roles:
13-
- the `PrivateDeployRole` with the minimum set of policies needed to build and deploy an instance of PCluster Manager
14-
- the `PrivateInfrastructureUpdateRole` with the minimum set of policies needed to update the infrastructure of an environment running PCluster Manager
11+
The stack will create three new roles:
12+
- the `PrivateDeployRole` with the minimum set of policies needed to build and deploy an instance of PCluster Manager, its arn should be put in the secret named `ACTION_DEMO_DEPLOY_JOB_BUILD_AND_DEPLOY_ROLE`
13+
- the `PrivateInfrastructureUpdateRole` with the minimum set of policies needed to update the infrastructure of an environment running PCluster Manager, its arn should be put in the secret named `ACTION_DEMO_DEPLOY_JOB_UPDATE_INFRASTRUCTURE_ROLE`
14+
- the `E2ETestExecutionRole` with the minimum set of policies needed to in order to run E2E tests workflow, its arn should be put in the secret named `ACTION_E2E_TESTS_ROLE`
15+
16+
The same steps are required for the production release workflow, using the `./github-env-setup-prod.yml` stack, to create the role `ProductionDeploy` that should be put in the secret named `ACTION_PRODUCTION_RELEASE_ROLE`.
1517

1618
**This procedure must be done only once per AWS account since IAM it's a global service.**
1719

infrastructure/environments/demo-cfn.yaml renamed to infrastructure/environments/demo-cfn-update-args.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
TemplateURL: https://pcluster-manager-github-infrastructurebucket-7y5h202iem8l.s3.eu-west-1.amazonaws.com/parallelcluster-ui.yaml
1+
TemplateURL: BUCKET_URL_PLACEHOLDER/parallelcluster-ui.yaml
22
Parameters:
33
- ParameterKey: Version
44
ParameterValue: 3.4.0
55
- ParameterKey: InfrastructureBucket
6-
ParameterValue: https://pcluster-manager-github-infrastructurebucket-7y5h202iem8l.s3.eu-west-1.amazonaws.com
6+
ParameterValue: BUCKET_URL_PLACEHOLDER
77
- ParameterKey: UserPoolId
88
UsePreviousValue: true
99
- ParameterKey: UserPoolAuthDomain
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
REGION=eu-west-1
2-
BUCKET=pcluster-manager-github-infrastructurebucket-7y5h202iem8l
3-
STACK_NAME=parallelcluster-ui-demo
2+
STACK_NAME=parallelcluster-ui-demo
3+
INFRA_BUCKET_STACK_NAME=pcluster-manager-github

infrastructure/github-env-setup-prod.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
13
Parameters:
24
GitHubOrg:
35
Type: String

infrastructure/github-env-setup.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
13
Parameters:
24
GitHubOrg:
35
Type: String
@@ -107,10 +109,12 @@ Resources:
107109
- Effect: Allow
108110
Action:
109111
- cloudformation:DescribeStacks
112+
- cloudformation:DescribeStackResources
110113
- cloudformation:UpdateStack
111114
- cloudformation:CreateChangeSet
112115
Resource:
113116
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/parallelcluster-ui-demo*
117+
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${AWS::StackName}*
114118
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:aws:transform/*
115119
- Effect: Allow
116120
Action:
@@ -123,8 +127,8 @@ Resources:
123127
- s3:GetObjectAcl
124128
- s3:PutObjectAcl
125129
Resource:
126-
- !Sub arn:${AWS::Partition}:s3:::pcluster-manager-github-infrastructurebucket-7y5h202iem8l
127-
- !Sub arn:${AWS::Partition}:s3:::pcluster-manager-github-infrastructurebucket-7y5h202iem8l/*
130+
- !GetAtt 'InfrastructureBucket.Arn'
131+
- !Join ['', [!GetAtt 'InfrastructureBucket.Arn', '/*']]
128132
- !Sub arn:${AWS::Partition}:s3:::${AWS::Region}-aws-parallelcluster
129133
- !Sub arn:${AWS::Partition}:s3:::${AWS::Region}-aws-parallelcluster/*
130134
- Effect: Allow
@@ -151,7 +155,7 @@ Resources:
151155
- cognito-idp:UpdateGroup
152156
- cognito-idp:DeleteGroup
153157
Resource:
154-
- arn:aws:cognito-idp:eu-west-1:***REMOVED***:userpool/*
158+
- !Sub arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/*
155159
- PolicyName: ImageBuilderPolicy
156160
PolicyDocument:
157161
Version: 2012-10-17
@@ -198,7 +202,7 @@ Resources:
198202
Resource: "*"
199203
- Effect: Allow
200204
Action: secretsmanager:GetSecretValue
201-
Resource: arn:aws:secretsmanager:eu-west-1:***REMOVED***:secret:e2e/test1-AUsDgk
205+
Resource: !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:e2e/test1-AUsDgk
202206

203207
Outputs:
204208
PrivateDeployRole:

infrastructure/update-environment-infra.sh

+21-5
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,34 @@
2121
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
2222
FILES=(SSMSessionProfile-cfn.yaml parallelcluster-ui-cognito.yaml parallelcluster-ui.yaml)
2323
ENVIRONMENT=$1
24-
. ${SCRIPT_DIR}/environments/${ENVIRONMENT}-variables.sh
24+
. "${SCRIPT_DIR}/environments/${ENVIRONMENT}-variables.sh"
25+
26+
BUCKET=$(aws cloudformation describe-stack-resources \
27+
--stack-name "${INFRA_BUCKET_STACK_NAME}" \
28+
--logical-resource-id InfrastructureBucket \
29+
--output json \
30+
--query 'StackResources[0].PhysicalResourceId'\
31+
| tr -d '"' )
2532

2633
# The yaml files describing the infrastructure are uploaded to a private S3 bucket
2734
# and then used to update the CloudFormation stack, where the same bucket is passed as parameters.
2835
# This is done to make sure that we deploy all the changes to the infrastructure, and not only the changes
2936
# made to parallelcluster-ui.yaml (the parent stack)
30-
echo Uploading to: ${BUCKET}
37+
echo Uploading to: "${BUCKET}"
3138
for FILE in "${FILES[@]}"
3239
do
33-
aws s3 cp ${SCRIPT_DIR}/${FILE} s3://${BUCKET}/${FILE}
40+
aws s3 cp "${SCRIPT_DIR}/${FILE}" "s3://${BUCKET}/${FILE}"
3441
done
3542

43+
BUCKET_URL="https://${BUCKET}.s3.${REGION}.amazonaws.com"
44+
CLI_INPUT_YAML=$(sed "s#BUCKET_URL_PLACEHOLDER#${BUCKET_URL}#g" "${SCRIPT_DIR}/environments/${ENVIRONMENT}-cfn-update-args.yaml")
45+
3646
# Launches a new CFN update: the script hangs until the stack is updated
37-
AWS_PAGER="cat" aws cloudformation update-stack --cli-input-yaml file://${SCRIPT_DIR}/environments/${ENVIRONMENT}-cfn.yaml --stack-name ${STACK_NAME} --region ${REGION}
38-
aws cloudformation wait stack-update-complete --stack-name ${STACK_NAME} --region ${REGION}
47+
AWS_PAGER="cat" aws cloudformation update-stack \
48+
--cli-input-yaml "${CLI_INPUT_YAML}" \
49+
--stack-name "${STACK_NAME}" \
50+
--region "${REGION}"
51+
52+
aws cloudformation wait stack-update-complete \
53+
--stack-name "${STACK_NAME}" \
54+
--region "${REGION}"

0 commit comments

Comments
 (0)