Skip to main content

Query the Organization's QueryMesh

If the Organization has QueryMesh configured, the application can use this same identity to query it. The query goes on behalf of the person who signed in. The organization's data policies, such as access, masks and filters defined by governance, decide what they see. Two people, the same query, different results:

const r = await nn.querymesh.query(req, 'SELECT name, regionkey FROM tpch.tiny.nation')
// r.columns, r.rows — only what THIS person's policies let them see

The platform runs the query, with the person's identity. The application does not provide the QueryMesh address, does not receive a token and filters no rows.

Before You Start​

  • Organization IAM turned on and deployed on the service.
  • The organization's QueryMesh configured in Zero. The organization administrator does this once, with the address of that organization's QueryMesh.
  • The organization's IAM with the zero-querymesh client scope, default on Zero's sign-in client. QueryMesh requires the trino-oidc audience in the token, and this scope adds it. Zero's provisioning in the organization guarantees it; there is no manual step in the IAM. Until then, people sign in normally, and the query says what is missing.
  • The querymesh capability turned on in the application. It is optional and takes effect immediately, without deploying.
  • In the console, the application's QueryMesh appears as Infinite Data access, under Login and data: on the web service card or under the project's Settings → Login and data. The organization's QueryMesh address is under Settings → Integrations → QueryMesh, at the organization level, and can also be set with the CLI or the API.
  • The service ID (svc_…) at hand: the commands take the ID, not the name — a name answers "not found" (exit code 6).

Step by Step​

  1. The organization administrator configures its QueryMesh, once. In the console: Settings → Integrations → QueryMesh → Configure. With the CLI:

    zero orgs integrations set querymesh --url https://<address of the organization's QueryMesh>

    Each organization has its own QueryMesh, at its own address. The address must be HTTPS and public. --disabled keeps the address with the integration turned off.

  2. Turn QueryMesh on in the application that will query. It requires Organization IAM on in it, and takes effect immediately, without deploying:

    zero services enable querymesh svc_…

    The answer starts with QueryMesh: habilitado (QueryMesh: on) and shows the address of the organization's QueryMesh, or says what is missing.

  3. Check it end to end:

    zero services doctor querymesh svc_…
    Check (as shown)Who fixes it
    A aplicação está com o IAM da organização ligado (the application has Organization IAM on)the application
    A publicação no ar já passa o login pela borda (the deployment in service already passes sign-in through the edge)the application
    A organização tem o QueryMesh configurado e ligado (the organization has QueryMesh configured and on)the organization administrator
    O broker de identidade está disponível (the identity broker is available)the platform
    A aplicação está com o QueryMesh ligado (the application has QueryMesh on)the application
  4. In your code, query with nn.querymesh.query(req, sql).

To stop in one application, use zero services disable querymesh svc_… (in the console, Infinite Data access → Turn off), which answers QueryMesh: desligado (QueryMesh: off): its next query is refused, and sign-in continues. To stop across the organization, the administrator turns the integration off (--disabled) or removes it (zero orgs integrations remove querymesh). With QueryMesh on, the application cannot turn Organization IAM off: turn QueryMesh off first.

In Your Code​

import { NNumbers, QueryMeshAccessDeniedError, UnauthenticatedError } from '@nnumbers/zero/app'

const nn = NNumbers.init()

app.get('/api/countries', async (req, res) => {
try {
const r = await nn.querymesh.query(req, 'SELECT name, regionkey FROM tpch.tiny.nation ORDER BY name')
res.json({ columns: r.columns, rows: r.rows })
} catch (e) {
if (e instanceof UnauthenticatedError) return res.redirect(e.loginPath)
if (e instanceof QueryMeshAccessDeniedError) return res.status(403).json({ code: e.code })
throw e
}
})

query(req, sql, { maxRows, signal }) returns { columns, rows }, with the name and type of each column. Use full names (catalog.schema.table).

  • maxRows (1 to 100,000; default 100,000) caps the rows. Above it, the platform cancels the query in QueryMesh.
  • signal cancels the request.
ErrorCodeStatusWhen
UnauthenticatedErrorUSER_SESSION_REQUIRED401nobody signed in, or the session ended — send them to loginPath
QueryMeshNotConfiguredErrorORGANIZATION_INTEGRATION_NOT_CONFIGURED409the organization has no QueryMesh configured, or it is off
QueryMeshNotEnabledErrorQUERYMESH_NOT_ENABLED409this application did not turn QueryMesh on: zero services enable querymesh svc_…
QueryMeshIdentityRejectedErrorQUERYMESH_IDENTITY_REJECTED502QueryMesh did not accept the person's identity (issuer, audience or scope). If the organization's realm does not have the default zero-querymesh scope yet, the message says so: Zero's provisioning of the realm fixes it, and signing in again does not help. Otherwise, it is a configuration of the organization's QueryMesh
QueryMeshAccessDeniedErrorQUERYMESH_ACCESS_DENIED403the data policies denied the query to this person
QueryMeshErrorQUERYMESH_UNAVAILABLE503QueryMesh did not answer or is busy; retryable says trying again may work
QueryMeshErrorQUERYMESH_QUERY_FAILED422 or 502syntax, missing table, maxRows exceeded (422); a QueryMesh answer outside the protocol (502)

In Another Language​

The application asks for the query at the address in NNUMBERS_BROKER_URL, with the identity it received on the request:

POST {NNUMBERS_BROKER_URL}/v1/querymesh/query
X-NNumbers-Identity: <the request's identity>
Content-Type: application/json

{"sql": "SELECT name, regionkey FROM tpch.tiny.nation", "max_rows": 1000}

The response is {"columns": [{"name": …, "type": …}], "rows": [[…]]}. Refusals come as JSON {"code", "message"}, with the codes and statuses in the table above. A 400 with VALIDATION_FAILED means a request without SQL, or with max_rows outside 1 to 100,000. Check the identity first, as in Who Signed In, in Your Code: with no person, do not ask. The runtime protocol has the identity check, the reserved paths and the status of each refusal.

The States​

State (as shown)What it meansWhat to do
Desligada (off)the capability is not on—
Falta configurar na organização (missing organization setup)the organization has no QueryMesh configured, or it is offthe organization administrator: zero orgs integrations set querymesh --url https://…
Espera o login da organização (waiting for organization sign-in)QueryMesh queries on behalf of who signed in, and Organization IAM is not live yetturn on and deploy Organization IAM
Pronta (ready)the query goes out on behalf of who signed in—

What the Platform Guarantees​

  • The query is the person's. The platform queries with the identity of who signed in, issued by the organization's IAM. With no person there is no query, because there is no "application" access to fall back to.
  • The address is the organization's. It comes from the administrator's configuration, and the identity only goes there, over HTTPS. If QueryMesh says to continue at another address, the query fails and the identity does not follow.
  • The application never sees the token. It receives columns and rows.
  • Turning off cuts the next query. With the capability off in the application, or the integration off or removed in the organization, the next query is refused, and sign-in continues.
  • Everyone in their place. Another application, another organization or an ended session cannot query.

The Session Token​

  • The browser never sees the access token, and neither does the application server. The platform runs the QueryMesh query, with the person's session token as Bearer. The application receives columns and rows.
  • The token lives as long as the organization's IAM sets for the access token: the realm's Access Token Lifespan. The Keycloak default is 5 minutes, and a realm can set more — some realms use 1 hour. The platform renews it while the session lives: 30 minutes without use, 12 hours in total.
  • The sign-in token is valid for both: the Zero API and the organization's QueryMesh, in every application and in the console. The audience alone turns nothing on: without the organization's integration and the application's capability, there is no query. If it leaks, whoever holds it can present it directly to QueryMesh, as the person, until it expires. That is why it never leaves the platform.
  • A compromised application server can request queries on behalf of whoever has an active session, while it lives. It does not obtain the token.
  • Turning off does not revoke what was already issued. Turning off the capability, the integration or Organization IAM cuts the next queries and sessions. Tokens already issued are not revoked in the IAM: they stay in the platform, unused, and expire on their own, at the end of the realm's access token lifetime.

Limits​

  • nn.querymesh is in the TypeScript, Python and Java SDKs; in another language, use the call above.
  • A query brings up to 100,000 rows and 32 MiB, and lasts up to 2 minutes.
  • The organization's QueryMesh must accept the identity the platform presents. If it refuses (QUERYMESH_IDENTITY_REJECTED), the administrator of the organization's QueryMesh adjusts it — except when the message says the realm lacks the zero-querymesh scope, which belongs to Zero's provisioning.
  • One integration per organization: QueryMesh.
  • Only whoever administers the organization sets the QueryMesh address: in the console, with the CLI or with the API. Other roles see the state and the address.

Next Steps​