Skip to content

Commit efa2d0d

Browse files
adityasakyjavanlacerda
authored andcommitted
Include IDP type and subject domain in configuration API response (sigstore#1824)
Signed-off-by: Aditya Sirish A Yelgundhalli <[email protected]>
1 parent 83238ce commit efa2d0d

File tree

8 files changed

+193
-98
lines changed

8 files changed

+193
-98
lines changed

fulcio.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,8 @@ message OIDCIssuer {
237237
string challenge_claim = 4;
238238
// The expected SPIFFE trust domain. Only present when the OIDC issuer issues tokens for SPIFFE identities.
239239
string spiffe_trust_domain = 5;
240+
// The type of the IDP (e.g. "email", "username", etc.).
241+
string issuer_type = 6;
242+
// The expected subject domain. Only present when the OIDC issuer issues tokens for URI or username identities.
243+
string subject_domain = 7;
240244
}

fulcio.swagger.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@
237237
"spiffeTrustDomain": {
238238
"type": "string",
239239
"description": "The expected SPIFFE trust domain. Only present when the OIDC issuer issues tokens for SPIFFE identities."
240+
},
241+
"issuerType": {
242+
"type": "string",
243+
"description": "The type of the IDP (e.g. \"email\", \"username\", etc.)."
244+
},
245+
"subjectDomain": {
246+
"type": "string",
247+
"description": "The expected subject domain. Only present when the OIDC issuer issues tokens for URI or username identities."
240248
}
241249
},
242250
"description": "Metadata about an OIDC issuer."

pkg/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ func (fc *FulcioConfig) ToIssuers() []*fulciogrpc.OIDCIssuer {
237237
Audience: cfgIss.ClientID,
238238
SpiffeTrustDomain: cfgIss.SPIFFETrustDomain,
239239
ChallengeClaim: issuerToChallengeClaim(cfgIss.Type, cfgIss.ChallengeClaim),
240+
IssuerType: cfgIss.Type.String(),
241+
SubjectDomain: cfgIss.SubjectDomain,
240242
}
241243
issuers = append(issuers, issuer)
242244
}
@@ -247,6 +249,8 @@ func (fc *FulcioConfig) ToIssuers() []*fulciogrpc.OIDCIssuer {
247249
Audience: cfgIss.ClientID,
248250
SpiffeTrustDomain: cfgIss.SPIFFETrustDomain,
249251
ChallengeClaim: issuerToChallengeClaim(cfgIss.Type, cfgIss.ChallengeClaim),
252+
IssuerType: cfgIss.Type.String(),
253+
SubjectDomain: cfgIss.SubjectDomain,
250254
}
251255
issuers = append(issuers, issuer)
252256
}
@@ -304,6 +308,10 @@ func (fc *FulcioConfig) prepare() error {
304308

305309
type IssuerType string
306310

311+
func (it IssuerType) String() string {
312+
return string(it)
313+
}
314+
307315
const (
308316
IssuerTypeBuildkiteJob = "buildkite-job"
309317
IssuerTypeEmail = "email"

pkg/config/config_test.go

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -540,46 +540,98 @@ func Test_issuerToChallengeClaim(t *testing.T) {
540540
}
541541

542542
func TestToIssuers(t *testing.T) {
543-
config := &FulcioConfig{
544-
OIDCIssuers: map[string]OIDCIssuer{
545-
"example.com": {
546-
IssuerURL: "example.com",
547-
ClientID: "sigstore",
548-
Type: IssuerTypeEmail,
543+
tests := []struct {
544+
config *FulcioConfig
545+
want []*protobuf.OIDCIssuer
546+
}{
547+
{
548+
config: &FulcioConfig{
549+
OIDCIssuers: map[string]OIDCIssuer{
550+
"example.com": {
551+
IssuerURL: "example.com",
552+
ClientID: "sigstore",
553+
Type: IssuerTypeEmail,
554+
},
555+
},
556+
MetaIssuers: map[string]OIDCIssuer{
557+
"wildcard.*.example.com": {
558+
ClientID: "sigstore",
559+
Type: IssuerTypeKubernetes,
560+
},
561+
},
549562
},
550-
},
551-
MetaIssuers: map[string]OIDCIssuer{
552-
"wildcard.*.example.com": {
553-
ClientID: "sigstore",
554-
Type: IssuerTypeKubernetes,
563+
want: []*protobuf.OIDCIssuer{
564+
{
565+
Audience: "sigstore",
566+
ChallengeClaim: "email",
567+
Issuer: &protobuf.OIDCIssuer_IssuerUrl{
568+
IssuerUrl: "example.com",
569+
},
570+
IssuerType: IssuerTypeEmail,
571+
},
572+
{
573+
Audience: "sigstore",
574+
ChallengeClaim: "sub",
575+
Issuer: &protobuf.OIDCIssuer_WildcardIssuerUrl{
576+
WildcardIssuerUrl: "wildcard.*.example.com",
577+
},
578+
IssuerType: IssuerTypeKubernetes,
579+
},
555580
},
556581
},
557-
}
558-
559-
issuers := config.ToIssuers()
560-
if len(issuers) != 2 {
561-
t.Fatalf("unexpected number of issues, expected 2, got %v", len(issuers))
562-
}
563-
564-
iss := &protobuf.OIDCIssuer{
565-
Audience: "sigstore",
566-
ChallengeClaim: "email",
567-
Issuer: &protobuf.OIDCIssuer_IssuerUrl{
568-
IssuerUrl: "example.com",
582+
{
583+
config: &FulcioConfig{
584+
OIDCIssuers: map[string]OIDCIssuer{
585+
"username.example.com": {
586+
IssuerURL: "username.example.com",
587+
ClientID: "sigstore",
588+
Type: IssuerTypeUsername,
589+
SubjectDomain: "username.example.com",
590+
},
591+
},
592+
},
593+
want: []*protobuf.OIDCIssuer{
594+
{
595+
Audience: "sigstore",
596+
ChallengeClaim: "sub",
597+
Issuer: &protobuf.OIDCIssuer_IssuerUrl{
598+
IssuerUrl: "username.example.com",
599+
},
600+
IssuerType: IssuerTypeUsername,
601+
SubjectDomain: "username.example.com",
602+
},
603+
},
569604
},
570-
}
571-
if !reflect.DeepEqual(issuers[0], iss) {
572-
t.Fatalf("expected issuer %v, got %v", iss, issuers[0])
573-
}
574-
iss = &protobuf.OIDCIssuer{
575-
Audience: "sigstore",
576-
ChallengeClaim: "sub",
577-
Issuer: &protobuf.OIDCIssuer_WildcardIssuerUrl{
578-
WildcardIssuerUrl: "wildcard.*.example.com",
605+
{
606+
config: &FulcioConfig{
607+
OIDCIssuers: map[string]OIDCIssuer{
608+
"uriissuer.example.com": {
609+
IssuerURL: "uriissuer.example.com",
610+
ClientID: "sigstore",
611+
Type: IssuerTypeURI,
612+
SubjectDomain: "uriissuer.example.com",
613+
},
614+
},
615+
},
616+
want: []*protobuf.OIDCIssuer{
617+
{
618+
Audience: "sigstore",
619+
ChallengeClaim: "sub",
620+
Issuer: &protobuf.OIDCIssuer_IssuerUrl{
621+
IssuerUrl: "uriissuer.example.com",
622+
},
623+
IssuerType: IssuerTypeURI,
624+
SubjectDomain: "uriissuer.example.com",
625+
},
626+
},
579627
},
580628
}
581-
if !reflect.DeepEqual(issuers[1], iss) {
582-
t.Fatalf("expected issuer %v, got %v", iss, issuers[1])
629+
630+
for _, test := range tests {
631+
issuers := test.config.ToIssuers()
632+
if !reflect.DeepEqual(issuers, test.want) {
633+
t.Fatalf("expected issuers %v, got %v", test.want, issuers)
634+
}
583635
}
584636
}
585637

pkg/generated/protobuf/fulcio.pb.go

Lines changed: 84 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)