@homeflare/alchemy 0.14.0 → 0.15.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/dist/openbao/index.d.ts +10 -3
- package/dist/openbao/index.d.ts.map +1 -1
- package/dist/proxmox/acl.d.ts.map +1 -1
- package/dist/proxmox/backup-job.d.ts.map +1 -1
- package/dist/proxmox/constraint-guard.d.ts +28 -0
- package/dist/proxmox/constraint-guard.d.ts.map +1 -0
- package/dist/proxmox/constraints.d.ts +71 -0
- package/dist/proxmox/constraints.d.ts.map +1 -0
- package/dist/proxmox/firewall-alias.d.ts.map +1 -1
- package/dist/proxmox/generated/constraints/index.d.ts +19 -0
- package/dist/proxmox/generated/constraints/index.d.ts.map +1 -0
- package/dist/proxmox/generated/constraints/pbs-config.d.ts +18 -0
- package/dist/proxmox/generated/constraints/pbs-config.d.ts.map +1 -0
- package/dist/proxmox/generated/constraints/pve-access.d.ts +18 -0
- package/dist/proxmox/generated/constraints/pve-access.d.ts.map +1 -0
- package/dist/proxmox/generated/constraints/pve-cluster.d.ts +18 -0
- package/dist/proxmox/generated/constraints/pve-cluster.d.ts.map +1 -0
- package/dist/proxmox/generated/constraints/pve-pools.d.ts +18 -0
- package/dist/proxmox/generated/constraints/pve-pools.d.ts.map +1 -0
- package/dist/proxmox/generated/constraints/pve-storage.d.ts +18 -0
- package/dist/proxmox/generated/constraints/pve-storage.d.ts.map +1 -0
- package/dist/proxmox/group.d.ts.map +1 -1
- package/dist/proxmox/ha-resource.d.ts.map +1 -1
- package/dist/proxmox/ha-rule.d.ts.map +1 -1
- package/dist/proxmox/index.d.ts +6 -1
- package/dist/proxmox/index.d.ts.map +1 -1
- package/dist/proxmox/index.js +816 -257
- package/dist/proxmox/index.js.map +33 -24
- package/dist/proxmox/notification-matcher.d.ts.map +1 -1
- package/dist/proxmox/pbs-datastore-endpoint.d.ts +22 -0
- package/dist/proxmox/pbs-datastore-endpoint.d.ts.map +1 -0
- package/dist/proxmox/pbs-datastore.d.ts.map +1 -1
- package/dist/proxmox/pbs-notification-matcher.d.ts.map +1 -1
- package/dist/proxmox/pbs-prune-job.d.ts.map +1 -1
- package/dist/proxmox/pbs-sync-job-form.d.ts.map +1 -1
- package/dist/proxmox/pbs-verify-job.d.ts.map +1 -1
- package/dist/proxmox/pool.d.ts.map +1 -1
- package/dist/proxmox/provision-baseline.d.ts +30 -5
- package/dist/proxmox/provision-baseline.d.ts.map +1 -1
- package/dist/proxmox/replication-job.d.ts.map +1 -1
- package/dist/proxmox/resource-spec.d.ts +120 -0
- package/dist/proxmox/resource-spec.d.ts.map +1 -0
- package/dist/proxmox/resource.d.ts +10 -91
- package/dist/proxmox/resource.d.ts.map +1 -1
- package/dist/proxmox/role.d.ts.map +1 -1
- package/dist/proxmox/sdn-vnet.d.ts.map +1 -1
- package/dist/proxmox/sdn-zone.d.ts.map +1 -1
- package/dist/proxmox/storage.d.ts.map +1 -1
- package/dist/proxmox/user.d.ts.map +1 -1
- package/docs/provision-baseline.md +34 -7
- package/docs/proxmox-lxc.md +40 -0
- package/package.json +1 -1
- package/src/openbao/index-types.test.ts +87 -0
- package/src/openbao/index.ts +15 -3
- package/src/proxmox/acl.ts +2 -0
- package/src/proxmox/backup-job.ts +2 -0
- package/src/proxmox/constraint-guard.ts +53 -0
- package/src/proxmox/constraints.test.ts +260 -0
- package/src/proxmox/constraints.ts +135 -0
- package/src/proxmox/firewall-alias.ts +5 -0
- package/src/proxmox/generated/constraints/index.ts +31 -0
- package/src/proxmox/generated/constraints/pbs-config.ts +141 -0
- package/src/proxmox/generated/constraints/pve-access.ts +57 -0
- package/src/proxmox/generated/constraints/pve-cluster.ts +174 -0
- package/src/proxmox/generated/constraints/pve-pools.ts +26 -0
- package/src/proxmox/generated/constraints/pve-storage.ts +75 -0
- package/src/proxmox/group.ts +2 -0
- package/src/proxmox/ha-resource.ts +5 -0
- package/src/proxmox/ha-rule.ts +2 -0
- package/src/proxmox/index.ts +12 -0
- package/src/proxmox/lxc-interior.test.ts +61 -0
- package/src/proxmox/notification-matcher.ts +5 -0
- package/src/proxmox/pbs-datastore-endpoint.ts +29 -0
- package/src/proxmox/pbs-datastore.ts +8 -1
- package/src/proxmox/pbs-notification-matcher.ts +5 -0
- package/src/proxmox/pbs-prune-job.ts +2 -0
- package/src/proxmox/pbs-sync-job-form.ts +2 -0
- package/src/proxmox/pbs-verify-job.ts +2 -0
- package/src/proxmox/pool.ts +2 -0
- package/src/proxmox/provision-baseline.test.ts +38 -0
- package/src/proxmox/provision-baseline.ts +73 -14
- package/src/proxmox/provision-bootstrap.test.ts +51 -0
- package/src/proxmox/replication-job.ts +5 -0
- package/src/proxmox/resource-spec.ts +117 -0
- package/src/proxmox/resource.ts +50 -91
- package/src/proxmox/role.ts +2 -0
- package/src/proxmox/sdn-vnet.ts +2 -0
- package/src/proxmox/sdn-zone.ts +2 -0
- package/src/proxmox/storage.ts +2 -0
- package/src/proxmox/user.ts +2 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PVE exposes no way to reach INSIDE a container, and this pins that as a measured fact rather
|
|
3
|
+
* than a thing people keep re-deriving.
|
|
4
|
+
*
|
|
5
|
+
* ★ WHY A TEST AND NOT ONLY A DOC. `Proxmox.Lxc` declares a guest's PVE-level config and nothing
|
|
6
|
+
* within its filesystem, and every consumer that meets that limit goes looking for the resource
|
|
7
|
+
* that must surely exist — an exec, a file write, a cloud-init. It does not, for containers. A
|
|
8
|
+
* grep proves that once; this proves it on every run, and fails the day PVE adds one, which is
|
|
9
|
+
* exactly when the kit would want to wrap it.
|
|
10
|
+
* ⛔ THE POSITIVE CONTROL IS LOAD BEARING. A test that only asserts absence passes for free if the
|
|
11
|
+
* generated file's comment shape ever changes. QEMU's `agent/exec` and `agent/file-write` are
|
|
12
|
+
* asserted present in the same pass, so a format change fails here instead of going quiet.
|
|
13
|
+
* ⚠️ SIBLING FAMILIES ARE NOT AT PARITY. QEMU and LXC sit under the same `/nodes/{node}/…` tree
|
|
14
|
+
* and have completely different reach. Never infer one family's endpoints from the other's.
|
|
15
|
+
*/
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
|
|
18
|
+
const schema = await Bun.file(new URL('./generated/pve.ts', import.meta.url)).text();
|
|
19
|
+
|
|
20
|
+
/** Every endpoint the generated schema documents, as `METHOD /path`. */
|
|
21
|
+
const endpoints = [...schema.matchAll(/(GET|POST|PUT|DELETE) (\/[A-Za-z0-9/{}_.-]+)/g)].map(
|
|
22
|
+
(match) => `${match[1]} ${match[2]}`,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const under = (prefix: string) =>
|
|
26
|
+
endpoints.filter((line) => line.slice(line.indexOf(' ') + 1).startsWith(prefix));
|
|
27
|
+
|
|
28
|
+
const LXC = '/nodes/{node}/lxc/{vmid}';
|
|
29
|
+
const QEMU = '/nodes/{node}/qemu/{vmid}';
|
|
30
|
+
|
|
31
|
+
describe('a container has no interior API', () => {
|
|
32
|
+
test('the schema was parsed at all', () => {
|
|
33
|
+
// ⛔ Without this, every absence assertion below would pass on an empty list.
|
|
34
|
+
expect(endpoints.length).toBeGreaterThan(100);
|
|
35
|
+
expect(under(LXC).length).toBeGreaterThan(20);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('QEMU can exec and write files inside a guest — the positive control', () => {
|
|
39
|
+
expect(under(QEMU)).toContain(`POST ${QEMU}/agent/exec`);
|
|
40
|
+
expect(under(QEMU)).toContain(`POST ${QEMU}/agent/file-write`);
|
|
41
|
+
expect(under(QEMU)).toContain(`GET ${QEMU}/agent/file-read`);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('no LXC endpoint execs, reads or writes a file, or takes cloud-init', () => {
|
|
45
|
+
// ⛔ So a generic, vendor-API-based Resource for a container's interior cannot be written:
|
|
46
|
+
// there is nothing to wrap. What is left is an image baked before create, a first-boot
|
|
47
|
+
// artifact, or a recorded human step — see docs/proxmox-lxc.md.
|
|
48
|
+
const reaching = under(LXC).filter((line) =>
|
|
49
|
+
/\/(agent|exec|file-read|file-write|cloudinit|cloud-init)(\/|$)/.test(line),
|
|
50
|
+
);
|
|
51
|
+
expect(reaching).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the only LXC reach inside is an interactive console, which is not declarative', () => {
|
|
55
|
+
// ⚠️ `termproxy` and `vncwebsocket` open a terminal for a person. They are not an API a
|
|
56
|
+
// resource can diff, and the kit wraps neither.
|
|
57
|
+
const consoles = under(LXC).filter((line) => /(termproxy|vncwebsocket|spiceproxy)/.test(line));
|
|
58
|
+
expect(consoles.length).toBeGreaterThan(0);
|
|
59
|
+
expect(schema.includes('LxcExec')).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -64,6 +64,11 @@ const handlers = pveHandlers<NotificationMatcherProps, NotificationMatcherAttrib
|
|
|
64
64
|
attributes: (live, props) => matcherAttributes(live, props.name),
|
|
65
65
|
collection: () => 'cluster/notifications/matchers',
|
|
66
66
|
createForm: matcherCreateForm,
|
|
67
|
+
/** The vendor rules these forms are checked against at plan time — resource-spec.ts. */
|
|
68
|
+
endpoint: {
|
|
69
|
+
create: 'pve:POST /cluster/notifications/matchers',
|
|
70
|
+
update: 'pve:PUT /cluster/notifications/matchers/{name}',
|
|
71
|
+
},
|
|
67
72
|
matches: matcherMatches,
|
|
68
73
|
path: (props) => `cluster/notifications/matchers/${props.name}`,
|
|
69
74
|
updateForm: matcherUpdateForm,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Pbs.Datastore`'s two vendor endpoints, and the plan-time check over its two forms.
|
|
3
|
+
*
|
|
4
|
+
* ★ A FILE OF ITS OWN BECAUSE THIS FAMILY DOES NOT USE `pveHandlers`. It writes its own `diff` and
|
|
5
|
+
* `reconcile` (a create answers with a task id, so it settles rather than reading back once), so
|
|
6
|
+
* it cannot inherit the guard from resource.ts — and a copy of the two calls inside that already
|
|
7
|
+
* long file is exactly the per-resource copy-paste the shared handler exists to prevent.
|
|
8
|
+
*
|
|
9
|
+
* ⛔ THE FOUR FIELDS THAT MADE THIS WORTH DOING, from the PBS 4.2.6 schema: `comment` is
|
|
10
|
+
* maxLength 128 with a no-control-characters pattern, `name` is 3..32 with a safe-id pattern,
|
|
11
|
+
* and every `keep-*` has minimum 1. All four were `string`/`number` with the limits in prose.
|
|
12
|
+
*/
|
|
13
|
+
import * as Effect from 'effect/Effect';
|
|
14
|
+
import { guardForm } from './constraint-guard.ts';
|
|
15
|
+
import type { EndpointKey } from './constraints.ts';
|
|
16
|
+
import { createForm, updateForm } from './pbs-datastore-form.ts';
|
|
17
|
+
import type { PbsDatastoreProps } from './pbs-datastore.ts';
|
|
18
|
+
|
|
19
|
+
export const DATASTORE_ENDPOINT: { readonly create: EndpointKey; readonly update: EndpointKey } = {
|
|
20
|
+
create: 'pbs:POST /config/datastore',
|
|
21
|
+
update: 'pbs:PUT /config/datastore/{name}',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** ⚠️ Presence on create only — an update form is partial by design (update-guard.ts). */
|
|
25
|
+
export const guardDatastoreForms = (props: PbsDatastoreProps): Effect.Effect<void> =>
|
|
26
|
+
Effect.gen(function* () {
|
|
27
|
+
yield* guardForm(DATASTORE_ENDPOINT.create, createForm(props), true);
|
|
28
|
+
yield* guardForm(DATASTORE_ENDPOINT.update, updateForm(props), false);
|
|
29
|
+
});
|
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
updateForm,
|
|
65
65
|
} from './pbs-datastore-form.ts';
|
|
66
66
|
import { guardBackend, guardPath, settle } from './pbs-datastore-guard.ts';
|
|
67
|
+
import { guardDatastoreForms } from './pbs-datastore-endpoint.ts';
|
|
67
68
|
import type { PveRequirements } from './resource.ts';
|
|
68
69
|
import { formToSend } from './update-guard.ts';
|
|
69
70
|
|
|
@@ -181,7 +182,11 @@ export const PbsDatastoreProvider = () =>
|
|
|
181
182
|
*/
|
|
182
183
|
diff: ({ news, output }) =>
|
|
183
184
|
Effect.gen(function* () {
|
|
184
|
-
if (
|
|
185
|
+
if (!isResolved(news)) return undefined;
|
|
186
|
+
// ⛔ BEFORE the `output === undefined` return: that branch IS the create, which is the
|
|
187
|
+
// one this family has never checked. resource.ts carries the argument in full.
|
|
188
|
+
yield* guardDatastoreForms(news);
|
|
189
|
+
if (output === undefined) return undefined;
|
|
185
190
|
const live = yield* readOne(news);
|
|
186
191
|
// ⚠️ `update`, not `create` — Alchemy's Diff admits only noop/update/replace, and an
|
|
187
192
|
// object Alchemy has state for but PBS does not is drift for reconcile to repair.
|
|
@@ -198,6 +203,8 @@ export const PbsDatastoreProvider = () =>
|
|
|
198
203
|
* ⛔ THE `matches` GUARD BEFORE THE PUT IS resource.ts's, AND IT IS WHY ADOPTION IS FREE.
|
|
199
204
|
*/
|
|
200
205
|
reconcile: Effect.fn(function* ({ news }) {
|
|
206
|
+
// ⚠️ Again here: an ADOPTED row's diff answer is discarded by Alchemy and reconcile runs.
|
|
207
|
+
yield* guardDatastoreForms(news);
|
|
201
208
|
const live = yield* readOne(news);
|
|
202
209
|
let upid: string | undefined;
|
|
203
210
|
if (live === undefined) {
|
|
@@ -69,6 +69,11 @@ const handlers = pveHandlers<PbsNotificationMatcherProps, NotificationMatcherAtt
|
|
|
69
69
|
attributes: (live, props) => matcherAttributes(live, props.name),
|
|
70
70
|
collection: () => 'config/notifications/matchers',
|
|
71
71
|
createForm: matcherCreateForm,
|
|
72
|
+
/** The vendor rules these forms are checked against at plan time — resource-spec.ts. */
|
|
73
|
+
endpoint: {
|
|
74
|
+
create: 'pbs:POST /config/notifications/matchers',
|
|
75
|
+
update: 'pbs:PUT /config/notifications/matchers/{name}',
|
|
76
|
+
},
|
|
72
77
|
matches: matcherMatches,
|
|
73
78
|
path: (props) => `config/notifications/matchers/${props.name}`,
|
|
74
79
|
updateForm: matcherUpdateForm,
|
|
@@ -194,6 +194,8 @@ const handlers = pveHandlers<PruneJobProps, PruneJobAttributes>({
|
|
|
194
194
|
* compared unconditionally. A changed `store` is an update, not a replace: PBS accepts `store`
|
|
195
195
|
* on PUT, so the job is re-pointed in place.
|
|
196
196
|
*/
|
|
197
|
+
/** The vendor rules these forms are checked against at plan time — resource-spec.ts. */
|
|
198
|
+
endpoint: { create: 'pbs:POST /config/prune', update: 'pbs:PUT /config/prune/{id}' },
|
|
197
199
|
matches: (attributes, props) =>
|
|
198
200
|
attributes.schedule === props.schedule &&
|
|
199
201
|
attributes.store === props.store &&
|
|
@@ -209,6 +209,8 @@ export const handlers = pveHandlers<SyncJobProps, SyncJobAttributes>({
|
|
|
209
209
|
* ⚠️ `id`, `group-filter` AND `sync-direction` ARE OUT. The first is the path, a change to which
|
|
210
210
|
* is a different object; the other two are argued on their props in pbs-sync-job.ts.
|
|
211
211
|
*/
|
|
212
|
+
/** The vendor rules these forms are checked against at plan time — resource-spec.ts. */
|
|
213
|
+
endpoint: { create: 'pbs:POST /config/sync', update: 'pbs:PUT /config/sync/{id}' },
|
|
212
214
|
matches: (attributes, props) =>
|
|
213
215
|
attributes['remove-vanished'] === (props['remove-vanished'] === true) &&
|
|
214
216
|
attributes.store === props.store &&
|
|
@@ -193,6 +193,8 @@ const handlers = pveHandlers<PbsVerifyJobProps, PbsVerifyJobAttributes>({
|
|
|
193
193
|
* ⚠️ `rechecks` IS ABSENT HERE ON PURPOSE. It is a rendering of the two fields on the lines
|
|
194
194
|
* above; comparing it too would report the same drift twice.
|
|
195
195
|
*/
|
|
196
|
+
/** The vendor rules these forms are checked against at plan time — resource-spec.ts. */
|
|
197
|
+
endpoint: { create: 'pbs:POST /config/verify', update: 'pbs:PUT /config/verify/{id}' },
|
|
196
198
|
matches: (attributes, props) =>
|
|
197
199
|
attributes.store === props.store &&
|
|
198
200
|
// ⚠️ `null` IS COMPARED AGAINST `''`, NOT SKIPPED. A parked job is a declaration like any
|
package/src/proxmox/pool.ts
CHANGED
|
@@ -71,6 +71,8 @@ const handlers = pveHandlers<PoolProps, PoolAttributes>({
|
|
|
71
71
|
},
|
|
72
72
|
collection: () => 'pools',
|
|
73
73
|
createForm: poolCreateForm,
|
|
74
|
+
/** The vendor rules these forms are checked against at plan time — resource-spec.ts. */
|
|
75
|
+
endpoint: { create: 'pve:POST /pools', update: 'pve:PUT /pools/{poolid}' },
|
|
74
76
|
matches: (attributes, props) => attributes.comment === (props.comment ?? ''),
|
|
75
77
|
path: (props) => `pools/${props.poolid}`,
|
|
76
78
|
updateForm: poolUpdateForm,
|
|
@@ -84,4 +84,42 @@ describe('provisionBaseline', () => {
|
|
|
84
84
|
test('refuses one user for both lanes', () => {
|
|
85
85
|
expect(() => provisionBaseline({ readUser: 'hf-provision@pve' })).toThrow(/one user/);
|
|
86
86
|
});
|
|
87
|
+
|
|
88
|
+
test('a comment per object, each defaulting to `comment` on its own', () => {
|
|
89
|
+
// \u2605 THE EXISTING-CLUSTER CASE: the group and the read user already carry their own live
|
|
90
|
+
// comments, and only the provision user is new. One shared comment could not say this.
|
|
91
|
+
const baseline = provisionBaseline({
|
|
92
|
+
comment: 'shared',
|
|
93
|
+
groupComment: '',
|
|
94
|
+
provisionComment: 'mint target: provision (ops)',
|
|
95
|
+
readComment: 'mint target: read (ops)',
|
|
96
|
+
});
|
|
97
|
+
expect(baseline.group.comment).toBe('');
|
|
98
|
+
expect(baseline.users.map((u) => u.comment)).toEqual([
|
|
99
|
+
'mint target: provision (ops)',
|
|
100
|
+
'mint target: read (ops)',
|
|
101
|
+
]);
|
|
102
|
+
// Overriding one leaves the others on `comment`; the generic case is still one string.
|
|
103
|
+
const one = provisionBaseline({ comment: 'shared', provisionComment: 'only this' });
|
|
104
|
+
expect([one.group.comment, ...one.users.map((u) => u.comment)]).toEqual([
|
|
105
|
+
'shared',
|
|
106
|
+
'only this',
|
|
107
|
+
'shared',
|
|
108
|
+
]);
|
|
109
|
+
expect(provisionBaseline({ comment: 'shared' }).group.comment).toBe('shared');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('every comment is refused by its own field name', () => {
|
|
113
|
+
const attempt = () =>
|
|
114
|
+
provisionBaseline({ groupComment: "it's", provisionComment: 'q{x}', readComment: '$(id)' });
|
|
115
|
+
expect(attempt).toThrow(/groupComment.*provisionComment.*readComment/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('readComment goes with its lane: unchecked, and unused, when readUser is null', () => {
|
|
119
|
+
// ⚠️ Nothing would ever paste it, so refusing it would be a refusal over a field the caller
|
|
120
|
+
// is not using. The lane it belongs to is gone.
|
|
121
|
+
const none = provisionBaseline({ readComment: "would need quoting'", readUser: null });
|
|
122
|
+
expect(none.users.map((u) => u.lane)).toEqual(['provision']);
|
|
123
|
+
expect(() => provisionBaseline({ readComment: "would need quoting'" })).toThrow(/readComment/);
|
|
124
|
+
});
|
|
87
125
|
});
|
|
@@ -54,7 +54,7 @@ export const PROVISION_PRIVILEGES: readonly string[] = Object.freeze([
|
|
|
54
54
|
]);
|
|
55
55
|
|
|
56
56
|
/** The names a baseline uses. Every field has a generic default (`PROVISION_DEFAULTS`). */
|
|
57
|
-
export interface
|
|
57
|
+
export interface CoreProvisionNames {
|
|
58
58
|
/** The role holding `PROVISION_PRIVILEGES` on `/`. */
|
|
59
59
|
readonly role?: string | undefined;
|
|
60
60
|
/** The user OpenBao's `provision` role mints tokens for, realm-qualified. */
|
|
@@ -69,11 +69,41 @@ export interface ProvisionNames {
|
|
|
69
69
|
readonly comment?: string | undefined;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/** Every name, resolved: what `PROVISION_DEFAULTS` holds and what a baseline is built from. */
|
|
72
|
+
/** Every core name, resolved: what `PROVISION_DEFAULTS` holds and what a baseline is built from. */
|
|
73
73
|
export type ResolvedProvisionNames = {
|
|
74
|
-
readonly [K in keyof
|
|
74
|
+
readonly [K in keyof CoreProvisionNames]-?: Exclude<CoreProvisionNames[K], undefined>;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* `CoreProvisionNames` plus a comment per object, each defaulting to `comment`.
|
|
79
|
+
*
|
|
80
|
+
* ⛔ WHY PER OBJECT: AN EXISTING CLUSTER IS THE NORMAL CASE, NOT THE EXCEPTION. One `comment` for
|
|
81
|
+
* three objects can only describe a cluster this baseline made. On one that already has a mint
|
|
82
|
+
* group and a read user — with their own live comments, which a stack elsewhere may already
|
|
83
|
+
* declare — a single comment makes `provisionBootstrap` rewrite objects nobody asked it to
|
|
84
|
+
* touch, and the next deploy of that stack writes them back. Measured on an estate cluster
|
|
85
|
+
* 2026-09-22, where `hf-mint` had NO comment and `hf-read@pve` named its own mount.
|
|
86
|
+
* ★ Overriding one does not change the others: `comment` stays the default for every object that
|
|
87
|
+
* has no override, so the generic case is still one string.
|
|
88
|
+
* ⚠️ Each is checked like `comment` is, and a `null` `readUser` drops `readComment` with its lane.
|
|
89
|
+
*/
|
|
90
|
+
export interface ProvisionNames extends CoreProvisionNames {
|
|
91
|
+
/** The mint group's comment. Defaults to `comment`. */
|
|
92
|
+
readonly groupComment?: string | undefined;
|
|
93
|
+
/** The provision user's comment. Defaults to `comment`. */
|
|
94
|
+
readonly provisionComment?: string | undefined;
|
|
95
|
+
/** The read user's comment. Defaults to `comment`. Ignored when `readUser` is `null`. */
|
|
96
|
+
readonly readComment?: string | undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The resolved comment for each object a baseline holds. */
|
|
100
|
+
export type ProvisionComments = {
|
|
101
|
+
readonly [K in 'group' | ProvisionLane]: string;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Which credential lane a user or a grant belongs to — the OpenBao role that mints for it. */
|
|
105
|
+
export type ProvisionLane = 'provision' | 'read';
|
|
106
|
+
|
|
77
107
|
/** ★ Generic, kit-prefixed names: nothing here is any one estate's. */
|
|
78
108
|
export const PROVISION_DEFAULTS: ResolvedProvisionNames = Object.freeze({
|
|
79
109
|
comment:
|
|
@@ -85,9 +115,6 @@ export const PROVISION_DEFAULTS: ResolvedProvisionNames = Object.freeze({
|
|
|
85
115
|
role: 'HfProvisioner',
|
|
86
116
|
});
|
|
87
117
|
|
|
88
|
-
/** Which credential lane a user or a grant belongs to — the OpenBao role that mints for it. */
|
|
89
|
-
export type ProvisionLane = 'provision' | 'read';
|
|
90
|
-
|
|
91
118
|
/** A baseline, resolved: exactly what the declaration holds and the bootstrap makes. */
|
|
92
119
|
export interface ProvisionBaseline {
|
|
93
120
|
readonly role: { readonly roleid: string; readonly privs: readonly string[] };
|
|
@@ -113,9 +140,13 @@ export interface ProvisionBaseline {
|
|
|
113
140
|
*/
|
|
114
141
|
const ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
115
142
|
const USERID = /^[A-Za-z0-9][A-Za-z0-9._-]*@[A-Za-z][A-Za-z0-9._-]*$/;
|
|
116
|
-
const COMMENT = /^[A-Za-z0-9 ._
|
|
143
|
+
const COMMENT = /^[A-Za-z0-9 ._,:()@/+-]*$/;
|
|
117
144
|
|
|
118
|
-
const problems = (
|
|
145
|
+
const problems = (
|
|
146
|
+
names: ResolvedProvisionNames,
|
|
147
|
+
comments: ProvisionComments,
|
|
148
|
+
given: ProvisionNames,
|
|
149
|
+
): string[] => {
|
|
119
150
|
const found: string[] = [];
|
|
120
151
|
if (!ID.test(names.role)) found.push(`role \`${names.role}\` is not a PVE role id`);
|
|
121
152
|
if (!ID.test(names.mintGroup)) found.push(`mintGroup \`${names.mintGroup}\` is not a group id`);
|
|
@@ -129,20 +160,48 @@ const problems = (names: ResolvedProvisionNames): string[] => {
|
|
|
129
160
|
}
|
|
130
161
|
}
|
|
131
162
|
if (names.readUser === names.provisionUser) found.push('readUser and provisionUser are one user');
|
|
132
|
-
|
|
133
|
-
|
|
163
|
+
// ⛔ EVERY comment THE BASELINE WILL HOLD, not just the shared one: each is pasted into `sh` and
|
|
164
|
+
// into a Perl `q{}`. ⚠️ `readComment` only when there is a read lane — a `null` `readUser`
|
|
165
|
+
// drops the user, so nothing would ever be pasted.
|
|
166
|
+
// ★ NAMED BY WHERE THE VALUE CAME FROM, and said once. A bad shared `comment` is one problem
|
|
167
|
+
// called `comment`, not three called after overrides the caller never passed.
|
|
168
|
+
const source = (override: string | undefined, field: string) =>
|
|
169
|
+
override === undefined ? 'comment' : field;
|
|
170
|
+
const checked: (readonly [string, string])[] = [
|
|
171
|
+
[source(given.groupComment, 'groupComment'), comments.group],
|
|
172
|
+
[source(given.provisionComment, 'provisionComment'), comments.provision],
|
|
173
|
+
];
|
|
174
|
+
if (names.readUser !== null) {
|
|
175
|
+
checked.push([source(given.readComment, 'readComment'), comments.read]);
|
|
176
|
+
}
|
|
177
|
+
const said = new Set<string>();
|
|
178
|
+
for (const [field, comment] of checked) {
|
|
179
|
+
if (COMMENT.test(comment) || said.has(field)) continue;
|
|
180
|
+
said.add(field);
|
|
181
|
+
found.push(`${field} holds a character the bootstrap will not quote`);
|
|
182
|
+
}
|
|
134
183
|
return found;
|
|
135
184
|
};
|
|
136
185
|
|
|
137
186
|
/** Resolve `names` over the defaults and check them. Throws with every problem at once. */
|
|
138
187
|
export const provisionBaseline = (names: ProvisionNames = {}): ProvisionBaseline => {
|
|
188
|
+
// ⚠️ The per-object comments are taken out first: they are not core names, so they must not land
|
|
189
|
+
// in `resolved`, which `PROVISION_DEFAULTS` types and a caller may build a literal of.
|
|
190
|
+
const { groupComment, provisionComment, readComment, ...core } = names;
|
|
139
191
|
// ⚠️ An explicit `undefined` means "the default", not "blank": spread alone would keep it.
|
|
140
|
-
const given = Object.entries(
|
|
192
|
+
const given = Object.entries(core).filter(([, value]) => value !== undefined);
|
|
141
193
|
const resolved: ResolvedProvisionNames = {
|
|
142
194
|
...PROVISION_DEFAULTS,
|
|
143
195
|
...Object.fromEntries(given),
|
|
144
196
|
};
|
|
145
|
-
|
|
197
|
+
// ★ `?? resolved.comment`, so an override changes ONE object and the generic case stays one
|
|
198
|
+
// string. ⚠️ `??` and not `||`: an empty comment is a real value — a live object with none.
|
|
199
|
+
const comments: ProvisionComments = {
|
|
200
|
+
group: groupComment ?? resolved.comment,
|
|
201
|
+
provision: provisionComment ?? resolved.comment,
|
|
202
|
+
read: readComment ?? resolved.comment,
|
|
203
|
+
};
|
|
204
|
+
const found = problems(resolved, comments, names);
|
|
146
205
|
if (found.length > 0) throw new Error(`provision baseline: ${found.join('; ')}`);
|
|
147
206
|
const lanes: [ProvisionLane, string, string][] = [
|
|
148
207
|
['provision', resolved.provisionUser, resolved.role],
|
|
@@ -150,10 +209,10 @@ export const provisionBaseline = (names: ProvisionNames = {}): ProvisionBaseline
|
|
|
150
209
|
if (resolved.readUser !== null) lanes.push(['read', resolved.readUser, resolved.readRole]);
|
|
151
210
|
return {
|
|
152
211
|
grants: lanes.map(([lane, userid, roleid]) => ({ lane, roleid, userid })),
|
|
153
|
-
group: { comment:
|
|
212
|
+
group: { comment: comments.group, groupid: resolved.mintGroup },
|
|
154
213
|
role: { privs: PROVISION_PRIVILEGES, roleid: resolved.role },
|
|
155
214
|
users: lanes.map(([lane, userid]) => ({
|
|
156
|
-
comment:
|
|
215
|
+
comment: comments[lane],
|
|
157
216
|
groups: [resolved.mintGroup],
|
|
158
217
|
lane,
|
|
159
218
|
userid,
|
|
@@ -113,6 +113,57 @@ describe('run against a cluster', () => {
|
|
|
113
113
|
expect(run.state.acl.map((g) => g.ugid)).toEqual(['hf-provision@pve']);
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
+
test('an EXISTING cluster: only the new object is written, comments and all', async () => {
|
|
117
|
+
// \u2605 THE CASE ONE SHARED COMMENT COULD NOT DESCRIBE. The cluster already has the mint group
|
|
118
|
+
// (no comment at all) and the read user (its own wording), both of them declared elsewhere
|
|
119
|
+
// at those live values. Only the provision user is new. With per-object comments the script
|
|
120
|
+
// writes exactly that user and its grant -- it does not touch the two that already match,
|
|
121
|
+
// so nothing is left for another stack's next deploy to write back.
|
|
122
|
+
const existing: CliState = {
|
|
123
|
+
acl: [{ path: '/', propagate: 1, roleid: 'PVEAuditor', type: 'user', ugid: 'hf-read@pve' }],
|
|
124
|
+
// \u26a0\ufe0f '' IS "no comment live": the fake's view drops an empty one, as PVE does.
|
|
125
|
+
groups: { 'hf-mint': { comment: '' } },
|
|
126
|
+
roles: { ...freshCluster().roles, Provisioner: ['VM.Audit'] },
|
|
127
|
+
users: { 'hf-read@pve': { ...lane(['hf-mint']), comment: 'mint target: read (ops)' } },
|
|
128
|
+
};
|
|
129
|
+
const run = await runScript(
|
|
130
|
+
provisionBootstrap({
|
|
131
|
+
groupComment: '',
|
|
132
|
+
provisionComment: 'mint target: provision (ops)',
|
|
133
|
+
readComment: 'mint target: read (ops)',
|
|
134
|
+
role: 'Provisioner',
|
|
135
|
+
}),
|
|
136
|
+
existing,
|
|
137
|
+
);
|
|
138
|
+
expect(run.code).toBe(0);
|
|
139
|
+
expect(run.stdout).toContain('group hf-mint: ok');
|
|
140
|
+
expect(run.stdout).toContain('user hf-read@pve: ok');
|
|
141
|
+
// The only writes: the role widened to the baseline, the new user, and its grant.
|
|
142
|
+
expect(run.writes.map((w) => w.split(' ').slice(0, 3).join(' '))).toEqual([
|
|
143
|
+
'pveum role modify',
|
|
144
|
+
'pveum user add',
|
|
145
|
+
'pveum acl modify',
|
|
146
|
+
]);
|
|
147
|
+
expect(run.state.groups['hf-mint']).toEqual({ comment: '' });
|
|
148
|
+
expect(run.state.users['hf-read@pve']?.comment).toBe('mint target: read (ops)');
|
|
149
|
+
expect(run.state.users['hf-provision@pve']?.comment).toBe('mint target: provision (ops)');
|
|
150
|
+
expect(run.state.roles['Provisioner']).toEqual([...PROVISION_PRIVILEGES]);
|
|
151
|
+
|
|
152
|
+
// \u26d4 NEGATIVE CONTROL, so this test can fail: the SAME cluster with one shared comment
|
|
153
|
+
// rewrites both objects that already matched. That is the write per-object comments exist
|
|
154
|
+
// to avoid, and it is what another stack's next deploy would put back.
|
|
155
|
+
const shared = await runScript(
|
|
156
|
+
provisionBootstrap({ comment: 'mint target: provision (ops)', role: 'Provisioner' }),
|
|
157
|
+
existing,
|
|
158
|
+
);
|
|
159
|
+
expect(shared.code).toBe(0);
|
|
160
|
+
expect(shared.writes.map((w) => w.split(' ').slice(0, 3).join(' '))).toContain(
|
|
161
|
+
'pveum group modify',
|
|
162
|
+
);
|
|
163
|
+
expect(shared.state.groups['hf-mint']).toEqual({ comment: 'mint target: provision (ops)' });
|
|
164
|
+
expect(shared.state.users['hf-read@pve']?.comment).toBe('mint target: provision (ops)');
|
|
165
|
+
});
|
|
166
|
+
|
|
116
167
|
test("a site's own names flow through every step", async () => {
|
|
117
168
|
const names = {
|
|
118
169
|
mintGroup: 'mint',
|
|
@@ -224,6 +224,11 @@ const handlers = pveHandlers<ReplicationJobProps, ReplicationJobAttributes>({
|
|
|
224
224
|
* that is busy deleting itself, and matching that would be a noop over a vanishing object. It
|
|
225
225
|
* settles because `updateBody` actually clears the marker — see there.
|
|
226
226
|
*/
|
|
227
|
+
/** The vendor rules these forms are checked against at plan time — resource-spec.ts. */
|
|
228
|
+
endpoint: {
|
|
229
|
+
create: 'pve:POST /cluster/replication',
|
|
230
|
+
update: 'pve:PUT /cluster/replication/{id}',
|
|
231
|
+
},
|
|
227
232
|
matches: (attributes, props) =>
|
|
228
233
|
attributes.remove_job === '' &&
|
|
229
234
|
attributes.schedule === (props.schedule ?? DEFAULT_SCHEDULE) &&
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHAT A PVE OBJECT DECLARES: one shape for every one of them, so the provider can cover Proxmox
|
|
3
|
+
* rather than a corner of it. The four operations that read this spec are in resource.ts.
|
|
4
|
+
*
|
|
5
|
+
* ⛔ THE ALTERNATIVE IS TWENTY COPIES OF THE SAME 130 LINES. Proxmox exposes LXC, QEMU, storage,
|
|
6
|
+
* pools, users, groups, roles, ACLs, API tokens, SDN zones/vnets/subnets, firewall rules and
|
|
7
|
+
* groups, HA resources, backup and replication jobs, metric servers and notification targets.
|
|
8
|
+
* Each is the same four operations over a different path and a different form body. Written by
|
|
9
|
+
* hand, resource number six is where someone quietly drops the read-back or the isResolved guard
|
|
10
|
+
* and nobody notices until a plan lies.
|
|
11
|
+
*
|
|
12
|
+
* ★ SO THE FOUR OPERATIONS LIVE HERE, ONCE, AND A RESOURCE DECLARES ONLY WHAT IS DIFFERENT:
|
|
13
|
+
* where it lives, how to recognise it, and which fields are mutable. A new PVE object should be
|
|
14
|
+
* thirty lines, not a hundred and thirty.
|
|
15
|
+
*
|
|
16
|
+
* ⚠️ EVERY PVE ANSWER IS WRAPPED IN `{"data": ...}` AND A FAILED CALL CAN STILL BE HTTP 200 with
|
|
17
|
+
* `{"data": null}`. That is why `reconcile` below READS BACK and refuses when the object is still
|
|
18
|
+
* absent, rather than trusting a status code — see the ⛔ in that function.
|
|
19
|
+
*/
|
|
20
|
+
import type * as HttpClient from 'effect/unstable/http/HttpClient';
|
|
21
|
+
import type { PveForm } from './client.ts';
|
|
22
|
+
import type { EndpointKey } from './constraints.ts';
|
|
23
|
+
import type { ApiTarget, PbsTarget, PveRole, PveTarget } from './credentials.ts';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* ★ WHY SEVERAL FAMILIES HERE DECLARE `defaultRemovalPolicy: 'retain'`, WRITTEN ONCE.
|
|
27
|
+
*
|
|
28
|
+
* Alchemy's own convention: a few resource types default to retain "because their contents are
|
|
29
|
+
* irreplaceable" — `GitHub.Repository` and `Cloudflare.Zone` do — and those opt into deletion
|
|
30
|
+
* with `destroy()`. `retain` means the engine SKIPS `provider.delete` entirely when a resource
|
|
31
|
+
* is orphaned or destroyed: the state row is dropped, the cluster object lives on.
|
|
32
|
+
*
|
|
33
|
+
* So the PVE families whose contents cannot be rebuilt from a line of TypeScript — CephOsd,
|
|
34
|
+
* CephPool, CephFs, CephDaemon, ZfsPool, Storage, NodeNetwork — carry that default. Their
|
|
35
|
+
* `delete` is FULLY IMPLEMENTED and runs the moment a caller opts in with
|
|
36
|
+
* `.pipe(RemovalPolicy.destroy())`. This is deliberately the Terraform `prevent_destroy` shape
|
|
37
|
+
* rather than a stubbed-out operation: a `delete` that silently does nothing lies to whoever is
|
|
38
|
+
* reading the plan, and the lie is discovered at the worst possible time.
|
|
39
|
+
*
|
|
40
|
+
* ⚠️ THE POLICY IS A DECORATION, NOT A PROP, so changing it produces NO DIFF — the resource plans
|
|
41
|
+
* as a noop and the deploy re-commits the row's policy in place. A policy change therefore takes
|
|
42
|
+
* effect from the very next deploy even though the plan shows nothing.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* ⛔ A RESOURCE IS PINNED TO ITS PRODUCT; ONLY THE FACTORY TAKES EITHER. The two hosts are the same
|
|
47
|
+
* two strings, so without a required discriminant TypeScript would accept a PBS host wherever a
|
|
48
|
+
* PVE one belongs — silently, with every call 401ing and `read` folding that into "absent". The
|
|
49
|
+
* whole argument is on `scheme` in credentials.ts.
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* ★ WHAT EVERY OPERATION IN THIS PACKAGE NEEDS FROM THE RUNTIME, NAMED ONCE.
|
|
53
|
+
*
|
|
54
|
+
* `HttpClient`, for both halves of every call: the credential is minted from OpenBao's HTTP API
|
|
55
|
+
* and the PVE call goes through the same client. That is what Alchemy's own providers do
|
|
56
|
+
* (src/Hetzner/Providers.ts builds on `FetchHttpClient.layer`, and there is no bare `fetch` in
|
|
57
|
+
* its Docker, Kubernetes or GitHub providers).
|
|
58
|
+
* ★ `ChildProcessSpawner` WAS HERE UNTIL 2026-09-14, while the mint shelled out to `bao`. The HTTP
|
|
59
|
+
* client replaced that (credentials.ts), so the requirement went with it.
|
|
60
|
+
*
|
|
61
|
+
* ⚠️ SPELLED OUT AT EACH OF THE FORTY-ODD RESOURCES this would be a union nobody keeps in step —
|
|
62
|
+
* one file left on the old shape is a type error at the stack, far from the cause. Named here,
|
|
63
|
+
* adding a third service later is one edit.
|
|
64
|
+
*/
|
|
65
|
+
export type PveRequirements = HttpClient.HttpClient;
|
|
66
|
+
|
|
67
|
+
export type WithTarget = { target: PveTarget };
|
|
68
|
+
export type WithPbsTarget = { target: PbsTarget };
|
|
69
|
+
export type WithApiTarget = { target: ApiTarget };
|
|
70
|
+
|
|
71
|
+
export type PveSpec<Props extends WithApiTarget, Attributes> = {
|
|
72
|
+
/** `pools/lab`, `nodes/node-b/lxc/101` — where ONE object is read, updated and deleted. */
|
|
73
|
+
readonly path: (props: Props) => string;
|
|
74
|
+
/** `pools`, `nodes/node-b/lxc` — where a NEW one is POSTed. */
|
|
75
|
+
readonly collection: (props: Props) => string;
|
|
76
|
+
/** Live JSON to attributes. Returning undefined means "this is not really there". */
|
|
77
|
+
readonly attributes: (live: Record<string, unknown>, props: Props) => Attributes | undefined;
|
|
78
|
+
/** The form PVE wants on create. ⚠️ PVE takes form encoding, not JSON. Arrays: client.ts. */
|
|
79
|
+
readonly createForm: (props: Props) => PveForm;
|
|
80
|
+
/**
|
|
81
|
+
* The form for an update, or undefined when the object has no mutable fields.
|
|
82
|
+
*
|
|
83
|
+
* ⚠️ SOME PVE OBJECTS CANNOT BE UPDATED AT ALL. Returning undefined makes a changed prop a
|
|
84
|
+
* REPLACE rather than a silent no-op, which is the honest answer for an immutable object.
|
|
85
|
+
*/
|
|
86
|
+
readonly updateForm?: (props: Props) => PveForm;
|
|
87
|
+
/** True when live already matches props. Decides noop vs update. */
|
|
88
|
+
readonly matches: (attributes: Attributes, props: Props) => boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Which lease reads this family. Defaults to `read`, the 3600s auditor-shaped one.
|
|
91
|
+
*
|
|
92
|
+
* ⛔ THREE FAMILIES SET THIS TO `provision`, AND THE FAILURE IT AVOIDS IS SILENT. PVE gates some
|
|
93
|
+
* SINGLE-OBJECT reads on the allocate privilege rather than the audit one — `/storage/{id}`,
|
|
94
|
+
* `/cluster/sdn/zones/{zone}`, `/cluster/sdn/vnets/{vnet}` — while their COLLECTION reads
|
|
95
|
+
* accept audit, so nothing looks wrong until a resource reads one object. `read` below folds
|
|
96
|
+
* every failure into `undefined`, right for a 404 and wrong for a 403, so the plan says create
|
|
97
|
+
* and PVE answers that the object already exists. Measured both ways on `local`, and written
|
|
98
|
+
* up with the alternative that was rejected, in docs/privileges.md.
|
|
99
|
+
*/
|
|
100
|
+
readonly readRole?: PveRole;
|
|
101
|
+
/**
|
|
102
|
+
* The vendor endpoints this family writes, as the generated tables key them —
|
|
103
|
+
* `'pbs:POST /config/verify'`, `'pve:PUT /cluster/sdn/zones/{zone}'`.
|
|
104
|
+
*
|
|
105
|
+
* ⛔ DECLARING IT IS WHAT MAKES THE VENDOR'S OWN LIMITS RUN AT PLAN TIME. Without it the family
|
|
106
|
+
* behaves exactly as it did on 2026-09-22, when `deploy:pbs` adopted ten objects and then
|
|
107
|
+
* failed its one create on a `maxLength` PBS publishes and our generated `comment?: string`
|
|
108
|
+
* does not carry. `codegen/constraints.ts` scans this package for these strings, so a key that
|
|
109
|
+
* names an endpoint the vendor does not have stops the GENERATOR rather than a deploy.
|
|
110
|
+
* ⚠️ The spelling is the vendor's own path TEMPLATE, braces and all — not `spec.path(props)`,
|
|
111
|
+
* which has the ids substituted in.
|
|
112
|
+
*/
|
|
113
|
+
readonly endpoint?: {
|
|
114
|
+
readonly create?: EndpointKey;
|
|
115
|
+
readonly update?: EndpointKey;
|
|
116
|
+
};
|
|
117
|
+
};
|