@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.
Files changed (276) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/backup/index.d.ts.map +1 -1
  3. package/dist/cjs/backup/index.js +6 -1
  4. package/dist/cjs/backup/index.js.map +1 -1
  5. package/dist/cjs/cli/migrate-cnpg-ownership.d.ts +43 -0
  6. package/dist/cjs/cli/migrate-cnpg-ownership.d.ts.map +1 -0
  7. package/dist/cjs/cli/migrate-cnpg-ownership.js +67 -0
  8. package/dist/cjs/cli/migrate-cnpg-ownership.js.map +1 -0
  9. package/dist/cjs/cli/migrate-cnpg-roles.d.ts +92 -0
  10. package/dist/cjs/cli/migrate-cnpg-roles.d.ts.map +1 -0
  11. package/dist/cjs/cli/migrate-cnpg-roles.js +337 -0
  12. package/dist/cjs/cli/migrate-cnpg-roles.js.map +1 -0
  13. package/dist/cjs/cli/migrate-cnpg.d.ts +38 -0
  14. package/dist/cjs/cli/migrate-cnpg.d.ts.map +1 -0
  15. package/dist/cjs/cli/migrate-cnpg.js +258 -0
  16. package/dist/cjs/cli/migrate-cnpg.js.map +1 -0
  17. package/dist/cjs/cli/migrate-exec.d.ts +45 -0
  18. package/dist/cjs/cli/migrate-exec.d.ts.map +1 -0
  19. package/dist/cjs/cli/migrate-exec.js +104 -0
  20. package/dist/cjs/cli/migrate-exec.js.map +1 -0
  21. package/dist/cjs/cli/migrate-psql.d.ts +125 -0
  22. package/dist/cjs/cli/migrate-psql.d.ts.map +1 -0
  23. package/dist/cjs/cli/migrate-psql.js +213 -0
  24. package/dist/cjs/cli/migrate-psql.js.map +1 -0
  25. package/dist/cjs/cli/migrate-report.d.ts +27 -0
  26. package/dist/cjs/cli/migrate-report.d.ts.map +1 -0
  27. package/dist/cjs/cli/migrate-report.js +29 -0
  28. package/dist/cjs/cli/migrate-report.js.map +1 -0
  29. package/dist/cjs/cli/migrate-superuser.d.ts +22 -0
  30. package/dist/cjs/cli/migrate-superuser.d.ts.map +1 -0
  31. package/dist/cjs/cli/migrate-superuser.js +73 -0
  32. package/dist/cjs/cli/migrate-superuser.js.map +1 -0
  33. package/dist/cjs/cli/migrate.d.ts +37 -0
  34. package/dist/cjs/cli/migrate.d.ts.map +1 -0
  35. package/dist/cjs/cli/migrate.js +67 -0
  36. package/dist/cjs/cli/migrate.js.map +1 -0
  37. package/dist/cjs/cli.d.ts +1 -0
  38. package/dist/cjs/cli.d.ts.map +1 -1
  39. package/dist/cjs/cli.js +6 -0
  40. package/dist/cjs/cli.js.map +1 -1
  41. package/dist/cjs/index.d.ts +1 -1
  42. package/dist/cjs/index.d.ts.map +1 -1
  43. package/dist/cjs/index.js.map +1 -1
  44. package/dist/cjs/operator/cnpg-common.d.ts +56 -0
  45. package/dist/cjs/operator/cnpg-common.d.ts.map +1 -0
  46. package/dist/cjs/operator/cnpg-common.js +82 -0
  47. package/dist/cjs/operator/cnpg-common.js.map +1 -0
  48. package/dist/cjs/operator/cnpg-database.d.ts +66 -0
  49. package/dist/cjs/operator/cnpg-database.d.ts.map +1 -0
  50. package/dist/cjs/operator/cnpg-database.js +296 -0
  51. package/dist/cjs/operator/cnpg-database.js.map +1 -0
  52. package/dist/cjs/operator/cnpg-roles.d.ts +173 -0
  53. package/dist/cjs/operator/cnpg-roles.d.ts.map +1 -0
  54. package/dist/cjs/operator/cnpg-roles.js +225 -0
  55. package/dist/cjs/operator/cnpg-roles.js.map +1 -0
  56. package/dist/cjs/operator/cnpg.d.ts.map +1 -1
  57. package/dist/cjs/operator/cnpg.js +50 -162
  58. package/dist/cjs/operator/cnpg.js.map +1 -1
  59. package/dist/cjs/operator/connection-uri.d.ts +44 -0
  60. package/dist/cjs/operator/connection-uri.d.ts.map +1 -0
  61. package/dist/cjs/operator/connection-uri.js +49 -0
  62. package/dist/cjs/operator/connection-uri.js.map +1 -0
  63. package/dist/cjs/operator/credentials.d.ts +76 -0
  64. package/dist/cjs/operator/credentials.d.ts.map +1 -0
  65. package/dist/cjs/operator/credentials.js +106 -0
  66. package/dist/cjs/operator/credentials.js.map +1 -0
  67. package/dist/cjs/operator/database-options.d.ts +121 -0
  68. package/dist/cjs/operator/database-options.d.ts.map +1 -0
  69. package/dist/cjs/operator/database-options.js +131 -0
  70. package/dist/cjs/operator/database-options.js.map +1 -0
  71. package/dist/cjs/operator/grants/postgres-job.d.ts +109 -0
  72. package/dist/cjs/operator/grants/postgres-job.d.ts.map +1 -0
  73. package/dist/cjs/operator/grants/postgres-job.js +232 -0
  74. package/dist/cjs/operator/grants/postgres-job.js.map +1 -0
  75. package/dist/cjs/operator/grants/postgres-sql.d.ts +130 -0
  76. package/dist/cjs/operator/grants/postgres-sql.d.ts.map +1 -0
  77. package/dist/cjs/operator/grants/postgres-sql.js +305 -0
  78. package/dist/cjs/operator/grants/postgres-sql.js.map +1 -0
  79. package/dist/cjs/operator/grants/privileges.d.ts +24 -0
  80. package/dist/cjs/operator/grants/privileges.d.ts.map +1 -0
  81. package/dist/cjs/operator/grants/privileges.js +35 -0
  82. package/dist/cjs/operator/grants/privileges.js.map +1 -0
  83. package/dist/cjs/operator/grants/role-config.d.ts +80 -0
  84. package/dist/cjs/operator/grants/role-config.d.ts.map +1 -0
  85. package/dist/cjs/operator/grants/role-config.js +134 -0
  86. package/dist/cjs/operator/grants/role-config.js.map +1 -0
  87. package/dist/cjs/operator/index.d.ts +1 -1
  88. package/dist/cjs/operator/index.d.ts.map +1 -1
  89. package/dist/cjs/operator/index.js.map +1 -1
  90. package/dist/cjs/operator/interfaces.d.ts +223 -1
  91. package/dist/cjs/operator/interfaces.d.ts.map +1 -1
  92. package/dist/cjs/operator/interfaces.js.map +1 -1
  93. package/dist/cjs/operator/mariadb-common.d.ts +99 -0
  94. package/dist/cjs/operator/mariadb-common.d.ts.map +1 -0
  95. package/dist/cjs/operator/mariadb-common.js +141 -0
  96. package/dist/cjs/operator/mariadb-common.js.map +1 -0
  97. package/dist/cjs/operator/mariadb-database.d.ts +65 -0
  98. package/dist/cjs/operator/mariadb-database.d.ts.map +1 -0
  99. package/dist/cjs/operator/mariadb-database.js +285 -0
  100. package/dist/cjs/operator/mariadb-database.js.map +1 -0
  101. package/dist/cjs/operator/mariadb-roles.d.ts +264 -0
  102. package/dist/cjs/operator/mariadb-roles.d.ts.map +1 -0
  103. package/dist/cjs/operator/mariadb-roles.js +366 -0
  104. package/dist/cjs/operator/mariadb-roles.js.map +1 -0
  105. package/dist/cjs/operator/mariadb.d.ts.map +1 -1
  106. package/dist/cjs/operator/mariadb.js +35 -147
  107. package/dist/cjs/operator/mariadb.js.map +1 -1
  108. package/dist/cjs/operator/neo4j-common.d.ts +62 -0
  109. package/dist/cjs/operator/neo4j-common.d.ts.map +1 -0
  110. package/dist/cjs/operator/neo4j-common.js +89 -0
  111. package/dist/cjs/operator/neo4j-common.js.map +1 -0
  112. package/dist/cjs/operator/neo4j-database.d.ts +88 -0
  113. package/dist/cjs/operator/neo4j-database.d.ts.map +1 -0
  114. package/dist/cjs/operator/neo4j-database.js +274 -0
  115. package/dist/cjs/operator/neo4j-database.js.map +1 -0
  116. package/dist/cjs/operator/neo4j-roles.d.ts +203 -0
  117. package/dist/cjs/operator/neo4j-roles.d.ts.map +1 -0
  118. package/dist/cjs/operator/neo4j-roles.js +298 -0
  119. package/dist/cjs/operator/neo4j-roles.js.map +1 -0
  120. package/dist/cjs/operator/neo4j.d.ts.map +1 -1
  121. package/dist/cjs/operator/neo4j.js +32 -132
  122. package/dist/cjs/operator/neo4j.js.map +1 -1
  123. package/dist/cjs/operator/resource-identity.d.ts +170 -0
  124. package/dist/cjs/operator/resource-identity.d.ts.map +1 -0
  125. package/dist/cjs/operator/resource-identity.js +231 -0
  126. package/dist/cjs/operator/resource-identity.js.map +1 -0
  127. package/dist/cjs/operator/role-registry.d.ts +85 -0
  128. package/dist/cjs/operator/role-registry.d.ts.map +1 -0
  129. package/dist/cjs/operator/role-registry.js +72 -0
  130. package/dist/cjs/operator/role-registry.js.map +1 -0
  131. package/dist/cjs/platform/components/image-pruner.d.ts +3 -1
  132. package/dist/cjs/platform/components/image-pruner.d.ts.map +1 -1
  133. package/dist/cjs/platform/components/image-pruner.js +38 -19
  134. package/dist/cjs/platform/components/image-pruner.js.map +1 -1
  135. package/dist/cjs/types/errors.d.ts +3 -0
  136. package/dist/cjs/types/errors.d.ts.map +1 -1
  137. package/dist/cjs/types/errors.js +3 -0
  138. package/dist/cjs/types/errors.js.map +1 -1
  139. package/dist/esm/backup/index.d.ts.map +1 -1
  140. package/dist/esm/backup/index.js +6 -1
  141. package/dist/esm/backup/index.js.map +1 -1
  142. package/dist/esm/cli/migrate-cnpg-ownership.d.ts +43 -0
  143. package/dist/esm/cli/migrate-cnpg-ownership.d.ts.map +1 -0
  144. package/dist/esm/cli/migrate-cnpg-ownership.js +67 -0
  145. package/dist/esm/cli/migrate-cnpg-ownership.js.map +1 -0
  146. package/dist/esm/cli/migrate-cnpg-roles.d.ts +92 -0
  147. package/dist/esm/cli/migrate-cnpg-roles.d.ts.map +1 -0
  148. package/dist/esm/cli/migrate-cnpg-roles.js +337 -0
  149. package/dist/esm/cli/migrate-cnpg-roles.js.map +1 -0
  150. package/dist/esm/cli/migrate-cnpg.d.ts +38 -0
  151. package/dist/esm/cli/migrate-cnpg.d.ts.map +1 -0
  152. package/dist/esm/cli/migrate-cnpg.js +258 -0
  153. package/dist/esm/cli/migrate-cnpg.js.map +1 -0
  154. package/dist/esm/cli/migrate-exec.d.ts +45 -0
  155. package/dist/esm/cli/migrate-exec.d.ts.map +1 -0
  156. package/dist/esm/cli/migrate-exec.js +104 -0
  157. package/dist/esm/cli/migrate-exec.js.map +1 -0
  158. package/dist/esm/cli/migrate-psql.d.ts +125 -0
  159. package/dist/esm/cli/migrate-psql.d.ts.map +1 -0
  160. package/dist/esm/cli/migrate-psql.js +213 -0
  161. package/dist/esm/cli/migrate-psql.js.map +1 -0
  162. package/dist/esm/cli/migrate-report.d.ts +27 -0
  163. package/dist/esm/cli/migrate-report.d.ts.map +1 -0
  164. package/dist/esm/cli/migrate-report.js +29 -0
  165. package/dist/esm/cli/migrate-report.js.map +1 -0
  166. package/dist/esm/cli/migrate-superuser.d.ts +22 -0
  167. package/dist/esm/cli/migrate-superuser.d.ts.map +1 -0
  168. package/dist/esm/cli/migrate-superuser.js +73 -0
  169. package/dist/esm/cli/migrate-superuser.js.map +1 -0
  170. package/dist/esm/cli/migrate.d.ts +37 -0
  171. package/dist/esm/cli/migrate.d.ts.map +1 -0
  172. package/dist/esm/cli/migrate.js +67 -0
  173. package/dist/esm/cli/migrate.js.map +1 -0
  174. package/dist/esm/cli.d.ts +1 -0
  175. package/dist/esm/cli.d.ts.map +1 -1
  176. package/dist/esm/cli.js +6 -0
  177. package/dist/esm/cli.js.map +1 -1
  178. package/dist/esm/index.d.ts +1 -1
  179. package/dist/esm/index.d.ts.map +1 -1
  180. package/dist/esm/index.js.map +1 -1
  181. package/dist/esm/operator/cnpg-common.d.ts +56 -0
  182. package/dist/esm/operator/cnpg-common.d.ts.map +1 -0
  183. package/dist/esm/operator/cnpg-common.js +82 -0
  184. package/dist/esm/operator/cnpg-common.js.map +1 -0
  185. package/dist/esm/operator/cnpg-database.d.ts +66 -0
  186. package/dist/esm/operator/cnpg-database.d.ts.map +1 -0
  187. package/dist/esm/operator/cnpg-database.js +296 -0
  188. package/dist/esm/operator/cnpg-database.js.map +1 -0
  189. package/dist/esm/operator/cnpg-roles.d.ts +173 -0
  190. package/dist/esm/operator/cnpg-roles.d.ts.map +1 -0
  191. package/dist/esm/operator/cnpg-roles.js +225 -0
  192. package/dist/esm/operator/cnpg-roles.js.map +1 -0
  193. package/dist/esm/operator/cnpg.d.ts.map +1 -1
  194. package/dist/esm/operator/cnpg.js +50 -162
  195. package/dist/esm/operator/cnpg.js.map +1 -1
  196. package/dist/esm/operator/connection-uri.d.ts +44 -0
  197. package/dist/esm/operator/connection-uri.d.ts.map +1 -0
  198. package/dist/esm/operator/connection-uri.js +49 -0
  199. package/dist/esm/operator/connection-uri.js.map +1 -0
  200. package/dist/esm/operator/credentials.d.ts +76 -0
  201. package/dist/esm/operator/credentials.d.ts.map +1 -0
  202. package/dist/esm/operator/credentials.js +106 -0
  203. package/dist/esm/operator/credentials.js.map +1 -0
  204. package/dist/esm/operator/database-options.d.ts +121 -0
  205. package/dist/esm/operator/database-options.d.ts.map +1 -0
  206. package/dist/esm/operator/database-options.js +131 -0
  207. package/dist/esm/operator/database-options.js.map +1 -0
  208. package/dist/esm/operator/grants/postgres-job.d.ts +109 -0
  209. package/dist/esm/operator/grants/postgres-job.d.ts.map +1 -0
  210. package/dist/esm/operator/grants/postgres-job.js +232 -0
  211. package/dist/esm/operator/grants/postgres-job.js.map +1 -0
  212. package/dist/esm/operator/grants/postgres-sql.d.ts +130 -0
  213. package/dist/esm/operator/grants/postgres-sql.d.ts.map +1 -0
  214. package/dist/esm/operator/grants/postgres-sql.js +305 -0
  215. package/dist/esm/operator/grants/postgres-sql.js.map +1 -0
  216. package/dist/esm/operator/grants/privileges.d.ts +24 -0
  217. package/dist/esm/operator/grants/privileges.d.ts.map +1 -0
  218. package/dist/esm/operator/grants/privileges.js +35 -0
  219. package/dist/esm/operator/grants/privileges.js.map +1 -0
  220. package/dist/esm/operator/grants/role-config.d.ts +80 -0
  221. package/dist/esm/operator/grants/role-config.d.ts.map +1 -0
  222. package/dist/esm/operator/grants/role-config.js +134 -0
  223. package/dist/esm/operator/grants/role-config.js.map +1 -0
  224. package/dist/esm/operator/index.d.ts +1 -1
  225. package/dist/esm/operator/index.d.ts.map +1 -1
  226. package/dist/esm/operator/index.js.map +1 -1
  227. package/dist/esm/operator/interfaces.d.ts +223 -1
  228. package/dist/esm/operator/interfaces.d.ts.map +1 -1
  229. package/dist/esm/operator/interfaces.js.map +1 -1
  230. package/dist/esm/operator/mariadb-common.d.ts +99 -0
  231. package/dist/esm/operator/mariadb-common.d.ts.map +1 -0
  232. package/dist/esm/operator/mariadb-common.js +141 -0
  233. package/dist/esm/operator/mariadb-common.js.map +1 -0
  234. package/dist/esm/operator/mariadb-database.d.ts +65 -0
  235. package/dist/esm/operator/mariadb-database.d.ts.map +1 -0
  236. package/dist/esm/operator/mariadb-database.js +285 -0
  237. package/dist/esm/operator/mariadb-database.js.map +1 -0
  238. package/dist/esm/operator/mariadb-roles.d.ts +264 -0
  239. package/dist/esm/operator/mariadb-roles.d.ts.map +1 -0
  240. package/dist/esm/operator/mariadb-roles.js +366 -0
  241. package/dist/esm/operator/mariadb-roles.js.map +1 -0
  242. package/dist/esm/operator/mariadb.d.ts.map +1 -1
  243. package/dist/esm/operator/mariadb.js +35 -147
  244. package/dist/esm/operator/mariadb.js.map +1 -1
  245. package/dist/esm/operator/neo4j-common.d.ts +62 -0
  246. package/dist/esm/operator/neo4j-common.d.ts.map +1 -0
  247. package/dist/esm/operator/neo4j-common.js +89 -0
  248. package/dist/esm/operator/neo4j-common.js.map +1 -0
  249. package/dist/esm/operator/neo4j-database.d.ts +88 -0
  250. package/dist/esm/operator/neo4j-database.d.ts.map +1 -0
  251. package/dist/esm/operator/neo4j-database.js +274 -0
  252. package/dist/esm/operator/neo4j-database.js.map +1 -0
  253. package/dist/esm/operator/neo4j-roles.d.ts +203 -0
  254. package/dist/esm/operator/neo4j-roles.d.ts.map +1 -0
  255. package/dist/esm/operator/neo4j-roles.js +298 -0
  256. package/dist/esm/operator/neo4j-roles.js.map +1 -0
  257. package/dist/esm/operator/neo4j.d.ts.map +1 -1
  258. package/dist/esm/operator/neo4j.js +32 -132
  259. package/dist/esm/operator/neo4j.js.map +1 -1
  260. package/dist/esm/operator/resource-identity.d.ts +170 -0
  261. package/dist/esm/operator/resource-identity.d.ts.map +1 -0
  262. package/dist/esm/operator/resource-identity.js +231 -0
  263. package/dist/esm/operator/resource-identity.js.map +1 -0
  264. package/dist/esm/operator/role-registry.d.ts +85 -0
  265. package/dist/esm/operator/role-registry.d.ts.map +1 -0
  266. package/dist/esm/operator/role-registry.js +72 -0
  267. package/dist/esm/operator/role-registry.js.map +1 -0
  268. package/dist/esm/platform/components/image-pruner.d.ts +3 -1
  269. package/dist/esm/platform/components/image-pruner.d.ts.map +1 -1
  270. package/dist/esm/platform/components/image-pruner.js +38 -19
  271. package/dist/esm/platform/components/image-pruner.js.map +1 -1
  272. package/dist/esm/types/errors.d.ts +3 -0
  273. package/dist/esm/types/errors.d.ts.map +1 -1
  274. package/dist/esm/types/errors.js +3 -0
  275. package/dist/esm/types/errors.js.map +1 -1
  276. package/package.json +1 -1
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Guards for {@link IOperatorDatabaseConfig} options an engine cannot honour.
3
+ *
4
+ * The rule this module exists to enforce is the one the rest of the operator
5
+ * module already follows for `owner`, `login: false`, `environments`, and
6
+ * `grants`: an option that cannot be honoured is refused at preview, never
7
+ * accepted and dropped. A silently ignored option is the worst outcome
8
+ * available — the config says one thing, the database does another, and
9
+ * nothing in the Pulumi diff explains the gap.
10
+ *
11
+ * That covers `engineOptions` too: a block addressed to one engine is refused
12
+ * by every other engine rather than ignored. See
13
+ * {@link assertNoForeignEngineOptions}.
14
+ *
15
+ * ## The one deliberate exception: `reclaimPolicy`
16
+ *
17
+ * `reclaimPolicy` is accepted on MariaDB and Neo4j and does nothing there. That
18
+ * is inconsistent with the rule above and is documented rather than fixed,
19
+ * because the rule cannot be applied to it:
20
+ *
21
+ * - **It is defaulted, so it is always "set".** `resolveRoleConfig` fills in
22
+ * `"retain"` when the caller omits it, so by the time any engine could check,
23
+ * there is no way to tell "the user asked for retain" from "the user said
24
+ * nothing". A guard would therefore have to reject every MariaDB and Neo4j
25
+ * database ever declared, including the ones already running. The guards this
26
+ * module does implement all cover options that are genuinely absent by
27
+ * default (`sql` is `undefined` unless asked for).
28
+ * - **Only CloudNativePG consumes it.** It becomes
29
+ * `Database.spec.databaseReclaimPolicy` and
30
+ * `DatabaseRole.spec.databaseRoleReclaimPolicy`. mariadb-operator's nearest
31
+ * equivalent is `spec.cleanupPolicy` on its `Database`/`User`/`Grant` CRs, and
32
+ * Neo4j is provisioned by a `cypher-shell` Job with no CR lifecycle at all.
33
+ * - **Adopting the MariaDB equivalent is not a documentation change.** Setting
34
+ * `cleanupPolicy` on the CRs of databases that already exist would change
35
+ * their deletion semantics on the next apply — a data-loss-shaped change made
36
+ * silently, which is worse than the gap it closes.
37
+ *
38
+ * So on MariaDB and Neo4j the lifecycle of a database, user, or grant is
39
+ * governed by the operator's own default (mariadb-operator retains its managed
40
+ * objects unless `cleanupPolicy` says otherwise; Neo4j has no such notion),
41
+ * not by this field. Nothing is deleted that would otherwise be kept — the
42
+ * exemption costs an unhonoured option, never data.
43
+ *
44
+ * @module operator/database-options
45
+ */
46
+ import type { IDatabaseRoleConfig, IOperatorDatabaseConfig } from "./interfaces.js";
47
+ /**
48
+ * Display names for the engines nimbus provisions databases on.
49
+ *
50
+ * Shared so that an error message naming one engine and a guard keyed on
51
+ * another cannot drift apart.
52
+ */
53
+ export declare const ENGINE_NAMES: {
54
+ /** CloudNativePG, the PostgreSQL operator. */
55
+ readonly CNPG: "CloudNativePG";
56
+ /** mariadb-operator. */
57
+ readonly MARIADB: "MariaDB";
58
+ /** Neo4j Community, provisioned by Helm and a `cypher-shell` Job. */
59
+ readonly NEO4J: "Neo4j";
60
+ };
61
+ /**
62
+ * Name of one `engineOptions` block.
63
+ *
64
+ * Derived from {@link IDatabaseRoleConfig} rather than restated, so adding a
65
+ * block to the public surface without teaching {@link ENGINE_OPTION_OWNERS} who
66
+ * honours it is a compile error rather than a silently unguarded option.
67
+ */
68
+ export type EngineOptionBlock = keyof NonNullable<IDatabaseRoleConfig["engineOptions"]>;
69
+ /** Inputs for {@link assertNoForeignEngineOptions}. */
70
+ export interface IForeignEngineOptionsCheck {
71
+ /** Role the configuration belongs to. */
72
+ readonly roleName: string;
73
+ /** Database the role is being added to. */
74
+ readonly databaseName: string;
75
+ /** Raw `engineOptions` from the role configuration, if any. */
76
+ readonly engineOptions?: IDatabaseRoleConfig["engineOptions"];
77
+ /**
78
+ * The block this engine reads, or omitted when it reads none.
79
+ *
80
+ * Neo4j honours no block at all: it has no operator, no CRs, and nothing in
81
+ * `postgresql` or `mariadb` maps onto `CREATE USER`.
82
+ */
83
+ readonly honoured?: EngineOptionBlock;
84
+ /** Engine name as it appears in the error message; see {@link ENGINE_NAMES}. */
85
+ readonly engine: string;
86
+ }
87
+ /**
88
+ * Reject an `engineOptions` block belonging to a different engine.
89
+ *
90
+ * `engineOptions` is one object carrying a block per engine, so nothing in the
91
+ * type system stops a CloudNativePG role from being handed
92
+ * `engineOptions.mariadb`. Such a role provisioned successfully with the
93
+ * requested host, connection cap, memberships or expiry simply absent — the
94
+ * exact silent-drop this module exists to prevent, and the more misleading for
95
+ * looking deliberate: the caller named an engine, and a *different* engine
96
+ * accepted it.
97
+ *
98
+ * Presence is what is checked, not content: an empty `{}` block still names an
99
+ * engine that will not run this role.
100
+ *
101
+ * @param check - Role, database, raw options, and which block this engine reads
102
+ * @throws {AnyCloudError} code `UNSUPPORTED_ROLE_OPTION` when a block for any
103
+ * other engine is present
104
+ */
105
+ export declare function assertNoForeignEngineOptions(check: IForeignEngineOptionsCheck): void;
106
+ /**
107
+ * Reject `config.sql` on an engine with no path for applying raw SQL.
108
+ *
109
+ * Only CloudNativePG has one: its grant-reconciliation Job already runs `psql`
110
+ * as the database owner, so `sql` rides along in that Job. MariaDB provisions
111
+ * everything through `Database`/`User`/`Grant` CRs and Neo4j through a
112
+ * `cypher-shell` Job that speaks Cypher — neither has anywhere to put a
113
+ * PostgreSQL-flavoured statement list, so the statements would simply never run.
114
+ *
115
+ * @param dbName - Database the configuration belongs to
116
+ * @param config - Raw per-database configuration
117
+ * @param engine - Engine name as it appears in the error message (e.g. "MariaDB")
118
+ * @throws {AnyCloudError} code `UNSUPPORTED_ROLE_OPTION` when `sql` is set
119
+ */
120
+ export declare function assertNoSql(dbName: string, config: Pick<IOperatorDatabaseConfig, "sql">, engine: string): void;
121
+ //# sourceMappingURL=database-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-options.d.ts","sourceRoot":"","sources":["../../../src/operator/database-options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAEpF;;;;;GAKG;AACH,eAAO,MAAM,YAAY;IACvB,8CAA8C;;IAE9C,wBAAwB;;IAExB,qEAAqE;;CAE7D,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,WAAW,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC,CAAC;AAQxF,uDAAuD;AACvD,MAAM,WAAW,0BAA0B;IACzC,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2CAA2C;IAC3C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC,eAAe,CAAC,CAAC;IAC9D;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IACtC,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,0BAA0B,GAAG,IAAI,CAwBpF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,EAC5C,MAAM,EAAE,MAAM,GACb,IAAI,CAUN"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * Guards for {@link IOperatorDatabaseConfig} options an engine cannot honour.
4
+ *
5
+ * The rule this module exists to enforce is the one the rest of the operator
6
+ * module already follows for `owner`, `login: false`, `environments`, and
7
+ * `grants`: an option that cannot be honoured is refused at preview, never
8
+ * accepted and dropped. A silently ignored option is the worst outcome
9
+ * available — the config says one thing, the database does another, and
10
+ * nothing in the Pulumi diff explains the gap.
11
+ *
12
+ * That covers `engineOptions` too: a block addressed to one engine is refused
13
+ * by every other engine rather than ignored. See
14
+ * {@link assertNoForeignEngineOptions}.
15
+ *
16
+ * ## The one deliberate exception: `reclaimPolicy`
17
+ *
18
+ * `reclaimPolicy` is accepted on MariaDB and Neo4j and does nothing there. That
19
+ * is inconsistent with the rule above and is documented rather than fixed,
20
+ * because the rule cannot be applied to it:
21
+ *
22
+ * - **It is defaulted, so it is always "set".** `resolveRoleConfig` fills in
23
+ * `"retain"` when the caller omits it, so by the time any engine could check,
24
+ * there is no way to tell "the user asked for retain" from "the user said
25
+ * nothing". A guard would therefore have to reject every MariaDB and Neo4j
26
+ * database ever declared, including the ones already running. The guards this
27
+ * module does implement all cover options that are genuinely absent by
28
+ * default (`sql` is `undefined` unless asked for).
29
+ * - **Only CloudNativePG consumes it.** It becomes
30
+ * `Database.spec.databaseReclaimPolicy` and
31
+ * `DatabaseRole.spec.databaseRoleReclaimPolicy`. mariadb-operator's nearest
32
+ * equivalent is `spec.cleanupPolicy` on its `Database`/`User`/`Grant` CRs, and
33
+ * Neo4j is provisioned by a `cypher-shell` Job with no CR lifecycle at all.
34
+ * - **Adopting the MariaDB equivalent is not a documentation change.** Setting
35
+ * `cleanupPolicy` on the CRs of databases that already exist would change
36
+ * their deletion semantics on the next apply — a data-loss-shaped change made
37
+ * silently, which is worse than the gap it closes.
38
+ *
39
+ * So on MariaDB and Neo4j the lifecycle of a database, user, or grant is
40
+ * governed by the operator's own default (mariadb-operator retains its managed
41
+ * objects unless `cleanupPolicy` says otherwise; Neo4j has no such notion),
42
+ * not by this field. Nothing is deleted that would otherwise be kept — the
43
+ * exemption costs an unhonoured option, never data.
44
+ *
45
+ * @module operator/database-options
46
+ */
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.ENGINE_NAMES = void 0;
49
+ exports.assertNoForeignEngineOptions = assertNoForeignEngineOptions;
50
+ exports.assertNoSql = assertNoSql;
51
+ const errors_js_1 = require("../types/errors.js");
52
+ /**
53
+ * Display names for the engines nimbus provisions databases on.
54
+ *
55
+ * Shared so that an error message naming one engine and a guard keyed on
56
+ * another cannot drift apart.
57
+ */
58
+ exports.ENGINE_NAMES = {
59
+ /** CloudNativePG, the PostgreSQL operator. */
60
+ CNPG: "CloudNativePG",
61
+ /** mariadb-operator. */
62
+ MARIADB: "MariaDB",
63
+ /** Neo4j Community, provisioned by Helm and a `cypher-shell` Job. */
64
+ NEO4J: "Neo4j",
65
+ };
66
+ /** The one engine that honours each `engineOptions` block. */
67
+ const ENGINE_OPTION_OWNERS = {
68
+ postgresql: exports.ENGINE_NAMES.CNPG,
69
+ mariadb: exports.ENGINE_NAMES.MARIADB,
70
+ };
71
+ /**
72
+ * Reject an `engineOptions` block belonging to a different engine.
73
+ *
74
+ * `engineOptions` is one object carrying a block per engine, so nothing in the
75
+ * type system stops a CloudNativePG role from being handed
76
+ * `engineOptions.mariadb`. Such a role provisioned successfully with the
77
+ * requested host, connection cap, memberships or expiry simply absent — the
78
+ * exact silent-drop this module exists to prevent, and the more misleading for
79
+ * looking deliberate: the caller named an engine, and a *different* engine
80
+ * accepted it.
81
+ *
82
+ * Presence is what is checked, not content: an empty `{}` block still names an
83
+ * engine that will not run this role.
84
+ *
85
+ * @param check - Role, database, raw options, and which block this engine reads
86
+ * @throws {AnyCloudError} code `UNSUPPORTED_ROLE_OPTION` when a block for any
87
+ * other engine is present
88
+ */
89
+ function assertNoForeignEngineOptions(check) {
90
+ const { roleName, databaseName, engineOptions, honoured, engine } = check;
91
+ if (!engineOptions) {
92
+ return;
93
+ }
94
+ for (const block of Object.keys(ENGINE_OPTION_OWNERS)) {
95
+ if (block === honoured || engineOptions[block] === undefined) {
96
+ continue;
97
+ }
98
+ const owner = ENGINE_OPTION_OWNERS[block];
99
+ const alternative = honoured === undefined
100
+ ? `${engine} honours no engineOptions block at all`
101
+ : `on ${engine} only "engineOptions.${honoured}" is honoured`;
102
+ throw new errors_js_1.AnyCloudError(`Role "${roleName}" on database "${databaseName}" sets ` +
103
+ `"engineOptions.${block}", which only ${owner} honours — ${alternative}, so every ` +
104
+ `option in that block would be silently dropped and the role provisioned without ` +
105
+ `the behaviour the config asks for. Remove "engineOptions.${block}", or add this ` +
106
+ `role to a ${owner} database instead.`, errors_js_1.ERROR_CODES.UNSUPPORTED_ROLE_OPTION);
107
+ }
108
+ }
109
+ /**
110
+ * Reject `config.sql` on an engine with no path for applying raw SQL.
111
+ *
112
+ * Only CloudNativePG has one: its grant-reconciliation Job already runs `psql`
113
+ * as the database owner, so `sql` rides along in that Job. MariaDB provisions
114
+ * everything through `Database`/`User`/`Grant` CRs and Neo4j through a
115
+ * `cypher-shell` Job that speaks Cypher — neither has anywhere to put a
116
+ * PostgreSQL-flavoured statement list, so the statements would simply never run.
117
+ *
118
+ * @param dbName - Database the configuration belongs to
119
+ * @param config - Raw per-database configuration
120
+ * @param engine - Engine name as it appears in the error message (e.g. "MariaDB")
121
+ * @throws {AnyCloudError} code `UNSUPPORTED_ROLE_OPTION` when `sql` is set
122
+ */
123
+ function assertNoSql(dbName, config, engine) {
124
+ if (config.sql !== undefined) {
125
+ throw new errors_js_1.AnyCloudError(`Database "${dbName}" cannot use "sql" on ${engine} — raw SQL is applied only on ` +
126
+ `CloudNativePG, by the same owner-authenticated psql Job that reconciles grants. ` +
127
+ `${engine} has no equivalent path, so the statements would never run. Remove "sql" ` +
128
+ "and apply the statements from an application migration instead.", errors_js_1.ERROR_CODES.UNSUPPORTED_ROLE_OPTION);
129
+ }
130
+ }
131
+ //# sourceMappingURL=database-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-options.js","sourceRoot":"","sources":["../../../src/operator/database-options.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,WAAW,CACzB,MAAc,EACd,MAA4C,EAC5C,MAAc;IAEd,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,yBAAa,CACrB,aAAa,MAAM,yBAAyB,MAAM,gCAAgC;YAChF,kFAAkF;YAClF,GAAG,MAAM,2EAA2E;YACpF,iEAAiE,EACnE,uBAAW,CAAC,uBAAuB,CACpC,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Applies compiled grant SQL to a CloudNativePG database.
3
+ *
4
+ * CNPG's `Database` and `DatabaseRole` CRDs create databases, roles, and
5
+ * ownership, but cannot express privilege grants — there is no CRD field for
6
+ * "GRANT SELECT ON ALL TABLES IN SCHEMA marts TO reader". This Job closes that
7
+ * gap: it runs `psql` against the cluster, authenticated as the database
8
+ * owner (never superuser), executing SQL compiled by
9
+ * {@link compileGrantSql}.
10
+ *
11
+ * The SQL reaches the container exclusively through a mounted ConfigMap, so
12
+ * no user-controlled value is ever interpolated into `command`. The Job's
13
+ * name embeds a checksum of the cluster, database, role, and compiled SQL, so
14
+ * an unchanged grant spec reuses the same Job (Pulumi diffs it as a no-op)
15
+ * and a changed spec — or the same grants applied to a different database —
16
+ * always produces a new, distinct Job.
17
+ *
18
+ * @module operator/grants/postgres-job
19
+ */
20
+ import * as k8s from "@pulumi/kubernetes";
21
+ import type * as pulumi from "@pulumi/pulumi";
22
+ import type { IDatabaseGrant } from "../interfaces.js";
23
+ /** Options for {@link createPostgresGrantJob}. */
24
+ export interface IGrantJobOptions {
25
+ /** CNPG cluster the database belongs to. */
26
+ readonly clusterName: string;
27
+ /** Database the grants apply to. */
28
+ readonly databaseName: string;
29
+ /** Role receiving the grants. */
30
+ readonly roleName: string;
31
+ /** Database owner; the Job authenticates as this role, never as superuser. */
32
+ readonly ownerName: string;
33
+ /** Secret holding the owner's existing credentials (must expose a `password` key). */
34
+ readonly ownerSecretName: string;
35
+ /**
36
+ * Desired grants, or `undefined` when privileges are not managed for this
37
+ * role.
38
+ *
39
+ * The two are not the same. `undefined` (with no `extraSql`) means there is
40
+ * nothing to apply and no Job is created. An **empty array** means the role
41
+ * should hold no privileges, which is a real reconciliation: the Job runs and
42
+ * {@link compileGrantSql}'s revoke preamble strips everything. Treating `[]`
43
+ * as "nothing to do" would make removing the last grant from a config a
44
+ * silent no-op, leaving the role holding privileges forever.
45
+ */
46
+ readonly grants?: ReadonlyArray<IDatabaseGrant>;
47
+ /** Raw SQL appended after the grants; see {@link compileGrantSql}'s `extraSql`. */
48
+ readonly extraSql?: ReadonlyArray<string>;
49
+ /** Namespace to create the Job and ConfigMap in. */
50
+ readonly namespace: string;
51
+ /** Cluster read-write endpoint the Job connects to. */
52
+ readonly endpoint: pulumi.Output<string>;
53
+ /** PostgreSQL major version, used to select the `psql` client image tag. */
54
+ readonly pgVersion: string;
55
+ /** Labels applied to the Job, its Pod template, and the SQL ConfigMap. */
56
+ readonly labels: Record<string, string>;
57
+ /** Kubernetes provider. */
58
+ readonly provider: k8s.Provider;
59
+ /**
60
+ * Resources the Job and ConfigMap must be created after.
61
+ *
62
+ * Include the previously created grant Job for the **same database** here:
63
+ * that is what serializes this database's grant transactions. See
64
+ * {@link createPostgresGrantJob}.
65
+ */
66
+ readonly dependsOn: pulumi.Resource[];
67
+ }
68
+ /**
69
+ * Create a Job that applies grants and extra SQL to a CNPG-managed database,
70
+ * or nothing at all when there is no SQL to run.
71
+ *
72
+ * The Job authenticates as `options.ownerName` using the password from
73
+ * `options.ownerSecretName`, and executes the compiled SQL with
74
+ * `psql -v ON_ERROR_STOP=1 -f <mounted file>` so a failing statement fails
75
+ * the Job instead of being silently skipped. The SQL itself is mounted from a
76
+ * ConfigMap — it never appears in `command`, so nothing derived from role,
77
+ * schema, or grant data is ever passed as a shell argument.
78
+ *
79
+ * The Job's name is derived from its content (cluster, database, role, and
80
+ * compiled SQL — see {@link deriveJobName}), so a Job that exhausts
81
+ * `backoffLimit` and permanently fails is **not** retried by a later
82
+ * `pulumi up` as long as the grant spec is unchanged: the same input still
83
+ * derives the same name, and Pulumi sees no diff against the existing
84
+ * (failed) Job. Recovering from a permanent failure requires deleting the
85
+ * failed Job manually (e.g. `kubectl delete job <name>`) before re-running
86
+ * Pulumi, so a new Job is created and actually runs.
87
+ *
88
+ * **Callers must serialize the Jobs they create for one database.** Every
89
+ * script revokes and re-grants across all of that database's schemas inside a
90
+ * single transaction, so two Jobs running concurrently against the same
91
+ * database contend for the same `pg_class`/`pg_namespace` rows and one can
92
+ * abort with `tuple concurrently updated`. Combined with the content-addressed
93
+ * name above, a transient collision that exhausts `backoffLimit` becomes a
94
+ * permanent, manually-recoverable failure. This function does not enforce the
95
+ * ordering itself — it has no view of the other Jobs — so the caller chains it,
96
+ * by passing the previously created Job for the same database in
97
+ * {@link IGrantJobOptions.dependsOn}. Jobs for *different* databases need no
98
+ * such chain: they are separate transactions on separate databases.
99
+ *
100
+ * @param options - Cluster, role, owner, grants, and dependencies
101
+ * @returns The Job, or `undefined` when privileges are unmanaged (`grants` is
102
+ * `undefined`) and there is no `extraSql`. An **empty** `grants` array still
103
+ * produces a Job — it means "this role should hold no privileges", and the
104
+ * compiled script revokes them.
105
+ * @throws {AnyCloudError} code `UNSUPPORTED_PRIVILEGE` when a grant lists a
106
+ * privilege {@link compileGrantSql} does not support
107
+ */
108
+ export declare function createPostgresGrantJob(options: IGrantJobOptions): k8s.batch.v1.Job | undefined;
109
+ //# sourceMappingURL=postgres-job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-job.d.ts","sourceRoot":"","sources":["../../../../src/operator/grants/postgres-job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAAE,cAA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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":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgLH,wDAuEC;AArPD,oDAAsC;AACtC,wDAA0C;AAE1C,uDAAoD;AACpD,kEAAiG;AAGjG,mEAAmE;AACnE,MAAM,aAAa,GAAG,mCAAmC,CAAC;AAC1D,qFAAqF;AACrF,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,mDAAmD;AACnD,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,mFAAmF;AACnF,MAAM,eAAe,GAAG,aAAa,CAAC;AACtC,0EAA0E;AAC1E,MAAM,sBAAsB,GAAG,MAAM,CAAC;AACtC,mEAAmE;AACnE,MAAM,kBAAkB,GAAG,YAAY,CAAC;AACxC,sEAAsE;AACtE,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,2EAA2E;AAC3E,MAAM,aAAa,GAAG,GAAG,cAAc,IAAI,kBAAkB,EAAE,CAAC;AAChE,0EAA0E;AAC1E,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,wDAAwD;AACxD,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,2DAA2D;AAC3D,MAAM,eAAe,GAAG,CAAC,CAA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