Skip to content

Iceberg REST catalog: expose OAuth2 scope (+ allow empty client_id) so Snowflake Horizon / Polaris session:role: auth works #1394

Closed

Description

@aaj3f

Summary

The Iceberg REST-catalog OAuth2 client-credentials auth supports a scope at the
engine level (OAuth2Config.scope, form-encoded into the token request), but
scope is not exposed through the public config surface — the builders, the
CLI, or the HTTP API all force it to None. As a result, connecting to any
Iceberg REST catalog that requires a token-exchange scope is impossible via the
supported config. The concrete blocked case is Snowflake Horizon Catalog
(Snowflake's built-in Apache-Polaris Iceberg REST endpoint), which requires
scope=session:role:<ROLE> on the /v1/oauth/tokens client-credentials exchange.

This blocks fluree/db-managed Iceberg connections to Snowflake-managed Iceberg
tables (a pattern we want to support / smoke-test).

Why it matters

Snowflake Horizon (and Polaris generally) gate the catalog session role through the
OAuth scope. Without passing scope, the token exchange either fails or yields a
token without the intended role, so the catalog returns no tables. The engine
already knows how to send scope; only the user-facing plumbing is missing.

Evidence (verified against a live Snowflake Horizon account)

Token exchange at https://<org>-<account>.snowflakecomputing.com/polaris/api/catalog/v1/oauth/tokens,
grant_type=client_credentials, client_secret=<PAT>:

Request Result
client_secret=<PAT> + scope=session:role:ICEBERG_READER, no client_id 200, access_token
client_id=<non-empty> + client_secret=<PAT> + same scope 400 invalid_scope
client_id="" (empty) + client_secret=<PAT> + same scope 200, access_token

So: (a) scope=session:role:<ROLE> is required; (b) client_id must be
empty — a non-empty client_id makes Snowflake interpret the request as the
Open-Catalog principal flow (which expects PRINCIPAL_ROLE: scope) and rejects
the session:role: scope.

Separately verified: with a correctly-scoped token, the REST catalog lists all
tables and an external engine (pyiceberg) reads data via vended credentials
(X-Iceberg-Access-Delegation: vended-credentials) — i.e. everything downstream of
the token exchange already works in fluree-db-iceberg.

Code references (HEAD d7f85144f)

  • fluree-db-iceberg/src/auth/oauth2.rs:17 — OAuth2Config.scope: Option<String> exists.
  • fluree-db-iceberg/src/auth/oauth2.rs:82-90 — scope is form-encoded when Some; client_id is sent unconditionally.
  • fluree-db-api/src/graph_source/config.rs:503-520 (IcebergCreateConfig::with_auth_oauth2) and :781 (R2rmlCreateConfig::with_auth_oauth2) — both hardcode scope: None, audience: None.
  • CLI: no --oauth2-scope flag; HTTP iceberg/map body has no scope field.

Proposed change

  1. Builders: let with_auth_oauth2 accept scope (and audience) — e.g. add a
    with_auth_oauth2_scoped(token_url, client_id, client_secret, scope, audience)
    or optional setters — threading into AuthConfig::OAuth2ClientCredentials.
  2. CLI: add --oauth2-scope (and --oauth2-audience) to fluree iceberg map.
  3. HTTP API: add oauth2_scope / oauth2_audience to the iceberg/map request.
  4. Empty client_id: it already works (it's a String), but document that
    Snowflake Horizon requires client_id="". Optional nicety: omit client_id
    from the form when empty.
  5. Docs: add a "Snowflake Horizon" section to docs/graph-sources/iceberg.md
    and docs/cli/iceberg.md with the exact config (token_url=.../v1/oauth/tokens,
    client_id="", scope=session:role:<ROLE>, vended_credentials=true,
    warehouse=<database>, UPPERCASE identifiers).

Acceptance criteria

  • Can register an R2RML/Iceberg graph source against a scope-gated Iceberg REST
    catalog (Snowflake Horizon / Polaris) via both the CLI and the Rust/HTTP API,
    passing scope.
  • An integration test exercises a token endpoint that requires scope (rejects
    the exchange without it).
  • Docs show the Snowflake Horizon happy path end-to-end.

Workarounds until fixed

  • Bearer auth with a pre-exchanged access_token (--auth-bearer), valid ~1h —
    good for a smoke test, not sustained (no auto-refresh).
  • Hand-write the stored AuthConfig JSON with scope (the struct supports it even
    though the builder doesn't).

Context: this came out of standing up a Snowflake-managed Iceberg dataset (552 M
rows, EXTERNAL_VOLUME = SNOWFLAKE_MANAGED) exposed via Horizon, and verifying
external reads, as the target for a fluree/db → Snowflake Iceberg smoke test.

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