Skip to content

Conversation

@sorindumitru
Copy link
Collaborator

We use our cached entry for requesting a new svid which may be different from the one that the server has. It may happen that entry gets updated around the same time that a cached SVID is renewed, including changing the SPIFFE ID. In this case the SPIFFE ID of the returned SVID may be different from the one of the entry we have.

Because of the above we shouldn't use the SPIFFE ID of our entry for caching the SVIDs. The NewJWTSVID API also returns the SPIFFE ID of the issued SVID so we can use that for caching purposes.

X509-SVID doesn't have this issue since there we cache using the entry ID.

We use our cached entry for requesting a new svid which may be different from
the one that the server has. It may happen that entry gets updated around the
same time that a cached SVID is renewed, including changing the SPIFFE ID. In
this case the SPIFFE ID of the returned SVID may be different from the one of
the entry we have.

Because of the above we shouldn't use the SPIFFE ID of our entry for caching
the SVIDs. The NewJWTSVID API also returns the SPIFFE ID of the issued SVID so
we can use that for caching purposes.

X509-SVID doesn't have this issue since there we cache using the entry ID.

Signed-off-by: Sorin Dumitru <sorin@returnze.ro>
Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

Thank you @sorindumitru for this!

If the SPIFFE ID changed, it seems like the old cached entry will remain in the cache forever? We may consider explicitly removing the old cache entry when the SPIFFE ID changes.

RenewSVID(ctx context.Context, csr []byte) (*X509SVID, error)
NewX509SVIDs(ctx context.Context, csrs map[string][]byte) (map[string]*X509SVID, error)
NewJWTSVID(ctx context.Context, entryID string, audience []string) (*JWTSVID, error)
NewJWTSVID(ctx context.Context, entryID string, audience []string) (*JWTSVID, string, error)
Copy link
Member

Choose a reason for hiding this comment

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

Have you considered returning spiffeid.ID directly instead of string to avoid the double parsing and improve type safety?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that's probably best. I think I had in mind that the SPIFFE ID gets converted to string when it's used in the cache, so string is probably going to be better for this. But I can see how that goes in a separate PR.

return cachedSVID, nil
}

spiffeID, err = spiffeid.FromString(spiffeIdString)
Copy link
Member

Choose a reason for hiding this comment

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

Overwriting the spiffeID var may be confusing. The initial parsing is still used for cache lookup, but it's replaced with the server's SPIFFE ID. If the two differ, the cache lookup might miss?
We should probably have two different var names.


spiffeID, err = spiffeid.FromString(spiffeIdString)
if err != nil {
return nil, errors.New("Invalid SPIFFE ID: " + err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

I think we should have fmt.Errorf with %w for error wrapping here.

Suggested change
return nil, errors.New("Invalid SPIFFE ID: " + err.Error())
return nil, fmt.Errorf("invalid SPIFFE ID: %w", err)

Signed-off-by: Sorin Dumitru <sorin@returnze.ro>
Copy link
Member

@amartinezfayo amartinezfayo left a comment

Choose a reason for hiding this comment

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

🎉

@sorindumitru sorindumitru merged commit 86d1b43 into spiffe:main Jan 6, 2026
49 checks passed
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.

2 participants