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

PLFM-8102: Use Admin Access #1254

Conversation

xschildw
Copy link
Contributor

@xschildw xschildw commented Oct 11, 2024

This PR switches from specifying the permissions to using a role created by cdk bootstrap that allows assuming a set of policies covering these permissions (also created by cdk bootstrap).

@xschildw xschildw requested a review from a team as a code owner October 11, 2024 21:47
- "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess"
- "arn:aws:iam::aws:policy/IAMFullAccess"
- "arn:aws:iam::aws:policy/AWSCloudFormationFullAccess"
- "arn:aws:iam::449435941126:policy/cdk-assume-role-policy"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is going to cause an error when used in SynapseProd account (where this particular policy does not exist).

Copy link
Member

Choose a reason for hiding this comment

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

This is a cross-account policy reference, the policy only needs to exist in 449435941126. as long as all of our other accounts have been granted access to this policy, it should be fine

Copy link
Contributor

Choose a reason for hiding this comment

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

First, I'm doubtful that this will work. Second, where is this policy created? Third, It's probably not a good practice to depend on a policy from a different account. I recommend not taking this approach, instead you should probably create this policy in every account you plan to deploy this stack to then you can just set ManagedPolicyArns to arn:aws:iam::aws:policy/cdk-assume-role-policy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a temporary test (i.e. not intended for prod use) but @zaro0508 's right, the cdk-assume-role-policy should be created by the 'cdk bootstrap' command in every account, I think it should be referred to as ' arn:aws:iam::${AWS::AccountId}:policy/cdk-assume-role-policy ' since it's user-managed.
Note re: if it works, I created an oidc role manually in the dev account using the policy and was able to use it to update a stack from a GH workflow.

@xschildw xschildw requested a review from zaro0508 October 11, 2024 21:50
- "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess"
- "arn:aws:iam::aws:policy/IAMFullAccess"
- "arn:aws:iam::aws:policy/AWSCloudFormationFullAccess"
- "arn:aws:iam::449435941126:policy/cdk-assume-role-policy"
Copy link
Member

Choose a reason for hiding this comment

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

This is a cross-account policy reference, the policy only needs to exist in 449435941126. as long as all of our other accounts have been granted access to this policy, it should be fine

- "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess"
- "arn:aws:iam::aws:policy/IAMFullAccess"
- "arn:aws:iam::aws:policy/AWSCloudFormationFullAccess"
- "arn:aws:iam::449435941126:policy/cdk-assume-role-policy"
Copy link
Contributor

Choose a reason for hiding this comment

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

First, I'm doubtful that this will work. Second, where is this policy created? Third, It's probably not a good practice to depend on a policy from a different account. I recommend not taking this approach, instead you should probably create this policy in every account you plan to deploy this stack to then you can just set ManagedPolicyArns to arn:aws:iam::aws:policy/cdk-assume-role-policy

@xschildw xschildw requested a review from zaro0508 November 11, 2024 21:11
@xschildw
Copy link
Contributor Author

Turns out that 'cdk-assume-role-policy' was not created by the CDK so I just use an equivalent inline policy.

"Sid": "AssumeRoleStatement",
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::${AWS::AccountId}:role/cdk-*-role-*-us-east-1"
Copy link
Contributor

Choose a reason for hiding this comment

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

to be more precise, how about arn:aws:iam::${AWS::AccountId}:role/cdk-*-cfn-exec-role-${AWS::AccountId}-us-east-1?

Copy link
Contributor

Choose a reason for hiding this comment

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

The idea here doesn't really make sense to me because if you look at the policy for the cdk cloudformation execution role you'll see that it is given AdministratorAccess therefore it would be equivalent to giving this OIDC admin access directly. Why give this role the runaround of assuming another role with admin access when you can give this role admin access directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was reading about it afterwards... As I understand the way to solve this is to create a custom policy then redo the bootstrap such that the default Admin perms are changed to more constrained permissions (I'm a bit lost as that set of permissions would have to cover all the cases in a given account...). Maybe you're right and we may as well be explicit. I'll change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to explicitly use AdministratorAccess.

@xschildw xschildw requested a review from zaro0508 November 25, 2024 20:27
@xschildw xschildw changed the title PLFM-8102: Use cdk role PLFM-8102: Use Admin Access Nov 25, 2024
- "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess"
- "arn:aws:iam::aws:policy/IAMFullAccess"
- "arn:aws:iam::aws:policy/AWSCloudFormationFullAccess"
- "arn:aws:iam::aws:policy/AdministratorAccess"
Copy link
Contributor

@zaro0508 zaro0508 Dec 2, 2024

Choose a reason for hiding this comment

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

This resource is now basically the same as the existing GithubOidcSageBionetworksSynapseDockerRegistry. Do you think it would make sense to consolidate these to a single generic GithubOidcSageBionetworksSynapse resource that gives access to multiple repos? The benefit is that when new repos pop up to deploy lambda or CDK they can just use the generic resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Renamed, added registry repo.

@xschildw xschildw requested a review from zaro0508 December 4, 2024 20:16
Copy link
Contributor

@zaro0508 zaro0508 left a comment

Choose a reason for hiding this comment

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

Generally looks good. Just remember to update the synapse-docker-registry with the new role.

@@ -166,6 +166,30 @@ GithubOidcSageBionetworksSynapseDockerRegistry:
- !Ref SynapseProdAccount
Region: us-east-1

GithubOidcSageBionetworksSynapse:
Copy link
Contributor

Choose a reason for hiding this comment

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

do you plan to also replace the role used by GH actions in synapse-docker-registry repo with the one generated from this new GithubOidcSageBionetworksSynapse resource? And then of course also remove GithubOidcSageBionetworksSynapseDockerRegistry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct.

@xschildw xschildw merged commit 1a7eae9 into Sage-Bionetworks-IT:master Dec 5, 2024
3 checks passed
@xschildw xschildw deleted the m-plfm-8102-use-cdk-bootstrap-role branch December 5, 2024 17:10
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.

3 participants