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

RFC: add a SignerWithContext interface for custom sign implementations #117

Open
jamestelfer opened this issue May 9, 2024 · 2 comments · May be fixed by #119
Open

RFC: add a SignerWithContext interface for custom sign implementations #117

jamestelfer opened this issue May 9, 2024 · 2 comments · May be fixed by #119

Comments

@jamestelfer
Copy link

jamestelfer commented May 9, 2024

The current sign interface has the single Sign method:

Sign(claims jwt.Claims) (string, error)

When implementing an AWS KMS signer, the lack of the context means the remote operation doesn't participate in the main context, so it's unaware of request timeouts or server shutdown.

What about adding:

type SignerWithContext interface {
    Sign(ctx context.Context, claims jwt.Claims) (string, error)
}

An existing Signer implementation can be supported through a simple wrapper function:

type SignerWithContextFunc func Sign(claims jwt.Claims) (string, error)

func (s SignerWithContextFunc) (_ context.Context, claims jwt.Claims) (string, error) {
    return s(claims)
}

// ... 

signer := // Signer implementation
contextSigner := SignerWithContextFunc(signer.Sign)

Then a configuration item for WithContextSigner or similar. Thoughts?

I am able to raise a PR for this, or some more acceptable variation.

@jamestelfer jamestelfer linked a pull request May 19, 2024 that will close this issue
@jamestelfer
Copy link
Author

jamestelfer commented May 19, 2024

I've created a PR fleshing out the idea if you're interested @bradleyfalzon. Feedback welcome!

@jamestelfer
Copy link
Author

Another valuable use case for the context is when using telemetry. The current trace is generally carried on the request context, so including the context allows actions taken during signing to be included in the wider request trace.

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 a pull request may close this issue.

1 participant