Skip to content

Add JWT handling to spiffe package #118

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

Merged
merged 16 commits into from
May 16, 2025

Conversation

jjcollinge
Copy link
Contributor

@jjcollinge jjcollinge commented Apr 11, 2025

Signed-off-by: Jonathan Collinge [email protected]

Description

This PR extends the spiffecontext package to support both X.509 SVID and JWT SVID sources. This will enable usages of this package as we add support for JWT Spiffe identity in the Dapr runtime.

The expectation is that Sentry will be updated so SignCertificateResponse will contain a JWT in addition to the existing x.509 certificate. Thus the RequestSVIDFn will be able to return both a JWT and x.509.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #[issue number]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests

Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
@jjcollinge jjcollinge force-pushed the jjcollinge/add-jwt-to-spiffe branch from d3a8882 to c529962 Compare May 10, 2025 08:11
Signed-off-by: Jonathan Collinge <[email protected]>
@jjcollinge
Copy link
Contributor Author

tests passing in CI on linux and locally on darwin... maybe a timing issue? Can someone re-run?

@jjcollinge jjcollinge marked this pull request as ready for review May 12, 2025 11:37
@jjcollinge jjcollinge requested review from a team as code owners May 12, 2025 11:37
Copy link
Contributor

@JoshVanL JoshVanL left a comment

Choose a reason for hiding this comment

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

whoop

Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
@jjcollinge
Copy link
Contributor Author

jjcollinge commented May 13, 2025

The tests is failing in CI on darwin but passing locally and in linux_arm, is this not a race condition in the existing tests?

--- FAIL: Test_Run (0.05s)
    --- FAIL: Test_Run/should_renew_certificate_when_it_has_expired (0.01s)
        spiffe_test.go:184: 
            	Error Trace:	/Users/runner/work/kit/kit/crypto/spiffe/spiffe_test.go:184
            	Error:      	readyCh should not be closed
            	Test:       	Test_Run/should_renew_certificate_when_it_has_expired
ctx, cancel := context.WithCancel(context.Background())
errCh := make(chan error)
go func() {
         // This will fetch the identity and then close the channel if error or success
	errCh <- s.Run(ctx)
}()

select {
// if the Run is succeeded or failed by the time we run this then the channel will be closed?
case <-s.readyCh:
	assert.Fail(t, "readyCh should not be closed")
default:
}

@jjcollinge jjcollinge requested a review from JoshVanL May 15, 2025 07:23
Copy link
Contributor

@JoshVanL JoshVanL left a comment

Choose a reason for hiding this comment

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

Few more things from me, but is looking good.

Signed-off-by: Jonathan Collinge <[email protected]>
Signed-off-by: Jonathan Collinge <[email protected]>
@jjcollinge jjcollinge requested a review from JoshVanL May 16, 2025 11:45
JoshVanL
JoshVanL previously approved these changes May 16, 2025
@JoshVanL
Copy link
Contributor

@jjcollinge linter failing

  crypto/spiffe/spiffe.go:262:10  revive  indent-error-flow: if block ends with a return statement, so drop this else and outdent its block

Signed-off-by: Jonathan Collinge <[email protected]>
@JoshVanL JoshVanL merged commit bc7dc56 into dapr:main May 16, 2025
6 checks passed
@mikeee
Copy link
Member

mikeee commented Jun 16, 2025

@jjcollinge Looks like the deprecation comments state the method signature as FromX509 but are defined as X509From, assuming the latter is more correct and is what we're running with or is this going to be refactored at a later date?

@jjcollinge
Copy link
Contributor Author

@jjcollinge Looks like the deprecation comments state the method signature as FromX509 but are defined as X509From, assuming the latter is more correct and is what we're running with or is this going to be refactored at a later date?

Good spot, that's an oversight on my part after a rename. Here's the fix #125

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.

3 participants