fix(filebeat/entityanalytics): fix Okta OAuth2 token refresh for jwk_pem and jwk_file authentication#50433
fix(filebeat/entityanalytics): fix Okta OAuth2 token refresh for jwk_pem and jwk_file authentication#50433wucm667 wants to merge 3 commits intoelastic:mainfrom
Conversation
…ile auth When using OktaJWKFile or OktaJWKPEM for Okta OAuth2 authentication, token refresh failed because oktaTokenSource always stored o.OktaJWKJSON (which is nil for file/PEM auth). Subsequent Token() calls passed empty data to generateOktaJWT, causing 'error decoding JWK'. Fix: Add oktaJWKPEM field to oktaTokenSource. Store actual JWK data from file read or PEM string based on auth method. Update Token() to call generateOktaJWTPEM when PEM data is available. Apply same fix to httpjson and cel inputs which share the same pattern. Fixes elastic#50426
|
💚 CLA has been signed |
🤖 GitHub commentsJust comment with:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis pull request fixes Okta OAuth2 token refresh when using PEM-formatted private keys. Previously, the token source only supported JWK JSON payloads, causing refresh attempts with 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
Pinging @elastic/security-service-integrations (Team:Security-Service Integrations) |
|
This pull request doesn't have a |
Fixes #50426
Bug
When using Okta OAuth2 authentication with
jwk_pemorjwk_fileconfiguration in the entityanalytics provider, token refresh fails because the JWK data is not correctly stored and retrieved during the OAuth2 token source lifecycle.Root Cause
The
oktaTokenSourcestruct initialization infetchOktaOauthClient()always writes the JWK data tooktaJWK: o.OktaJWKJSON, which is only valid for thejwk(inline JSON) authentication mode. When usingjwk_fileorjwk_pemmodes, this field remains nil because the JWK data is loaded from a file or PEM-encoded string instead.During token refresh, the
Token()method checks these fields to determine which JWT construction function to call:generateJWTFromKeysWithPEMrequiresoktaJWKPEMgenerateJWTFromKeysrequiresoktaJWKSince the PEM/file modes stored their data in the wrong fields (or not at all), the refresh path could not find the correct JWK data and fell back to the wrong JWT generation function, causing authentication failures.
Fix
oktaJWKPEMfield to theoktaTokenSourcestruct to hold PEM-encoded JWK data.fetchOktaOauthClient(), now correctly routes JWK data into the appropriate fields based on the configured authentication mode:jwk→oktaJWK(JSON)jwk_file→oktaJWK(file contents)jwk_pem→oktaJWKPEM(PEM string)Token()method to check bothoktaJWKandoktaJWKPEMfields and call the correct JWT generation function accordingly.Verification
make testpasses forx-pack/filebeat/input/entityanalytics/provider/okta(all 8 tests)make testpasses forx-pack/filebeat/input/httpjson(22 tests, includes okta auth config)make testpasses forx-pack/filebeat/input/cel(5 tests, includes okta auth config)