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

Add ability to set a repository permission policy#100

Open
drboyer wants to merge 8 commits intomasterfrom
set-repo-policy
Open

Add ability to set a repository permission policy#100
drboyer wants to merge 8 commits intomasterfrom
set-repo-policy

Conversation

@drboyer
Copy link
Copy Markdown

@drboyer drboyer commented Jun 7, 2017

This change enables ecs-conex to set a Permissions Policy on all repositories watched by this instance of conex. ECR Permissions policies enable you to share an ECR repository in one account with another AWS account.

➡️ Documentation on ECR Repository Policies

How this feature was implemented
I've implemented this feature where including an IAM policy document as the RepositoryPermissionPolicy stack parameter will set it as an environment variable on the watchbot worker. When a worker is processing a job, after ensuring the ECR repo exists in a given region, the policy for the repository will be set as well (this is an idempotent operation if the policy does not change).

Testing
I added what I think are appropriate unit tests to the test/utils.test.sh file. I also tested creating an ECR repository using this stack both when the RepositoryPermissionPolicy parameter was blank and when it was set to a valid policy to share with another account. In both cases, the expected result happened (the repository was published on ECR, in the former case with no permissions set, in the latter with the specified policy set).

@drboyer drboyer requested review from emilymdubois and rclark June 8, 2017 20:28
@drboyer
Copy link
Copy Markdown
Author

drboyer commented Jun 8, 2017

@rclark @emilymdubois whenever you get a chance, one of you mind reviewing my change?

Comment thread utils.sh Outdated

function set_policy() {
local region=$1
RepositoryPermissionPolicy=$(printenv | grep RepositoryPermissionPolicy | sed 's/.*=//')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there this complex pipeline here rather than just relying on the -n condition on the next line?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh this was probably from where I had originally tried stuffing this in the credentials() function instead. I'll switch it out.

Comment thread utils.sh Outdated
function set_policy() {
local region=$1
RepositoryPermissionPolicy=$(printenv | grep RepositoryPermissionPolicy | sed 's/.*=//')
if [ -n "$RepositoryPermissionPolicy" ]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus ⭐️ s will be rewarded for consistent { } variable bracketing!

Comment thread cloudformation/ecs-conex.template.js Outdated
},
RepositoryPermissionPolicy: {
Type: 'String',
Description: 'An IAM policy granting access for other AWS accounts to access this repository',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really this policy could be granting anything on the repositories that conex creates. Its just your particular use-case for cross-account access, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll tweak the wording appropriately

@drboyer drboyer deployed to staging June 9, 2017 15:32 Active
@drboyer
Copy link
Copy Markdown
Author

drboyer commented Jun 9, 2017

Made a few changes to address things brought up in the code review. I also added a quick note to the readme for context, let me know if you still see anything else!

Comment thread utils.sh Outdated
local region=$1
RepositoryPermissionPolicy=$(printenv | grep RepositoryPermissionPolicy | sed 's/.*=//')
if [ -n "$RepositoryPermissionPolicy" ]
RepositoryPermissionPolicy=$(printenv RepositoryPermissionPolicy)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even this line is excess, isn't it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I just include the if [ -n "${RepositoryPermissionPolicy}" ] by itself, the script fails to load due to RepositoryPermissionPolicy being an unbound variable (and set -u being set). Perhaps there's another way around that beyond the realm of my shell scripting knowledge.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O_o that doesn't really make sense to me. Why are these two lines of code different than each other?

RepositoryPermissionPolicy=$(printenv RepositoryPermissionPolicy)
RepositoryPermissionPolicy=${RepositoryPermissionPolicy}

If RepositoryPermissionPolicy is set in the env, then why would set -u be a problem?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If RepositoryPermissionPolicy is set in the env, then why would set -u be a problem?

Had to chew on this for probably longer than I should've, as it seemed like a totally valid point. And it was. Issue was actually with my test script where I was unsetting this variable to test the "no-policy" case. When I switched to testing a realistic no-policy case (RepositoryPermissionPolicy=""), just having the -n test worked fine!

Sorry it took so long to get to this. 🙃

@drboyer drboyer deployed to staging June 12, 2017 13:56 Active
@drboyer drboyer deployed to staging June 12, 2017 14:24 Active
@drboyer drboyer deployed to staging June 12, 2017 14:40 Active
@drboyer drboyer deployed to staging June 12, 2017 15:11 Active
@drboyer drboyer deployed to staging June 12, 2017 15:32 Active
@emilymdubois emilymdubois removed their request for review November 6, 2017 23:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants