Repository navigation
Description
Summary
A provider document that declares an OAuth2 client-credentials config.auth whose token_url uses {variable} placeholders resolved by config.auth.variables (x-stackQL-envVar / x-stackQL-envVarSelector, added in #887 with omnisdk v0.1.10) cannot obtain a token unless the user passes --auth for that provider. Without --auth, the host registers the document's own auth block as the provider's runtime credential, and omnisdk then treats the document token URL as a runtime override that bypasses the document's variable declarations.
Reproduction (generic)
Provider document, the shape from the omnisdk developer guide and from test/robot/functional/EndpointSelectorLibrary.py:
config:
auth:
type: oauth2
grant_type: client_credentials
client_id_env_var: EXAMPLE_CLIENT_ID
client_secret_env_var: EXAMPLE_CLIENT_SECRET
token_url: https://{account_host}/oauth/token
variables:
account_host:
default: accounts.example.com
x-stackQL-envVar: EXAMPLE_ACCOUNT_HOST
x-stackQL-envVarSelector:
envVar: EXAMPLE_CLOUD
default: aws
values:
aws: accounts.example.com
azure: accounts.example.net-
stackql exec "SELECT ... FROM example.svc.resource"with only the client id and secret in the environment and no--authfails with:Post "https:///oauth/token": http: no Host in request URLSetting
EXAMPLE_CLOUD, settingEXAMPLE_ACCOUNT_HOST, or adding anaccount_hostSQL predicate does not change this. -
The same statement with
--auth '{"example": {"type": "oauth2", "grant_type": "client_credentials", "client_id_env_var": "EXAMPLE_CLIENT_ID", "client_secret_env_var": "EXAMPLE_CLIENT_SECRET"}}'(notoken_url) succeeds, and the selector default, the selector choice and the direct override all resolve as documented.
stackql_endpoint_selectors.robot only covers case 2: execute_selector_sql always passes --auth without a token URL, so the suite does not see the default path.
Observed on v1.0.875-rc (fdcabb2, omnisdk v0.1.10-alpha04), Linux and Windows, with a document that follows the developer guide exactly.
Cause
internal/stackql/handler/handler.go: when no--authentry exists for the provider,GetProviderregisterstransformOpenapiStackqlAuthToLocal(authDTO)throughupdateAuthContextIfNotExists. ThatAuthCtxcarries the document'stoken_urlverbatim.internal/stackql/runtimeconfig/omnisdk_auth.gocopies it intoomnisdk.Auth.TokenURL, so on the omnisdk sideauthOf(args).TokenURL != "".- omnisdk
pkg/omnisdk/omnisdk.go(plan construction, around line 1604) loadsAuthDefaults().TokenURLVariablesonly when the runtime auth has no token URL. That follows omnisdk's documented contract ("A runtime Auth.TokenURL overrides the document endpoint and bypasses its variable declarations"), so the host is presenting the document's URL as if an alias had set it. expandEnvstill fills{{ .__env__NAME }}, then the token exchange request fills{name}placeholders from its inputs, which do not contain the server variable, which yields the empty host.
Expected
The document's declared variables apply whenever the effective token URL is the document's, with the precedence documented in docs/developer_guide.md (SQL input, alias parameter, x-stackQL-envVar, selector choice, selector default). A token_url supplied through --auth or a provider alias keeps overriding.
Suggested fix (host side, provider independent)
Do not present a document-registered auth context as a runtime token URL override. For contexts recorded in hc.docAuthProviders, leave TokenURL empty in OmniAuth (omnisdk then overlays the document default and applies TokenURLVariables), or carry an origin flag so the omnisdk call can tell "from the document" from "set by the caller". A complementary hardening on the omnisdk side is proposed separately (see the linked omnisdk issue).
Impact
Any provider whose token authority depends on the environment: multi-cloud account consoles, sovereign or government clouds, self-hosted OAuth servers (GitHub Enterprise Server, GitLab), partitioned endpoints. None of them can authenticate on the omnisdk-based engine without --auth or an alias, even though the document is written exactly as the developer guide describes.
Workaround
Pass --auth for the provider with the credential environment variable names and no token_url.
Companion omnisdk hardening proposal: stackql-labs/omnisdk#35
Activity
multiple-fixes