fix(source-okta): Fix OAuth with private key PEM parsing issue#69831
fix(source-okta): Fix OAuth with private key PEM parsing issue#69831Airbyte Support (Airbyte-Support) wants to merge 4 commits into
Conversation
The private key string from Airbyte Cloud contains escaped newlines (\n) instead of actual newline characters, causing PyJWT to fail parsing the PEM-formatted key with 'InvalidKeyError: Could not parse the provided public key.' This fix normalizes the escaped newlines to actual newlines before passing the key to jwt.encode(), following the same pattern used in other parts of the codebase (see commit e53e290). This resolves the issue for both the Okta connector and any other connectors using OAuth with private key authentication in the connector builder. Co-Authored-By: syed.khadeer@airbyte.io <cloud-support@airbyte.io>
Original prompt from syed.khadeer@airbyte.io |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. Helpful Resources
PR Slash CommandsAirbyte Maintainers (that's you!) can execute the following slash commands on your PR:
|
|
Co-Authored-By: syed.khadeer@airbyte.io <cloud-support@airbyte.io>
|
Deploy preview for airbyte-docs ready! ✅ Preview Built with commit 41c27ea. |
User Blocked - Needs v0.3.22 Deployed to CloudA user is currently blocked in Airbyte Cloud trying to use OAuth with private key authentication for the Okta connector. Current situation:
Validation:
Impact:
Next steps:
cc Ian Alton (@ian-at-airbyte) for visibility on this customer-impacting issue. Comment posted by Devin on behalf of Airbyte Support (@Airbyte-Support) (syed.khadeer@airbyte.io) |
Fixes an issue where JWT authentication fails when PEM-formatted private keys contain escaped newlines (\n) instead of actual newline characters. This commonly occurs when keys are stored in configuration systems like Airbyte Cloud. The fix adds normalization logic in JwtAuthenticator._get_secret_key() that: - Detects PEM-style keys (containing '-----BEGIN' and 'KEY-----') - Converts escaped newlines to actual newlines before JWT signing - Is guarded to only affect PEM keys, leaving other secret types unchanged This resolves the same issue fixed for the Okta connector in airbytehq/airbyte#69831, but at the CDK level so all declarative/Builder connectors using JWT authentication with private keys benefit from the fix. Includes a unit test that verifies JWT signing works with escaped newlines. Co-Authored-By: syed.khadeer@airbyte.io <cloud-support@airbyte.io>
CDK-Level Fix for Builder ConnectorsI've created a companion PR for the CDK that fixes the same escaped newline issue for Builder/declarative connectors using JWT authentication with private keys: airbytehq/airbyte-python-cdk#855 This means:
Both fixes use the same PEM-specific normalization approach and have been verified with the user's actual private key locally. Comment posted by Devin on behalf of Airbyte Support (@Airbyte-Support) (syed.khadeer@airbyte.io) |
The newer Poetry version in the Docker build environment performs stricter validation and rejects main.py with 'does not contain any element' error. Removing main.py from the packages list resolves this while keeping the source_okta package and console script entrypoint intact. Co-Authored-By: syed.khadeer@airbyte.io <cloud-support@airbyte.io>
What
Fixes a critical issue where OAuth authentication with private key fails in the Okta connector (and potentially other connectors using OAuth with private key in the connector builder) with the error:
This occurs because the private key string from Airbyte Cloud contains escaped newlines (
\\n) instead of actual newline characters, causing PyJWT to fail parsing the PEM-formatted key.How
Added a normalization step in
CustomOauth2PrivateKeyAuthenticator.token()that converts escaped newlines to actual newlines before passing the private key tojwt.encode(). This follows the same pattern used elsewhere in the codebase (see commit e53e290).Additionally, removed
{include = "main.py"}from the packages list inpyproject.tomlto fix a Poetry 2.x validation error that was blocking the publish workflow. The newer Poetry version in the Docker build environment performs stricter validation and rejectsmain.pywith the error "does not contain any element". The connector still works correctly via thesource-oktaconsole script entrypoint.Review guide
airbyte-integrations/connectors/source-okta/source_okta/components.py- Review the normalization logic in thetoken()method (lines 91-93)airbyte-integrations/connectors/source-okta/pyproject.toml- Review the removal ofmain.pyfrom packages list (line 15)User Impact
Positive:
Negative:
Can this PR be safely reverted and rolled back?
The changes are minimal and only affect the OAuth with private key authentication flow and the packaging configuration. Reverting would restore the broken authentication behavior and the publish workflow failure.
Link to Devin run: https://app.devin.ai/sessions/ccfafd12c230478f82106eb1bac5de88
Requested by: Airbyte Support (@Airbyte-Support) (syed.khadeer@airbyte.io)
Note: The OAuth fix was implemented based on error logs and pattern matching with historical fixes in the codebase. The packaging fix was needed to resolve a Poetry 2.x validation error during Docker build. Ideally, both changes should be tested with an actual Okta instance using OAuth with private key authentication before merging.