Repository navigation
Support Modal OAuth client credentials on the modal connection - #77829
Merged
Merged
Conversation
The modal connection type only modelled an API token, so a deployment that was given Modal OAuth client credentials had to fall back to MODAL_OAUTH_* environment variables on every worker. The connection now accepts oauth_refresh_token, oauth_client_id and oauth_client_secret in its extra. With all three set and login/password empty, ModalHook builds the client with Client.from_oauth_credentials, on both the sync and the async (trigger) path. A token field together with an OAuth field, or only some of the OAuth fields, raises ModalConnectionError instead of falling back to ambient credentials. Client.from_oauth_credentials first shipped in modal 1.5.5, so the floor moves from 1.5.0 to 1.5.5. The async path now reads the connection extra with get_async_extra_dejson, since Connection.extra_dejson masks secrets through a synchronous supervisor call that must not run on the triggerer's event loop. The Common AI Modal sandbox backend's rejected-credentials message no longer says "login and password", which would be wrong for an OAuth connection.
Lee-W
approved these changes
Dec 1, 2026
The "What this provider does not do yet" list still said the connection supports token authentication only, which contradicted the new OAuth section. It now names what is still unsupported, OAuth clients that use a JWT key, and points at the connection docs.
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.
The
modalconnection type models one of Modal's two ways to authenticate a client: an API token id and secret. Modal's SDK also accepts OAuth client credentials (modal.Client.from_oauth_credentials), which Modal describes as the method for managing Modal on behalf of third-party users. A deployment that is handed OAuth credentials instead of an API token cannot put them on the connection today, and has to setMODAL_OAUTH_*environment variables on every worker.This adds three optional extra fields to the connection:
oauth_refresh_token,oauth_client_idandoauth_client_secret. When all three are set and login/password are empty,ModalHookbuilds its client withfrom_oauth_credentials, on both the sync path and the async path the trigger uses.I ran it against
modal1.6.3 and Modal's live API with placeholder credentials, as a Dag task using a connection saved through the UI: the hook resolvesModalOAuthCredentials(client_id='oc-not-real'), and bothtest_connectionandlookup_appcome back with Modal'sAuthError: OAuth refresh token is malformed, so the three values reach Modal as OAuth credentials. A successful OAuth login was not exercised: that needs a Modal-issued OAuth client.Design rationale
Half-filled and mixed connections raise instead of guessing. The hook already raises
ModalConnectionErrorwhen one of the two token fields is set, because falling back to ambient credentials would hide the misconfiguration. The same rule now covers one or two of the three OAuth fields, and a token field set together with an OAuth field. The Modal SDK rejects the token-plus-OAuth combination on its own ambient path too.The credentials live in the extra, not in new columns or a second connection type. The extra is encrypted at rest, and Airflow's secrets masker redacts
oauth_refresh_tokenandoauth_client_secretby name, so they come back as***from the REST API. A separate connection type would split one hook across two forms for the same service.ModalHook.credentialsnow returns a token pair, aModalOAuthCredentials, orNone. The Common AI Modal sandbox backend readscredentials is not Noneas "the credentials came from the connection", and that stays true for OAuth connections. Its rejected-credentials message said "Update its login and password", which is reworded here because it would be wrong for an OAuth connection.The async path reads the extra with
get_async_extra_dejson. Until nowget_async_clientonly read login and password.Connection.extra_dejsonmasks secrets through a synchronous supervisor call, which must not run on the triggerer's event loop, so the async path awaits the common.compat helper and passes the dict to the shared validator.Gotchas
modalfloor moves from 1.5.0 to 1.5.5:Client.from_oauth_credentialsis absent in 1.5.3 and present in 1.5.5.Client.verifyopens and closes a throwaway client but takes only a token pair, andmodalhas no publicClient.close()before 1.6.4. The docs say so. Testing an API token connection is unchanged.from_oauth_credentialsgained anoauth_jwt_keyalternative to the client secret inmodal1.6.3 (it needs themodal[oauth]extra). This PR covers the client-secret form only.