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

Ensure Non-Empty JWT Bundles Before Adding to FetchJWTBundles Response #5031

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/agent/endpoints/workload/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ func TestFetchJWTBundles(t *testing.T) {
require.NoError(t, err)
bundleJWKS = indent(bundleJWKS)

emptyJWKSBytes := indent([]byte(`{"keys": []}`))

federatedBundle := testca.New(t, spiffeid.RequireTrustDomainFromString("domain2.test")).Bundle()
federatedBundleJWKS, err := federatedBundle.JWTBundle().Marshal()
require.NoError(t, err)
Expand Down Expand Up @@ -1018,6 +1020,27 @@ func TestFetchJWTBundles(t *testing.T) {
},
},
},
{
name: "federated bundle with JWKS empty keys array",
updates: []*cache.WorkloadUpdate{
{
Identities: []cache.Identity{
identityFromX509SVID(x509SVID, "id1"),
},
Bundle: bundle,
FederatedBundles: map[spiffeid.TrustDomain]*spiffebundle.Bundle{
federatedBundle.TrustDomain(): spiffebundle.New(federatedBundle.TrustDomain()),
},
},
},
expectCode: codes.OK,
expectResp: &workloadPB.JWTBundlesResponse{
Bundles: map[string][]byte{
bundle.TrustDomain().IDString(): bundleJWKS,
federatedBundle.TrustDomain().IDString(): emptyJWKSBytes,
},
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/common/bundleutil/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func Marshal(bundle *spiffebundle.Bundle, opts ...MarshalOption) ([]byte, error)
}

var jwks jose.JSONWebKeySet
jwks.Keys = make([]jose.JSONWebKey, 0)

maybeUse := func(use string) string {
if !c.standardJWKS {
return use
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/bundleutil/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ func TestMarshal(t *testing.T) {
{
name: "empty bundle",
empty: true,
out: `{"keys":null, "spiffe_refresh_hint": 60, "spiffe_sequence": 42}`,
out: `{"keys":[], "spiffe_refresh_hint": 60, "spiffe_sequence": 42}`,
},
{
name: "with refresh hint override",
empty: true,
opts: []MarshalOption{
OverrideRefreshHint(time.Second * 10),
},
out: `{"keys":null, "spiffe_refresh_hint": 10, "spiffe_sequence": 42}`,
out: `{"keys":[], "spiffe_refresh_hint": 10, "spiffe_sequence": 42}`,
},
{
name: "with sequence number override",
empty: true,
opts: []MarshalOption{
OverrideSequenceNumber(1),
},
out: `{"keys":null, "spiffe_refresh_hint": 60, "spiffe_sequence": 1}`,
out: `{"keys":[], "spiffe_refresh_hint": 60, "spiffe_sequence": 1}`,
},
{
name: "without X509 SVID keys",
Expand Down
Loading