Skip to content

feat(qwp): add owned_by to name the owner of the tables a sender auto-creates - #130

Open
glasstiger wants to merge 8 commits into
mainfrom
ia_qwp_owned_by
Open

glasstiger wants to merge 8 commits into
mainfrom
ia_qwp_owned_by

Conversation

@glasstiger

@glasstiger glasstiger commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Companion to questdb/questdb#8504 and questdb/questdb-enterprise#1572; docs in questdb/documentation#652. Matching branch ia_qwp_owned_by.

Problem

QWP ingestion auto-creates the tables and columns a sender writes, and QuestDB Enterprise grants the creator the owner permissions on them. An external user, one authenticated with an OIDC token such as an Entra ID managed identity, cannot hold permissions, so it could not auto-create anything over QWP. SQL solves this with OWNED BY; QWP had no equivalent.

Changes

  • owned_by=<name> connect-string key (an ingress key in ConfigSchema) and LineSenderBuilder.ownedBy(String). ws/wss only: http, tcp and udp connect strings and builders reject it. The QwpQueryClient accepts it as a no-op, like the other ingress keys.
  • The sender sends it as X-QWP-Owned-By on every upgrade, reconnects, failovers and background drainers included. The value is percent-encoded UTF-8 (RFC 3986 unreserved characters as they are, upper-case hex digits), so names outside ASCII survive.
  • The upgrade fails unless the server echoes the owner: a server that predates the header ignores it, and the tables it creates would not get the owner. The failure is a QwpOwnedByMismatchException, a non-421 WebSocketUpgradeException that the connect walk treats as terminal, also when another endpoint of the round answered 421: like a missing durable-ack echo, it comes from a writable endpoint that lacks the capability, so the round reports it instead of a missing primary. It carries no HTTP status (STATUS_NONE), as the server answered 101, so connection health reports none, as for a missing durable-ack echo.
  • A connect round that meets a capability gap, a missing owned_by or durable-ack echo, after a plain non-421 upgrade failure such as a proxy's 503, now reports the gap when another endpoint answered 421, as it does in any other order. It reported a missing primary before. Fixes Durable-ack mismatch reported as a missing primary in mixed connect rounds #131.
  • A rejected upgrade now carries the plain-text body of the response as its reason, when it arrived with the headers: length-capped, sanitized with CredentialRedaction, appended to the WebSocketUpgradeException message and exposed as QwpAuthFailedException.getReason(). A refused owner (403) reads auth-rejected: ... [reason=owned_by refused: bob is not part of group team] instead of looking like a rejected credential.
  • New master QwpWebSocketSender.connectWithCredentialSupplier(...) overload with ownedBy; the previous master delegates to it with null.

Tests

  • QwpOwnedByTest: the header and its canonical encoding, including the ends of the unreserved ranges, the echo accepted, missing and mismatched, the header sent again on a reconnect, the reject reason with and without a body, its absence when the body is unusable (a Content-Length beyond the bytes received, malformed or not positive, another content type, a blank body), its sanitizing and length cap, both sender build paths (connect string and builder), a 403 refusal surfacing as QwpAuthFailedException with its reason, connect rounds that also meet a replica's 421 reporting the missing echo, also behind a 503, and the 403 refusal rather than a missing primary, and connection health on a missing echo.
  • BackgroundDrainerEndToEndTest: an orphan drainer's upgrade names the owner too.
  • WriteFailoverTest: a 503, a primary without durable ack and a replica, walked in that order, report the durable-ack mismatch.
  • LineSenderBuilderWebSocketTest, WsSenderConfigHonoredTest and QwpQueryClientFromConfigTest: parsing, validation and the key-registry drift guard.
  • The server side is covered end to end in the OSS and Enterprise PRs.

… auto-creates

The owned_by connect-string key, and LineSenderBuilder.ownedBy(), name the user,
group or service account that QuestDB Enterprise grants the owner permissions on
every table and column the sender auto-creates, as OWNED BY does in SQL. An
external (OIDC) user cannot hold those permissions itself, so it must name one of
its groups to auto-create anything.

- The sender sends the owner as X-QWP-Owned-By, percent-encoded UTF-8, on every
  upgrade, reconnects and failovers included. WebSocket only: http, tcp and udp
  connect strings and builders reject it.
- The upgrade fails unless the server echoes the owner, so a server that
  predates the header fails the connection instead of creating tables without
  the owner. The failure is a non-421 WebSocketUpgradeException, which the
  connect walk treats as terminal.
- A rejected upgrade now carries the plain-text body of the response as its
  reason, sanitized and length-capped, in WebSocketUpgradeException and in
  QwpAuthFailedException (getReason()), so a refused owner is told apart from a
  rejected credential.
The owned_by helpers were inserted between pollDurableAckRequest() and
its javadoc, which then documented pollOwnedByRequest() instead. Move
the javadoc back, give the new helpers their own, and attach an older
javadoc that sat loose above them to setSuppressDurableAckHeader(),
the method it describes.
WebSocketClient.upgrade() throws WebSocketUpgradeException with status
101 when the server completes the upgrade without echoing the owned_by
the client asked for, but the class javadoc still said the exception
means a non-101 status. The javadoc now names that case.
Tests now pin the parts of owned_by and of the upgrade reject reason
that nothing checked before:

- A reconnect and an orphan drainer's upgrade send X-QWP-Owned-By
  again, not only the first connect (QwpOwnedByTest,
  BackgroundDrainerEndToEndTest).
- The reject reason stays null when the Content-Length exceeds the
  bytes received, is malformed or not positive, the body is not
  text/plain, or it is blank, and it reaches messages only sanitized
  and capped at 256 characters. TestWebSocketServer can now send
  reject headers that do not describe the body.
- encodeOwnedBy keeps the ends of the unreserved ranges and encodes
  the characters just outside them, as the server's re-encoded echo
  must match it byte for byte.

The owned_by echo failure now carries STATUS_NONE instead of 101: the
server answered 101 and rejected nothing, so Sender.health() reports
status 0 for it, as it does for the durable-ack gap and as
ConnectionHealth documents.

The ownedBy() javadoc no longer says the built-in admin may name any
entity: Enterprise refuses an external user as the owner, the admin's
choice included.
WebSocketClient's comment on the owned_by echo check said that the
connect walk latches a missing echo as terminal. That holds for the
initial connect and for an orphan drainer, but a sender that has
connected before keeps retrying the error, as
QwpOwnedByTest.testHealthReportsUnconfirmedOwnedByWithoutStatus
asserts. The comment now says so, and so does the test helper that
repeated it.

TestWebSocketServer's suppressOwnedByEcho flag becomes
isOwnedByEchoSuppressed, set with setOwnedByEchoSuppressed(), as the
project names booleans with an is or has prefix.
A connect round that met a 421 role reject on one endpoint demoted a
101 without the owned_by echo from another endpoint to a role
mismatch, as it demotes every plain non-421 upgrade error. build()
then reported a missing primary, an async sender retried forever while
its health said every endpoint was a replica, and the real cause
survived only as a suppressed exception.

The missing or mismatched echo now throws QwpOwnedByMismatchException,
a WebSocketUpgradeException that the round epilogue does not demote:
like a missing durable-ack echo, it comes from a writable endpoint
that lacks the capability. A sender fails its initial connect with it
and an orphan drainer quarantines its slot, as they already did with a
single endpoint, and a sender that has connected before keeps
retrying it.

QwpOwnedByTest covers both mixed rounds: a 101 without the echo, and a
403 refusal, which surfaces with its reason.
@glasstiger

Copy link
Copy Markdown
Contributor Author

Review: questdb-enterprise#1572 + questdb/questdb#8504 (+ #130)

Tandem review at level 3 of questdb-enterprise 187bdb097, questdb c5f7ed703 and java-questdb-client 017caf5.

Verdict: approve for #1572, #8504 and #130. There are no Critical or Moderate findings, and the one Minor test-hygiene item has since been fixed.

Critical

None.

Moderate

None.

Minor (fixed)

[OSS] core/src/test/java/io/questdb/test/cutlass/websocket/QwpIngressUpgradeProcessorOnHeadersReadyTest.java:521

  • Problem: The assertNull(securityContext.owner) check could never fail.
  • Net impact: None for users; it was a dead check in a new test.
  • Evidence: Static, at c5f7ed703. testOnHeadersReadyFailsHardWhenRefusedOwnedByResponseDoesNotFitBuffer builds OwnerRecordingSecurityContext("bob is not part of group team"), whose setAutoCreateOwner throws before it assigns owner (lines 1552–1555). So owner stayed null whatever negotiateOwnedBy did. The rest of the test still checks the 403 overflow, that nothing is sent and that no state is allocated.

Fixed in questdb 98cd2ed5fc, which questdb-enterprise picks up in 898a0ab5c.

Coverage

The test gate passes, with no coverage gaps that block or need a fix.

The two testOwnedBySurvivesRoleRoundTrip tests (ACL and OIDC) were run at the reviewed revision. In each, one upgrade names the owner, the same connection survives the switch to REPLICA and back, and only then auto-creates the second table and the new column, both granted to the named group. So the tests exercise DispatchingSecurityContext naming the owner again on the re-resolved delegate, not a reconnect.

Summary

  • Correctness gate: passes; there is no Critical finding.
  • Severity: 0 Critical, 0 Moderate, 1 Minor (in-diff, fixed).
  • Every callsite of the changed symbols was checked across questdb-enterprise, questdb and the client. That covered SQL and ILP DDL owner resolution, in-place role switches with live QWP connections, concurrent CREATE and ALTER, and the client's store-and-forward reconnect and orphan-drainer paths.
  • Submodule provenance:
  • Titles and descriptions follow Conventional Commits and describe user impact.

Intended behaviour change, worth a release note: an external (OIDC) principal that names no owner is now refused (SECURITY_ERROR) before any QWP auto-create, including adding a new column to an existing table. The PR body states this, and testAutoCreateRefusedWithoutOwnedBy pins it. OIDC producers that rely on column auto-creation will need client 1.3.13 and owned_by after the server upgrade.

An orphan drainer quarantined its slot on the first connect round in
which a writable endpoint answered 101 without the X-QWP-Owned-By echo.
Such an endpoint lacks the feature, as one without durable ack lacks
that, and a rolling upgrade or a failover back to an upgraded node
clears it. Yet the drainer took the missing echo for a rejected upgrade
and set the slot's rows aside behind a .failed sentinel that nothing in
production clears, where a missing durable-ack echo gets a settle
budget of 16 sweeps for exactly this reason.

BackgroundDrainer now counts QwpOwnedByMismatchException toward the
same capability-gap episode as QwpDurableAckMismatchException, and
quarantines the slot only once that budget runs out, with a reason that
names owned_by. Mid-drain, CursorWebSocketSendLoop hands the exception
back to the drainer as a capability-gap terminal rather than a final
one, so the drainer re-enters the budget. The durable-ack listener
callbacks keep reporting durable ack only. A sender that has connected
before keeps retrying, and the initial connect still fails at once.

Tests cover the ride-out, the escalation and the shared budget at the
initial connect, the same mid-drain, and the sender's own connect walk
against a server that leaves the echo out for two sweeps.
@glasstiger

Copy link
Copy Markdown
Contributor Author

Review: questdb/questdb-enterprise#1572 + questdb/questdb#8504 + #130

Tandem review at level 3 of questdb-enterprise 898a0ab5c, questdb 7dc4950814 (the head of questdb/questdb#8504; the enterprise branch still pins 98cd2ed5fc) and java-questdb-client 033d87af.

Verdict: approve for questdb/questdb-enterprise#1572, questdb/questdb#8504 and #130. There are no Critical or Moderate findings. The one Minor item has since been fixed.

Critical

None.

Moderate

None.

Minor (fixed)

[ENT] questdb-ent/src/test/java/com/questdb/security/DispatchingSecurityContextCoverageTest.java:176

  • Problem: The test comment called the owner delegate state, "like OWNED BY".
  • Net impact: None for users. It could mislead maintainers about what happens to the owner in a role switch.
  • Evidence: Static, at 898a0ab5c. DispatchingSecurityContext.java:103-104 and the class javadoc at :31-34 say the opposite: the proxy holds the owner itself, unlike OWNED BY, so that it survives a role switch.

Fixed in questdb-enterprise 45496e263.

Coverage

The test gate passes, with no coverage gaps.

The enterprise owner suites pass at questdb-enterprise 898a0ab5c with questdb 7dc4950814 and client 033d87af. That is 105 tests across QwpWebSocketOidcTest, QwpWebSocketAclTest, AdminSecurityContextTest, ReplicaAdminSecurityContextTest, EntSecurityContextBaseTest, DispatchingSecurityContextProxyTest and DispatchingSecurityContextCoverageTest.

In that run, the OIDC concurrent-create test took the retriable "table is being created" branch. QwpTudCacheAutoCreateOwnerTest also covers that branch deterministically.

Summary

  • Correctness gate: passes. Test gate: passes.
  • Severity: 0 Critical, 0 Moderate, 1 Minor (in-diff, fixed).
  • Every callsite of the changed symbols was checked across questdb-enterprise, questdb and the client. That covered:
    • owner resolution in EntDdlListener for SQL, ILP, CSV import and mat-view DDL;
    • every SecurityContext implementation;
    • the client's store-and-forward reconnect and orphan-drainer paths;
    • the order of the in-place role switch against the 421 gate.
  • Submodule provenance:
  • CI: the latest questdb run has one red job, WalWriterFuzzTest.testConvertPartitionToParquet on linux-arm64 ("ascii flag set to 'true' for non-ASCII value"). It is a known flaky failure, tracked in WalWriterFuzzTest.testConvertPartitionToParquet reads a non-ASCII VARCHAR value flagged as ASCII questdb#8353. That issue was opened on 2026-11-12, before this branch's first commit, for the same assertion on another PR. This change does not touch the Parquet VARCHAR path it fails in. Enterprise CI is green.
  • Titles and descriptions follow Conventional Commits and describe user impact.

Intended behaviour changes, worth a release note:

  • An external (OIDC) user with no owned_by is now refused (SECURITY_ERROR) before any QWP auto-create, including a new column on an existing table. Such producers need client 1.3.13 and owned_by.
  • A sender configured with owned_by fails to connect to a server that predates the feature, by design.

A connect round latches its first non-421 upgrade failure, and a 421
from another endpoint demotes a plain one, such as a proxy's 503, to
a role mismatch. When that plain failure came before an endpoint that
answered 101 without the durable ack or the owned_by echo the sender
asked for, the demotion hid the capability gap as well. The initial
connect then reported "no endpoint matches target=PRIMARY", a SYNC
connect retried it for its whole reconnect budget, and an ASYNC one
never failed, while the same endpoints in another order reported the
gap.

connectWalk now keeps the round's first capability gap apart from the
latch and throws it when the 421 demotes the latched error, which it
attaches as suppressed. A round without a 421 behaves as before.

QwpOwnedByTest and WriteFailoverTest walk a 503, a primary without
the echo and a replica, in that order.

Fixes #131
@mtopolnik

Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 129 / 130 (99.23%)

file detail

path covered line new line coverage
🔵 io/questdb/client/Sender.java 16 17 94.12%
🔵 io/questdb/client/cutlass/qwp/client/sf/cursor/BackgroundDrainer.java 40 40 100.00%
🔵 io/questdb/client/cutlass/http/client/WebSocketClient.java 44 44 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpAuthFailedException.java 6 6 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpOwnedByMismatchException.java 3 3 100.00%
🔵 io/questdb/client/impl/ConfigSchema.java 1 1 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpWebSocketSender.java 12 12 100.00%
🔵 io/questdb/client/cutlass/qwp/client/sf/cursor/CursorWebSocketSendLoop.java 6 6 100.00%
🔵 io/questdb/client/cutlass/qwp/client/QwpUpgradeFailures.java 1 1 100.00%

@glasstiger

Copy link
Copy Markdown
Contributor Author

Review: questdb/questdb-enterprise#1572 + questdb/questdb#8504 + #130

Tandem review at level 3 of questdb-enterprise 84bb775c8 (base dbf3d0497), questdb 6b81fb48bc (base b4e3c1167c) and java-questdb-client 9e9ab4fb (base 0f6c100c).

Verdict: approve for questdb/questdb-enterprise#1572, questdb/questdb#8504 and #130. There are no Critical, Moderate or Minor findings.

Critical

None.

Moderate

None.

Minor

None.

Coverage

The test gate passes, with no coverage gaps that block or need a fix.

Summary

  • Correctness gate: passes. Test gate: passes.
  • Severity: 0 Critical, 0 Moderate, 0 Minor.
  • Submodule provenance:
  • Every caller of the changed code was checked across questdb-enterprise, questdb and the client. That covered:
    • owner resolution in EntDdlListener for SQL, ILP, CSV import, views and mat views, which is unchanged when no owner is named;
    • every security context class, including DispatchingSecurityContext across role switches and the shared anonymous contexts. The HTTP security context is built per request, so the owner cannot leak to other requests or connections;
    • the order of the 421 role check and the owner check, and that the read-only marker survives both new refusal points;
    • table and column auto-create over QWP WebSocket and UDP, including the commit-batch path and the rename cases;
    • the client's reconnect after the initial connect, which retries owner failures with no time limit, the orphan drainers' settle budget and the mixed-round error reporting.
  • Titles and descriptions follow Conventional Commits and describe user impact.
  • CI: questdb and java-questdb-client are green. questdb-enterprise has two jobs still running; its "check oss is mergeable" job fails only because the submodule points at the open feat(qwp): let QWP senders choose the owner of the tables and columns they auto-create questdb#8504 branch.

Behaviour changes worth a release note:

  • An external (OIDC) user without owned_by now gets a final SECURITY_ERROR before any QWP auto-create, including a new column on an existing table. Before, such a column was created but got no owner. These producers need client 1.3.13 and owned_by. The PR documents this.
  • A sender configured with owned_by fails its initial connect against a server that predates the feature, by design.
  • QWP over UDP: a datagram that adds a column to a table renamed while the receiver held it in its table cache is now dropped. Before, it landed in the renamed table. The receiver recovers at its next commit pass, within qwp.udp.commit.interval (2 s by default), and the next datagram then creates the table again under the old name. Confirmed with a throwaway UDP test run at questdb head and base.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Durable-ack mismatch reported as a missing primary in mixed connect rounds

2 participants