Skip to content

feat: add jwt pkg #14928

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 25 commits into from
Oct 4, 2024
Merged

feat: add jwt pkg #14928

merged 25 commits into from
Oct 4, 2024

Conversation

sreya
Copy link
Collaborator

@sreya sreya commented Oct 2, 2024

This PR adds a jwtutils package to be shared amongst the various packages in the codebase that make use of JWTs. It's intended to help us standardize on one library instead of some implementations using go-jose and others using golang-jwt.

The main reason we're converging on go-jose is due to its support for JWEs, golang-jwt also has a repo to handle it but it doesn't look maintained

sreya added 4 commits October 2, 2024 05:07
This refactor encapsulates key management for JWT signing and verification by:
- Introducing `ParseKeyFunc` and `SecuringKeyFn` to streamline key operations.
- Moving key-related functions to `jwt.go` to improve package modularity.
- Simplifying `Encrypt` and `Decrypt` function documentation and usage.
- Updating tests to align with the new function signatures and logic flow.
The JWT functionality has been refactored, and its associated test values are no longer required. Removing the test file helps maintain code clarity and prevents outdated test logic from impacting the current codebase.
- Renamed key functions to clarify their use.
- Removed unused `featureHeaderKey`.
- Added comprehensive tests for JWT signing and verifying.
@sreya sreya marked this pull request as ready for review October 2, 2024 05:14
@sreya sreya requested a review from deansheather October 2, 2024 05:14
sreya added 2 commits October 3, 2024 01:19
- Streamlines key retrieval by integrating with the cryptokeys package.
- Simplifies key handling by decoding directly using hex utilities.
- Enhances validation by using context for managing key operations.
- Improves test robustness with clearer setup and consistent mocking.
- Rename package `jwt` to `jwtutils` for better context.
- Consolidate constants and enhance error messages.
- Simplify key management for JWT signing and verification.
@sreya sreya requested a review from deansheather October 3, 2024 01:30
sreya added 7 commits October 3, 2024 04:24
Refactor JWT utility code to replace `ParseOptions` with more specific
`VerifyOptions` and `DecryptOptions`. This change enhances clarity and
flexibility, accommodating different needs for JWS and JWE operations. Update
tests to align with the refactored structure, ensuring robust coverage and
functionality verification.
Increase OIDC secret length for added security and clarity.
Optimize JWT test coverage with custom claims and key cache tests.
@sreya sreya requested a review from deansheather October 3, 2024 08:12
sreya added 2 commits October 3, 2024 22:30
- Enhance comments for key interfaces to clarify usage
  and considerations for time validity and clock skew.
- Refactor JWE/JWS logic to simplify serialization and
  deserialization processes, ensuring more efficient and
  concise handling of JWTs. Implement compact serialization
  and remove unnecessary base64 encoding.
Removing unused test and mock code simplifies maintenance and reduces clutter.
@sreya sreya requested a review from Emyrk October 3, 2024 22:37
sreya added 3 commits October 3, 2024 23:02
Deleting unnecessary cryptokeys keycachemock ensures clarity and reduces maintenance.
Ensure that the dbCache methods for encrypting, decrypting, signing,
and verifying keys validate the feature flag before proceeding with
operations. This validation step prevents using keys for unintended
purposes, maintaining proper alignment with their intended
cryptographic feature.
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

LG, would like to have the "fetcher" interface so we can use this in wsproxy too at some point 👍

@sreya
Copy link
Collaborator Author

sreya commented Oct 4, 2024

LG, would like to have the "fetcher" interface so we can use this in wsproxy too at some point 👍

Yeah I'll open an issue to work on a refactor once I get this running in dev.

@sreya sreya merged commit 68ec532 into main Oct 4, 2024
27 of 29 checks passed
@sreya sreya deleted the jon/jwt branch October 4, 2024 02:09
@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants