@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,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Role attribute baseline and parsing for the `nimbus migrate` CNPG check.
|
|
4
|
+
*
|
|
5
|
+
* `DatabaseRole` adoption ALTERs an existing role to match the manifest,
|
|
6
|
+
* forcing attributes the manifest omits back to their defaults. nimbus's
|
|
7
|
+
* manifest sets only `login: true`, so every other attribute must already sit
|
|
8
|
+
* at the PostgreSQL default for adoption to be a no-op. This module parses the
|
|
9
|
+
* `pg_roles` query from `docs/cnpg-declarative-databases.md` (reused verbatim,
|
|
10
|
+
* see {@link ROLE_ATTRIBUTES_QUERY}) and flags rows that deviate.
|
|
11
|
+
*
|
|
12
|
+
* The baseline covers every attribute `DatabaseRole.spec` can express, not the
|
|
13
|
+
* subset that is easy to query. Checking fewer is the same false all-clear as
|
|
14
|
+
* skipping a row: `replication`, `validUntil` and `comment` were missing, so a
|
|
15
|
+
* role carrying `REPLICATION` or a finite `VALID UNTIL` was reported as sitting
|
|
16
|
+
* on the baseline and then had exactly that stripped on the first reconcile.
|
|
17
|
+
* Every field of the CRD's `spec` that maps onto a role attribute is read here;
|
|
18
|
+
* the ones that do not (`cluster`, `name`, `ensure`, `databaseRoleReclaimPolicy`,
|
|
19
|
+
* `clientCertificate`) name or govern the CR rather than the role, and
|
|
20
|
+
* `passwordSecret` carries the password migration re-applies deliberately.
|
|
21
|
+
*
|
|
22
|
+
* The query is run through {@link toJsonRowsQuery} rather than read as `psql`'s
|
|
23
|
+
* pipe-delimited output: a role name may contain a `|`, and psql escapes
|
|
24
|
+
* nothing, so such a row parsed as ten fields instead of nine and was discarded.
|
|
25
|
+
* The check then reported that every role matched the baseline while having
|
|
26
|
+
* skipped precisely the role whose attributes adoption would reset. Nothing is
|
|
27
|
+
* dropped now — a row that still cannot be read is returned as a warning.
|
|
28
|
+
*
|
|
29
|
+
* @module cli/migrate-cnpg-roles
|
|
30
|
+
*/
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.ROLE_ATTRIBUTES_JSON_QUERY = exports.ROLE_ATTRIBUTES_QUERY = exports.BUILTIN_ROLE_NAMES = void 0;
|
|
33
|
+
exports.parseRoleRows = parseRoleRows;
|
|
34
|
+
exports.roleMatchesBaseline = roleMatchesBaseline;
|
|
35
|
+
exports.describeRoleDeviation = describeRoleDeviation;
|
|
36
|
+
const migrate_psql_js_1 = require("./migrate-psql.js");
|
|
37
|
+
/**
|
|
38
|
+
* Operator-managed roles that intentionally do not follow the nimbus baseline
|
|
39
|
+
* (e.g. `postgres` is a superuser by definition). Excluded from role deviation
|
|
40
|
+
* reporting so the check only flags roles nimbus actually provisions.
|
|
41
|
+
*/
|
|
42
|
+
exports.BUILTIN_ROLE_NAMES = [
|
|
43
|
+
"postgres",
|
|
44
|
+
"streaming_replica",
|
|
45
|
+
"cnpg_pooler_pgbouncer",
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* `pg_roles` query from `docs/cnpg-declarative-databases.md`, reused verbatim so this
|
|
49
|
+
* check and the documented manual procedure never drift apart.
|
|
50
|
+
*/
|
|
51
|
+
exports.ROLE_ATTRIBUTES_QUERY = `SELECT r.rolname, r.rolcanlogin, r.rolsuper, r.rolcreatedb, r.rolcreaterole,
|
|
52
|
+
r.rolinherit, r.rolconnlimit, r.rolbypassrls, r.rolreplication, r.rolvaliduntil,
|
|
53
|
+
shobj_description(r.oid, 'pg_authid') AS rolcomment,
|
|
54
|
+
coalesce(array_agg(m.rolname) FILTER (WHERE m.rolname IS NOT NULL), '{}') AS memberof
|
|
55
|
+
FROM pg_roles r
|
|
56
|
+
LEFT JOIN pg_auth_members am ON am.member = r.oid
|
|
57
|
+
LEFT JOIN pg_roles m ON m.oid = am.roleid
|
|
58
|
+
WHERE r.rolname NOT LIKE 'pg\\_%'
|
|
59
|
+
GROUP BY 1,2,3,4,5,6,7,8,9,10,11 ORDER BY 1`;
|
|
60
|
+
/** {@link ROLE_ATTRIBUTES_QUERY} as the JSON document {@link parseRoleRows} reads. */
|
|
61
|
+
exports.ROLE_ATTRIBUTES_JSON_QUERY = (0, migrate_psql_js_1.toJsonRowsQuery)(exports.ROLE_ATTRIBUTES_QUERY);
|
|
62
|
+
/** What this query reads, named in warnings. */
|
|
63
|
+
const SUBJECT = "pg_roles";
|
|
64
|
+
/** Columns {@link ROLE_ATTRIBUTES_QUERY} returns, by the name `row_to_json` gives them. */
|
|
65
|
+
const ROLE_COLUMNS = {
|
|
66
|
+
NAME: "rolname",
|
|
67
|
+
CAN_LOGIN: "rolcanlogin",
|
|
68
|
+
IS_SUPERUSER: "rolsuper",
|
|
69
|
+
CAN_CREATE_DB: "rolcreatedb",
|
|
70
|
+
CAN_CREATE_ROLE: "rolcreaterole",
|
|
71
|
+
INHERITS: "rolinherit",
|
|
72
|
+
CONNECTION_LIMIT: "rolconnlimit",
|
|
73
|
+
BYPASSES_RLS: "rolbypassrls",
|
|
74
|
+
CAN_REPLICATE: "rolreplication",
|
|
75
|
+
VALID_UNTIL: "rolvaliduntil",
|
|
76
|
+
COMMENT: "rolcomment",
|
|
77
|
+
MEMBER_OF: "memberof",
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* PostgreSQL's other spelling of "this password never expires".
|
|
81
|
+
*
|
|
82
|
+
* `ALTER ROLE` cannot set `VALID UNTIL NULL`, so CNPG writes `infinity` when the
|
|
83
|
+
* manifest omits `validUntil`. A role already carrying `infinity` is therefore
|
|
84
|
+
* on the baseline just as surely as one carrying NULL.
|
|
85
|
+
*/
|
|
86
|
+
const INFINITE_VALID_UNTIL = "infinity";
|
|
87
|
+
/** How a password with no expiry is rendered in a deviation line. */
|
|
88
|
+
const NEVER_EXPIRES = "(never)";
|
|
89
|
+
/** How a role with no comment is rendered in a deviation line. */
|
|
90
|
+
const NO_COMMENT = "(none)";
|
|
91
|
+
/** Longest role comment echoed back in a deviation line. */
|
|
92
|
+
const MAX_COMMENT_LENGTH = 60;
|
|
93
|
+
/**
|
|
94
|
+
* The attribute set `DatabaseRole` adoption leaves untouched.
|
|
95
|
+
*
|
|
96
|
+
* Both the baseline check and the deviation message are derived from this one
|
|
97
|
+
* value, so the message can never describe a baseline the check does not apply.
|
|
98
|
+
*/
|
|
99
|
+
const BASELINE_ATTRIBUTES = {
|
|
100
|
+
canLogin: true,
|
|
101
|
+
isSuperuser: false,
|
|
102
|
+
canCreateDb: false,
|
|
103
|
+
canCreateRole: false,
|
|
104
|
+
inherits: true,
|
|
105
|
+
connectionLimit: -1,
|
|
106
|
+
bypassesRls: false,
|
|
107
|
+
canReplicate: false,
|
|
108
|
+
validUntil: null,
|
|
109
|
+
comment: null,
|
|
110
|
+
memberOf: [],
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Render a boolean back into psql's `t`/`f` notation for report output.
|
|
114
|
+
*
|
|
115
|
+
* @param value - Boolean to render
|
|
116
|
+
* @returns "t" or "f"
|
|
117
|
+
*/
|
|
118
|
+
function toPsqlBoolean(value) {
|
|
119
|
+
return value ? "t" : "f";
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Render role memberships the way psql prints a `text[]`, for report output.
|
|
123
|
+
*
|
|
124
|
+
* @param memberOf - Roles this role is a member of
|
|
125
|
+
* @returns The memberships in `{a,b}` form
|
|
126
|
+
*/
|
|
127
|
+
function toPsqlArray(memberOf) {
|
|
128
|
+
return `{${memberOf.join(",")}}`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Whether a role's password expiry is the one adoption would leave alone.
|
|
132
|
+
*
|
|
133
|
+
* @param validUntil - `rolvaliduntil`, or null for a SQL NULL
|
|
134
|
+
* @returns True when the password never expires
|
|
135
|
+
*/
|
|
136
|
+
function hasNoPasswordExpiry(validUntil) {
|
|
137
|
+
return validUntil === null || validUntil.trim().toLowerCase() === INFINITE_VALID_UNTIL;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Whether a role carries no comment for adoption to clear.
|
|
141
|
+
*
|
|
142
|
+
* An empty comment and no comment at all are indistinguishable to the operator,
|
|
143
|
+
* which reads both as the empty string, so both sit on the baseline.
|
|
144
|
+
*
|
|
145
|
+
* @param comment - `rolcomment`, or null for a SQL NULL
|
|
146
|
+
* @returns True when the role has nothing adoption would overwrite
|
|
147
|
+
*/
|
|
148
|
+
function hasNoComment(comment) {
|
|
149
|
+
return comment === null || comment === "";
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Render a password expiry for report output.
|
|
153
|
+
*
|
|
154
|
+
* A password that never expires reads as {@link NEVER_EXPIRES} whichever way
|
|
155
|
+
* PostgreSQL spells it, so a role on the baseline renders identically to the
|
|
156
|
+
* baseline rather than as a deviation with the same meaning.
|
|
157
|
+
*
|
|
158
|
+
* @param validUntil - `rolvaliduntil`, or null for a SQL NULL
|
|
159
|
+
* @returns The expiry, or a phrase saying there is none
|
|
160
|
+
*/
|
|
161
|
+
function toReportedValidUntil(validUntil) {
|
|
162
|
+
// The null test is redundant against hasNoPasswordExpiry and kept because it
|
|
163
|
+
// is what narrows the type of the value returned below.
|
|
164
|
+
if (validUntil === null || hasNoPasswordExpiry(validUntil)) {
|
|
165
|
+
return NEVER_EXPIRES;
|
|
166
|
+
}
|
|
167
|
+
return validUntil;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Render a role comment for report output.
|
|
171
|
+
*
|
|
172
|
+
* A comment is free text an operator wrote: it may be long and may contain
|
|
173
|
+
* newlines, and a deviation line is one line, so it is collapsed and truncated.
|
|
174
|
+
*
|
|
175
|
+
* @param comment - `rolcomment`, or null for a SQL NULL
|
|
176
|
+
* @returns The quoted comment, or a phrase saying there is none
|
|
177
|
+
*/
|
|
178
|
+
function toReportedComment(comment) {
|
|
179
|
+
if (comment === null || comment === "") {
|
|
180
|
+
return NO_COMMENT;
|
|
181
|
+
}
|
|
182
|
+
const oneLine = comment.replace(/\s+/g, " ").trim();
|
|
183
|
+
const shortened = oneLine.length > MAX_COMMENT_LENGTH ? `${oneLine.slice(0, MAX_COMMENT_LENGTH)}…` : oneLine;
|
|
184
|
+
return `"${shortened}"`;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Render one role's attributes in the compact form the report prints.
|
|
188
|
+
*
|
|
189
|
+
* @param attributes - A parsed role's attributes, or {@link BASELINE_ATTRIBUTES}
|
|
190
|
+
* @returns A single line of `key=value` pairs
|
|
191
|
+
*/
|
|
192
|
+
function describeAttributes(attributes) {
|
|
193
|
+
return (`login=${toPsqlBoolean(attributes.canLogin)} super=${toPsqlBoolean(attributes.isSuperuser)} ` +
|
|
194
|
+
`createdb=${toPsqlBoolean(attributes.canCreateDb)} ` +
|
|
195
|
+
`createrole=${toPsqlBoolean(attributes.canCreateRole)} ` +
|
|
196
|
+
`inherit=${toPsqlBoolean(attributes.inherits)} connlimit=${attributes.connectionLimit} ` +
|
|
197
|
+
`bypassrls=${toPsqlBoolean(attributes.bypassesRls)} ` +
|
|
198
|
+
`replication=${toPsqlBoolean(attributes.canReplicate)} ` +
|
|
199
|
+
`validuntil=${toReportedValidUntil(attributes.validUntil)} ` +
|
|
200
|
+
`comment=${toReportedComment(attributes.comment)} memberof=${toPsqlArray(attributes.memberOf)}`);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Name a row in a warning, using its role name when that much was readable.
|
|
204
|
+
*
|
|
205
|
+
* @param index - Zero-based position in the result
|
|
206
|
+
* @param name - Role name, when it could be read
|
|
207
|
+
* @returns A phrase identifying the row to an operator
|
|
208
|
+
*/
|
|
209
|
+
function describeRow(index, name) {
|
|
210
|
+
return name === undefined ? `${SUBJECT} row ${index + 1}` : `role "${name}"`;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Parse one row of {@link ROLE_ATTRIBUTES_QUERY}.
|
|
214
|
+
*
|
|
215
|
+
* @param row - One object from the query's JSON output
|
|
216
|
+
* @param index - Zero-based position in the result, for the warning
|
|
217
|
+
* @returns The parsed row, or a warning naming the row and its bad columns
|
|
218
|
+
*/
|
|
219
|
+
function parseRoleRow(row, index) {
|
|
220
|
+
const name = (0, migrate_psql_js_1.readString)(row, ROLE_COLUMNS.NAME);
|
|
221
|
+
const canLogin = (0, migrate_psql_js_1.readBoolean)(row, ROLE_COLUMNS.CAN_LOGIN);
|
|
222
|
+
const isSuperuser = (0, migrate_psql_js_1.readBoolean)(row, ROLE_COLUMNS.IS_SUPERUSER);
|
|
223
|
+
const canCreateDb = (0, migrate_psql_js_1.readBoolean)(row, ROLE_COLUMNS.CAN_CREATE_DB);
|
|
224
|
+
const canCreateRole = (0, migrate_psql_js_1.readBoolean)(row, ROLE_COLUMNS.CAN_CREATE_ROLE);
|
|
225
|
+
const inherits = (0, migrate_psql_js_1.readBoolean)(row, ROLE_COLUMNS.INHERITS);
|
|
226
|
+
const connectionLimit = (0, migrate_psql_js_1.readNumber)(row, ROLE_COLUMNS.CONNECTION_LIMIT);
|
|
227
|
+
const bypassesRls = (0, migrate_psql_js_1.readBoolean)(row, ROLE_COLUMNS.BYPASSES_RLS);
|
|
228
|
+
const canReplicate = (0, migrate_psql_js_1.readBoolean)(row, ROLE_COLUMNS.CAN_REPLICATE);
|
|
229
|
+
const validUntil = (0, migrate_psql_js_1.readNullableString)(row, ROLE_COLUMNS.VALID_UNTIL);
|
|
230
|
+
const comment = (0, migrate_psql_js_1.readNullableString)(row, ROLE_COLUMNS.COMMENT);
|
|
231
|
+
const memberOf = (0, migrate_psql_js_1.readStringArray)(row, ROLE_COLUMNS.MEMBER_OF);
|
|
232
|
+
const unreadable = [
|
|
233
|
+
[ROLE_COLUMNS.NAME, name],
|
|
234
|
+
[ROLE_COLUMNS.CAN_LOGIN, canLogin],
|
|
235
|
+
[ROLE_COLUMNS.IS_SUPERUSER, isSuperuser],
|
|
236
|
+
[ROLE_COLUMNS.CAN_CREATE_DB, canCreateDb],
|
|
237
|
+
[ROLE_COLUMNS.CAN_CREATE_ROLE, canCreateRole],
|
|
238
|
+
[ROLE_COLUMNS.INHERITS, inherits],
|
|
239
|
+
[ROLE_COLUMNS.CONNECTION_LIMIT, connectionLimit],
|
|
240
|
+
[ROLE_COLUMNS.BYPASSES_RLS, bypassesRls],
|
|
241
|
+
[ROLE_COLUMNS.CAN_REPLICATE, canReplicate],
|
|
242
|
+
[ROLE_COLUMNS.VALID_UNTIL, validUntil],
|
|
243
|
+
[ROLE_COLUMNS.COMMENT, comment],
|
|
244
|
+
[ROLE_COLUMNS.MEMBER_OF, memberOf],
|
|
245
|
+
];
|
|
246
|
+
if (name === undefined ||
|
|
247
|
+
canLogin === undefined ||
|
|
248
|
+
isSuperuser === undefined ||
|
|
249
|
+
canCreateDb === undefined ||
|
|
250
|
+
canCreateRole === undefined ||
|
|
251
|
+
inherits === undefined ||
|
|
252
|
+
connectionLimit === undefined ||
|
|
253
|
+
bypassesRls === undefined ||
|
|
254
|
+
canReplicate === undefined ||
|
|
255
|
+
validUntil === undefined ||
|
|
256
|
+
comment === undefined ||
|
|
257
|
+
memberOf === undefined) {
|
|
258
|
+
const columns = unreadable
|
|
259
|
+
.filter(([, value]) => value === undefined)
|
|
260
|
+
.map(([column]) => column)
|
|
261
|
+
.join(", ");
|
|
262
|
+
return {
|
|
263
|
+
warning: `${describeRow(index, name)}: could not read ${columns} from the ${SUBJECT} query ` +
|
|
264
|
+
"output, so this role was NOT checked against the adoption baseline.",
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
role: {
|
|
269
|
+
name,
|
|
270
|
+
canLogin,
|
|
271
|
+
isSuperuser,
|
|
272
|
+
canCreateDb,
|
|
273
|
+
canCreateRole,
|
|
274
|
+
inherits,
|
|
275
|
+
connectionLimit,
|
|
276
|
+
bypassesRls,
|
|
277
|
+
canReplicate,
|
|
278
|
+
validUntil,
|
|
279
|
+
comment,
|
|
280
|
+
memberOf,
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Parse every row returned by {@link ROLE_ATTRIBUTES_JSON_QUERY}.
|
|
286
|
+
*
|
|
287
|
+
* @param stdout - Raw `psql -tAc` output of the JSON-wrapped query
|
|
288
|
+
* @returns The roles that parsed, and a warning for every row that did not
|
|
289
|
+
*/
|
|
290
|
+
function parseRoleRows(stdout) {
|
|
291
|
+
const parsed = (0, migrate_psql_js_1.parseJsonRows)(stdout, SUBJECT);
|
|
292
|
+
const roles = [];
|
|
293
|
+
const warnings = [...parsed.warnings];
|
|
294
|
+
parsed.rows.forEach((row, index) => {
|
|
295
|
+
const outcome = parseRoleRow(row, index);
|
|
296
|
+
if ("role" in outcome) {
|
|
297
|
+
roles.push(outcome.role);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
warnings.push(outcome.warning);
|
|
301
|
+
});
|
|
302
|
+
return { roles, warnings };
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Whether `DatabaseRole` adoption would leave this role's attributes alone.
|
|
306
|
+
*
|
|
307
|
+
* Every attribute `DatabaseRole.spec` can express is compared, because adoption
|
|
308
|
+
* resets each one the manifest omits — checking a subset reports roles as safe
|
|
309
|
+
* that adoption is about to change. See {@link BASELINE_ATTRIBUTES}.
|
|
310
|
+
*
|
|
311
|
+
* @param role - Parsed role row
|
|
312
|
+
* @returns True when every attribute matches the baseline
|
|
313
|
+
*/
|
|
314
|
+
function roleMatchesBaseline(role) {
|
|
315
|
+
return (role.canLogin === BASELINE_ATTRIBUTES.canLogin &&
|
|
316
|
+
role.isSuperuser === BASELINE_ATTRIBUTES.isSuperuser &&
|
|
317
|
+
role.canCreateDb === BASELINE_ATTRIBUTES.canCreateDb &&
|
|
318
|
+
role.canCreateRole === BASELINE_ATTRIBUTES.canCreateRole &&
|
|
319
|
+
role.inherits === BASELINE_ATTRIBUTES.inherits &&
|
|
320
|
+
role.connectionLimit === BASELINE_ATTRIBUTES.connectionLimit &&
|
|
321
|
+
role.bypassesRls === BASELINE_ATTRIBUTES.bypassesRls &&
|
|
322
|
+
role.canReplicate === BASELINE_ATTRIBUTES.canReplicate &&
|
|
323
|
+
hasNoPasswordExpiry(role.validUntil) &&
|
|
324
|
+
hasNoComment(role.comment) &&
|
|
325
|
+
role.memberOf.length === 0);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Describe how a role's attributes deviate from the nimbus baseline, for report output.
|
|
329
|
+
*
|
|
330
|
+
* @param role - Parsed role row that failed {@link roleMatchesBaseline}
|
|
331
|
+
* @returns A one-line, human-readable description of the deviation
|
|
332
|
+
*/
|
|
333
|
+
function describeRoleDeviation(role) {
|
|
334
|
+
return (`role "${role.name}": ${describeAttributes(role)} ` +
|
|
335
|
+
`(baseline: ${describeAttributes(BASELINE_ATTRIBUTES)})`);
|
|
336
|
+
}
|
|
337
|
+
//# sourceMappingURL=migrate-cnpg-roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-cnpg-roles.js","sourceRoot":"","sources":["../../../src/cli/migrate-cnpg-roles.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AAqUH,sCAeC;AAYD,kDAcC;AAQD,sDAKC;AAzXD,uDAQ2B;AAE3B;;;;GAIG;AACU,QAAA,kBAAkB,GAAsB;IACnD,UAAU;IACV,mBAAmB;IACnB,uBAAuB;CACxB,CAAC;AAEF;;;GAGG;AACU,QAAA,qBAAqB,GAAG;;;;;;;;4CAQO,CAAC;AAE7C,sFAAsF;AACzE,QAAA,0BAA0B,GAAG,IAAA,iCAAe,EAAC,6BAAqB,CAAC,CAAC;AAEjF,gDAAgD;AAChD,MAAM,OAAO,GAAG,UAA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C;IAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,mBAAmB,CAAC,IAAoB;IACtD,OAAO,CACL,IAAI,CAAC,QAAQ,KAAK,mBAAmB,CAAC,QAAQ;QAC9C,IAAI,CAAC,WAAW,KAAK,mBAAmB,CAAC,WAAW;QACpD,IAAI,CAAC,WAAW,KAAK,mBAAmB,CAAC,WAAW;QACpD,IAAI,CAAC,aAAa,KAAK,mBAAmB,CAAC,aAAa;QACxD,IAAI,CAAC,QAAQ,KAAK,mBAAmB,CAAC,QAAQ;QAC9C,IAAI,CAAC,eAAe,KAAK,mBAAmB,CAAC,eAAe;QAC5D,IAAI,CAAC,WAAW,KAAK,mBAAmB,CAAC,WAAW;QACpD,IAAI,CAAC,YAAY,KAAK,mBAAmB,CAAC,YAAY;QACtD,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC;QACpC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAC3B,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,IAAoB;IACxD,OAAO,CACL,SAAS,IAAI,CAAC,IAAI,MAAM,kBAAkB,CAAC,IAAI,CAAC,GAAG;QACnD,cAAc,kBAAkB,CAAC,mBAAmB,CAAC,GAAG,CACzD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CNPG-specific checks for `nimbus migrate`: CRD presence, role attributes,
|
|
3
|
+
* and database ownership.
|
|
4
|
+
*
|
|
5
|
+
* @module cli/migrate-cnpg
|
|
6
|
+
*/
|
|
7
|
+
import type { ISectionResult } from "./migrate-report.js";
|
|
8
|
+
/** CRD name backing the `Database` custom resource. */
|
|
9
|
+
export declare const CNPG_DATABASE_CRD_NAME = "databases.postgresql.cnpg.io";
|
|
10
|
+
/** CRD name backing the `DatabaseRole` custom resource. */
|
|
11
|
+
export declare const CNPG_DATABASE_ROLE_CRD_NAME = "databaseroles.postgresql.cnpg.io";
|
|
12
|
+
/** Outcome of {@link checkCnpgCrds}. */
|
|
13
|
+
export interface ICrdCheckOutcome {
|
|
14
|
+
readonly section: ISectionResult;
|
|
15
|
+
readonly clusterReachable: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check that both CNPG CRDs required by the declarative path exist.
|
|
19
|
+
*
|
|
20
|
+
* @returns The section result plus whether the cluster was reachable, so
|
|
21
|
+
* downstream checks know whether to attempt a `kubectl exec`
|
|
22
|
+
*/
|
|
23
|
+
export declare function checkCnpgCrds(): ICrdCheckOutcome;
|
|
24
|
+
/** Role attribute and database ownership section results for one migrate run. */
|
|
25
|
+
export interface IClusterSections {
|
|
26
|
+
readonly roleSection: ISectionResult;
|
|
27
|
+
readonly ownershipSection: ISectionResult;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Check every nimbus-managed CNPG cluster's role attributes and database
|
|
31
|
+
* ownership against the baseline that makes `Database`/`DatabaseRole`
|
|
32
|
+
* adoption a no-op.
|
|
33
|
+
*
|
|
34
|
+
* @param clusterReachable - Whether {@link checkCnpgCrds} could reach the cluster
|
|
35
|
+
* @returns Section results for role attributes and database ownership
|
|
36
|
+
*/
|
|
37
|
+
export declare function checkClusterState(clusterReachable: boolean): IClusterSections;
|
|
38
|
+
//# sourceMappingURL=migrate-cnpg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-cnpg.d.ts","sourceRoot":"","sources":["../../../src/cli/migrate-cnpg.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAc1D,uDAAuD;AACvD,eAAO,MAAM,sBAAsB,iCAAiC,CAAC;AACrE,2DAA2D;AAC3D,eAAO,MAAM,2BAA2B,qCAAqC,CAAC;AAE9E,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACpC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,gBAAgB,CA0DhD;AA4DD,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;IACrC,QAAQ,CAAC,gBAAgB,EAAE,cAAc,CAAC;CAC3C;AAkBD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,GAAG,gBAAgB,CA6H7E"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CNPG-specific checks for `nimbus migrate`: CRD presence, role attributes,
|
|
4
|
+
* and database ownership.
|
|
5
|
+
*
|
|
6
|
+
* @module cli/migrate-cnpg
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CNPG_DATABASE_ROLE_CRD_NAME = exports.CNPG_DATABASE_CRD_NAME = void 0;
|
|
10
|
+
exports.checkCnpgCrds = checkCnpgCrds;
|
|
11
|
+
exports.checkClusterState = checkClusterState;
|
|
12
|
+
const cnpg_common_js_1 = require("../operator/cnpg-common.js");
|
|
13
|
+
const migrate_exec_js_1 = require("./migrate-exec.js");
|
|
14
|
+
const migrate_report_js_1 = require("./migrate-report.js");
|
|
15
|
+
const migrate_cnpg_roles_js_1 = require("./migrate-cnpg-roles.js");
|
|
16
|
+
const migrate_cnpg_ownership_js_1 = require("./migrate-cnpg-ownership.js");
|
|
17
|
+
/** CRD name backing the `Database` custom resource. */
|
|
18
|
+
exports.CNPG_DATABASE_CRD_NAME = "databases.postgresql.cnpg.io";
|
|
19
|
+
/** CRD name backing the `DatabaseRole` custom resource. */
|
|
20
|
+
exports.CNPG_DATABASE_ROLE_CRD_NAME = "databaseroles.postgresql.cnpg.io";
|
|
21
|
+
/**
|
|
22
|
+
* Check that both CNPG CRDs required by the declarative path exist.
|
|
23
|
+
*
|
|
24
|
+
* @returns The section result plus whether the cluster was reachable, so
|
|
25
|
+
* downstream checks know whether to attempt a `kubectl exec`
|
|
26
|
+
*/
|
|
27
|
+
function checkCnpgCrds() {
|
|
28
|
+
const result = (0, migrate_exec_js_1.runCommand)("kubectl", [
|
|
29
|
+
"get",
|
|
30
|
+
"crd",
|
|
31
|
+
exports.CNPG_DATABASE_CRD_NAME,
|
|
32
|
+
exports.CNPG_DATABASE_ROLE_CRD_NAME,
|
|
33
|
+
"-o",
|
|
34
|
+
"name",
|
|
35
|
+
]);
|
|
36
|
+
if (result.ok) {
|
|
37
|
+
return {
|
|
38
|
+
section: {
|
|
39
|
+
status: migrate_report_js_1.CHECK_STATUS.PASS,
|
|
40
|
+
lines: [`Found ${exports.CNPG_DATABASE_CRD_NAME} and ${exports.CNPG_DATABASE_ROLE_CRD_NAME}.`],
|
|
41
|
+
},
|
|
42
|
+
clusterReachable: true,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (result.reason === "not-found") {
|
|
46
|
+
return {
|
|
47
|
+
section: {
|
|
48
|
+
status: migrate_report_js_1.CHECK_STATUS.WARN,
|
|
49
|
+
lines: [
|
|
50
|
+
`"kubectl" was not found on PATH. Install kubectl and re-run this check.`,
|
|
51
|
+
"Role attribute and database ownership checks below are skipped as a result.",
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
clusterReachable: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (/notfound/i.test(result.message)) {
|
|
58
|
+
return {
|
|
59
|
+
section: {
|
|
60
|
+
status: migrate_report_js_1.CHECK_STATUS.FAIL,
|
|
61
|
+
lines: [
|
|
62
|
+
`Missing one or both CRDs: ${exports.CNPG_DATABASE_CRD_NAME}, ${exports.CNPG_DATABASE_ROLE_CRD_NAME}.`,
|
|
63
|
+
"The declarative Database/DatabaseRole path requires CloudNativePG 1.30 or newer.",
|
|
64
|
+
"Upgrade the CNPG operator before adopting this release.",
|
|
65
|
+
result.message,
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
clusterReachable: false,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
section: {
|
|
73
|
+
status: migrate_report_js_1.CHECK_STATUS.WARN,
|
|
74
|
+
lines: [
|
|
75
|
+
`Could not reach the cluster to verify CRDs: ${result.message}`,
|
|
76
|
+
"Role attribute and database ownership checks below are skipped as a result.",
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
clusterReachable: false,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* List CNPG cluster names in the namespace nimbus always deploys to.
|
|
84
|
+
*
|
|
85
|
+
* @returns Cluster names on success, or a failure with an explanatory message
|
|
86
|
+
*/
|
|
87
|
+
function listCnpgClusters() {
|
|
88
|
+
const result = (0, migrate_exec_js_1.runCommand)("kubectl", [
|
|
89
|
+
"get",
|
|
90
|
+
"clusters.postgresql.cnpg.io",
|
|
91
|
+
"-n",
|
|
92
|
+
cnpg_common_js_1.DATA_NAMESPACE,
|
|
93
|
+
"-o",
|
|
94
|
+
"jsonpath={.items[*].metadata.name}",
|
|
95
|
+
]);
|
|
96
|
+
if (!result.ok) {
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
const names = result.stdout
|
|
100
|
+
.trim()
|
|
101
|
+
.split(/\s+/)
|
|
102
|
+
.filter((name) => name.length > 0);
|
|
103
|
+
return { ok: true, names };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Resolve the primary instance's pod name for a CNPG cluster, so queries run
|
|
107
|
+
* against a writable connection. Falls back to the conventional `<cluster>-1`
|
|
108
|
+
* pod name (used by every nimbus-provisioned cluster's first instance) when
|
|
109
|
+
* the cluster's status has not reported a primary yet.
|
|
110
|
+
*
|
|
111
|
+
* @param clusterName - CNPG `Cluster` object name
|
|
112
|
+
* @returns The pod name to `kubectl exec` into
|
|
113
|
+
*/
|
|
114
|
+
function resolvePrimaryPod(clusterName) {
|
|
115
|
+
const result = (0, migrate_exec_js_1.runCommand)("kubectl", [
|
|
116
|
+
"get",
|
|
117
|
+
"cluster.postgresql.cnpg.io",
|
|
118
|
+
clusterName,
|
|
119
|
+
"-n",
|
|
120
|
+
cnpg_common_js_1.DATA_NAMESPACE,
|
|
121
|
+
"-o",
|
|
122
|
+
"jsonpath={.status.currentPrimary}",
|
|
123
|
+
]);
|
|
124
|
+
const primary = result.ok ? result.stdout.trim() : "";
|
|
125
|
+
return primary.length > 0 ? primary : `${clusterName}-1`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Run a read-only `psql -tAc` query inside a cluster's primary pod via `kubectl exec`.
|
|
129
|
+
*
|
|
130
|
+
* @param pod - Pod name to exec into
|
|
131
|
+
* @param query - SQL query text (never built from unsanitised input)
|
|
132
|
+
* @returns The query's unaligned, tuples-only output on success
|
|
133
|
+
*/
|
|
134
|
+
function runPsqlQuery(pod, query) {
|
|
135
|
+
return (0, migrate_exec_js_1.runCommand)("kubectl", ["exec", "-n", cnpg_common_js_1.DATA_NAMESPACE, pod, "--", "psql", "-tAc", query]);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Build a matching WARN result for both cluster-dependent sections, used when
|
|
139
|
+
* they must be skipped for the same reason (kubectl missing, cluster
|
|
140
|
+
* unreachable, or no clusters found).
|
|
141
|
+
*
|
|
142
|
+
* @param reason - Human-readable explanation shown in both sections
|
|
143
|
+
* @returns Identical WARN results for the role and ownership sections
|
|
144
|
+
*/
|
|
145
|
+
function skippedClusterSections(reason) {
|
|
146
|
+
const lines = [reason];
|
|
147
|
+
return {
|
|
148
|
+
roleSection: { status: migrate_report_js_1.CHECK_STATUS.WARN, lines },
|
|
149
|
+
ownershipSection: { status: migrate_report_js_1.CHECK_STATUS.WARN, lines },
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check every nimbus-managed CNPG cluster's role attributes and database
|
|
154
|
+
* ownership against the baseline that makes `Database`/`DatabaseRole`
|
|
155
|
+
* adoption a no-op.
|
|
156
|
+
*
|
|
157
|
+
* @param clusterReachable - Whether {@link checkCnpgCrds} could reach the cluster
|
|
158
|
+
* @returns Section results for role attributes and database ownership
|
|
159
|
+
*/
|
|
160
|
+
function checkClusterState(clusterReachable) {
|
|
161
|
+
if (!clusterReachable) {
|
|
162
|
+
return skippedClusterSections("Skipped: could not reach the cluster to verify CRDs (see check 1 above).");
|
|
163
|
+
}
|
|
164
|
+
const discovery = listCnpgClusters();
|
|
165
|
+
if (!discovery.ok) {
|
|
166
|
+
return skippedClusterSections(`Skipped: could not list CloudNativePG clusters in namespace "${cnpg_common_js_1.DATA_NAMESPACE}": ${discovery.message}`);
|
|
167
|
+
}
|
|
168
|
+
const clusterNames = discovery.names;
|
|
169
|
+
if (clusterNames.length === 0) {
|
|
170
|
+
return skippedClusterSections(`No CloudNativePG clusters found in namespace "${cnpg_common_js_1.DATA_NAMESPACE}". ` +
|
|
171
|
+
"If you expected clusters here, verify your kubectl context.");
|
|
172
|
+
}
|
|
173
|
+
const roleLines = [];
|
|
174
|
+
const ownershipLines = [];
|
|
175
|
+
let roleDeviationCount = 0;
|
|
176
|
+
let ownershipMismatchCount = 0;
|
|
177
|
+
let rolesChecked = 0;
|
|
178
|
+
let databasesChecked = 0;
|
|
179
|
+
let roleCheckIncomplete = false;
|
|
180
|
+
let ownershipCheckIncomplete = false;
|
|
181
|
+
for (const clusterName of clusterNames) {
|
|
182
|
+
const pod = resolvePrimaryPod(clusterName);
|
|
183
|
+
const roleResult = runPsqlQuery(pod, migrate_cnpg_roles_js_1.ROLE_ATTRIBUTES_JSON_QUERY);
|
|
184
|
+
if (!roleResult.ok) {
|
|
185
|
+
roleCheckIncomplete = true;
|
|
186
|
+
roleLines.push(`cluster "${clusterName}": could not query pg_roles on pod "${pod}": ${roleResult.message}`);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
const parsed = (0, migrate_cnpg_roles_js_1.parseRoleRows)(roleResult.stdout);
|
|
190
|
+
// A row that could not be parsed is a role this check did NOT inspect, so
|
|
191
|
+
// it downgrades the section rather than shrinking the set it claims to
|
|
192
|
+
// have covered. Reporting "all roles match" while having skipped one is
|
|
193
|
+
// the failure mode this whole command exists to prevent.
|
|
194
|
+
for (const warning of parsed.warnings) {
|
|
195
|
+
roleCheckIncomplete = true;
|
|
196
|
+
roleLines.push(`cluster "${clusterName}": ${warning}`);
|
|
197
|
+
}
|
|
198
|
+
const roles = parsed.roles.filter((role) => !migrate_cnpg_roles_js_1.BUILTIN_ROLE_NAMES.includes(role.name));
|
|
199
|
+
rolesChecked += roles.length;
|
|
200
|
+
for (const role of roles) {
|
|
201
|
+
if (!(0, migrate_cnpg_roles_js_1.roleMatchesBaseline)(role)) {
|
|
202
|
+
roleDeviationCount += 1;
|
|
203
|
+
roleLines.push(`cluster "${clusterName}": ${(0, migrate_cnpg_roles_js_1.describeRoleDeviation)(role)}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const ownershipResult = runPsqlQuery(pod, migrate_cnpg_ownership_js_1.DATABASE_OWNERSHIP_JSON_QUERY);
|
|
208
|
+
if (!ownershipResult.ok) {
|
|
209
|
+
ownershipCheckIncomplete = true;
|
|
210
|
+
ownershipLines.push(`cluster "${clusterName}": could not query pg_database on pod "${pod}": ${ownershipResult.message}`);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
const parsed = (0, migrate_cnpg_ownership_js_1.parseDatabaseRows)(ownershipResult.stdout);
|
|
214
|
+
for (const warning of parsed.warnings) {
|
|
215
|
+
ownershipCheckIncomplete = true;
|
|
216
|
+
ownershipLines.push(`cluster "${clusterName}": ${warning}`);
|
|
217
|
+
}
|
|
218
|
+
const databases = parsed.databases.filter((database) => !migrate_cnpg_ownership_js_1.SYSTEM_DATABASE_NAMES.includes(database.name));
|
|
219
|
+
databasesChecked += databases.length;
|
|
220
|
+
for (const database of databases) {
|
|
221
|
+
if (database.owner !== database.name) {
|
|
222
|
+
ownershipMismatchCount += 1;
|
|
223
|
+
ownershipLines.push(`cluster "${clusterName}": database "${database.name}" is owned by role "${database.owner}" ` +
|
|
224
|
+
`— confirm this matches the "owner" set for this database in your Pulumi config.`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (roleDeviationCount === 0 && !roleCheckIncomplete) {
|
|
230
|
+
roleLines.unshift(`Checked ${rolesChecked} role(s) across ${clusterNames.length} cluster(s); all match the nimbus baseline.`);
|
|
231
|
+
}
|
|
232
|
+
else if (roleDeviationCount > 0) {
|
|
233
|
+
roleLines.unshift(`${roleDeviationCount} role(s) deviate from the nimbus baseline. DatabaseRole adoption ` +
|
|
234
|
+
"forces attributes the manifest omits back to this baseline, so any hand-granted " +
|
|
235
|
+
"privilege or membership listed below would be silently revoked.");
|
|
236
|
+
}
|
|
237
|
+
if (ownershipMismatchCount === 0 && !ownershipCheckIncomplete) {
|
|
238
|
+
ownershipLines.unshift(`Checked ${databasesChecked} database(s) across ${clusterNames.length} cluster(s); ` +
|
|
239
|
+
"ownership matches the nimbus naming convention.");
|
|
240
|
+
}
|
|
241
|
+
else if (ownershipMismatchCount > 0) {
|
|
242
|
+
ownershipLines.unshift(`${ownershipMismatchCount} database(s) have an owner that does not match the nimbus default ` +
|
|
243
|
+
"naming convention (owner name equal to database name).");
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
roleSection: {
|
|
247
|
+
status: roleDeviationCount > 0 || roleCheckIncomplete ? migrate_report_js_1.CHECK_STATUS.WARN : migrate_report_js_1.CHECK_STATUS.PASS,
|
|
248
|
+
lines: roleLines,
|
|
249
|
+
},
|
|
250
|
+
ownershipSection: {
|
|
251
|
+
status: ownershipMismatchCount > 0 || ownershipCheckIncomplete
|
|
252
|
+
? migrate_report_js_1.CHECK_STATUS.WARN
|
|
253
|
+
: migrate_report_js_1.CHECK_STATUS.PASS,
|
|
254
|
+
lines: ownershipLines,
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=migrate-cnpg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-cnpg.js","sourceRoot":"","sources":["../../../src/cli/migrate-cnpg.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAqCH,sCA0DC;AA0FD,8CA6HC;AApTD,+DAA4D;AAE5D,uDAA+C;AAC/C,2DAAmD;AAEnD,mEAMiC;AACjC,2EAIqC;AAErC,uDAAuD;AAC1C,QAAA,sBAAsB,GAAG,8BAA8B,CAAC;AACrE,2DAA2D;AAC9C,QAAA,2BAA2B,GAAG,kCAAkC,CAAC;AAQ9E;;;;;GAKG;AACH,SAAgB,aAAa;IAC3B,MAAM,MAAM,GAAG,IAAA,4BAAU,EAAC,SAAS,EAAE;QACnC,KAAK;QACL,KAAK;QACL,8BAAsB;QACtB,mCAA2B;QAC3B,IAAI;QACJ,MAAM;KACP,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,OAAO;YACL,OAAO,EAAE;gBACP,MAAM,EAAE,gCAAY,CAAC,IAAI;gBACzB,KAAK,EAAE,CAAC,SAAS,8BAAsB,QAAQ,mCAA2B,GAAG,CAAC;aAC/E;YACD,gBAAgB,EAAE,IAAI;SACvB,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO;YACL,OAAO,EAAE;gBACP,MAAM,EAAE,gCAAY,CAAC,IAAI;gBACzB,KAAK,EAAE;oBACL,yEAAyE;oBACzE,6EAA6E;iBAC9E;aACF;YACD,gBAAgB,EAAE,KAAK;SACxB,CAAC;IACJ,CAAC;IAED,IAAI,WAAW,CA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