Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

add static openid provider #41

Merged
merged 1 commit into from
Dec 2, 2021
Merged

add static openid provider #41

merged 1 commit into from
Dec 2, 2021

Conversation

doodzik
Copy link

@doodzik doodzik commented Nov 25, 2021

Problem

The current implementation of the id provider requires interaction with a web browser, which doesn't work in an automated environment.

Solution

The folks over at sigstore/cosign solved this problem by allowing cosign to accept an id token. This PR ports that approach over.

At a later point (#42), we can also enable the usage of env variables, but that isn't required to get this tool working in ShipIt, which is the biggest unknown in my opinion. See sigstore/cosign#644 for reference.

ref #24

@doodzik doodzik force-pushed the add_static_openid_provider_2 branch 3 times, most recently from 4808273 to af1bd30 Compare December 1, 2021 21:30
@doodzik doodzik force-pushed the add_static_openid_provider_2 branch 3 times, most recently from 6bfd422 to 26171c9 Compare December 2, 2021 03:22
@@ -2,6 +2,7 @@
require 'webmock/test_unit'
require 'rubygems/mock_gem_ui'
require 'json/jwt'
require 'byebug'
Copy link
Author

Choose a reason for hiding this comment

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

making debugging in tests a bit easier so we don't have to type require 'byebug';

end

def public_keys
@public_keys ||= oidc_discovery.jwks
Copy link
Author

@doodzik doodzik Dec 2, 2021

Choose a reason for hiding this comment

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

We are loading the public key from the provider specified in the config file, which is probably good enough for now, but we might want to revisit it in the future.

Choose a reason for hiding this comment

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

Your oidc issuer may be different for dynamic vs static flows. In the dynamic flow, you would rely on oauth.sigstore.dev. For CI, it would be GitHub.

Does it make sense to add a new config key in settings.yml, static_token_oidc_issuer ? Or perhaps look for an oidc-issuer command parameter/environment variable?

Copy link
Author

Choose a reason for hiding this comment

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

I think it makes sense to come up with another way of specifying the oidc-issuer, because the current solution will not scale as you pointed out. I'm not sure how it should look through. My plan was to make the static flow work with Shipit and adjust the command based on my learnings.

end
end

def subject
Copy link
Author

@doodzik doodzik Dec 2, 2021

Choose a reason for hiding this comment

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

I'm copying cosign's flow of retrieving the subject of a claim as seen in this flow. We might want to chat with the people of sigstore about they utilize the subject field.

@doodzik doodzik marked this pull request as ready for review December 2, 2021 05:29
@doodzik doodzik requested review from rochlefebvre and a team December 2, 2021 05:30
Copy link

@jchestershopify jchestershopify left a comment

Choose a reason for hiding this comment

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

Some nits and questions.

Where would I find the original cosign code for comparison?

@@ -41,7 +46,8 @@ def execute
gemfile = Gem::Sigstore::Gemfile.new(get_one_gem_name)
rekor_entry = Gem::Sigstore::GemSigner.new(
gemfile: gemfile,
config: Gem::Sigstore::Config.read
config: Gem::Sigstore::Config.read,
token: options[:identity_token],

Choose a reason for hiding this comment

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

Nitpick: perhaps token: should be identity_token: for consistency with :identity_token and --identity-token.

@@ -9,9 +9,10 @@ class Gem::Sigstore::GemSigner

Data = Struct.new(:digest, :signature, :raw)

def initialize(gemfile:, config:)
def initialize(gemfile:, config:, token: nil)

Choose a reason for hiding this comment

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

I suggest this also be identity_token.

if parsed_token["email"]
# ensure that the OIDC provider has verified the email address
# note: this may have happened some time in the past
if parsed_token["email_verified"] != true

Choose a reason for hiding this comment

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

Would unless parsed_token["email_verified"] be better here?

if parsed_token["email_verified"] != true
abort 'Email address in OIDC token has not been verified by provider'
end
return parsed_token["email"]

Choose a reason for hiding this comment

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

Any reason for using return here?

Copy link
Author

Choose a reason for hiding this comment

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

It is an early return, but I could move the email retrieval into a separate method to clear things up a bit.

# ensure that the OIDC provider has verified the email address
# note: this may have happened some time in the past
if parsed_token["email_verified"] != true
abort 'Email address in OIDC token has not been verified by provider'

Choose a reason for hiding this comment

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

Nit: has not been verified could be replaced with the shorter was not verified.

I'd also change provider to identity provider, because provider is a bit ambiguous by itself.

@doodzik doodzik force-pushed the add_static_openid_provider_2 branch from 26171c9 to 574e658 Compare December 2, 2021 17:49
@doodzik
Copy link
Author

doodzik commented Dec 2, 2021

Where would I find the original cosign code for comparison?

@jchestershopify Have a look at this PR and verification flow.

@doodzik doodzik merged commit 1d573e1 into main Dec 2, 2021
@unparsed_token = token
end

# https://www.youtube.com/watch?v=ZsgA77j5LyY

Choose a reason for hiding this comment

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

This made my day 🤣

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.

4 participants