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

CiProvider as a new OIDCIssuer type #1679

Merged
merged 47 commits into from
Jul 9, 2024

Conversation

javanlacerda
Copy link
Contributor

@javanlacerda javanlacerda commented May 27, 2024

Contribute towards #1111

Summary

It adds CiProvider as a new OIDCIssuer type. We will migrate all ci providers to use a generic principal by changing their types to this new type.

It should not change any current behavior.

Release Note

Documentation

cc @haydentherapper

@javanlacerda javanlacerda marked this pull request as draft May 27, 2024 18:04
Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

and when you have time can you describe the PR and why we need that?

thanks!

pkg/identity/generic/issuer_test.go Outdated Show resolved Hide resolved
@javanlacerda
Copy link
Contributor Author

javanlacerda commented May 28, 2024

and when you have time can you describe the PR and why we need that?

thanks!

Sure! I apologize I hadn't do that already. I am working on this issue #1111.
My plan is having a generic module that handle ci providers id tokens claims defined in a configuration file, in this case, a yaml file.

I'll put a more detailed description in the PR summary soon.

@haydentherapper
Copy link
Contributor

@cpanato, the motivation is to simplify CI/CD OIDC provider onboarding. Rather than have each OIDC provider have to modify code to add a new provider, they instead should only need to modify a configuration file which will contain the mapping between OIDC claim and x509 extension value.

@cpanato
Copy link
Member

cpanato commented May 29, 2024

@cpanato, the motivation is to simplify CI/CD OIDC provider onboarding. Rather than have each OIDC provider have to modify code to add a new provider, they instead should only need to modify a configuration file which will contain the mapping between OIDC claim and x509 extension value.

that is nice! thanks for the clarification

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 82.00000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 49.62%. Comparing base (cf238ac) to head (e248f43).
Report is 133 commits behind head on main.

Files Patch % Lines
pkg/identity/ciprovider/principal.go 80.00% 7 Missing and 7 partials ⚠️
pkg/challenges/challenges.go 0.00% 2 Missing ⚠️
pkg/identity/ciprovider/issuer.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1679      +/-   ##
==========================================
- Coverage   57.93%   49.62%   -8.31%     
==========================================
  Files          50       71      +21     
  Lines        3119     4181    +1062     
==========================================
+ Hits         1807     2075     +268     
- Misses       1154     1878     +724     
- Partials      158      228      +70     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@javanlacerda javanlacerda changed the title Drafting generic issuer implementation Adding CI provider flag for OIDCIssuers Jun 6, 2024
@javanlacerda javanlacerda marked this pull request as ready for review June 6, 2024 15:37
@javanlacerda javanlacerda requested a review from cpanato June 6, 2024 16:27
pkg/identity/generic/issuer.go Outdated Show resolved Hide resolved
pkg/challenges/challenges.go Outdated Show resolved Hide resolved
@javanlacerda javanlacerda force-pushed the javan.oidc-provider-yaml branch 5 times, most recently from ea867b7 to e3c0e82 Compare June 11, 2024 16:43
@javanlacerda javanlacerda changed the title Adding CI provider flag for OIDCIssuers CiProvider as a new OIDCIssuer type Jun 11, 2024
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
config/fulcio-config.yaml Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
@javanlacerda javanlacerda force-pushed the javan.oidc-provider-yaml branch 2 times, most recently from 07c9a86 to 0a16f86 Compare June 24, 2024 18:38
@haydentherapper
Copy link
Contributor

Once this PR is ready for review and all comments addressed, can you post here?

Signed-off-by: Javan lacerda <[email protected]>
Signed-off-by: Javan lacerda <[email protected]>
go.mod Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/server/issuer_pool.go Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
pkg/certificate/extensions.go Outdated Show resolved Hide resolved
pkg/identity/ciprovider/principal.go Outdated Show resolved Hide resolved
Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

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

Just a few comments mostly around testing, this is coming together well!

}

for _, ciIssuerMetadata := range fulcioConfig.CIIssuerMetadata {
v := reflect.Indirect(reflect.ValueOf(&ciIssuerMetadata.ExtensionTemplates))
Copy link
Contributor

Choose a reason for hiding this comment

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

Does reflect.ValueOf(ciIssuerMetadata.ExtensionTemplates) work, or do we need the indirect reflection to resolve the pointer?

Copy link
Contributor Author

@javanlacerda javanlacerda Jul 3, 2024

Choose a reason for hiding this comment

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

Does reflect.ValueOf(ciIssuerMetadata.ExtensionTemplates) work, or do we need the indirect reflection to resolve the pointer?

Exactly, we need it for resolving the pointer

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 need to take a pointer to ciIssuerMetadata.ExtensionTemplates though? Are reflect.ValueOf(ciIssuerMetadata.ExtensionTemplates) and reflect.Indirect(reflect.ValueOf(&ciIssuerMetadata.ExtensionTemplates)) equivalent?

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 seems that reflect.ValueOf(ciIssuerMetadata.ExtensionTemplates) works. I assumed that I should use indirect for this case, as I needed to do this for using SetString. Without the indirect I got reflect.Value.SetString using unaddressable value as an error

pkg/config/config_network_test.go Outdated Show resolved Hide resolved
pkg/config/config_network_test.go Outdated Show resolved Hide resolved
err = validateCIIssuerMetadata(fulcioConfig)
if err == nil {
t.Error("It should raise an error")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you want to test for a valid SAN template 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.

yep! just did. thanks!!

}
uris := []*url.URL{sanURL}
cert.URIs = uris
v := reflect.Indirect(reflect.ValueOf(&claimsTemplates))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here, is reflect.Indirect needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case it is. As I mentioned, getting the pointer directly by reflect.ValueOf, I have an unaddressable value. Setting it as a reference and then using the indirect was the workaround I found for this.

uris := []*url.URL{sanURL}
cert.URIs = uris
v := reflect.Indirect(reflect.ValueOf(&claimsTemplates))
vType := v.Type()
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment about why we need the Type, that it's needed access struct field names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! thanks

"github.com/sigstore/fulcio/pkg/certificate"
"github.com/sigstore/fulcio/pkg/config"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any tests we can add for applyTemplateOrReplace, to check any edge cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! I added the test structure just with the happy path, I'll add more tests for edge cases soon

@@ -1123,6 +1131,178 @@ func TestAPIWithGitHub(t *testing.T) {
}
}

// Tests API for CiProvider subject types
func TestAPIWithCiProvider(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice test!

Signed-off-by: Javan lacerda <[email protected]>
Signed-off-by: Javan lacerda <[email protected]>
Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

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

🥳

@haydentherapper
Copy link
Contributor

In terms of release, I'm planning to cut 1.5 from before this PR, then we'll merge this and the other related changes and cut v1.6

@haydentherapper haydentherapper merged commit 66485b6 into sigstore:main Jul 9, 2024
13 checks passed
haydentherapper added a commit that referenced this pull request Jul 10, 2024
haydentherapper added a commit that referenced this pull request Jul 10, 2024
haydentherapper added a commit that referenced this pull request Jul 10, 2024
haydentherapper added a commit that referenced this pull request Jul 11, 2024
This adds a new generic CI provider so that new CI providers can be added via configuration without any code changes. The existing CI providers will be migrated over.

Ref: #1111
Add back #1679

Signed-off-by: Javan lacerda [email protected]
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.

None yet

4 participants