IF Commons GitHub

sql/extensions/access/access

Written to: 5 requirements: 5 proved, 0 partly, 0 failing, 0 with no test recorded. 0009-sql-features FR-008, 0009-sql-features FR-009, 0009-sql-features FR-010, 0009-sql-features FR-019, 0009-sql-features FR-020

Access (commons data 0009-sql-features FR-008 to FR-010): what governance says of who may see what becomes what the engine enforces. A column that carries security.scope makes its table's rows visible only where the column equals the setting of the scope; a concept that carries security.access grants its read roles SELECT and its write roles INSERT, UPDATE and DELETE, and, where the table is scoped, gives each of them a policy for what they may do. A dialect without the feature gets nothing, and the annotation stays in the governance tables.

The policy reads current_setting('<prefix>.<scope>', true) and compares it with the column as text, which is PostgreSQL's way; no other dialect has row-security yet.

Source: commons/data/sql/extensions/access/access.ts

4 of 6 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

accessSourcefunction
function accessSource(settings?: AccessSettings): StatementSource

The source of row-level security and grants.

ParameterWhat it is
settingswhat a project says of access

Returns: a statement source

Imported by 29 tests of the run (29 passed, 0 failed): the library's results

governedTablesconstno test imports it
const governedTables: (tables: readonly Table[]) => readonly Table[]

The tables of a schema that carry a scope or an access, which an access source acts on.

grantOffunction
function grantOf(values: "*" | readonly string[]): string

What a scope of a set reaches: the tenants, or every one (*). A value with a comma in it cannot be listed, since the comma is what separates them.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

scopeStatementconst
const scopeStatement: (key: string, name: string, value: string, prefix?: string, local?: boolean) => string

The statement that sets a sealed scope for the transaction (or, where local is false, the session) that runs it.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

sealedScopeconst
const sealedScope: (key: string, name: string, value: string) => string

The value to give a sealed scope setting: the value and its mark, made by the issuer that holds the key.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

AccessSettingsinterfaceno test imports it
interface AccessSettings

What a project says of access; what is not said is the default.

MemberTypeWhat it is
unsupported?"carry" | "error"What to do where the dialect lacks the feature: carry writes nothing and leaves the annotation to the governance tables (the default), error returns an error value.
settingPrefix?stringThe prefix of the settings a policy reads; app by default.
viewsSchema?stringSet where the tables are wrapped by views (0014-sql-protected-access): the rights are then the views' to grant, so none is granted here, and a table with a scope has one policy that names no role, forced on its owner.
seal?{ readonly key: string; readonly unlock?: string | undefined; }Seals the scope (0009-sql-features FR-019, PostgreSQL): a policy trusts the setting of a scope only where it carries the mark that only a holder of key can make, so that a session of the application, or a statement injected into it, cannot set the scope to another tenant's. The key is kept in a table that no role but the deployer's can read; the issuer of the scope (the service that has authenticated the caller) makes the mark with sealedScope. Row security is forced on the tables' owners and a guard refuses to disable it, or drop a policy or a table of it unless the session holds the secret whose hash is unlock.
reach?"exact" | "set"How far a scope reaches (0009-sql-features FR-020, PostgreSQL). exact, the default, shows a row where its scope column equals the setting. set reads the setting as a list of values, separated by commas (acme,acme-eu), and shows a row where its column is one of them: a reseller reaches the tenants beneath it, a support role the few it is asked to help, and the issuer of the scope (which has authenticated the caller and knows the hierarchy) decides which. With wildcard, the value * reaches every row, for a platform operator. A reach is only as trustworthy as the scope: seal it.
wildcard?booleanWith reach: "set", whether the value * reaches every row; off by default.

Titles, headings, exports, tables, columns and requirements. Esc closes.