Closed
Conversation
Implement DPoP support for OAuth2 clients. Co-authored-by: robert.kortschak <robert.kortschak@elastic.co>
|
Cursor Agent can help with this pull request. Just |
Co-authored-by: robert.kortschak <robert.kortschak@elastic.co>
Co-authored-by: robert.kortschak <robert.kortschak@elastic.co>
This commit updates the DPoP implementation to use the `golang-jwt/jwt/v5` library for signing JWTs. This simplifies the code by delegating the signing logic to the library, removing the need for custom signing functions. The `go.mod` and `go.sum` files have been updated to reflect the new dependency. Co-authored-by: robert.kortschak <robert.kortschak@elastic.co>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhancement
What does this PR do?
This PR introduces a new Go package
libbeat/common/dpopoauth2to integrate DPoP (Demonstrating Proof-of-Possession) authentication into standard OAuth2.0 flows usinggolang.org/x/oauth2.Key components include:
ProofGenerator: Handles the creation of DPoP proofs (JWTs containingjwk,htm,htu,iat,jti, and optionallynonceandathclaims).TokenTransport: Anhttp.RoundTripperfor the OAuth2 token endpoint, which adds theDPoPheader and implements a retry mechanism forDPoP-Noncechallenges.Transport: Anhttp.RoundTripperfor protected resource access, which wraps anoauth2.TokenSource, sets theAuthorization: DPoP <access_token>header, includes theDPoPproof (withath), and handlesDPoP-Nonceretries.NewTokenClient,NewResourceClientfor easy client construction, andGenerateECDSAP256Key,GenerateRSAPrivateKeyfor key generation.Why is it important?
This package enables the use of DPoP with OAuth2.0, providing enhanced security by binding access tokens to a cryptographic key held by the client. This prevents token replay attacks and ensures that only the legitimate client can use the token. This is specifically intended to add DPoP authentication capabilities to the
x-pack/filebeat/input/celpackage.Checklist
CHANGELOG.next.asciidocorCHANGELOG-developer.next.asciidoc.Author's Checklist
How to test this PR locally
To test this PR, you can integrate the new
dpopoauth2package into an application that usesgolang.org/x/oauth2.Generate a private key:
For token acquisition (e.g., code exchange, client credentials grant):
For protected resource access:
The included unit tests (
proof_test.go) also demonstrate the expected behavior of proof generation, resource header setting, and nonce-based retries.Related issues
Use cases
dpopoauth2.NewTokenClientto ensure that its requests to the OAuth2 token endpoint are DPoP-protected, preventing malicious actors from replaying token requests.dpopoauth2.NewResourceClientto make requests to protected APIs. The DPoP proof included in these requests cryptographically links the access token to the client's private key, ensuring only the token-possessing client can use it.x-pack/filebeat/input/cel: This package provides the necessary building blocks for thecelinput to securely authenticate with DPoP-enabled OAuth2.0 providers.Screenshots
Logs