Skip to content

Commit

Permalink
rename issuers metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Javan lacerda <javanlacerda@google.com>
  • Loading branch information
javanlacerda committed Jun 24, 2024
1 parent e40bb8f commit 07c9a86
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion config/fulcio-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ data:
"Type": "github-workflow"
}
},
"IssuersMetadata": null
"DefaultTemplateValues": null
}
server.yaml: |-
host: 0.0.0.0
Expand Down
26 changes: 16 additions & 10 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,23 @@ type FulcioConfig struct {
MetaIssuers map[string]OIDCIssuer `json:"MetaIssuers,omitempty" yaml:"meta-issuers,omitempty"`

// defines the metadata for the issuers
IssuersMetadata map[string]IssuersMetadata
CIIssuerMetadata map[string]DefaultTemplateValues

// verifiers is a fixed mapping from our OIDCIssuers to their OIDC verifiers.
verifiers map[string][]*verifierWithConfig
// lru is an LRU cache of recently used verifiers for our meta issuers.
lru *lru.TwoQueueCache
}

type IssuersMetadata struct {
Defaults map[string]string
ClaimsMapper certificate.Extensions
type DefaultTemplateValues struct {
// Default key and values that can be used for filling the templates
// If a key cannot be found on the token claims, the template will use the defaults
Defaults map[string]string
// It is the mapper from the id token claims to the Extensions.
// It expects strings with templates syntax https://pkg.go.dev/text/template
// or raw strings with claims keys to be replaced
ClaimsMapper certificate.Extensions
// A alternative name for the issuer subject
SubjectAlternativeName string
}

Expand All @@ -86,8 +92,8 @@ type OIDCIssuer struct {
// Used to determine the subject of the certificate and if additional
// certificate values are needed
Type IssuerType `json:"Type" yaml:"type,omitempty"`
// Issuers subtype
SubType string `json:"SubType,omitempty" yaml:"sub-type,omitempty"`
// Issuers CiProvider type
CIProvider string `json:"CIProvider,omitempty" yaml:"ci-provider,omitempty"`
// Optional, if the issuer is in a different claim in the OIDC token
IssuerClaim string `json:"IssuerClaim,omitempty" yaml:"issuer-claim,omitempty"`
// The domain that must be present in the subject for 'uri' issuer types
Expand Down Expand Up @@ -471,20 +477,20 @@ func LoadCiProvidersConfig(cfg *FulcioConfig) (*FulcioConfig, error) {
fmt.Printf("Unmarshal: %v", err)
}

cfg.IssuersMetadata = make(map[string]IssuersMetadata)
cfg.CIIssuerMetadata = make(map[string]DefaultTemplateValues)
for k, v := range ciProvidersConfig.Providers {
cfg.IssuersMetadata[k] = IssuersMetadata{
cfg.CIIssuerMetadata[k] = DefaultTemplateValues{
v.Defaults,
v.Extensions,
v.SubjectAlternativeName,
}
for _, issuer := range v.OIDCIssuers {
issuer.SubType = k
issuer.CIProvider = k
issuer.Type = IssuerTypeCiProvider
cfg.OIDCIssuers[issuer.IssuerURL] = issuer
}
for _, issuer := range v.MetaIssuers {
issuer.SubType = k
issuer.CIProvider = k
issuer.Type = IssuerTypeCiProvider
cfg.MetaIssuers[issuer.IssuerURL] = issuer
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/identity/ciprovider/issuer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func TestIssuer(t *testing.T) {
OIDCIssuers :=
map[string]config.OIDCIssuer{
token.Issuer: {
IssuerURL: token.Issuer,
Type: config.IssuerTypeCiProvider,
SubType: "github-workflow",
ClientID: "sigstore",
IssuerURL: token.Issuer,
Type: config.IssuerTypeCiProvider,
CIProvider: "github-workflow",
ClientID: "sigstore",
},
}
cfg := &config.FulcioConfig{
Expand Down
4 changes: 2 additions & 2 deletions pkg/identity/ciprovider/principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func applyTemplateOrReplace(path string, data map[string]string, defaultData map

type Config struct {
Token *oidc.IDToken
Metadata config.IssuersMetadata
Metadata config.DefaultTemplateValues
}

func WorkflowPrincipalFromIDToken(ctx context.Context, token *oidc.IDToken) (identity.Principal, error) {
Expand All @@ -85,7 +85,7 @@ func WorkflowPrincipalFromIDToken(ctx context.Context, token *oidc.IDToken) (ide

return Config{
token,
cfg.IssuersMetadata[issuer.SubType],
cfg.CIIssuerMetadata[issuer.CIProvider],
}, nil
}

Expand Down
26 changes: 13 additions & 13 deletions pkg/identity/ciprovider/principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestWorkflowPrincipalFromIDToken(t *testing.T) {
}{
`Github workflow challenge should have all Github workflow extensions and issuer set`: {
ExpectedPrincipal: Config{
Metadata: config.IssuersMetadata{
Metadata: config.DefaultTemplateValues{
ClaimsMapper: certificate.Extensions{
Issuer: "issuer",
GithubWorkflowTrigger: "event_name",
Expand Down Expand Up @@ -101,17 +101,17 @@ func TestWorkflowPrincipalFromIDToken(t *testing.T) {
OIDCIssuers :=
map[string]config.OIDCIssuer{
token.Issuer: {
IssuerURL: token.Issuer,
Type: config.IssuerTypeCiProvider,
SubType: "github-workflow",
ClientID: "sigstore",
IssuerURL: token.Issuer,
Type: config.IssuerTypeCiProvider,
CIProvider: "github-workflow",
ClientID: "sigstore",
},
}
meta := make(map[string]config.IssuersMetadata)
meta := make(map[string]config.DefaultTemplateValues)
meta["github-workflow"] = test.ExpectedPrincipal.Metadata
cfg := &config.FulcioConfig{
OIDCIssuers: OIDCIssuers,
IssuersMetadata: meta,
OIDCIssuers: OIDCIssuers,
CIIssuerMetadata: meta,
}
ctx = config.With(ctx, cfg)
principal, err := WorkflowPrincipalFromIDToken(ctx, token)
Expand Down Expand Up @@ -183,10 +183,10 @@ func TestName(t *testing.T) {
OIDCIssuers :=
map[string]config.OIDCIssuer{
token.Issuer: {
IssuerURL: token.Issuer,
Type: config.IssuerTypeCiProvider,
SubType: "ci-provider",
ClientID: "sigstore",
IssuerURL: token.Issuer,
Type: config.IssuerTypeCiProvider,
CIProvider: "ci-provider",
ClientID: "sigstore",
},
}
cfg := &config.FulcioConfig{
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestEmbed(t *testing.T) {
`Certificate has correct source repository visibility extension`: factExtensionIs(asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 22}, "public"),
},
Principal: Config{
Metadata: config.IssuersMetadata{
Metadata: config.DefaultTemplateValues{
ClaimsMapper: certificate.Extensions{
Issuer: "issuer",
GithubWorkflowTrigger: "event_name",
Expand Down

0 comments on commit 07c9a86

Please sign in to comment.