Skip to content

Document auth registered as the runtime credential bypasses config.auth.variables in the OAuth token URL #890

Closed

Description

@jeffreyaven

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
  1. stackql exec "SELECT ... FROM example.svc.resource" with only the client id and secret in the environment and no --auth fails with:

    Post "https:///oauth/token": http: no Host in request URL
    

    Setting EXAMPLE_CLOUD, setting EXAMPLE_ACCOUNT_HOST, or adding an account_host SQL predicate does not change this.

  2. 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"}}' (no token_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 --auth entry exists for the provider, GetProvider registers transformOpenapiStackqlAuthToLocal(authDTO) through updateAuthContextIfNotExists. That AuthCtx carries the document's token_url verbatim.
  • internal/stackql/runtimeconfig/omnisdk_auth.go copies it into omnisdk.Auth.TokenURL, so on the omnisdk side authOf(args).TokenURL != "".
  • omnisdk pkg/omnisdk/omnisdk.go (plan construction, around line 1604) loads AuthDefaults().TokenURLVariables only 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.
  • expandEnv still 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

  1. added a commit that references this issue on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions