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

Adding Github Action for CodeGuru Reviewer #1000

Merged
merged 5 commits into from
Dec 7, 2021

Conversation

martinschaef
Copy link
Contributor

Description of changes:
Runs CodeGuru Reviewer on push and pull_request events and posts recommendations in the Security tab.
Example run can be seen here: https://github.com/martinschaef/smithy/runs/4414789132?check_suite_focus=true

This uses the new OIDC-way to assume an IAM role. That is, no credentials are required. Only authorized repos can assume the role.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@martinschaef martinschaef requested a review from a team as a code owner December 4, 2021 19:50
@martinschaef
Copy link
Contributor Author

Somehow the action fails to assume the role in the Pull Request; probably because I am not a member of the Smithy repo. Created an issue with aws-actions/configure-aws-credentials. It works if the person starting the action has permissions on the repo. See here

uses: aws-actions/[email protected]
continue-on-error: false
with:
s3_bucket: codeguru-reviewer-github-profiler-demo-048169001733-uw2
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does this bucket come from, and who owns 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.

It's owned by the CodeGuru team and was created using this Stack:
https://github.com/aws-samples/aws-codeguru-reviewer-cicd-cdk-sample

@adamthom-amzn adamthom-amzn merged commit f4feebe into smithy-lang:main Dec 7, 2021
adamthom-amzn added a commit that referenced this pull request Dec 8, 2021
@adamthom-amzn
Copy link
Contributor

I'm reverting this in #1008, as it did not work even when the PR was opened by a smithy developer: #1007

adamthom-amzn added a commit that referenced this pull request Dec 8, 2021
@martinschaef
Copy link
Contributor Author

Ugh ... that's a problem. The permissions are per account, so it makes sense that it doesn't work. You don't want people that do a PR against your repo be allowed to assume a role in your account.

Would it be ok if the action just succeeds if it cannot assume the role?

@adamthom-amzn
Copy link
Contributor

Yes, I think that's fine, but who would this role assumption work for?

@martinschaef
Copy link
Contributor Author

martinschaef commented Dec 8, 2021

On second thought, the only way to do this is to trigger the action only on push events. So the action would only run after you merge the pull request. This is a little bit counter intuitive but makes sense from an IAM point of view. Anyone could open a PR against your repo and they should not be allowed to just assume that role because they could create charges in that account.

@martinschaef
Copy link
Contributor Author

Oh wait ... this is a different issue: https://github.com/awslabs/smithy/runs/4458443115?check_suite_focus=true#step:8:38 here the analysis actually timed out

@adamthom-amzn
Copy link
Contributor

@martinschaef
Copy link
Contributor Author

Yeah, this makes sense. This is because JordonPhillips is not allowed to assume the IAM Role. I'll add proper error handling to the action.

@adamthom-amzn
Copy link
Contributor

Who has permission to assume it? Jordon's a core smithy developer

@martinschaef
Copy link
Contributor Author

This works via OICD, so it works by repo. The container creates this JWT token to authenticate which is matched against an allow-list of orgs. So only if the container is run under awslabs/smithy it'll work, but this container tried to authenticate as JordonPhillips/smithy. That's why you basically can only use this in push events.

Fwiw, this is an IAM thing, not a CodeGuru thing.

@martinschaef
Copy link
Contributor Author

I changed it so it only does any of the steps if assuming the role succeeded:
https://github.com/martinschaef/smithy/runs/4462569719?check_suite_focus=true

@adamthom-amzn
Copy link
Contributor

Will that require a new PR, or were the changes on your side such that a revert of the revert should be sufficient?

@martinschaef
Copy link
Contributor Author

No, it requires code changes, I'll do a new PR

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