Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions documentation/connect/clients/connect-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ caveats), follow the section links from the [Key index](#key-index).
| Basic-auth credentials | both | `username`, `password` | `auth_timeout_ms` |
| Bearer-token credentials | both | `token` | `auth_timeout_ms` |
| Entra ID tokens that the client renews (Java) | both | `token_provider=azure`, `azure_resource` | `azure_credential`, `azure_client_id` |
| Auto-create tables owned by a group (Java) | ingress | `owned_by` | Required for an external (OIDC) user to auto-create tables and columns; QuestDB Enterprise |
| Multi-host failover | both | `addr=h1,h2,…` | `target`, `zone`, `reconnect_*` (ingress), `failover_*` (egress) |
| Query only the primary (freshest data) | egress | `target=primary` | — |
| Query only replicas (offload primary) | egress | `target=replica` | — |
Expand Down Expand Up @@ -303,6 +304,62 @@ equivalent connect strings share one provider in a process. See
[Token providers](/docs/connect/clients/java/#token-providers) in the Java
client reference.

### Owner of auto-created tables {#owned-by}

*Applies to: ingress. Available in the Java client 1.3.13 or later only, with
QuestDB Enterprise 4.2.2 or later.*

When a batch names a table or a column that does not exist yet, the server
creates it, if the principal holds `CREATE TABLE` or `ADD COLUMN`. The creator
then receives every permission on the new table or column, with the `GRANT`
option: the [owner permissions](/docs/security/rbac/#owner-grants). `owned_by`
hands them to another entity instead, the way the
[`OWNED BY`](/docs/query/sql/create-table/#owned-by) clause does in SQL:

- `owned_by` — the user, group, or service account that receives the owner
permissions on every table the sender creates and every column it adds,
including columns of tables it did not create. A principal may name itself
or one of its groups, and the built-in admin any existing user, group, or
service account. Unset by default.

```
wss::addr=db.example.com:9000;token=<OIDC token>;owned_by=fxIngest;
```

An [external user](/docs/security/oidc/#user-permissions), one that
authenticates with an OIDC token, such as an Entra ID token from a token
provider, cannot receive permissions itself. It must name one of its groups
for the server to create tables and columns for it at all: without
`owned_by`, the server refuses them. Writing to existing tables and columns
needs no owner.

The client sends the owner on the WebSocket upgrade of every connection,
reconnects and failovers included, and the server checks it there:

- An owner the principal may not name fails the connection with HTTP `403`
and the reason, such as `owned_by refused: fxIngest does not exist`.
- QuestDB open source, and QuestDB Enterprise with access control disabled,
cannot set an owner, so they fail the connection with HTTP `403` too.
- A server that predates `owned_by` ignores it, so the client fails the
connection itself rather than create tables that the owner does not own.

The server checks the owner again before it creates each table or column,
because the permissions may have changed since the connection opened. If the
principal may no longer name it, for example because the group was dropped,
the batch fails with a security error and nothing is created.

Other clients do not support `owned_by` yet, so leave it out of a connect
string shared with them. The Java client accepts it only on the `ws` and
`wss` schemas. The wire format is described in the
[QWP ingress protocol](/docs/connect/wire-protocols/qwp-ingress-websocket/#owner-of-auto-created-tables).

:::note QuestDB Enterprise

`owned_by` needs QuestDB Enterprise with access control. Try it with a
[free 30-day trial](https://questdb.com/enterprise/trial/).

:::

## TLS {#tls}

*Applies to: ingress and egress.*
Expand Down Expand Up @@ -1088,6 +1145,7 @@ description and behaviour notes.
| `on_security_error` | enum | `terminal` | [Error handling](#error-handling) |
| `on_server_error` | enum | `auto` | [Error handling](#error-handling) |
| `on_write_error` | enum | `retriable` | [Error handling](#error-handling) |
| `owned_by` | string | unset | [Owner of auto-created tables](#owned-by) (Java only) |
| `pass` | string | unset | [Authentication](#auth) (alias of `password`) |
| `password` | string | unset | [Authentication](#auth) |
| `poison_min_escalation_window_millis` | int (ms) | `5000` | [Error handling](#error-handling) |
Expand Down
1 change: 1 addition & 0 deletions documentation/connect/clients/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,7 @@ Common WebSocket-specific options:
| `sf_dir` | unset | Store-and-forward directory. |
| `sender_id` | `default` | Sender directory name for SF. |
| `request_durable_ack` | `off` | Durable acknowledgement tier: `off`, `local`, `replicated`, `local,replicated`, or `on` (the original name of `replicated`). |
| `owned_by` | unset | Owner of the tables and columns the sender auto-creates (QuestDB Enterprise 4.2.2 or later, client 1.3.13 or later); an external user must name one of its groups. Builder: `ownedBy(...)`. See [Owner of auto-created tables](/docs/connect/clients/connect-string/#owned-by). |
| `reconnect_max_duration_millis` | `300000` | Sync initial-connect budget only. |
| `failover` | `on` | Egress per-query reconnect switch. |
| `compression` | `raw` | Egress batch compression (`raw`, `zstd`, `auto`). |
Expand Down
52 changes: 52 additions & 0 deletions documentation/connect/wire-protocols/qwp-ingress-websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ using custom headers.
| `X-QWP-Max-Version` | No | Maximum QWP version the client supports (positive integer). Defaults to 1 if absent. |
| `X-QWP-Client-Id` | No | Free-form client identifier (e.g., `java/1.0.2`, `zig/0.1.0`). |
| `X-QWP-Request-Durable-Ack` | No | Durable-ack tiers to request: `local`, `replicated`, `local,replicated`, or `true` (the original value, same as `replicated`). See [Durable acknowledgement](#durable-acknowledgement). |
| `X-QWP-Owned-By` | No | Owner of the tables and columns that the server auto-creates for the connection, as percent-encoded UTF-8. QuestDB Enterprise only. See [Owner of auto-created tables](#owner-of-auto-created-tables). |

**Server response headers:**

Expand All @@ -115,6 +116,7 @@ using custom headers.
| `X-QWP-Version` | The QWP version selected for this connection. |
| `X-QWP-Max-Batch-Size` | Server's effective per-message payload cap in bytes, computed as `min(http.recv.buffer.size − 14, 16 MiB)` (the protocol ceiling clamped by the actual WebSocket recv buffer minus the worst-case frame header). Clients should size batches to stay under this value. Absent on servers older than the introduction of this header — clients fall back to their locally configured byte budget. |
| `X-QWP-Durable-Ack` | The granted durable-ack tiers: `local`, `replicated`, or `local,replicated`, or `enabled` for a `true` request. Sent only when the client opted in via `X-QWP-Request-Durable-Ack` *and* the server can grant every requested tier. Absent in every other case. |
| `X-QWP-Owned-By` | The accepted owner, in the canonical encoding described in [Owner of auto-created tables](#owner-of-auto-created-tables). Sent only when the client named an owner. |

The server selects the version as `min(clientMax, serverMax)`. The selected
version is never higher than either side's maximum. The server may also
Expand Down Expand Up @@ -157,6 +159,51 @@ one on its next connect, such as a reconnect or a failover. The Java client
client 6.1.0 or later can request and renew tokens with a token provider for
this; see [Rotating bearer tokens](/docs/security/oidc/#rotating-bearer-tokens).

### Owner of auto-created tables

The server creates a table or a column that a batch names and that does not
exist yet, and grants the creator every permission on it, as
[`OWNED BY`](/docs/query/sql/create-table/#owned-by) does in SQL. The
`X-QWP-Owned-By` request header names a user, group, or service account to
receive these permissions instead, for every table and column the connection
auto-creates. It carries the
[`owned_by`](/docs/connect/clients/connect-string/#owned-by) connect-string
key, and needs QuestDB Enterprise 4.2.2 or later.

- **Encoding.** The value is the name as UTF-8, percent-encoded as in
[RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-2.1): the
unreserved characters `A`–`Z`, `a`–`z`, `0`–`9`, `-`, `.`, `_`, and `~`
stay as they are, and every other byte becomes `%XX`, with upper-case hex
digits. `+` stands for itself, not for a space. A browser, which cannot set
the header, can send the name in the `qwp_owned_by` URL parameter instead,
URL-encoded like any query parameter, as `encodeURIComponent()` does. The
server reads the parameter only when the header is absent.
- **Confirmation.** The server checks the owner before it completes the
upgrade, by the rules of `OWNED BY`: a principal may name itself or one of
its groups, and the built-in admin any existing entity. The `101` response
echoes an accepted owner in `X-QWP-Owned-By`, in the encoding above. A
client that named an owner must fail the connection when the echo is absent
or names another owner: a server that predates the header ignores it, and
the tables it creates would not get the owner. This holds even when another
host of the same endpoint walk answered `421`: the host that answered `101`
accepts writes, so the walk did find a primary, one that cannot set the
owner, and reports that rather than a missing primary.
- **Refusal.** A malformed value gets `400 Bad Request`. An owner that the
principal may not name gets `403 Forbidden`, and so does any owner when the
server cannot set one, because it is QuestDB open source or Enterprise with
access control disabled. Like a failed authentication, the refusal holds on
every host, so it ends the endpoint walk. Both responses carry the reason
as a `text/plain` body.
- **Each auto-create.** The server checks the owner again before it creates
each table or column. The batch fails with `SECURITY_ERROR`, and nothing is
created, when the principal may no longer name the owner, or when the
principal is an [external user](/docs/security/oidc/#user-permissions) and
the connection named no owner: an external user cannot hold permissions
itself. A table or column that another connection creates at the same
moment needs no owner from this one, so the write lands in it. While the
other connection still holds the name of a table it is creating, the server
refuses the batch with `WRITE_ERROR`, which a client retries.

## Client lifecycle

The end-to-end shape of a QWP client session, before the encoding details:
Expand All @@ -169,6 +216,9 @@ The end-to-end shape of a QWP client session, before the encoding details:
- Authentication header (`Authorization: Basic …` or `Authorization: Bearer …`).
- `X-QWP-Request-Durable-Ack: <tiers>` — optional, opt-in for durable
acks: `local`, `replicated`, `local,replicated`, or `true`.
- `X-QWP-Owned-By: <owner>` — optional, the percent-encoded owner of the
tables and columns that the server auto-creates for the connection
(Enterprise). See [Owner of auto-created tables](#owner-of-auto-created-tables).
2. **Verify the upgrade.** On `101 Switching Protocols`, read the response
headers:
- `X-QWP-Version` — the version the connection runs on. Use it for the
Expand All @@ -178,6 +228,8 @@ The end-to-end shape of a QWP client session, before the encoding details:
you opted in. It must name exactly the requested tiers (`enabled` for
`true`). If you opted in and this header is absent or different, fail the
connection (don't silently wait for acks the server will never send).
- `X-QWP-Owned-By` — confirms the owner, only if you named one. If it is
absent or names another owner, fail the connection.
- `X-QWP-Max-Batch-Size` (optional, older servers omit it) — server's
effective per-message payload cap in bytes. Clients should clamp their
batch-size triggers to fit under this value (a safety margin of ~10%
Expand Down
11 changes: 8 additions & 3 deletions documentation/security/oidc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2046,9 +2046,14 @@ GRANT HTTP TO fxIngest;
GRANT INSERT ON fx_trades TO fxIngest;
```

Ingestion cannot create a table or add a column for an external user, so
create the table, with every column that the service writes, in advance, as a
database user such as the built-in admin:
An external user cannot hold permissions itself, so ingestion creates a table
or adds a column for it only when the connection names a group to own them
with [`owned_by`](/docs/connect/clients/connect-string/#owned-by), such as
`owned_by=fxIngest`. This needs QuestDB Enterprise 4.2.2 or later and the Java
client 1.3.13 or later, and the service needs `CREATE TABLE`, or `ADD COLUMN`
on the table, through its groups. Otherwise, create the table, with every
column that the service writes, in advance, as a database user such as the
built-in admin:

```questdb-sql title="Create the table that the service ingests into"
CREATE TABLE fx_trades (
Expand Down
Loading