@reyemtech/nimbus 2.12.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cjs/aws/cloudfront.d.ts +17 -0
- package/dist/cjs/aws/cloudfront.d.ts.map +1 -0
- package/dist/cjs/aws/cloudfront.js +147 -0
- package/dist/cjs/aws/cloudfront.js.map +1 -0
- package/dist/cjs/aws/index.d.ts +1 -0
- package/dist/cjs/aws/index.d.ts.map +1 -1
- package/dist/cjs/aws/index.js +3 -1
- package/dist/cjs/aws/index.js.map +1 -1
- package/dist/cjs/cdn/index.d.ts +7 -0
- package/dist/cjs/cdn/index.d.ts.map +1 -0
- package/dist/cjs/cdn/index.js +8 -0
- package/dist/cjs/cdn/index.js.map +1 -0
- package/dist/cjs/cdn/interfaces.d.ts +43 -0
- package/dist/cjs/cdn/interfaces.d.ts.map +1 -0
- package/dist/cjs/cdn/interfaces.js +8 -0
- package/dist/cjs/cdn/interfaces.js.map +1 -0
- package/dist/cjs/cli/migrate-cnpg-ownership.d.ts +43 -0
- package/dist/cjs/cli/migrate-cnpg-ownership.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-cnpg-ownership.js +67 -0
- package/dist/cjs/cli/migrate-cnpg-ownership.js.map +1 -0
- package/dist/cjs/cli/migrate-cnpg-roles.d.ts +92 -0
- package/dist/cjs/cli/migrate-cnpg-roles.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-cnpg-roles.js +337 -0
- package/dist/cjs/cli/migrate-cnpg-roles.js.map +1 -0
- package/dist/cjs/cli/migrate-cnpg.d.ts +38 -0
- package/dist/cjs/cli/migrate-cnpg.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-cnpg.js +258 -0
- package/dist/cjs/cli/migrate-cnpg.js.map +1 -0
- package/dist/cjs/cli/migrate-exec.d.ts +45 -0
- package/dist/cjs/cli/migrate-exec.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-exec.js +104 -0
- package/dist/cjs/cli/migrate-exec.js.map +1 -0
- package/dist/cjs/cli/migrate-psql.d.ts +125 -0
- package/dist/cjs/cli/migrate-psql.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-psql.js +213 -0
- package/dist/cjs/cli/migrate-psql.js.map +1 -0
- package/dist/cjs/cli/migrate-report.d.ts +27 -0
- package/dist/cjs/cli/migrate-report.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-report.js +29 -0
- package/dist/cjs/cli/migrate-report.js.map +1 -0
- package/dist/cjs/cli/migrate-superuser.d.ts +22 -0
- package/dist/cjs/cli/migrate-superuser.d.ts.map +1 -0
- package/dist/cjs/cli/migrate-superuser.js +73 -0
- package/dist/cjs/cli/migrate-superuser.js.map +1 -0
- package/dist/cjs/cli/migrate.d.ts +37 -0
- package/dist/cjs/cli/migrate.d.ts.map +1 -0
- package/dist/cjs/cli/migrate.js +67 -0
- package/dist/cjs/cli/migrate.js.map +1 -0
- package/dist/cjs/cli.d.ts +1 -0
- package/dist/cjs/cli.d.ts.map +1 -1
- package/dist/cjs/cli.js +6 -0
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/edge/index.d.ts +8 -0
- package/dist/cjs/edge/index.d.ts.map +1 -0
- package/dist/cjs/edge/index.js +13 -0
- package/dist/cjs/edge/index.js.map +1 -0
- package/dist/cjs/edge/interfaces.d.ts +35 -0
- package/dist/cjs/edge/interfaces.d.ts.map +1 -0
- package/dist/cjs/edge/interfaces.js +8 -0
- package/dist/cjs/edge/interfaces.js.map +1 -0
- package/dist/cjs/edge/verify.d.ts +22 -0
- package/dist/cjs/edge/verify.d.ts.map +1 -0
- package/dist/cjs/edge/verify.js +105 -0
- package/dist/cjs/edge/verify.js.map +1 -0
- package/dist/cjs/factories/cdn.d.ts +15 -0
- package/dist/cjs/factories/cdn.d.ts.map +1 -0
- package/dist/cjs/factories/cdn.js +28 -0
- package/dist/cjs/factories/cdn.js.map +1 -0
- package/dist/cjs/factories/index.d.ts +1 -0
- package/dist/cjs/factories/index.d.ts.map +1 -1
- package/dist/cjs/factories/index.js +3 -1
- package/dist/cjs/factories/index.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/operator/cnpg-common.d.ts +56 -0
- package/dist/cjs/operator/cnpg-common.d.ts.map +1 -0
- package/dist/cjs/operator/cnpg-common.js +82 -0
- package/dist/cjs/operator/cnpg-common.js.map +1 -0
- package/dist/cjs/operator/cnpg-database.d.ts +66 -0
- package/dist/cjs/operator/cnpg-database.d.ts.map +1 -0
- package/dist/cjs/operator/cnpg-database.js +296 -0
- package/dist/cjs/operator/cnpg-database.js.map +1 -0
- package/dist/cjs/operator/cnpg-roles.d.ts +173 -0
- package/dist/cjs/operator/cnpg-roles.d.ts.map +1 -0
- package/dist/cjs/operator/cnpg-roles.js +225 -0
- package/dist/cjs/operator/cnpg-roles.js.map +1 -0
- package/dist/cjs/operator/cnpg.d.ts.map +1 -1
- package/dist/cjs/operator/cnpg.js +50 -162
- package/dist/cjs/operator/cnpg.js.map +1 -1
- package/dist/cjs/operator/connection-uri.d.ts +44 -0
- package/dist/cjs/operator/connection-uri.d.ts.map +1 -0
- package/dist/cjs/operator/connection-uri.js +49 -0
- package/dist/cjs/operator/connection-uri.js.map +1 -0
- package/dist/cjs/operator/credentials.d.ts +76 -0
- package/dist/cjs/operator/credentials.d.ts.map +1 -0
- package/dist/cjs/operator/credentials.js +106 -0
- package/dist/cjs/operator/credentials.js.map +1 -0
- package/dist/cjs/operator/database-options.d.ts +121 -0
- package/dist/cjs/operator/database-options.d.ts.map +1 -0
- package/dist/cjs/operator/database-options.js +131 -0
- package/dist/cjs/operator/database-options.js.map +1 -0
- package/dist/cjs/operator/grants/postgres-job.d.ts +109 -0
- package/dist/cjs/operator/grants/postgres-job.d.ts.map +1 -0
- package/dist/cjs/operator/grants/postgres-job.js +232 -0
- package/dist/cjs/operator/grants/postgres-job.js.map +1 -0
- package/dist/cjs/operator/grants/postgres-sql.d.ts +130 -0
- package/dist/cjs/operator/grants/postgres-sql.d.ts.map +1 -0
- package/dist/cjs/operator/grants/postgres-sql.js +305 -0
- package/dist/cjs/operator/grants/postgres-sql.js.map +1 -0
- package/dist/cjs/operator/grants/privileges.d.ts +24 -0
- package/dist/cjs/operator/grants/privileges.d.ts.map +1 -0
- package/dist/cjs/operator/grants/privileges.js +35 -0
- package/dist/cjs/operator/grants/privileges.js.map +1 -0
- package/dist/cjs/operator/grants/role-config.d.ts +80 -0
- package/dist/cjs/operator/grants/role-config.d.ts.map +1 -0
- package/dist/cjs/operator/grants/role-config.js +134 -0
- package/dist/cjs/operator/grants/role-config.js.map +1 -0
- package/dist/cjs/operator/index.d.ts +1 -1
- package/dist/cjs/operator/index.d.ts.map +1 -1
- package/dist/cjs/operator/index.js.map +1 -1
- package/dist/cjs/operator/interfaces.d.ts +223 -1
- package/dist/cjs/operator/interfaces.d.ts.map +1 -1
- package/dist/cjs/operator/interfaces.js.map +1 -1
- package/dist/cjs/operator/mariadb-common.d.ts +99 -0
- package/dist/cjs/operator/mariadb-common.d.ts.map +1 -0
- package/dist/cjs/operator/mariadb-common.js +141 -0
- package/dist/cjs/operator/mariadb-common.js.map +1 -0
- package/dist/cjs/operator/mariadb-database.d.ts +65 -0
- package/dist/cjs/operator/mariadb-database.d.ts.map +1 -0
- package/dist/cjs/operator/mariadb-database.js +285 -0
- package/dist/cjs/operator/mariadb-database.js.map +1 -0
- package/dist/cjs/operator/mariadb-roles.d.ts +264 -0
- package/dist/cjs/operator/mariadb-roles.d.ts.map +1 -0
- package/dist/cjs/operator/mariadb-roles.js +366 -0
- package/dist/cjs/operator/mariadb-roles.js.map +1 -0
- package/dist/cjs/operator/mariadb.d.ts.map +1 -1
- package/dist/cjs/operator/mariadb.js +35 -147
- package/dist/cjs/operator/mariadb.js.map +1 -1
- package/dist/cjs/operator/neo4j-common.d.ts +62 -0
- package/dist/cjs/operator/neo4j-common.d.ts.map +1 -0
- package/dist/cjs/operator/neo4j-common.js +89 -0
- package/dist/cjs/operator/neo4j-common.js.map +1 -0
- package/dist/cjs/operator/neo4j-database.d.ts +88 -0
- package/dist/cjs/operator/neo4j-database.d.ts.map +1 -0
- package/dist/cjs/operator/neo4j-database.js +274 -0
- package/dist/cjs/operator/neo4j-database.js.map +1 -0
- package/dist/cjs/operator/neo4j-roles.d.ts +203 -0
- package/dist/cjs/operator/neo4j-roles.d.ts.map +1 -0
- package/dist/cjs/operator/neo4j-roles.js +298 -0
- package/dist/cjs/operator/neo4j-roles.js.map +1 -0
- package/dist/cjs/operator/neo4j.d.ts.map +1 -1
- package/dist/cjs/operator/neo4j.js +32 -132
- package/dist/cjs/operator/neo4j.js.map +1 -1
- package/dist/cjs/operator/resource-identity.d.ts +170 -0
- package/dist/cjs/operator/resource-identity.d.ts.map +1 -0
- package/dist/cjs/operator/resource-identity.js +231 -0
- package/dist/cjs/operator/resource-identity.js.map +1 -0
- package/dist/cjs/operator/role-registry.d.ts +85 -0
- package/dist/cjs/operator/role-registry.d.ts.map +1 -0
- package/dist/cjs/operator/role-registry.js +72 -0
- package/dist/cjs/operator/role-registry.js.map +1 -0
- package/dist/cjs/types/errors.d.ts +3 -0
- package/dist/cjs/types/errors.d.ts.map +1 -1
- package/dist/cjs/types/errors.js +3 -0
- package/dist/cjs/types/errors.js.map +1 -1
- package/dist/esm/aws/cloudfront.d.ts +17 -0
- package/dist/esm/aws/cloudfront.d.ts.map +1 -0
- package/dist/esm/aws/cloudfront.js +147 -0
- package/dist/esm/aws/cloudfront.js.map +1 -0
- package/dist/esm/aws/index.d.ts +1 -0
- package/dist/esm/aws/index.d.ts.map +1 -1
- package/dist/esm/aws/index.js +3 -1
- package/dist/esm/aws/index.js.map +1 -1
- package/dist/esm/cdn/index.d.ts +7 -0
- package/dist/esm/cdn/index.d.ts.map +1 -0
- package/dist/esm/cdn/index.js +8 -0
- package/dist/esm/cdn/index.js.map +1 -0
- package/dist/esm/cdn/interfaces.d.ts +43 -0
- package/dist/esm/cdn/interfaces.d.ts.map +1 -0
- package/dist/esm/cdn/interfaces.js +8 -0
- package/dist/esm/cdn/interfaces.js.map +1 -0
- package/dist/esm/cli/migrate-cnpg-ownership.d.ts +43 -0
- package/dist/esm/cli/migrate-cnpg-ownership.d.ts.map +1 -0
- package/dist/esm/cli/migrate-cnpg-ownership.js +67 -0
- package/dist/esm/cli/migrate-cnpg-ownership.js.map +1 -0
- package/dist/esm/cli/migrate-cnpg-roles.d.ts +92 -0
- package/dist/esm/cli/migrate-cnpg-roles.d.ts.map +1 -0
- package/dist/esm/cli/migrate-cnpg-roles.js +337 -0
- package/dist/esm/cli/migrate-cnpg-roles.js.map +1 -0
- package/dist/esm/cli/migrate-cnpg.d.ts +38 -0
- package/dist/esm/cli/migrate-cnpg.d.ts.map +1 -0
- package/dist/esm/cli/migrate-cnpg.js +258 -0
- package/dist/esm/cli/migrate-cnpg.js.map +1 -0
- package/dist/esm/cli/migrate-exec.d.ts +45 -0
- package/dist/esm/cli/migrate-exec.d.ts.map +1 -0
- package/dist/esm/cli/migrate-exec.js +104 -0
- package/dist/esm/cli/migrate-exec.js.map +1 -0
- package/dist/esm/cli/migrate-psql.d.ts +125 -0
- package/dist/esm/cli/migrate-psql.d.ts.map +1 -0
- package/dist/esm/cli/migrate-psql.js +213 -0
- package/dist/esm/cli/migrate-psql.js.map +1 -0
- package/dist/esm/cli/migrate-report.d.ts +27 -0
- package/dist/esm/cli/migrate-report.d.ts.map +1 -0
- package/dist/esm/cli/migrate-report.js +29 -0
- package/dist/esm/cli/migrate-report.js.map +1 -0
- package/dist/esm/cli/migrate-superuser.d.ts +22 -0
- package/dist/esm/cli/migrate-superuser.d.ts.map +1 -0
- package/dist/esm/cli/migrate-superuser.js +73 -0
- package/dist/esm/cli/migrate-superuser.js.map +1 -0
- package/dist/esm/cli/migrate.d.ts +37 -0
- package/dist/esm/cli/migrate.d.ts.map +1 -0
- package/dist/esm/cli/migrate.js +67 -0
- package/dist/esm/cli/migrate.js.map +1 -0
- package/dist/esm/cli.d.ts +1 -0
- package/dist/esm/cli.d.ts.map +1 -1
- package/dist/esm/cli.js +6 -0
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/edge/index.d.ts +8 -0
- package/dist/esm/edge/index.d.ts.map +1 -0
- package/dist/esm/edge/index.js +13 -0
- package/dist/esm/edge/index.js.map +1 -0
- package/dist/esm/edge/interfaces.d.ts +35 -0
- package/dist/esm/edge/interfaces.d.ts.map +1 -0
- package/dist/esm/edge/interfaces.js +8 -0
- package/dist/esm/edge/interfaces.js.map +1 -0
- package/dist/esm/edge/verify.d.ts +22 -0
- package/dist/esm/edge/verify.d.ts.map +1 -0
- package/dist/esm/edge/verify.js +105 -0
- package/dist/esm/edge/verify.js.map +1 -0
- package/dist/esm/factories/cdn.d.ts +15 -0
- package/dist/esm/factories/cdn.d.ts.map +1 -0
- package/dist/esm/factories/cdn.js +28 -0
- package/dist/esm/factories/cdn.js.map +1 -0
- package/dist/esm/factories/index.d.ts +1 -0
- package/dist/esm/factories/index.d.ts.map +1 -1
- package/dist/esm/factories/index.js +3 -1
- package/dist/esm/factories/index.js.map +1 -1
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +7 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/operator/cnpg-common.d.ts +56 -0
- package/dist/esm/operator/cnpg-common.d.ts.map +1 -0
- package/dist/esm/operator/cnpg-common.js +82 -0
- package/dist/esm/operator/cnpg-common.js.map +1 -0
- package/dist/esm/operator/cnpg-database.d.ts +66 -0
- package/dist/esm/operator/cnpg-database.d.ts.map +1 -0
- package/dist/esm/operator/cnpg-database.js +296 -0
- package/dist/esm/operator/cnpg-database.js.map +1 -0
- package/dist/esm/operator/cnpg-roles.d.ts +173 -0
- package/dist/esm/operator/cnpg-roles.d.ts.map +1 -0
- package/dist/esm/operator/cnpg-roles.js +225 -0
- package/dist/esm/operator/cnpg-roles.js.map +1 -0
- package/dist/esm/operator/cnpg.d.ts.map +1 -1
- package/dist/esm/operator/cnpg.js +50 -162
- package/dist/esm/operator/cnpg.js.map +1 -1
- package/dist/esm/operator/connection-uri.d.ts +44 -0
- package/dist/esm/operator/connection-uri.d.ts.map +1 -0
- package/dist/esm/operator/connection-uri.js +49 -0
- package/dist/esm/operator/connection-uri.js.map +1 -0
- package/dist/esm/operator/credentials.d.ts +76 -0
- package/dist/esm/operator/credentials.d.ts.map +1 -0
- package/dist/esm/operator/credentials.js +106 -0
- package/dist/esm/operator/credentials.js.map +1 -0
- package/dist/esm/operator/database-options.d.ts +121 -0
- package/dist/esm/operator/database-options.d.ts.map +1 -0
- package/dist/esm/operator/database-options.js +131 -0
- package/dist/esm/operator/database-options.js.map +1 -0
- package/dist/esm/operator/grants/postgres-job.d.ts +109 -0
- package/dist/esm/operator/grants/postgres-job.d.ts.map +1 -0
- package/dist/esm/operator/grants/postgres-job.js +232 -0
- package/dist/esm/operator/grants/postgres-job.js.map +1 -0
- package/dist/esm/operator/grants/postgres-sql.d.ts +130 -0
- package/dist/esm/operator/grants/postgres-sql.d.ts.map +1 -0
- package/dist/esm/operator/grants/postgres-sql.js +305 -0
- package/dist/esm/operator/grants/postgres-sql.js.map +1 -0
- package/dist/esm/operator/grants/privileges.d.ts +24 -0
- package/dist/esm/operator/grants/privileges.d.ts.map +1 -0
- package/dist/esm/operator/grants/privileges.js +35 -0
- package/dist/esm/operator/grants/privileges.js.map +1 -0
- package/dist/esm/operator/grants/role-config.d.ts +80 -0
- package/dist/esm/operator/grants/role-config.d.ts.map +1 -0
- package/dist/esm/operator/grants/role-config.js +134 -0
- package/dist/esm/operator/grants/role-config.js.map +1 -0
- package/dist/esm/operator/index.d.ts +1 -1
- package/dist/esm/operator/index.d.ts.map +1 -1
- package/dist/esm/operator/index.js.map +1 -1
- package/dist/esm/operator/interfaces.d.ts +223 -1
- package/dist/esm/operator/interfaces.d.ts.map +1 -1
- package/dist/esm/operator/interfaces.js.map +1 -1
- package/dist/esm/operator/mariadb-common.d.ts +99 -0
- package/dist/esm/operator/mariadb-common.d.ts.map +1 -0
- package/dist/esm/operator/mariadb-common.js +141 -0
- package/dist/esm/operator/mariadb-common.js.map +1 -0
- package/dist/esm/operator/mariadb-database.d.ts +65 -0
- package/dist/esm/operator/mariadb-database.d.ts.map +1 -0
- package/dist/esm/operator/mariadb-database.js +285 -0
- package/dist/esm/operator/mariadb-database.js.map +1 -0
- package/dist/esm/operator/mariadb-roles.d.ts +264 -0
- package/dist/esm/operator/mariadb-roles.d.ts.map +1 -0
- package/dist/esm/operator/mariadb-roles.js +366 -0
- package/dist/esm/operator/mariadb-roles.js.map +1 -0
- package/dist/esm/operator/mariadb.d.ts.map +1 -1
- package/dist/esm/operator/mariadb.js +35 -147
- package/dist/esm/operator/mariadb.js.map +1 -1
- package/dist/esm/operator/neo4j-common.d.ts +62 -0
- package/dist/esm/operator/neo4j-common.d.ts.map +1 -0
- package/dist/esm/operator/neo4j-common.js +89 -0
- package/dist/esm/operator/neo4j-common.js.map +1 -0
- package/dist/esm/operator/neo4j-database.d.ts +88 -0
- package/dist/esm/operator/neo4j-database.d.ts.map +1 -0
- package/dist/esm/operator/neo4j-database.js +274 -0
- package/dist/esm/operator/neo4j-database.js.map +1 -0
- package/dist/esm/operator/neo4j-roles.d.ts +203 -0
- package/dist/esm/operator/neo4j-roles.d.ts.map +1 -0
- package/dist/esm/operator/neo4j-roles.js +298 -0
- package/dist/esm/operator/neo4j-roles.js.map +1 -0
- package/dist/esm/operator/neo4j.d.ts.map +1 -1
- package/dist/esm/operator/neo4j.js +32 -132
- package/dist/esm/operator/neo4j.js.map +1 -1
- package/dist/esm/operator/resource-identity.d.ts +170 -0
- package/dist/esm/operator/resource-identity.d.ts.map +1 -0
- package/dist/esm/operator/resource-identity.js +231 -0
- package/dist/esm/operator/resource-identity.js.map +1 -0
- package/dist/esm/operator/role-registry.d.ts +85 -0
- package/dist/esm/operator/role-registry.d.ts.map +1 -0
- package/dist/esm/operator/role-registry.js +72 -0
- package/dist/esm/operator/role-registry.js.map +1 -0
- package/dist/esm/types/errors.d.ts +3 -0
- package/dist/esm/types/errors.d.ts.map +1 -1
- package/dist/esm/types/errors.js +3 -0
- package/dist/esm/types/errors.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure compiler from portable grant specs to PostgreSQL SQL.
|
|
3
|
+
*
|
|
4
|
+
* Emits an atomic revoke-then-grant script: every privilege the role currently
|
|
5
|
+
* holds is revoked, then the desired grants are applied. This converges without
|
|
6
|
+
* needing to introspect prior state, and removal works because anything not
|
|
7
|
+
* re-granted stays revoked. The whole script runs in one transaction so no
|
|
8
|
+
* window of missing privileges is ever observable.
|
|
9
|
+
*
|
|
10
|
+
* The one exception is a script whose role IS the owner: revoking there would
|
|
11
|
+
* take the owner's access to its own objects away, so the preamble is skipped.
|
|
12
|
+
*
|
|
13
|
+
* @module operator/grants/postgres-sql
|
|
14
|
+
*/
|
|
15
|
+
import type { IDatabaseGrant } from "../interfaces.js";
|
|
16
|
+
/**
|
|
17
|
+
* Privileges granted on sequences for a role that holds a write grant — and,
|
|
18
|
+
* by construction, the exact set the revoke preamble strips from sequences.
|
|
19
|
+
*
|
|
20
|
+
* `USAGE` is what `nextval()` requires; `SELECT` allows reading the current
|
|
21
|
+
* value (`currval`). `UPDATE` — which would let the role `setval()` a sequence
|
|
22
|
+
* to an arbitrary value — is deliberately excluded, and correspondingly never
|
|
23
|
+
* revoked. See {@link compileGrantSql} for the invariant that ties the two.
|
|
24
|
+
*
|
|
25
|
+
* This is the single source for both directions: {@link SEQUENCE_PRIVILEGE_CLAUSE}
|
|
26
|
+
* is rendered from it once and interpolated into every sequence `GRANT` **and**
|
|
27
|
+
* every sequence `REVOKE` this compiler emits, so the two sets cannot drift.
|
|
28
|
+
* Adding an entry here widens both at the same time; there is no second list to
|
|
29
|
+
* forget.
|
|
30
|
+
*/
|
|
31
|
+
export declare const SEQUENCE_GRANT_PRIVILEGES: ReadonlyArray<string>;
|
|
32
|
+
/** Options for {@link compileGrantSql}. */
|
|
33
|
+
export interface ICompileOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Role receiving the privileges. When it equals {@link ICompileOptions.owner}
|
|
36
|
+
* the revoke preamble is omitted — see {@link compileGrantSql}.
|
|
37
|
+
*/
|
|
38
|
+
readonly role: string;
|
|
39
|
+
/** Database owner — the role whose future objects default privileges apply to. */
|
|
40
|
+
readonly owner: string;
|
|
41
|
+
/** Desired grants. An empty list revokes everything the role holds. */
|
|
42
|
+
readonly grants: ReadonlyArray<IDatabaseGrant>;
|
|
43
|
+
/**
|
|
44
|
+
* Raw SQL appended after the grants and before `COMMIT;` — it runs inside
|
|
45
|
+
* the same surrounding transaction as everything else in the script, not
|
|
46
|
+
* in a transaction of its own. It must therefore be both idempotent and
|
|
47
|
+
* transaction-safe: statements that PostgreSQL refuses to run inside a
|
|
48
|
+
* transaction block (e.g. `CREATE INDEX CONCURRENTLY`, `VACUUM`) will
|
|
49
|
+
* error, and a stray `COMMIT;` here would close the transaction early and
|
|
50
|
+
* leave the script's real trailing `COMMIT;` erroring outside any
|
|
51
|
+
* transaction.
|
|
52
|
+
*/
|
|
53
|
+
readonly extraSql?: ReadonlyArray<string>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Quote a PostgreSQL identifier, escaping embedded double quotes.
|
|
57
|
+
*
|
|
58
|
+
* @param name - Raw identifier
|
|
59
|
+
* @returns The identifier wrapped in double quotes and safe to interpolate
|
|
60
|
+
*/
|
|
61
|
+
export declare function quoteIdentifier(name: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Validate and normalise a privilege keyword for PostgreSQL.
|
|
64
|
+
*
|
|
65
|
+
* Privileges are SQL keywords and cannot be quoted, so they are checked against
|
|
66
|
+
* an allowlist rather than escaped. The allowlist is PostgreSQL's own — see
|
|
67
|
+
* {@link normalizePrivilegeAgainst} for why it is not shared with MariaDB.
|
|
68
|
+
*
|
|
69
|
+
* @param privilege - Raw privilege name, any case
|
|
70
|
+
* @returns The upper-cased privilege
|
|
71
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when not in the allowlist
|
|
72
|
+
*/
|
|
73
|
+
export declare function normalizePrivilege(privilege: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Reject any privilege {@link compileGrantSql} would refuse, without compiling.
|
|
76
|
+
*
|
|
77
|
+
* `compileGrantSql` is the only thing that validates privileges, and it runs
|
|
78
|
+
* deep inside grant-Job creation — after the caller has already mutated shared
|
|
79
|
+
* state such as the cluster's role registry. Callers that must fail before
|
|
80
|
+
* mutating anything run this first: it applies exactly the check the compiler
|
|
81
|
+
* applies and produces exactly the same error, so the two cannot diverge into
|
|
82
|
+
* a config the guard accepts and the compiler then rejects.
|
|
83
|
+
*
|
|
84
|
+
* @param grants - Desired grants, or `undefined` when privileges are unmanaged
|
|
85
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a privilege is not
|
|
86
|
+
* in the allowlist
|
|
87
|
+
*/
|
|
88
|
+
export declare function assertSupportedPrivileges(grants: ReadonlyArray<IDatabaseGrant> | undefined): void;
|
|
89
|
+
/**
|
|
90
|
+
* Compile a grant spec into an idempotent, transactional SQL script.
|
|
91
|
+
*
|
|
92
|
+
* **Invariant: the revoke preamble never strips a privilege the grant path
|
|
93
|
+
* cannot restore.** Convergence only works if every privilege the preamble
|
|
94
|
+
* removes can be put back by some grant this compiler is able to emit —
|
|
95
|
+
* otherwise a role loses access permanently the first time any grant is
|
|
96
|
+
* reconciled, with no configuration that brings it back. The preamble is
|
|
97
|
+
* therefore scoped to exactly three things: all privileges on tables (restored
|
|
98
|
+
* by `ALL PRIVILEGES`), {@link SEQUENCE_GRANT_PRIVILEGES} on sequences (restored
|
|
99
|
+
* alongside any write grant, see {@link SEQUENCE_IMPLYING_PRIVILEGES}), and
|
|
100
|
+
* `USAGE` on the schema (restored for every grant). Schema `CREATE` and sequence
|
|
101
|
+
* `UPDATE` are left alone precisely because nothing here can grant them.
|
|
102
|
+
*
|
|
103
|
+
* The sequence half of that invariant holds **by construction, not by review**:
|
|
104
|
+
* the grant statements and the revoke statements interpolate the same rendered
|
|
105
|
+
* {@link SEQUENCE_GRANT_PRIVILEGES}, so there is no second list that could be
|
|
106
|
+
* widened on its own. Widening the constant widens both directions in one edit.
|
|
107
|
+
*
|
|
108
|
+
* When `role` and `owner` name the same role the revoke preamble is omitted:
|
|
109
|
+
* an owner's rights over its own objects are ordinary ACL entries it is
|
|
110
|
+
* allowed to revoke from itself, so reconciling "the owner holds exactly these
|
|
111
|
+
* grants" would lock the owner out of its own tables. Such a script therefore
|
|
112
|
+
* carries only the grants and `extraSql` it was given.
|
|
113
|
+
*
|
|
114
|
+
* @param options - Role, owner, desired grants, and optional trailing SQL
|
|
115
|
+
* @returns A complete SQL script beginning with `BEGIN;` and ending `COMMIT;`
|
|
116
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a privilege is not
|
|
117
|
+
* in the allowlist
|
|
118
|
+
*
|
|
119
|
+
* @example Read-only access to every current and future table in a schema
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const sql = compileGrantSql({
|
|
122
|
+
* role: "reader",
|
|
123
|
+
* owner: "etl",
|
|
124
|
+
* grants: [{ privileges: ["SELECT"], schema: "marts", objects: "all" }],
|
|
125
|
+
* });
|
|
126
|
+
* // sql === "BEGIN;\nDO $nimbus$ ... GRANT SELECT ON ALL TABLES IN SCHEMA \"marts\" TO \"reader\";\n...\nCOMMIT;"
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function compileGrantSql(options: ICompileOptions): string;
|
|
130
|
+
//# sourceMappingURL=postgres-sql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-sql.d.ts","sourceRoot":"","sources":["../../../../src/operator/grants/postgres-sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAkDvD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,EAAE,aAAa,CAAC,MAAM,CAAgC,CAAC;AAmB7F,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kFAAkF;IAClF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC/C;;;;;;;;;OASG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,GAAG,SAAS,GAAG,IAAI,CAMjG;AAwCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAwGhE"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pure compiler from portable grant specs to PostgreSQL SQL.
|
|
4
|
+
*
|
|
5
|
+
* Emits an atomic revoke-then-grant script: every privilege the role currently
|
|
6
|
+
* holds is revoked, then the desired grants are applied. This converges without
|
|
7
|
+
* needing to introspect prior state, and removal works because anything not
|
|
8
|
+
* re-granted stays revoked. The whole script runs in one transaction so no
|
|
9
|
+
* window of missing privileges is ever observable.
|
|
10
|
+
*
|
|
11
|
+
* The one exception is a script whose role IS the owner: revoking there would
|
|
12
|
+
* take the owner's access to its own objects away, so the preamble is skipped.
|
|
13
|
+
*
|
|
14
|
+
* @module operator/grants/postgres-sql
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SEQUENCE_GRANT_PRIVILEGES = void 0;
|
|
18
|
+
exports.quoteIdentifier = quoteIdentifier;
|
|
19
|
+
exports.normalizePrivilege = normalizePrivilege;
|
|
20
|
+
exports.assertSupportedPrivileges = assertSupportedPrivileges;
|
|
21
|
+
exports.compileGrantSql = compileGrantSql;
|
|
22
|
+
const privileges_js_1 = require("./privileges.js");
|
|
23
|
+
/**
|
|
24
|
+
* Privileges accepted in {@link IDatabaseGrant.privileges}.
|
|
25
|
+
*
|
|
26
|
+
* Deliberately narrow: every entry is a privilege PostgreSQL allows in the
|
|
27
|
+
* only grant statements this compiler emits — `GRANT ... ON ALL TABLES IN
|
|
28
|
+
* SCHEMA <schema>` and `GRANT ... ON <schema>.<table>`. A keyword that is a
|
|
29
|
+
* real PostgreSQL privilege elsewhere but has no emission path here is
|
|
30
|
+
* rejected at compile time rather than passing validation and failing when
|
|
31
|
+
* the script runs:
|
|
32
|
+
*
|
|
33
|
+
* - `EXECUTE` applies to functions, `CONNECT` and `TEMPORARY` to databases.
|
|
34
|
+
* - `USAGE` and `CREATE` apply to schemas (and `USAGE` to sequences and
|
|
35
|
+
* types), never to relations. They were briefly accepted here, which was a
|
|
36
|
+
* bug: with `objects` defaulting to `"all"` they rendered as
|
|
37
|
+
* `GRANT USAGE ON ALL TABLES IN SCHEMA "x" TO "r";`, which PostgreSQL
|
|
38
|
+
* rejects with `invalid privilege type USAGE for relation`. Nothing is lost
|
|
39
|
+
* by removing them — {@link compileGrantSql} already emits
|
|
40
|
+
* `GRANT USAGE ON SCHEMA` for every grant, and schema `CREATE` is not
|
|
41
|
+
* something this compiler grants at all.
|
|
42
|
+
*/
|
|
43
|
+
const ALLOWED_PRIVILEGES = new Set([
|
|
44
|
+
"SELECT",
|
|
45
|
+
"INSERT",
|
|
46
|
+
"UPDATE",
|
|
47
|
+
"DELETE",
|
|
48
|
+
"TRUNCATE",
|
|
49
|
+
"REFERENCES",
|
|
50
|
+
"TRIGGER",
|
|
51
|
+
"ALL PRIVILEGES",
|
|
52
|
+
]);
|
|
53
|
+
/**
|
|
54
|
+
* Privileges whose holder needs the schema's sequences to be usable.
|
|
55
|
+
*
|
|
56
|
+
* Inserting into a `serial`/`identity` column calls `nextval()` on the column's
|
|
57
|
+
* owning sequence, which is a separate object with its own ACL: without
|
|
58
|
+
* `USAGE` on it every such `INSERT` fails with `permission denied for
|
|
59
|
+
* sequence`. `UPDATE` is included because updating a key column can call
|
|
60
|
+
* `nextval()` the same way, and `ALL PRIVILEGES` because it subsumes both.
|
|
61
|
+
* `SELECT`, `DELETE`, `TRUNCATE`, `REFERENCES`, and `TRIGGER` never consume a
|
|
62
|
+
* sequence value, so a read-only role is not silently widened.
|
|
63
|
+
*/
|
|
64
|
+
const SEQUENCE_IMPLYING_PRIVILEGES = new Set([
|
|
65
|
+
"INSERT",
|
|
66
|
+
"UPDATE",
|
|
67
|
+
"ALL PRIVILEGES",
|
|
68
|
+
]);
|
|
69
|
+
/**
|
|
70
|
+
* Privileges granted on sequences for a role that holds a write grant — and,
|
|
71
|
+
* by construction, the exact set the revoke preamble strips from sequences.
|
|
72
|
+
*
|
|
73
|
+
* `USAGE` is what `nextval()` requires; `SELECT` allows reading the current
|
|
74
|
+
* value (`currval`). `UPDATE` — which would let the role `setval()` a sequence
|
|
75
|
+
* to an arbitrary value — is deliberately excluded, and correspondingly never
|
|
76
|
+
* revoked. See {@link compileGrantSql} for the invariant that ties the two.
|
|
77
|
+
*
|
|
78
|
+
* This is the single source for both directions: {@link SEQUENCE_PRIVILEGE_CLAUSE}
|
|
79
|
+
* is rendered from it once and interpolated into every sequence `GRANT` **and**
|
|
80
|
+
* every sequence `REVOKE` this compiler emits, so the two sets cannot drift.
|
|
81
|
+
* Adding an entry here widens both at the same time; there is no second list to
|
|
82
|
+
* forget.
|
|
83
|
+
*/
|
|
84
|
+
exports.SEQUENCE_GRANT_PRIVILEGES = ["USAGE", "SELECT"];
|
|
85
|
+
/**
|
|
86
|
+
* {@link SEQUENCE_GRANT_PRIVILEGES} rendered as a SQL privilege list.
|
|
87
|
+
*
|
|
88
|
+
* Interpolated verbatim into both the sequence grants and the sequence revokes.
|
|
89
|
+
*/
|
|
90
|
+
const SEQUENCE_PRIVILEGE_CLAUSE = exports.SEQUENCE_GRANT_PRIVILEGES.join(", ");
|
|
91
|
+
/** Engine name used when reporting a rejected privilege. */
|
|
92
|
+
const ENGINE_NAME = "PostgreSQL";
|
|
93
|
+
/** Sentinel meaning "every current and future object in the schema". */
|
|
94
|
+
const ALL_OBJECTS = "all";
|
|
95
|
+
/** Schema used for a grant when {@link IDatabaseGrant.schema} is omitted. */
|
|
96
|
+
const DEFAULT_SCHEMA = "public";
|
|
97
|
+
/** Base tag for the `DO $tag$ ... $tag$;` block; bumped on collision. See {@link chooseDollarTag}. */
|
|
98
|
+
const BASE_DOLLAR_TAG = "nimbus";
|
|
99
|
+
/**
|
|
100
|
+
* Quote a PostgreSQL identifier, escaping embedded double quotes.
|
|
101
|
+
*
|
|
102
|
+
* @param name - Raw identifier
|
|
103
|
+
* @returns The identifier wrapped in double quotes and safe to interpolate
|
|
104
|
+
*/
|
|
105
|
+
function quoteIdentifier(name) {
|
|
106
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Validate and normalise a privilege keyword for PostgreSQL.
|
|
110
|
+
*
|
|
111
|
+
* Privileges are SQL keywords and cannot be quoted, so they are checked against
|
|
112
|
+
* an allowlist rather than escaped. The allowlist is PostgreSQL's own — see
|
|
113
|
+
* {@link normalizePrivilegeAgainst} for why it is not shared with MariaDB.
|
|
114
|
+
*
|
|
115
|
+
* @param privilege - Raw privilege name, any case
|
|
116
|
+
* @returns The upper-cased privilege
|
|
117
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when not in the allowlist
|
|
118
|
+
*/
|
|
119
|
+
function normalizePrivilege(privilege) {
|
|
120
|
+
return (0, privileges_js_1.normalizePrivilegeAgainst)(privilege, ALLOWED_PRIVILEGES, ENGINE_NAME);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Reject any privilege {@link compileGrantSql} would refuse, without compiling.
|
|
124
|
+
*
|
|
125
|
+
* `compileGrantSql` is the only thing that validates privileges, and it runs
|
|
126
|
+
* deep inside grant-Job creation — after the caller has already mutated shared
|
|
127
|
+
* state such as the cluster's role registry. Callers that must fail before
|
|
128
|
+
* mutating anything run this first: it applies exactly the check the compiler
|
|
129
|
+
* applies and produces exactly the same error, so the two cannot diverge into
|
|
130
|
+
* a config the guard accepts and the compiler then rejects.
|
|
131
|
+
*
|
|
132
|
+
* @param grants - Desired grants, or `undefined` when privileges are unmanaged
|
|
133
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a privilege is not
|
|
134
|
+
* in the allowlist
|
|
135
|
+
*/
|
|
136
|
+
function assertSupportedPrivileges(grants) {
|
|
137
|
+
for (const grant of grants ?? []) {
|
|
138
|
+
for (const privilege of grant.privileges) {
|
|
139
|
+
normalizePrivilege(privilege);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Quote a string as a SQL literal, escaping embedded single quotes.
|
|
145
|
+
*
|
|
146
|
+
* Used for values passed to functions such as `has_schema_privilege(...)` and
|
|
147
|
+
* `format(...)`, never for identifiers interpolated directly into DDL.
|
|
148
|
+
*
|
|
149
|
+
* @param value - Raw string value
|
|
150
|
+
* @returns The value wrapped in single quotes and safe to interpolate
|
|
151
|
+
*/
|
|
152
|
+
function quoteLiteral(value) {
|
|
153
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Derive a dollar-quote tag for a `DO $tag$ ... $tag$;` block that cannot
|
|
157
|
+
* collide with any of the given values.
|
|
158
|
+
*
|
|
159
|
+
* PostgreSQL's dollar-quoting has no escape mechanism: whichever `$tag$`
|
|
160
|
+
* appears first inside the body — even embedded in what the author intended
|
|
161
|
+
* as inert string data — closes the block early, and everything after is
|
|
162
|
+
* parsed as top-level SQL. Hardcoding a tag is therefore an injection hole
|
|
163
|
+
* whenever a role or owner name is attacker-influenced. This starts at
|
|
164
|
+
* `nimbus` and, on collision, tries `nimbus0`, `nimbus1`, ... until the
|
|
165
|
+
* candidate tag does not appear (as `$tag$`) in any supplied value.
|
|
166
|
+
*
|
|
167
|
+
* @param values - Every string that will be embedded inside the DO block body
|
|
168
|
+
* @returns A tag guaranteed not to appear as `$tag$` in any of `values`
|
|
169
|
+
*/
|
|
170
|
+
function chooseDollarTag(values) {
|
|
171
|
+
let candidate = BASE_DOLLAR_TAG;
|
|
172
|
+
let suffix = 0;
|
|
173
|
+
while (values.some((value) => value.includes(`$${candidate}$`))) {
|
|
174
|
+
candidate = `${BASE_DOLLAR_TAG}${suffix}`;
|
|
175
|
+
suffix += 1;
|
|
176
|
+
}
|
|
177
|
+
return candidate;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Compile a grant spec into an idempotent, transactional SQL script.
|
|
181
|
+
*
|
|
182
|
+
* **Invariant: the revoke preamble never strips a privilege the grant path
|
|
183
|
+
* cannot restore.** Convergence only works if every privilege the preamble
|
|
184
|
+
* removes can be put back by some grant this compiler is able to emit —
|
|
185
|
+
* otherwise a role loses access permanently the first time any grant is
|
|
186
|
+
* reconciled, with no configuration that brings it back. The preamble is
|
|
187
|
+
* therefore scoped to exactly three things: all privileges on tables (restored
|
|
188
|
+
* by `ALL PRIVILEGES`), {@link SEQUENCE_GRANT_PRIVILEGES} on sequences (restored
|
|
189
|
+
* alongside any write grant, see {@link SEQUENCE_IMPLYING_PRIVILEGES}), and
|
|
190
|
+
* `USAGE` on the schema (restored for every grant). Schema `CREATE` and sequence
|
|
191
|
+
* `UPDATE` are left alone precisely because nothing here can grant them.
|
|
192
|
+
*
|
|
193
|
+
* The sequence half of that invariant holds **by construction, not by review**:
|
|
194
|
+
* the grant statements and the revoke statements interpolate the same rendered
|
|
195
|
+
* {@link SEQUENCE_GRANT_PRIVILEGES}, so there is no second list that could be
|
|
196
|
+
* widened on its own. Widening the constant widens both directions in one edit.
|
|
197
|
+
*
|
|
198
|
+
* When `role` and `owner` name the same role the revoke preamble is omitted:
|
|
199
|
+
* an owner's rights over its own objects are ordinary ACL entries it is
|
|
200
|
+
* allowed to revoke from itself, so reconciling "the owner holds exactly these
|
|
201
|
+
* grants" would lock the owner out of its own tables. Such a script therefore
|
|
202
|
+
* carries only the grants and `extraSql` it was given.
|
|
203
|
+
*
|
|
204
|
+
* @param options - Role, owner, desired grants, and optional trailing SQL
|
|
205
|
+
* @returns A complete SQL script beginning with `BEGIN;` and ending `COMMIT;`
|
|
206
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a privilege is not
|
|
207
|
+
* in the allowlist
|
|
208
|
+
*
|
|
209
|
+
* @example Read-only access to every current and future table in a schema
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const sql = compileGrantSql({
|
|
212
|
+
* role: "reader",
|
|
213
|
+
* owner: "etl",
|
|
214
|
+
* grants: [{ privileges: ["SELECT"], schema: "marts", objects: "all" }],
|
|
215
|
+
* });
|
|
216
|
+
* // sql === "BEGIN;\nDO $nimbus$ ... GRANT SELECT ON ALL TABLES IN SCHEMA \"marts\" TO \"reader\";\n...\nCOMMIT;"
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
function compileGrantSql(options) {
|
|
220
|
+
const { role, owner, grants, extraSql = [] } = options;
|
|
221
|
+
const qRole = quoteIdentifier(role);
|
|
222
|
+
const qOwner = quoteIdentifier(owner);
|
|
223
|
+
const statements = ["BEGIN;"];
|
|
224
|
+
// Revoke the privileges the role currently holds, discovered at runtime.
|
|
225
|
+
// Every non-system schema is visited unconditionally (not just ones the
|
|
226
|
+
// role currently has USAGE on) so that privileges surviving under a
|
|
227
|
+
// separately-revoked schema are still caught — REVOKE against a schema the
|
|
228
|
+
// role holds nothing in is a harmless no-op. format(%I) quotes
|
|
229
|
+
// identifiers; the role/owner names are passed as literal parameters to
|
|
230
|
+
// format rather than concatenated into DDL.
|
|
231
|
+
//
|
|
232
|
+
// What is revoked is bounded by what the grant loop below can emit: tables
|
|
233
|
+
// (any privilege), sequences (USAGE, SELECT), and schema USAGE. Schema
|
|
234
|
+
// CREATE and sequence UPDATE are untouched because no grant spec can ask
|
|
235
|
+
// for them back — see the invariant documented on this function.
|
|
236
|
+
//
|
|
237
|
+
// Skipped entirely when the role IS the owner. PostgreSQL records an owner's
|
|
238
|
+
// rights over its own objects as ordinary entries in the object's ACL, and a
|
|
239
|
+
// role is allowed to revoke its own privileges — so running this preamble
|
|
240
|
+
// against the owner strips the owner's access to the very tables it owns
|
|
241
|
+
// (and, via ALTER DEFAULT PRIVILEGES, to tables it has yet to create) until
|
|
242
|
+
// something grants them back. Convergence is also meaningless there: an
|
|
243
|
+
// owner-scoped script exists to run `extraSql`, never to reconcile a grant
|
|
244
|
+
// spec the owner does not have.
|
|
245
|
+
if (role !== owner) {
|
|
246
|
+
const lRole = quoteLiteral(role);
|
|
247
|
+
const lOwner = quoteLiteral(owner);
|
|
248
|
+
const tag = chooseDollarTag([role, owner]);
|
|
249
|
+
statements.push([
|
|
250
|
+
`DO $${tag}$`,
|
|
251
|
+
"DECLARE s record;",
|
|
252
|
+
"BEGIN",
|
|
253
|
+
" FOR s IN",
|
|
254
|
+
" SELECT nspname FROM pg_namespace",
|
|
255
|
+
" WHERE nspname NOT LIKE 'pg\\_%'",
|
|
256
|
+
" AND nspname <> 'information_schema'",
|
|
257
|
+
" LOOP",
|
|
258
|
+
` EXECUTE format('REVOKE ALL ON ALL TABLES IN SCHEMA %I FROM %I', s.nspname, ${lRole});`,
|
|
259
|
+
` EXECUTE format('REVOKE ${SEQUENCE_PRIVILEGE_CLAUSE} ON ALL SEQUENCES IN SCHEMA %I FROM %I', s.nspname, ${lRole});`,
|
|
260
|
+
` EXECUTE format('REVOKE USAGE ON SCHEMA %I FROM %I', s.nspname, ${lRole});`,
|
|
261
|
+
` EXECUTE format('ALTER DEFAULT PRIVILEGES FOR ROLE %I IN SCHEMA %I REVOKE ALL ON TABLES FROM %I', ${lOwner}, s.nspname, ${lRole});`,
|
|
262
|
+
` EXECUTE format('ALTER DEFAULT PRIVILEGES FOR ROLE %I IN SCHEMA %I REVOKE ${SEQUENCE_PRIVILEGE_CLAUSE} ON SEQUENCES FROM %I', ${lOwner}, s.nspname, ${lRole});`,
|
|
263
|
+
" END LOOP;",
|
|
264
|
+
"END",
|
|
265
|
+
`$${tag}$;`,
|
|
266
|
+
].join("\n"));
|
|
267
|
+
}
|
|
268
|
+
// Schemas whose sequences have already been granted, so two write grants in
|
|
269
|
+
// the same schema emit the sequence statements once rather than twice.
|
|
270
|
+
const sequenceGrantedSchemas = new Set();
|
|
271
|
+
for (const grant of grants) {
|
|
272
|
+
const normalized = grant.privileges.map(normalizePrivilege);
|
|
273
|
+
const privileges = normalized.join(", ");
|
|
274
|
+
const schema = grant.schema ?? DEFAULT_SCHEMA;
|
|
275
|
+
const qSchema = quoteIdentifier(schema);
|
|
276
|
+
const objects = grant.objects ?? ALL_OBJECTS;
|
|
277
|
+
statements.push(`GRANT USAGE ON SCHEMA ${qSchema} TO ${qRole};`);
|
|
278
|
+
if (objects === ALL_OBJECTS) {
|
|
279
|
+
statements.push(`GRANT ${privileges} ON ALL TABLES IN SCHEMA ${qSchema} TO ${qRole};`);
|
|
280
|
+
statements.push(`ALTER DEFAULT PRIVILEGES FOR ROLE ${qOwner} IN SCHEMA ${qSchema} ` +
|
|
281
|
+
`GRANT ${privileges} ON TABLES TO ${qRole};`);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
statements.push(`GRANT ${privileges} ON ${qSchema}.${quoteIdentifier(objects)} TO ${qRole};`);
|
|
285
|
+
}
|
|
286
|
+
// A write grant is useless on a table with a serial/identity column unless
|
|
287
|
+
// the column's sequence is usable too, so the sequences of the grant's
|
|
288
|
+
// schema come with it. They are granted schema-wide even for an
|
|
289
|
+
// object-scoped grant: a sequence is a separate object whose link to its
|
|
290
|
+
// table lives in pg_depend, and this compiler emits static SQL rather than
|
|
291
|
+
// introspecting the catalog. The privileges are the narrow
|
|
292
|
+
// read-and-advance pair, never sequence UPDATE (`setval`).
|
|
293
|
+
if (!sequenceGrantedSchemas.has(schema) &&
|
|
294
|
+
normalized.some((privilege) => SEQUENCE_IMPLYING_PRIVILEGES.has(privilege))) {
|
|
295
|
+
sequenceGrantedSchemas.add(schema);
|
|
296
|
+
statements.push(`GRANT ${SEQUENCE_PRIVILEGE_CLAUSE} ON ALL SEQUENCES IN SCHEMA ${qSchema} TO ${qRole};`);
|
|
297
|
+
statements.push(`ALTER DEFAULT PRIVILEGES FOR ROLE ${qOwner} IN SCHEMA ${qSchema} ` +
|
|
298
|
+
`GRANT ${SEQUENCE_PRIVILEGE_CLAUSE} ON SEQUENCES TO ${qRole};`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
statements.push(...extraSql);
|
|
302
|
+
statements.push("COMMIT;");
|
|
303
|
+
return statements.join("\n");
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=postgres-sql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-sql.js","sourceRoot":"","sources":["../../../../src/operator/grants/postgres-sql.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared validation for privilege keywords in {@link IDatabaseGrant.privileges}.
|
|
3
|
+
*
|
|
4
|
+
* A privilege is a SQL keyword, not a value: it cannot be quoted or escaped on
|
|
5
|
+
* its way into a `GRANT` statement, so the only defence is to check it against
|
|
6
|
+
* an allowlist before it is emitted. That check is shared, but the allowlist is
|
|
7
|
+
* not — PostgreSQL and MariaDB spell privileges differently and support
|
|
8
|
+
* different sets (`INDEX`, `DROP`, and `EVENT` are MariaDB-only; `TRUNCATE` is
|
|
9
|
+
* PostgreSQL-only). Each engine therefore passes its own set, and neither
|
|
10
|
+
* inherits the other's by accident.
|
|
11
|
+
*
|
|
12
|
+
* @module operator/grants/privileges
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Validate and normalise a privilege keyword against one engine's allowlist.
|
|
16
|
+
*
|
|
17
|
+
* @param privilege - Raw privilege name, any case or internal spacing
|
|
18
|
+
* @param allowed - Privileges the engine's grant path can emit, upper-cased
|
|
19
|
+
* @param engine - Engine name for the error message (e.g. "PostgreSQL")
|
|
20
|
+
* @returns The trimmed, upper-cased, single-spaced privilege
|
|
21
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when not in `allowed`
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizePrivilegeAgainst(privilege: string, allowed: ReadonlySet<string>, engine: string): string;
|
|
24
|
+
//# sourceMappingURL=privileges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privileges.d.ts","sourceRoot":"","sources":["../../../../src/operator/grants/privileges.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAC5B,MAAM,EAAE,MAAM,GACb,MAAM,CAUR"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared validation for privilege keywords in {@link IDatabaseGrant.privileges}.
|
|
4
|
+
*
|
|
5
|
+
* A privilege is a SQL keyword, not a value: it cannot be quoted or escaped on
|
|
6
|
+
* its way into a `GRANT` statement, so the only defence is to check it against
|
|
7
|
+
* an allowlist before it is emitted. That check is shared, but the allowlist is
|
|
8
|
+
* not — PostgreSQL and MariaDB spell privileges differently and support
|
|
9
|
+
* different sets (`INDEX`, `DROP`, and `EVENT` are MariaDB-only; `TRUNCATE` is
|
|
10
|
+
* PostgreSQL-only). Each engine therefore passes its own set, and neither
|
|
11
|
+
* inherits the other's by accident.
|
|
12
|
+
*
|
|
13
|
+
* @module operator/grants/privileges
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.normalizePrivilegeAgainst = normalizePrivilegeAgainst;
|
|
17
|
+
const errors_js_1 = require("../../types/errors.js");
|
|
18
|
+
/**
|
|
19
|
+
* Validate and normalise a privilege keyword against one engine's allowlist.
|
|
20
|
+
*
|
|
21
|
+
* @param privilege - Raw privilege name, any case or internal spacing
|
|
22
|
+
* @param allowed - Privileges the engine's grant path can emit, upper-cased
|
|
23
|
+
* @param engine - Engine name for the error message (e.g. "PostgreSQL")
|
|
24
|
+
* @returns The trimmed, upper-cased, single-spaced privilege
|
|
25
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when not in `allowed`
|
|
26
|
+
*/
|
|
27
|
+
function normalizePrivilegeAgainst(privilege, allowed, engine) {
|
|
28
|
+
const normalized = privilege.trim().toUpperCase().replace(/\s+/g, " ");
|
|
29
|
+
if (!allowed.has(normalized)) {
|
|
30
|
+
throw new errors_js_1.AnyCloudError(`Unsupported privilege "${privilege}" for ${engine}. ` +
|
|
31
|
+
`Allowed: ${[...allowed].join(", ")}.`, errors_js_1.ERROR_CODES.UNSUPPORTED_PRIVILEGE);
|
|
32
|
+
}
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=privileges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privileges.js","sourceRoot":"","sources":["../../../../src/operator/grants/privileges.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAaH,8DAcC;AAzBD,qDAAmE;AAEnE;;;;;;;;GAQG;AACH,SAAgB,yBAAyB,CACvC,SAAiB,EACjB,OAA4B,EAC5B,MAAc;IAEd,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,yBAAa,CACrB,0BAA0B,SAAS,SAAS,MAAM,IAAI;YACpD,YAAY,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EACxC,uBAAW,CAAC,qBAAqB,CAClC,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure defaults resolution and validation for database role configuration, and
|
|
3
|
+
* the shared validators every backend runs over caller-supplied identifiers.
|
|
4
|
+
*
|
|
5
|
+
* @module operator/grants/role-config
|
|
6
|
+
*/
|
|
7
|
+
import type { IDatabaseGrant, IDatabaseRoleConfig, ReclaimPolicy } from "../interfaces.js";
|
|
8
|
+
/** Role configuration with all defaults applied. */
|
|
9
|
+
export interface IResolvedRoleConfig {
|
|
10
|
+
readonly login: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Desired privileges, or `undefined` when nimbus does not manage this role's
|
|
13
|
+
* privileges at all.
|
|
14
|
+
*
|
|
15
|
+
* The distinction is load-bearing and must survive defaults resolution: an
|
|
16
|
+
* empty array means "this role should hold no privileges" and reconciles to
|
|
17
|
+
* a revoke of everything, while `undefined` means "leave the role's
|
|
18
|
+
* privileges alone". Collapsing the two — defaulting to `[]` — would make
|
|
19
|
+
* removing the last grant from a config indistinguishable from never having
|
|
20
|
+
* configured grants, and the role would silently keep every privilege it had.
|
|
21
|
+
*/
|
|
22
|
+
readonly grants: ReadonlyArray<IDatabaseGrant> | undefined;
|
|
23
|
+
readonly reclaimPolicy: ReclaimPolicy;
|
|
24
|
+
readonly namespaces: ReadonlyArray<string>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Reject a role name that cannot be safely embedded in a database identifier.
|
|
28
|
+
*
|
|
29
|
+
* This is a choke point, not a per-engine concern. CloudNativePG's grants go
|
|
30
|
+
* through an identifier quoter and MariaDB's go through `Grant` CRs rather than
|
|
31
|
+
* SQL, so neither is exploitable today — but Neo4j interpolates the name
|
|
32
|
+
* directly into a Cypher `CREATE USER` statement between escaped backticks, and
|
|
33
|
+
* one validator all three call is easier to reason about than three separate
|
|
34
|
+
* arguments for why each backend happens to be fine.
|
|
35
|
+
*
|
|
36
|
+
* A blank name is refused here for the same reason: accepted, all three backends
|
|
37
|
+
* would register a full set of resources — the CR or Job, the credential Secret,
|
|
38
|
+
* the replicated connection Secrets — and the failure would surface only once
|
|
39
|
+
* the controller or provisioning Job tried to create an account with no name,
|
|
40
|
+
* long after `pulumi up` reported success.
|
|
41
|
+
*
|
|
42
|
+
* @param roleName - Role name as it would be created in the engine
|
|
43
|
+
* @param databaseName - Database the role belongs to, for the error message
|
|
44
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_ROLE_OPTION` when the name is blank,
|
|
45
|
+
* or contains a backtick, single quote, double quote, backslash, or NUL byte
|
|
46
|
+
*/
|
|
47
|
+
export declare function assertValidRoleName(roleName: string, databaseName: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Reject a database name no engine could create a database under.
|
|
50
|
+
*
|
|
51
|
+
* The same hole as a blank role name, one level up: `createDatabase("")` — or a
|
|
52
|
+
* name resolved from a config value that turned out to be empty — reaches the
|
|
53
|
+
* backends as a database with no name, and every CR, Job and Secret is
|
|
54
|
+
* registered before anything notices. On CloudNativePG and Neo4j the owner
|
|
55
|
+
* defaults to the database name and would be caught by
|
|
56
|
+
* {@link assertValidRoleName}, but only while no explicit `owner` is set, which
|
|
57
|
+
* is exactly the case a caller is most likely to have configured.
|
|
58
|
+
*
|
|
59
|
+
* Only blankness is checked. The character set is not narrowed here: a database
|
|
60
|
+
* name reaches the engine through CR `spec` fields rather than through SQL this
|
|
61
|
+
* library composes, and on every backend it is additionally run through
|
|
62
|
+
* {@link assertValidRoleName} whenever it is also the owner's name.
|
|
63
|
+
*
|
|
64
|
+
* @param databaseName - Database name as it would be created in the engine
|
|
65
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_ROLE_OPTION` when the name is blank
|
|
66
|
+
*/
|
|
67
|
+
export declare function assertValidDatabaseName(databaseName: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Apply defaults to a role config and validate its grants.
|
|
70
|
+
*
|
|
71
|
+
* `grants` is deliberately **not** defaulted: see
|
|
72
|
+
* {@link IResolvedRoleConfig.grants} for why `undefined` and `[]` must stay
|
|
73
|
+
* distinguishable.
|
|
74
|
+
*
|
|
75
|
+
* @param config - Raw user-supplied configuration
|
|
76
|
+
* @returns Configuration with every optional field resolved
|
|
77
|
+
* @throws {AnyCloudError} code `INVALID_GRANT` when a grant lists no privileges
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveRoleConfig(config?: IDatabaseRoleConfig): IResolvedRoleConfig;
|
|
80
|
+
//# sourceMappingURL=role-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role-config.d.ts","sourceRoot":"","sources":["../../../../src/operator/grants/role-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE3F,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAC3D,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC5C;AAqCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAqBhF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAUlE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,mBAAmB,CAkBnF"}
|