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

Support GitLab OIDC for pipeline bootstrap #4037

Merged
merged 3 commits into from
Jul 7, 2022

Conversation

sidhujus
Copy link
Contributor

@sidhujus sidhujus commented Jul 6, 2022

Which issue(s) does this change fix?

Supports GitLab for OIDC provider during bootstrap flow

Why is this change necessary?

Currently only the GitHub Actions OIDC provider is implemented and because configuring the assume role policy differs slightly for each OIDC provider they need to be supported individually

How does it address the issue?

adds click prompts/options to get the necessary information from the user before configuring the assume role policy for the pipeline execution role correctly

What side effects does this change have?

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

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

@github-actions github-actions bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. area/pipeline labels Jul 6, 2022
Comment on lines 323 to 328
elif oidc_provider == GITLAB:
gitlab_oidc_params: dict = {
"gitlab-project": gitlab_project,
"gitlab-group": gitlab_group,
"deployment-branch": deployment_branch,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking if we could re-use the logic here. The deployment_branch is the same. github-org seems match to gitlab-group and github_repo seems match to gitlab-project. Maybe we could use general parameters name for all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub and GitLab are close enough to each other in information that we need that it would probably be fine for those two, but with Bitbucket we will need only a single new parameter, instead of the three that GitHub and GitLab need, the repository UUID which is a bitbucket specific value so I don't think it would be possible to generalize the parameters once we add Bitbucket and if in the future we decide to add any other providers. I think keeping them all separate helps reinforce that to anybody whos reading the code for the first time and is unfamiliar with the concepts

samcli/commands/pipeline/bootstrap/cli.py Outdated Show resolved Hide resolved
samcli/commands/pipeline/bootstrap/cli.py Outdated Show resolved Hide resolved
samcli/commands/pipeline/bootstrap/guided_context.py Outdated Show resolved Hide resolved
@@ -159,7 +159,7 @@ Resources:
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"ForAllValues:StringEquals": {
"ForAllValues:StringLike": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its not really needed for GitHub or GitLab because its pretty easy to build the entire sub claim in the OIDC token, but for Bitbucket the claim changes weather or not a step is assigned to a deployment environment (our templates dont do this) and it also contains a UUID for the pipeline step which I couldn't find a way to get so using StringLike becomes necessary for that.

https://support.atlassian.com/bitbucket-cloud/docs/deploy-on-aws-using-bitbucket-pipelines-openid-connect/#Using-claims-in-ID-tokens-to-limit-access-to-the-IAM-role-in-AWS

@@ -292,6 +320,13 @@ def do_cli(
"deployment-branch": deployment_branch,
}
pipeline_oidc_provider = GitHubOidcProvider(github_oidc_params, common_oidc_params, GITHUB_ACTIONS)
elif oidc_provider == GITLAB:
gitlab_oidc_params: dict = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish there was stronger typing here, it's quite easy to mistype or spend time figuring out the correct names. Can't probably use TypedDict since it's 3.8+, but should be able to use the constants from GitLabOidcProvider and friends directly.

@xazhao xazhao merged commit 74bffa8 into aws:feat/sam-pipeline-oidc Jul 7, 2022
hawflau pushed a commit that referenced this pull request Oct 13, 2022
* Add OIDC support (#3995)

* support for GitHub Actions OIDC

* GitHub Actions oidc support

* Unit tests for GitHub Actions OIDC support

* Add tests for GitHub Actions OIDC support

* Add comments for new methods and fix formatting

* use choice for identity provider instead of flag

* Create pipeline oidc provider class

* Remove unused methods

* Add defaults for OIDC URL and ClientID

* Get subject claim from object and use Session to get Client

* Mock Session during test

* Create method to share common logic

* Add AllowedValues to CreateNewOidcProvider

* Remove duplicate calls to samconfig

* Add text to prompt

* fix formatting

* Add links to technical methods comments

* Support GitLab OIDC for pipeline bootstrap (#4037)

* Support GitLab OIDC for pipeline bootstrap

* Fix incorrect variable mappings

* use constants instead of strings

* Support Bitbucket OIDC in pipeline bootstrap (#4041)

* Support Bitbucket OIDC in pipeline bootstrap

* Add documentation

* Make capitlization consistent

* Add comments to method

* Re-use permissions provider answer for init

* Make help text shorter

* add constant inside constructor

* Fix comments

* move variables into class

* change saved iam parameter

* change help message

* use dataclass

* Optimize interactive flow and fix bugs

* Support bootstrap stack update

* fix duplicate bootstrap bug

* bug fix

* Update UX and fix unit tests

* Improve UX and add more tests

* recover the link

* Address comments

* Re-organize imports

* Use AWS Partition instead of hardcoding aws

* Address some comments

* Recover imports

Co-authored-by: sidhujus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/pipeline pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants