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

BuildWorkloadJWTSVIDClaims fix for real credential composer implementation #4489

Merged
merged 2 commits into from
Sep 22, 2023

Conversation

enj
Copy link
Contributor

@enj enj commented Sep 12, 2023

TestBuildWorkloadJWTSVIDClaims/real_no-op_composer fails with the following error without this change:

rpc error: code = Internal desc = credentialcomposer(noop):
invalid workload JWTSVID attributes: failed to encode claims:
proto: invalid type: *jwt.NumericDate

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality

Commands such as spire-server jwt mint (and their associated RPC APIs)

Description of change

json.Marshal the JWTSVIDAttributes.Claims before attempting to convert to structpb.Struct.

…ation

TestBuildWorkloadJWTSVIDClaims/real_no-op_composer fails with the
following error without this change:

rpc error: code = Internal desc = credentialcomposer(noop):
invalid workload JWTSVID attributes: failed to encode claims:
proto: invalid type: *jwt.NumericDate

Signed-off-by: Monis Khan <i@monis.app>
@azdagron
Copy link
Member

Hey @enj! Thanks for expanding the test coverage and providing a fix. I think the proposed solution is pretty robust and probably just fine. I do wonder about paying the marshaling/unmarshalling cost for each svid minting (multiplied by the number of cred composers in the chain) but that probably is a very small fraction of the CPU spent on each RPC.

One option is to change the callers to not use these custom types. The only place this is called currently is by the credtemplate.Builder, which could trivially be changed to use sometimevar.Unix() on the fields that it is currently using jwt.NumericDate for.

Another option here would be change the credentialcomposer facade interface to take in structpb.Struct for the claims instead of map[string]interface{} so callers have worry about this concern instead. This has the added value that the loop that invokes credential composers no longer needs to do conversions in and out of structpb.Struct for each iteration.

Copy link
Member

@azdagron azdagron left a comment

Choose a reason for hiding this comment

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

Thanks again @enj. After some thought, I think we'll take this as-is. I might get around to changing up the code to side step the problem but at any rate this is a solid fix and the increase in test coverage is 🦸 .

@MarcosDY MarcosDY merged commit dcd1c90 into spiffe:main Sep 22, 2023
31 checks passed
@MarcosDY MarcosDY added this to the 1.8.1 milestone Sep 22, 2023
@amartinezfayo amartinezfayo modified the milestones: 1.8.1, 1.8.2, 1.8.3 Oct 11, 2023
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.

4 participants