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

Feat/sam pipeline OIDC #4270

Merged
merged 19 commits into from
Oct 13, 2022
Merged

Feat/sam pipeline OIDC #4270

merged 19 commits into from
Oct 13, 2022

Conversation

xazhao
Copy link
Contributor

@xazhao xazhao commented Sep 30, 2022

Which issue(s) does this change fix?

Adding OIDC support to SAM Pipeline.

Why is this change necessary?

How does it address the issue?

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.

* 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

* Fix incorrect variable mappings

* use constants instead of strings
* 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
@xazhao xazhao marked this pull request as ready for review October 7, 2022 18:43
requirements/base.txt Show resolved Hide resolved
samcli/commands/pipeline/bootstrap/cli.py Outdated Show resolved Hide resolved
samcli/commands/pipeline/bootstrap/cli.py Outdated Show resolved Hide resolved
@@ -121,6 +121,7 @@ def run_interactive_flows(self, context: Optional[Dict] = None) -> Dict:
"""
try:
context = context if context else {}
context["shared_values"] = "default"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why this is needed? And can you also confirm that it won't break sam init flow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it won't break the sam init flow. This value is used in sam pipeline init templates to utilize previous answer to skip some questions.

@xazhao xazhao requested a review from mndeveci October 7, 2022 23:43
Comment on lines 12 to 22

from samcli.commands.pipeline.bootstrap.pipeline_oidc_provider import PipelineOidcProvider
from samcli.lib.config.samconfig import SamConfig
from samcli.lib.pipeline.bootstrap.stage import Stage

from samcli.commands.pipeline.bootstrap.oidc_config import (
BitbucketOidcConfig,
GitHubOidcConfig,
OidcConfig,
GitLabOidcConfig,
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies for been picky, but these imports can be moved down as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These imports are also used in another function as input, so I think they need to be at the top. Correct me if I'm wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like they are used in other functions only for type indication. We can wrap them by quotes instead, e.g.

def my_function(arg: "MyClass"):
    pass

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 suggestion! Make it work. Thanks!

Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

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

This is a large PR and will require another pass.

required=False,
)
@click.option(
"--gitlab-group",
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these options don't play well with each other I'm assuming. There needs to be appropriate error messaging if they are specified together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently it takes all options then decides which option to use based on what oidc-provider is. I see your point is helpful. I'm thinking we can leave it to another PR for improvements which includes some refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

I learned from @xazhao that these new options, if not applicable, will just be ignored. I think it makes sense to handle them for now, as at least these different groups (GH Action, Gitlab and Bitbucket) won't conflict each other. But IMO there's a room to improve in terms of UX, to give customers clearer messages about what options they really need to supply.

samcli/commands/pipeline/bootstrap/cli.py Show resolved Hide resolved
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::${AWS::AccountId}:oidc-provider/${Url}"
Copy link
Contributor

Choose a reason for hiding this comment

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

use AWS::Partition instead of :aws: , other places need to be cross checked as well.

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 catch! Will update it.

click.echo("\t1 - IAM (default)")
click.echo("\t2 - OpenID Connect (OIDC)")
user_provider = click.prompt("Choice", type=click.Choice((["1", "2"])), show_default=False, default="1")
self.permissions_provider = OPEN_ID_CONNECT if user_provider == "2" else "iam"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why not also use a constant for "iam"?

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 catch. Updating it to a constant.

Comment on lines 12 to 22

from samcli.commands.pipeline.bootstrap.pipeline_oidc_provider import PipelineOidcProvider
from samcli.lib.config.samconfig import SamConfig
from samcli.lib.pipeline.bootstrap.stage import Stage

from samcli.commands.pipeline.bootstrap.oidc_config import (
BitbucketOidcConfig,
GitHubOidcConfig,
OidcConfig,
GitLabOidcConfig,
)

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like they are used in other functions only for type indication. We can wrap them by quotes instead, e.g.

def my_function(arg: "MyClass"):
    pass

@sriram-mv sriram-mv self-requested a review October 12, 2022 23:33
@xazhao xazhao requested review from hawflau and sriram-mv and removed request for sriram-mv and hawflau October 12, 2022 23:37
Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

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

Conditionally approving this based on following follow-on improvements.

  • Improved error messaging when conflicting options are chosen.
  • Improved handling on changing the entities referenced within the configuration file through parameters
  • Showcase in the help text which options are related and go together, there are a lot of options for this command at present.
  • Lazy imports within cli() instead of top level imports, this causes the help text loading to slow down.

@xazhao xazhao requested a review from mndeveci October 13, 2022 00:23
@hawflau hawflau dismissed mndeveci’s stale review October 13, 2022 00:32

dismissing as two approvals are obtained

@hawflau hawflau merged commit 393db0c into aws:develop Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants