@reyemtech/nimbus 2.12.5 → 3.0.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/backup/index.d.ts.map +1 -1
- package/dist/cjs/backup/index.js +6 -1
- package/dist/cjs/backup/index.js.map +1 -1
- 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/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- 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/platform/components/image-pruner.d.ts +3 -1
- package/dist/cjs/platform/components/image-pruner.d.ts.map +1 -1
- package/dist/cjs/platform/components/image-pruner.js +38 -19
- package/dist/cjs/platform/components/image-pruner.js.map +1 -1
- 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/backup/index.d.ts.map +1 -1
- package/dist/esm/backup/index.js +6 -1
- package/dist/esm/backup/index.js.map +1 -1
- 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/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- 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/platform/components/image-pruner.d.ts +3 -1
- package/dist/esm/platform/components/image-pruner.d.ts.map +1 -1
- package/dist/esm/platform/components/image-pruner.js +38 -19
- package/dist/esm/platform/components/image-pruner.js.map +1 -1
- 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,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Applies compiled grant SQL to a CloudNativePG database.
|
|
4
|
+
*
|
|
5
|
+
* CNPG's `Database` and `DatabaseRole` CRDs create databases, roles, and
|
|
6
|
+
* ownership, but cannot express privilege grants — there is no CRD field for
|
|
7
|
+
* "GRANT SELECT ON ALL TABLES IN SCHEMA marts TO reader". This Job closes that
|
|
8
|
+
* gap: it runs `psql` against the cluster, authenticated as the database
|
|
9
|
+
* owner (never superuser), executing SQL compiled by
|
|
10
|
+
* {@link compileGrantSql}.
|
|
11
|
+
*
|
|
12
|
+
* The SQL reaches the container exclusively through a mounted ConfigMap, so
|
|
13
|
+
* no user-controlled value is ever interpolated into `command`. The Job's
|
|
14
|
+
* name embeds a checksum of the cluster, database, role, and compiled SQL, so
|
|
15
|
+
* an unchanged grant spec reuses the same Job (Pulumi diffs it as a no-op)
|
|
16
|
+
* and a changed spec — or the same grants applied to a different database —
|
|
17
|
+
* always produces a new, distinct Job.
|
|
18
|
+
*
|
|
19
|
+
* @module operator/grants/postgres-job
|
|
20
|
+
*/
|
|
21
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
24
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
25
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
26
|
+
}
|
|
27
|
+
Object.defineProperty(o, k2, desc);
|
|
28
|
+
}) : (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
o[k2] = m[k];
|
|
31
|
+
}));
|
|
32
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
33
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
34
|
+
}) : function(o, v) {
|
|
35
|
+
o["default"] = v;
|
|
36
|
+
});
|
|
37
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
38
|
+
var ownKeys = function(o) {
|
|
39
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
40
|
+
var ar = [];
|
|
41
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
42
|
+
return ar;
|
|
43
|
+
};
|
|
44
|
+
return ownKeys(o);
|
|
45
|
+
};
|
|
46
|
+
return function (mod) {
|
|
47
|
+
if (mod && mod.__esModule) return mod;
|
|
48
|
+
var result = {};
|
|
49
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
50
|
+
__setModuleDefault(result, mod);
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
})();
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.createPostgresGrantJob = createPostgresGrantJob;
|
|
56
|
+
const crypto = __importStar(require("node:crypto"));
|
|
57
|
+
const k8s = __importStar(require("@pulumi/kubernetes"));
|
|
58
|
+
const postgres_sql_js_1 = require("./postgres-sql.js");
|
|
59
|
+
const resource_identity_js_1 = require("../resource-identity.js");
|
|
60
|
+
/** Image repository for the `psql` client used to apply grants. */
|
|
61
|
+
const PG_IMAGE_REPO = "ghcr.io/cloudnative-pg/postgresql";
|
|
62
|
+
/** How long a finished Job (and its Pods) stick around before garbage collection. */
|
|
63
|
+
const JOB_TTL_SECONDS = 300;
|
|
64
|
+
/** Retries before the Job is considered failed. */
|
|
65
|
+
const JOB_BACKOFF_LIMIT = 5;
|
|
66
|
+
/** Prefix identifying grant-reconciliation Jobs, distinct from CNPG's own Jobs. */
|
|
67
|
+
const JOB_NAME_PREFIX = "cnpg-grants";
|
|
68
|
+
/** Suffix appended to the Job name to derive the SQL ConfigMap's name. */
|
|
69
|
+
const CONFIG_MAP_NAME_SUFFIX = "-sql";
|
|
70
|
+
/** Key under which the compiled SQL is stored in the ConfigMap. */
|
|
71
|
+
const SQL_CONFIG_MAP_KEY = "grants.sql";
|
|
72
|
+
/** Directory the SQL ConfigMap is mounted at inside the container. */
|
|
73
|
+
const SQL_MOUNT_PATH = "/sql";
|
|
74
|
+
/** Full in-container path to the mounted SQL file, passed to `psql -f`. */
|
|
75
|
+
const SQL_FILE_PATH = `${SQL_MOUNT_PATH}/${SQL_CONFIG_MAP_KEY}`;
|
|
76
|
+
/** Name of the ConfigMap volume and its mount inside the Pod template. */
|
|
77
|
+
const SQL_VOLUME_NAME = "sql";
|
|
78
|
+
/** Name of the `psql` container in the Pod template. */
|
|
79
|
+
const PSQL_CONTAINER_NAME = "psql";
|
|
80
|
+
/** Hex length of the checksum embedded in the Job name. */
|
|
81
|
+
const CHECKSUM_LENGTH = 8;
|
|
82
|
+
/**
|
|
83
|
+
* Effective max length for the Job name itself. Reserved below
|
|
84
|
+
* {@link DNS_1123_LABEL_MAX_LENGTH} by the length of {@link CONFIG_MAP_NAME_SUFFIX}
|
|
85
|
+
* so that `${jobName}${CONFIG_MAP_NAME_SUFFIX}` — the ConfigMap's name — is
|
|
86
|
+
* also a valid DNS-1123 label.
|
|
87
|
+
*/
|
|
88
|
+
const JOB_NAME_MAX_LENGTH = resource_identity_js_1.DNS_1123_LABEL_MAX_LENGTH - CONFIG_MAP_NAME_SUFFIX.length;
|
|
89
|
+
/**
|
|
90
|
+
* Derive the Job name: a sanitized, checksum-suffixed DNS-1123 label.
|
|
91
|
+
*
|
|
92
|
+
* The checksum is computed over `clusterName`, `databaseName`, `roleName`,
|
|
93
|
+
* and the compiled SQL — newline-joined in that fixed order — not over the
|
|
94
|
+
* SQL alone. `compileGrantSql`'s output encodes only role, owner, schema, and
|
|
95
|
+
* grants; it never encodes the database name. Hashing the SQL by itself would
|
|
96
|
+
* therefore let two different databases in the same cluster that happen to
|
|
97
|
+
* share a role name and identical grants (e.g. a `readonly` role repeated
|
|
98
|
+
* per-database) produce byte-identical SQL, and thus an identical checksum —
|
|
99
|
+
* and if the descriptive prefix is also truncated down to something
|
|
100
|
+
* indistinguishable between them (see below), the two would collide on the
|
|
101
|
+
* same Job name. Including the resource identity in the hash makes that
|
|
102
|
+
* collision impossible while preserving the property the checksum exists
|
|
103
|
+
* for: `clusterName`, `databaseName`, and `roleName` are stable for a given
|
|
104
|
+
* resource, so an unchanged grant spec (unchanged SQL) still yields an
|
|
105
|
+
* unchanged Job name and does not re-run, while a changed spec — anywhere in
|
|
106
|
+
* cluster, database, role, or SQL — always produces a different name and
|
|
107
|
+
* therefore a Job that actually runs.
|
|
108
|
+
*
|
|
109
|
+
* Cluster, database, and role names are user-controlled and unbounded in
|
|
110
|
+
* length, so the composed name is bounded by {@link toBoundedName}: when it
|
|
111
|
+
* would exceed {@link JOB_NAME_MAX_LENGTH} the descriptive head is truncated
|
|
112
|
+
* and a hash of the whole name — content checksum included — is appended, so
|
|
113
|
+
* two Jobs whose heads truncate alike still differ and a changed spec still
|
|
114
|
+
* yields a changed name.
|
|
115
|
+
*
|
|
116
|
+
* @param clusterName - CNPG cluster name
|
|
117
|
+
* @param databaseName - Database name
|
|
118
|
+
* @param roleName - Role name
|
|
119
|
+
* @param sql - Compiled SQL the Job will apply
|
|
120
|
+
* @returns A DNS-1123-label-safe Job name, at most {@link JOB_NAME_MAX_LENGTH} characters
|
|
121
|
+
*/
|
|
122
|
+
function deriveJobName(clusterName, databaseName, roleName, sql) {
|
|
123
|
+
const identity = [clusterName, databaseName, roleName, sql].join("\n");
|
|
124
|
+
const checksum = crypto
|
|
125
|
+
.createHash("sha256")
|
|
126
|
+
.update(identity)
|
|
127
|
+
.digest("hex")
|
|
128
|
+
.slice(0, CHECKSUM_LENGTH);
|
|
129
|
+
const descriptive = (0, resource_identity_js_1.toDnsSegment)(`${JOB_NAME_PREFIX}-${clusterName}-${databaseName}-${roleName}`);
|
|
130
|
+
return (0, resource_identity_js_1.toBoundedName)(`${descriptive}-${checksum}`, JOB_NAME_MAX_LENGTH);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create a Job that applies grants and extra SQL to a CNPG-managed database,
|
|
134
|
+
* or nothing at all when there is no SQL to run.
|
|
135
|
+
*
|
|
136
|
+
* The Job authenticates as `options.ownerName` using the password from
|
|
137
|
+
* `options.ownerSecretName`, and executes the compiled SQL with
|
|
138
|
+
* `psql -v ON_ERROR_STOP=1 -f <mounted file>` so a failing statement fails
|
|
139
|
+
* the Job instead of being silently skipped. The SQL itself is mounted from a
|
|
140
|
+
* ConfigMap — it never appears in `command`, so nothing derived from role,
|
|
141
|
+
* schema, or grant data is ever passed as a shell argument.
|
|
142
|
+
*
|
|
143
|
+
* The Job's name is derived from its content (cluster, database, role, and
|
|
144
|
+
* compiled SQL — see {@link deriveJobName}), so a Job that exhausts
|
|
145
|
+
* `backoffLimit` and permanently fails is **not** retried by a later
|
|
146
|
+
* `pulumi up` as long as the grant spec is unchanged: the same input still
|
|
147
|
+
* derives the same name, and Pulumi sees no diff against the existing
|
|
148
|
+
* (failed) Job. Recovering from a permanent failure requires deleting the
|
|
149
|
+
* failed Job manually (e.g. `kubectl delete job <name>`) before re-running
|
|
150
|
+
* Pulumi, so a new Job is created and actually runs.
|
|
151
|
+
*
|
|
152
|
+
* **Callers must serialize the Jobs they create for one database.** Every
|
|
153
|
+
* script revokes and re-grants across all of that database's schemas inside a
|
|
154
|
+
* single transaction, so two Jobs running concurrently against the same
|
|
155
|
+
* database contend for the same `pg_class`/`pg_namespace` rows and one can
|
|
156
|
+
* abort with `tuple concurrently updated`. Combined with the content-addressed
|
|
157
|
+
* name above, a transient collision that exhausts `backoffLimit` becomes a
|
|
158
|
+
* permanent, manually-recoverable failure. This function does not enforce the
|
|
159
|
+
* ordering itself — it has no view of the other Jobs — so the caller chains it,
|
|
160
|
+
* by passing the previously created Job for the same database in
|
|
161
|
+
* {@link IGrantJobOptions.dependsOn}. Jobs for *different* databases need no
|
|
162
|
+
* such chain: they are separate transactions on separate databases.
|
|
163
|
+
*
|
|
164
|
+
* @param options - Cluster, role, owner, grants, and dependencies
|
|
165
|
+
* @returns The Job, or `undefined` when privileges are unmanaged (`grants` is
|
|
166
|
+
* `undefined`) and there is no `extraSql`. An **empty** `grants` array still
|
|
167
|
+
* produces a Job — it means "this role should hold no privileges", and the
|
|
168
|
+
* compiled script revokes them.
|
|
169
|
+
* @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a grant lists a
|
|
170
|
+
* privilege {@link compileGrantSql} does not support
|
|
171
|
+
*/
|
|
172
|
+
function createPostgresGrantJob(options) {
|
|
173
|
+
const { grants, extraSql = [] } = options;
|
|
174
|
+
if (grants === undefined && extraSql.length === 0) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
const sql = (0, postgres_sql_js_1.compileGrantSql)({
|
|
178
|
+
role: options.roleName,
|
|
179
|
+
owner: options.ownerName,
|
|
180
|
+
grants: grants ?? [],
|
|
181
|
+
extraSql,
|
|
182
|
+
});
|
|
183
|
+
const jobName = deriveJobName(options.clusterName, options.databaseName, options.roleName, sql);
|
|
184
|
+
const configMapName = `${jobName}${CONFIG_MAP_NAME_SUFFIX}`;
|
|
185
|
+
const sqlConfigMap = new k8s.core.v1.ConfigMap(configMapName, {
|
|
186
|
+
metadata: {
|
|
187
|
+
name: configMapName,
|
|
188
|
+
namespace: options.namespace,
|
|
189
|
+
labels: options.labels,
|
|
190
|
+
},
|
|
191
|
+
data: { [SQL_CONFIG_MAP_KEY]: sql },
|
|
192
|
+
}, { provider: options.provider, dependsOn: options.dependsOn });
|
|
193
|
+
return new k8s.batch.v1.Job(jobName, {
|
|
194
|
+
metadata: {
|
|
195
|
+
name: jobName,
|
|
196
|
+
namespace: options.namespace,
|
|
197
|
+
labels: options.labels,
|
|
198
|
+
},
|
|
199
|
+
spec: {
|
|
200
|
+
ttlSecondsAfterFinished: JOB_TTL_SECONDS,
|
|
201
|
+
backoffLimit: JOB_BACKOFF_LIMIT,
|
|
202
|
+
template: {
|
|
203
|
+
metadata: { labels: options.labels },
|
|
204
|
+
spec: {
|
|
205
|
+
restartPolicy: "Never",
|
|
206
|
+
containers: [
|
|
207
|
+
{
|
|
208
|
+
name: PSQL_CONTAINER_NAME,
|
|
209
|
+
image: `${PG_IMAGE_REPO}:${options.pgVersion}`,
|
|
210
|
+
command: ["psql", "-v", "ON_ERROR_STOP=1", "-f", SQL_FILE_PATH],
|
|
211
|
+
env: [
|
|
212
|
+
{ name: "PGHOST", value: options.endpoint },
|
|
213
|
+
{ name: "PGDATABASE", value: options.databaseName },
|
|
214
|
+
{ name: "PGUSER", value: options.ownerName },
|
|
215
|
+
{
|
|
216
|
+
name: "PGPASSWORD",
|
|
217
|
+
valueFrom: {
|
|
218
|
+
secretKeyRef: { name: options.ownerSecretName, key: "password" },
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
{ name: "PGSSLMODE", value: "require" },
|
|
222
|
+
],
|
|
223
|
+
volumeMounts: [{ name: SQL_VOLUME_NAME, mountPath: SQL_MOUNT_PATH }],
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
volumes: [{ name: SQL_VOLUME_NAME, configMap: { name: configMapName } }],
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
}, { provider: options.provider, dependsOn: [...options.dependsOn, sqlConfigMap] });
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=postgres-job.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-job.js","sourceRoot":"","sources":["../../../../src/operator/grants/postgres-job.ts"],"names":[],"mappings":"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"}
|
|
@@ -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"}
|