@gebit/stax-cli 1.3.3 → 1.8.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 CHANGED
@@ -77,7 +77,7 @@ stax validate config other-dir -r --strict
77
77
  | Invalid YAML; wrong field types (e.g. `local_backend: "false"` instead of a boolean) | Fields the schema does not know (often typos such as `depend_on`) |
78
78
  | Missing `id` or `type`; unknown `type`; more than one `github-pages-site-deploy` stack or `destroy` on it | `depends_on` or `stack.<id>.var.<key>` pointing to a stack in another config |
79
79
  | Type-specific required fields: `folder` for `terraform`/`opentofu`/`function-build-deploy`, Packer `packer_directory`/`packer_version`, `s3-site-deploy` `location`, `script` `script`, `bizep` `template`, `function-build-deploy` `runtime` | `source_repo` alias not defined in this file (configs deployed together share `externalRepos`) |
80
- | Packer paths that are absolute, contain `..`, backslashes, empty segments or control characters; non-exact `packer_version` | No stacks defined |
80
+ | Packer paths that are absolute, contain `..`, backslashes, empty segments or control characters; non-exact `packer_version`; `build_target: hetzner` without `hetzner`; destination fields for a different build target (also rejected by deployment setup) | No stacks defined; deprecated Gallery aliases (`gallery_name` and the other top-level Gallery fields); `build_target: aws` (reserved, the workflow rejects it) |
81
81
  | Duplicate stack ids; malformed `stack.<id>.var.<key>` references | |
82
82
  | Dependency cycles (including through `stack.<id>...` inputs); dependency chains deeper than 14 levels | |
83
83
 
package/dist/schema.js CHANGED
@@ -8,11 +8,21 @@ ajv.addKeyword({
8
8
  });
9
9
  export const validateDeployConfig = ajv.compile(schema);
10
10
  export const STACK_TYPES = schema.$defs.stack.properties.type?.enum ?? [];
11
- /** Fields the schema requires for `type`, besides id and type, in schema order. */
11
+ export const CREDENTIAL_NAMES = schema.$defs.credentials.propertyNames.enum;
12
+ /**
13
+ * Fields the schema requires for `type`, besides id and type, in schema order.
14
+ * Conditions that also depend on another field (build_target, for example) are
15
+ * not unconditional requirements of the type.
16
+ */
12
17
  export function requiredStackFields(type) {
13
18
  return schema.$defs.stack.allOf
14
19
  .filter(({ if: condition }) => {
15
- const { const: single, enum: anyOf } = condition.properties.type;
20
+ const keys = Object.keys(condition.properties);
21
+ if (keys.length !== 1 || keys[0] !== "type")
22
+ return false;
23
+ if ((condition.required ?? ["type"]).some((field) => field !== "type"))
24
+ return false;
25
+ const { const: single, enum: anyOf } = condition.properties.type ?? {};
16
26
  return single === type || (anyOf?.includes(type) ?? false);
17
27
  })
18
28
  .flatMap((rule) => rule.then.required);
package/dist/templates.js CHANGED
@@ -1,4 +1,54 @@
1
1
  export const WORKFLOW_REPOSITORY = "GEBITSolutions/stax";
2
+ /** Optional secrets a-wf-setup-ci.yml accepts. Cross-org callers must map these by name. */
3
+ const SETUP_CI_SECRETS = [
4
+ "ARM_CLIENT_ID",
5
+ "ARM_CLIENT_SECRET",
6
+ "ARM_SUBSCRIPTION_ID",
7
+ "ARM_TENANT_ID",
8
+ "AWS_ACCESS_KEY_ID",
9
+ "AWS_SECRET_ACCESS_KEY",
10
+ "AWS_SESSION_TOKEN",
11
+ "AWS_ROLE_ARN",
12
+ "CONFIG_GITHUB_TOKEN",
13
+ "RELEASE_APP_CLIENT_SECRET",
14
+ "RELEASE_GH_APP_PRIVATE_KEY",
15
+ ];
16
+ /** Optional secrets a-wf-deploy-levels.yml accepts and forwards to stack workflows. */
17
+ const DEPLOY_LEVELS_SECRETS = [
18
+ "ARM_CLIENT_ID",
19
+ "ARM_CLIENT_SECRET",
20
+ "ARM_SUBSCRIPTION_ID",
21
+ "ARM_TENANT_ID",
22
+ "AWS_ACCESS_KEY_ID",
23
+ "AWS_ROLE_ARN",
24
+ "AWS_SECRET_ACCESS_KEY",
25
+ "AWS_SESSION_TOKEN",
26
+ "CI_AZURE_STATIC_WEB_APPS_API_TOKEN",
27
+ "CI_ENV_TRANSFER_GH_TOKEN",
28
+ "CI_GITHUB_PAT",
29
+ "CI_GITHUB_TOKEN_TERRAFORM",
30
+ "GPG_PASSPHRASE",
31
+ "GPG_PRIVATE_KEY",
32
+ "GPG_PUBLIC_KEY",
33
+ "HCLOUD_TOKEN",
34
+ "INFRACOST_API_KEY",
35
+ "PULP_HOSTNAME",
36
+ "PULP_PASSWORD",
37
+ "PULP_USERNAME",
38
+ "RELEASE_APP_CLIENT_SECRET",
39
+ "RELEASE_GH_APP_PRIVATE_KEY",
40
+ "REPO_KEYSTORE_SP_CLIENT_SECRET",
41
+ "TF_PROVIDER_GH_OWNER",
42
+ ];
43
+ /** Render a `secrets:` map that passes each named secret through from the caller. */
44
+ function renderNamedSecrets(names, indent = 4) {
45
+ const pad = " ".repeat(indent);
46
+ const lines = [`${pad}secrets:`];
47
+ for (const name of names) {
48
+ lines.push(`${pad} ${name}: \${{ secrets.${name} }}`);
49
+ }
50
+ return lines.join("\n");
51
+ }
2
52
  export const DEPLOY_WORKFLOW_PATH = ".github/workflows/deploy.yml";
3
53
  export const DEPLOY_CONFIG_PATH = "configs/default.yaml";
4
54
  const PROJECT_PATTERN = /^[a-z][a-z0-9-]*$/;
@@ -136,8 +186,10 @@ concurrency:
136
186
  jobs:
137
187
  setup:
138
188
  name: Setup CI/CD
189
+ # secrets: inherit only works same-org/enterprise. Map by name for cross-org
190
+ # callers of GEBITSolutions/stax (Environment secrets resolve on nested jobs).
139
191
  uses: ${workflowPrefix}/a-wf-setup-ci.yml@${frameworkRef}
140
- secrets: inherit
192
+ ${renderNamedSecrets(SETUP_CI_SECRETS)}
141
193
  with:
142
194
  actions-version: ${JSON.stringify(frameworkRef)}
143
195
  environment: \${{ inputs.environment }}
@@ -151,7 +203,7 @@ jobs:
151
203
  name: Deploy Levels
152
204
  needs: setup
153
205
  uses: ${workflowPrefix}/a-wf-deploy-levels.yml@${frameworkRef}
154
- secrets: inherit
206
+ ${renderNamedSecrets(DEPLOY_LEVELS_SECRETS)}
155
207
  with:
156
208
  actions-version: ${JSON.stringify(frameworkRef)}
157
209
  ci_config: \${{ needs.setup.outputs.ci-config }}
package/dist/validate.js CHANGED
@@ -2,7 +2,7 @@ import { readdirSync, statSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { isMap, isScalar, LineCounter, parseDocument } from "yaml";
4
4
  import { isRecord } from "./guards.js";
5
- import { schema, validateDeployConfig as validateSchema } from "./schema.js";
5
+ import { ajv, CREDENTIAL_NAMES, schema, validateDeployConfig as validateSchema } from "./schema.js";
6
6
  /** a-wf-deploy-levels runs dependency levels l0 to l13. */
7
7
  const MAX_LEVELS = 14;
8
8
  const KNOWN_KEYS = {
@@ -79,10 +79,18 @@ function checkSchema(data, report) {
79
79
  // "if" errors only say a "then" branch failed; the branch's own error carries the detail.
80
80
  if (error.keyword === "if")
81
81
  continue;
82
+ // Ajv reports both the name schema's enum/pattern error and its propertyNames wrapper.
83
+ // For credential maps, use the wrapper so the finding points to the offending YAML key.
84
+ if (error.schemaPath.includes("/$defs/credentials/propertyNames/"))
85
+ continue;
82
86
  const path = error.instancePath
83
87
  .split("/")
84
88
  .slice(1)
85
89
  .map((segment) => (/^\d+$/.test(segment) ? Number(segment) : segment.replaceAll("~1", "/").replaceAll("~0", "~")));
90
+ if (error.keyword === "propertyNames" && path.at(-1) === "credentials") {
91
+ report.add("error", [...path, String(error.params.propertyName)], `unsupported credential name; expected one of: ${CREDENTIAL_NAMES.join(", ")}`);
92
+ continue;
93
+ }
86
94
  report.add("error", path, schemaMessage(error, path));
87
95
  }
88
96
  }
@@ -109,6 +117,77 @@ function packerPathProblem(value) {
109
117
  return "must not contain empty path segments";
110
118
  return undefined;
111
119
  }
120
+ const GALLERY_FIELDS = [
121
+ "image_resource_group_name",
122
+ "gallery_name",
123
+ "image_definition_name",
124
+ "image_version",
125
+ "target_regions",
126
+ ];
127
+ const RESERVED_SNAPSHOT_LABELS = ["managed_by", "stax_stack_id", "stax_env", "stax_git_sha", "stax_build_target"];
128
+ function sameJson(left, right) {
129
+ return JSON.stringify(left) === JSON.stringify(right);
130
+ }
131
+ /** build_target rules that JSON Schema if/then cannot express: aliases, conflicts, and the AWS stub. */
132
+ function checkPackerBuildTarget(stack, index, report) {
133
+ const target = stack.build_target === undefined ? "azure" : stack.build_target;
134
+ if (target !== "azure" && target !== "hetzner" && target !== "aws")
135
+ return;
136
+ if (target === "aws") {
137
+ report.add("warning", ["stacks", index, "build_target"], "aws is reserved and not implemented; the workflow rejects it until an AMI executor exists");
138
+ }
139
+ for (const field of GALLERY_FIELDS) {
140
+ if (stack[field] !== undefined) {
141
+ report.add("warning", ["stacks", index, field], `deprecated alias of azure.${field}; move it under azure`);
142
+ }
143
+ }
144
+ const azure = isRecord(stack.azure) ? stack.azure : undefined;
145
+ if (azure) {
146
+ for (const field of GALLERY_FIELDS) {
147
+ if (stack[field] !== undefined && azure[field] !== undefined && !sameJson(stack[field], azure[field])) {
148
+ report.add("error", ["stacks", index, "azure", field], `conflicts with deprecated alias ${field}`);
149
+ }
150
+ }
151
+ }
152
+ if (target === "azure" && stack.hetzner !== undefined) {
153
+ report.add("error", ["stacks", index, "hetzner"], "does not apply when build_target is azure");
154
+ }
155
+ if (target === "azure" && stack.aws !== undefined) {
156
+ report.add("error", ["stacks", index, "aws"], "does not apply when build_target is azure");
157
+ }
158
+ if (target === "hetzner" && (azure || GALLERY_FIELDS.some((field) => stack[field] !== undefined))) {
159
+ report.add("error", ["stacks", index, "build_target"], "hetzner does not use Azure Gallery fields");
160
+ }
161
+ if (target === "hetzner" && stack.aws !== undefined) {
162
+ report.add("error", ["stacks", index, "aws"], "does not apply when build_target is hetzner");
163
+ }
164
+ if (target === "aws" && (azure || stack.hetzner !== undefined || GALLERY_FIELDS.some((field) => stack[field] !== undefined))) {
165
+ report.add("error", ["stacks", index, "build_target"], "aws does not use Azure Gallery or Hetzner fields");
166
+ }
167
+ if (isRecord(stack.hetzner) && isRecord(stack.hetzner.snapshot_labels)) {
168
+ for (const key of RESERVED_SNAPSHOT_LABELS) {
169
+ if (stack.hetzner.snapshot_labels[key] !== undefined) {
170
+ report.add("warning", ["stacks", index, "hetzner", "snapshot_labels", key], "reserved label; STAX overwrites it");
171
+ }
172
+ }
173
+ }
174
+ if ((stack.destroy === true || stack.destroy === "true") && target !== "hetzner") {
175
+ report.add("warning", ["stacks", index, "destroy"], "Packer destroy is only supported for build_target hetzner; Azure Gallery builds stay build-only");
176
+ }
177
+ }
178
+ /** Extra scan rules: goss path shape. Schema covers the rest. */
179
+ function checkPackerScan(stack, index, report) {
180
+ if (stack.scan === undefined)
181
+ return;
182
+ if (!isRecord(stack.scan))
183
+ return;
184
+ const goss = stack.scan.goss;
185
+ if (!isRecord(goss) || typeof goss.spec !== "string")
186
+ return;
187
+ const problem = packerPathProblem(goss.spec);
188
+ if (problem)
189
+ report.add("error", ["stacks", index, "scan", "goss", "spec"], problem);
190
+ }
112
191
  /** Collects stack.<id>.var|secret.<key> references in an input value, like update_deploy_config. */
113
192
  function collectStackReferences(value, path, out) {
114
193
  if (typeof value === "string") {
@@ -172,6 +251,19 @@ function checkPipelineRules(data, report) {
172
251
  if (problem)
173
252
  report.add("error", ["stacks", index, field], problem);
174
253
  }
254
+ checkPackerBuildTarget(stack, index, report);
255
+ checkPackerScan(stack, index, report);
256
+ }
257
+ else {
258
+ if (stack.build_target !== undefined) {
259
+ report.add("warning", ["stacks", index, "build_target"], "applies to packer stacks only");
260
+ }
261
+ if (stack.scan !== undefined) {
262
+ report.add("warning", ["stacks", index, "scan"], "applies to packer stacks only");
263
+ }
264
+ if (isRecord(stack.hetzner) && stack.hetzner.token !== undefined) {
265
+ report.add("error", ["stacks", index, "hetzner", "token"], "applies to packer stacks with build_target hetzner only");
266
+ }
175
267
  }
176
268
  // Mirrors validateGitHubPagesConfig and github-pages-config.mjs.
177
269
  if (stack.type === "github-pages-site-deploy") {
@@ -245,8 +337,102 @@ function checkPipelineRules(data, report) {
245
337
  }
246
338
  }
247
339
  }
248
- /** Validates one deploy config. Findings are sorted by position. */
249
- export function validateConfigText(text) {
340
+ const AWS_OPTION_DEFAULTS = {
341
+ aws_endpoint_url: "",
342
+ aws_endpoint_url_s3: "",
343
+ aws_endpoint_url_sts: "",
344
+ aws_endpoint_url_iam: "",
345
+ aws_s3_compatible: "false",
346
+ aws_skip_sts_check: "false",
347
+ state_use_lockfile: "true",
348
+ state_use_path_style: "false",
349
+ };
350
+ const ENDPOINT_FIELDS = ["aws_endpoint_url", "aws_endpoint_url_s3", "aws_endpoint_url_sts", "aws_endpoint_url_iam"];
351
+ function checkEndpointURLs(deployment, report) {
352
+ const endpointShape = ajv.getSchema(`${schema.$id}#/$defs/endpointUrl`);
353
+ if (!endpointShape)
354
+ throw new Error("endpointUrl schema definition is missing");
355
+ for (const field of ENDPOINT_FIELDS) {
356
+ const raw = deployment[field];
357
+ if (typeof raw !== "string" || !raw.trim() || !endpointShape(raw))
358
+ continue;
359
+ const value = raw.trim();
360
+ try {
361
+ new URL(value);
362
+ }
363
+ catch {
364
+ report.add("error", ["deployment", field], "must be a valid absolute URL with a hostname and valid port");
365
+ continue;
366
+ }
367
+ if (!value.startsWith("https://") && !/^http:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::[0-9]+)?(?:\/|$)/.test(value)) {
368
+ report.add("error", ["deployment", field], "must use https (http is only allowed for localhost / 127.0.0.1 / [::1])");
369
+ }
370
+ }
371
+ }
372
+ function deploymentText(value) {
373
+ return value === undefined || value === null ? "" : String(value).trim();
374
+ }
375
+ /** Hetzner's token alias cannot coexist with an explicit HCLOUD_TOKEN mapping, including an inherited one. */
376
+ function checkCredentialRules(data, report) {
377
+ const inherited = isRecord(data.deployment) && isRecord(data.deployment.credentials) ? data.deployment.credentials : undefined;
378
+ if (!Array.isArray(data.stacks))
379
+ return;
380
+ data.stacks.forEach((stack, index) => {
381
+ if (!isRecord(stack) || stack.type !== "packer" || stack.build_target !== "hetzner")
382
+ return;
383
+ if (!isRecord(stack.hetzner) || stack.hetzner.token === undefined)
384
+ return;
385
+ const mapped = isRecord(stack.credentials) && Object.hasOwn(stack.credentials, "HCLOUD_TOKEN")
386
+ ? stack.credentials
387
+ : inherited;
388
+ if (mapped && Object.hasOwn(mapped, "HCLOUD_TOKEN")) {
389
+ report.add("error", ["stacks", index, "hetzner", "token"], "conflicts with effective credentials.HCLOUD_TOKEN; use only one reference");
390
+ }
391
+ });
392
+ }
393
+ /** GitHub Environment variables are available only when the caller provides them (CLI defaults to its process). */
394
+ function checkCredentialVaultUrl(data, report, variables) {
395
+ if (variables.REPO_KEYSTORE_KEY_VAULT_URL?.trim())
396
+ return;
397
+ const deployment = isRecord(data.deployment) ? data.deployment : undefined;
398
+ const defaults = deployment && isRecord(deployment.credentials) ? deployment.credentials : undefined;
399
+ const hasDefaults = defaults !== undefined && Object.keys(defaults).length > 0;
400
+ if (!Array.isArray(data.stacks))
401
+ return;
402
+ data.stacks.forEach((stack, index) => {
403
+ if (!isRecord(stack))
404
+ return;
405
+ const backend = stack.secret_backend ?? deployment?.secret_backend ?? "gh";
406
+ const overrides = isRecord(stack.credentials) ? stack.credentials : undefined;
407
+ if (backend !== "keyvault" || (!hasDefaults && !(overrides && Object.keys(overrides).length > 0)))
408
+ return;
409
+ const path = deployment?.secret_backend === "keyvault" && hasDefaults
410
+ ? ["deployment", "credentials"] : ["stacks", index, "credentials"];
411
+ report.add("error", path, "REPO_KEYSTORE_KEY_VAULT_URL is required for keyvault-backed credentials");
412
+ });
413
+ }
414
+ /** Mirrors the AWS option checks in .github/scripts/deployment-config.mjs and a-wf-setup-ci. */
415
+ function checkDeploymentRules(data, report) {
416
+ const deployment = data.deployment;
417
+ if (!isRecord(deployment))
418
+ return;
419
+ const cloud = deploymentText(deployment.cloud).toLowerCase();
420
+ checkEndpointURLs(deployment, report);
421
+ const changed = Object.entries(AWS_OPTION_DEFAULTS)
422
+ .filter(([field, fallback]) => {
423
+ const value = deploymentText(deployment[field]);
424
+ return value !== "" && value !== fallback;
425
+ })
426
+ .map(([field]) => field);
427
+ // An unset cloud may still resolve to aws from the CLOUD variable.
428
+ if (cloud !== "" && cloud !== "aws") {
429
+ for (const field of changed)
430
+ report.add("error", ["deployment", field], `only applies to cloud "aws" (cloud is "${cloud}")`);
431
+ return;
432
+ }
433
+ }
434
+ /** Validates one deploy config. Pass Environment variables explicitly when available; the CLI uses process.env. Findings are sorted by position. */
435
+ export function validateConfigText(text, variables = process.env) {
250
436
  const lineCounter = new LineCounter();
251
437
  const doc = parseDocument(text, { lineCounter, prettyErrors: false });
252
438
  const report = new Reporter(doc, lineCounter);
@@ -273,6 +459,9 @@ export function validateConfigText(text) {
273
459
  if (Array.isArray(data.stacks)) {
274
460
  data.stacks.forEach((stack, index) => checkUnknownKeys(stack, KNOWN_KEYS.stack, ["stacks", index], report));
275
461
  }
462
+ checkCredentialRules(data, report);
463
+ checkCredentialVaultUrl(data, report, variables);
464
+ checkDeploymentRules(data, report);
276
465
  checkPipelineRules(data, report);
277
466
  return report.findings.sort((a, b) => a.line - b.line || a.column - b.column);
278
467
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gebit/stax-cli",
3
- "version": "1.3.3",
3
+ "version": "1.8.0",
4
4
  "description": "Scaffold, extend and validate projects for the stax stack framework",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",
@@ -31,11 +31,28 @@
31
31
  },
32
32
  "$defs": {
33
33
  "deploymentValue": { "type": ["string", "null"], "pattern": "^[^\\r\\n]*$" },
34
+ "deploymentFlag": { "type": ["boolean", "string", "null"], "pattern": "^(?:true|false|[^\\S\\r\\n]*)$" },
35
+ "credentialReference": { "type": "string", "pattern": "^(secret_backend|gh)\\.secret\\.[A-Za-z0-9_]+$" },
36
+ "credentials": {
37
+ "description": "Explicit credential references. Only listed runtime credential names are accepted; values must reference GitHub or the selected secret backend.",
38
+ "type": "object",
39
+ "propertyNames": {
40
+ "pattern": "^[A-Z][A-Z0-9_]*$",
41
+ "enum": ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "HCLOUD_TOKEN", "INFRACOST_API_KEY", "CI_GITHUB_PAT", "CI_GITHUB_TOKEN_TERRAFORM", "TF_PROVIDER_GH_OWNER"]
42
+ },
43
+ "additionalProperties": { "$ref": "#/$defs/credentialReference" }
44
+ },
45
+ "endpointUrl": {
46
+ "type": ["string", "null"],
47
+ "pattern": "^(?:[^\\S\\r\\n]*(?:https://[^\\s@/?#\\\\]+(?:/[^\\s@?#\\\\]*)?|http://(?:localhost|127\\.0\\.0\\.1|\\[::1\\])(?::[0-9]+)?(?:/[^\\s@?#\\\\]*)?)[^\\S\\r\\n]*|[^\\S\\r\\n]*)$"
48
+ },
34
49
  "deployment": {
35
50
  "type": ["object", "null"],
36
51
  "additionalProperties": false,
37
52
  "properties": {
38
53
  "project": { "description": "Project name; falls back to GitHub PROJECT.", "$ref": "#/$defs/deploymentValue" },
54
+ "secret_backend": { "description": "Default secret store for secret_backend.secret.<key> references. Overridable per stack. Default gh.", "type": "string", "enum": ["keyvault", "gh"], "default": "gh" },
55
+ "credentials": { "description": "Default credential references for stacks in this deployment. A stack can override individual names.", "$ref": "#/$defs/credentials" },
39
56
  "customer_id": { "description": "Customer identifier; falls back to CUSTOMER_ID.", "$ref": "#/$defs/deploymentValue" },
40
57
  "stage": { "description": "Deployment stage; falls back to STAGE.", "$ref": "#/$defs/deploymentValue" },
41
58
  "cloud": { "description": "Azure or AWS, case-insensitive; falls back to CLOUD.", "type": ["string", "null"], "pattern": "^(?:[aA][zZ][uU][rR][eE]|[aA][wW][sS]|[^\\S\\r\\n]*)$" },
@@ -48,7 +65,15 @@
48
65
  "state_container_name": { "description": "Azure state container; falls back to STATE_CONTAINER_NAME.", "$ref": "#/$defs/deploymentValue" },
49
66
  "state_resource_group_name": { "description": "Azure state resource group; falls back to STATE_RESOURCE_GROUP_NAME.", "$ref": "#/$defs/deploymentValue" },
50
67
  "state_bucket_name": { "description": "AWS state bucket; falls back to STATE_BUCKET_NAME.", "$ref": "#/$defs/deploymentValue" },
51
- "state_region": { "description": "AWS state region; falls back to STATE_REGION.", "$ref": "#/$defs/deploymentValue" }
68
+ "state_region": { "description": "AWS state region; falls back to STATE_REGION.", "$ref": "#/$defs/deploymentValue" },
69
+ "aws_endpoint_url": { "description": "AWS only: base endpoint for every AWS service, e.g. a MinIO server; falls back to AWS_ENDPOINT_URL. https, or http on localhost.", "$ref": "#/$defs/endpointUrl" },
70
+ "aws_endpoint_url_s3": { "description": "AWS only: S3 endpoint for the state backend and the AWS provider, e.g. https://s3.eu-central-2.wasabisys.com; falls back to AWS_ENDPOINT_URL_S3.", "$ref": "#/$defs/endpointUrl" },
71
+ "aws_endpoint_url_sts": { "description": "AWS only: STS endpoint; falls back to AWS_ENDPOINT_URL_STS. Not supported with OIDC_ENABLED.", "$ref": "#/$defs/endpointUrl" },
72
+ "aws_endpoint_url_iam": { "description": "AWS only: IAM endpoint; falls back to AWS_ENDPOINT_URL_IAM.", "$ref": "#/$defs/endpointUrl" },
73
+ "aws_s3_compatible": { "description": "AWS only: S3-compatible storage mode (checksums only when required, no region or account-id lookups); falls back to AWS_S3_COMPATIBLE. Default false.", "$ref": "#/$defs/deploymentFlag" },
74
+ "aws_skip_sts_check": { "description": "AWS only: skip the STS get-caller-identity check and backend credential validation; falls back to AWS_SKIP_STS_CHECK. Default false.", "$ref": "#/$defs/deploymentFlag" },
75
+ "state_use_lockfile": { "description": "AWS only: S3 native state locking (use_lockfile); falls back to STATE_USE_LOCKFILE. Default true; set false only for stores without conditional writes.", "$ref": "#/$defs/deploymentFlag" },
76
+ "state_use_path_style": { "description": "AWS only: path-style S3 addressing for the state backend; falls back to STATE_USE_PATH_STYLE. Default false.", "$ref": "#/$defs/deploymentFlag" }
52
77
  }
53
78
  },
54
79
  "externalRepo": {
@@ -89,6 +114,8 @@
89
114
  "depends_on": { "description": "Stack ids deployed before this one.", "$ref": "#/$defs/stringList", "examples": [[]], "x-stax-types": "all" },
90
115
  "stack-groups": { "description": "Groups for selecting stacks in the deploy form.", "$ref": "#/$defs/stringList", "examples": [["core"]], "x-stax-types": "all" },
91
116
  "runs-on": { "description": "Runner label.", "type": "string", "examples": ["ubuntu-24.04"], "x-stax-types": "all" },
117
+ "secret_backend": { "description": "Overrides deployment.secret_backend for this stack. Default inherits deployment, then gh.", "type": "string", "enum": ["keyvault", "gh"], "examples": ["gh"], "x-stax-types": "all" },
118
+ "credentials": { "description": "Credential references merged over deployment.credentials by name. A mapped but missing secret fails deployment.", "$ref": "#/$defs/credentials", "examples": [{ "AWS_ACCESS_KEY_ID": "secret_backend.secret.aws_access_key_id" }], "x-stax-types": "all" },
92
119
  "input": {
93
120
  "description": "Inputs: reference strings (global.pipeline.var.<key>, stack.<id>.var.<key>, ...) or key/value maps.",
94
121
  "type": "array",
@@ -113,7 +140,7 @@
113
140
  "examples": ["main"],
114
141
  "x-stax-types": ["terraform", "opentofu", "packer", "swa-site-deploy", "swa-docs-site-deploy", "s3-site-deploy", "script", "bizep", "github-pages-site-deploy"]
115
142
  },
116
- "destroy": { "description": "Destroy the stack instead of deploying it.", "type": ["boolean", "string"], "examples": [false], "x-stax-types": ["terraform", "opentofu", "swa-site-deploy", "swa-docs-site-deploy"] },
143
+ "destroy": { "description": "Destroy the stack instead of deploying it. For Packer, only build_target hetzner honors this; Azure Gallery builds stay build-only.", "type": ["boolean", "string"], "examples": [false], "x-stax-types": ["terraform", "opentofu", "packer", "swa-site-deploy", "swa-docs-site-deploy"] },
117
144
 
118
145
  "folder": {
119
146
  "description": "Stack directory: below stack_base_path for terraform/opentofu, below functions/ for function-build-deploy.",
@@ -133,6 +160,138 @@
133
160
  "packer_directory": { "description": "Packer project path, relative to the source repository.", "$ref": "#/$defs/relativePath", "examples": ["packer/ubuntu"], "x-stax-types": ["packer"] },
134
161
  "packer_template": { "description": "Template file or directory relative to packer_directory; defaults to '.'.", "$ref": "#/$defs/relativePath", "examples": ["azure.pkr.hcl"], "x-stax-types": ["packer"] },
135
162
  "packer_version": { "description": "Exact Packer version.", "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$", "examples": ["1.11.2"], "x-stax-types": ["packer"] },
163
+ "build_target": {
164
+ "description": "Packer publisher. Omit or set azure for Compute Gallery. hetzner publishes a labelled snapshot and requires hetzner. aws is reserved and not implemented.",
165
+ "enum": ["azure", "hetzner", "aws"],
166
+ "default": "azure",
167
+ "examples": ["azure"],
168
+ "x-stax-types": ["packer"]
169
+ },
170
+ "azure": {
171
+ "description": "Azure Compute Gallery destination. Required on apply unless the same fields are still set as deprecated aliases or stack inputs.",
172
+ "type": "object",
173
+ "additionalProperties": false,
174
+ "properties": {
175
+ "image_resource_group_name": { "type": "string", "minLength": 1, "examples": ["rg-images"] },
176
+ "gallery_name": { "type": "string", "minLength": 1, "examples": ["corp_gallery"] },
177
+ "image_definition_name": { "type": "string", "minLength": 1, "examples": ["ubuntu2404"] },
178
+ "image_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$", "examples": ["1.2.3"] },
179
+ "target_regions": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 }, "examples": [["westeurope", "northeurope"]] }
180
+ },
181
+ "examples": [{
182
+ "image_resource_group_name": "rg-images",
183
+ "gallery_name": "corp_gallery",
184
+ "image_definition_name": "ubuntu2404",
185
+ "image_version": "1.2.3",
186
+ "target_regions": ["westeurope", "northeurope"]
187
+ }],
188
+ "x-stax-types": ["packer"]
189
+ },
190
+ "hetzner": {
191
+ "description": "Hetzner snapshot destination. Required when build_target is hetzner. cax* server types are arm64; the template's source image must match.",
192
+ "type": "object",
193
+ "additionalProperties": false,
194
+ "required": ["location", "server_type"],
195
+ "properties": {
196
+ "location": { "description": "Hetzner location, for example fsn1.", "type": "string", "pattern": "^[a-z]{2,4}[0-9]?$", "examples": ["fsn1"] },
197
+ "server_type": { "description": "Temporary build server type, for example cax11.", "type": "string", "pattern": "^[a-z][a-z0-9]{1,31}$", "examples": ["cax11"] },
198
+ "token": { "description": "Hetzner API token reference; alias of credentials.HCLOUD_TOKEN. Do not set both, including an inherited deployment credential. When unset, the workflow uses the HCLOUD_TOKEN GitHub Environment secret.", "$ref": "#/$defs/credentialReference", "examples": ["secret_backend.secret.hcloud_token", "gh.secret.hcloud_token"], "x-stax-types": ["packer"] },
199
+ "snapshot_name": { "description": "Snapshot name. Defaults to the stack id.", "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$", "examples": ["personal-assistant-golden"] },
200
+ "snapshot_labels": {
201
+ "description": "Extra snapshot labels. STAX adds stax_stack_id, stax_env, stax_git_sha, stax_build_target and managed_by=stax.",
202
+ "type": "object",
203
+ "additionalProperties": { "type": "string", "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9_.-]{0,61}[A-Za-z0-9])?$" },
204
+ "propertyNames": { "pattern": "^[A-Za-z](?:[A-Za-z0-9_.-]{0,61}[A-Za-z0-9])?$" },
205
+ "examples": [{ "personal-assistant": "true", "role": "golden" }]
206
+ },
207
+ "keep_last": { "description": "Matching snapshots to retain after a successful build. Default 3. 0 keeps only the snapshot just built; on destroy, 0 deletes every match.", "type": "integer", "minimum": 0, "maximum": 100, "default": 3, "examples": [3] }
208
+ }
209
+ },
210
+ "aws": {
211
+ "description": "Reserved for a later AMI publisher. build_target aws is rejected by the workflow.",
212
+ "type": "object",
213
+ "additionalProperties": false,
214
+ "required": ["regions"],
215
+ "properties": {
216
+ "regions": {
217
+ "type": "array",
218
+ "minItems": 1,
219
+ "items": { "type": "string", "pattern": "^[a-z]{2}-[a-z]+-[0-9]+$" },
220
+ "examples": [["eu-central-1"]]
221
+ }
222
+ }
223
+ },
224
+ "scan": {
225
+ "description": "Optional Packer image scan/test hooks. Omit to keep build-only behaviour. When set, STAX materialises .stax/scan/run.sh and runs it on the build VM before the image is captured; a failing hook fails packer build so Azure Gallery and Hetzner never publish. Requires the template to declare stax_scan_enabled and reference .stax/scan/run.sh.",
226
+ "type": "object",
227
+ "additionalProperties": false,
228
+ "minProperties": 1,
229
+ "properties": {
230
+ "trivy": {
231
+ "description": "Vulnerability/misconfig scan via aquasecurity/trivy rootfs. Fails when findings meet or exceed severity.",
232
+ "type": "object",
233
+ "additionalProperties": false,
234
+ "properties": {
235
+ "severity": {
236
+ "description": "Comma-separated uppercase severities passed to trivy --severity.",
237
+ "type": "string",
238
+ "pattern": "^[A-Z]+(?:,[A-Z]+)*$",
239
+ "default": "HIGH,CRITICAL",
240
+ "examples": ["HIGH,CRITICAL", "CRITICAL"]
241
+ },
242
+ "scanners": {
243
+ "description": "Trivy scanners to enable.",
244
+ "type": "array",
245
+ "minItems": 1,
246
+ "items": { "enum": ["vuln", "misconfig", "secret", "license"] },
247
+ "default": ["vuln"],
248
+ "examples": [["vuln"], ["vuln", "misconfig"]]
249
+ }
250
+ }
251
+ },
252
+ "lynis": {
253
+ "description": "Hardening audit via CISOfy Lynis. Fails when the hardening index is below min_hardening_index.",
254
+ "type": "object",
255
+ "additionalProperties": false,
256
+ "properties": {
257
+ "min_hardening_index": {
258
+ "description": "Minimum acceptable Lynis hardening index (0-100).",
259
+ "type": "integer",
260
+ "minimum": 0,
261
+ "maximum": 100,
262
+ "default": 50,
263
+ "examples": [50, 65]
264
+ }
265
+ }
266
+ },
267
+ "goss": {
268
+ "description": "Server spec tests via goss. Fails on any failed expectation.",
269
+ "type": "object",
270
+ "additionalProperties": false,
271
+ "required": ["spec"],
272
+ "properties": {
273
+ "spec": {
274
+ "description": "Goss spec path relative to packer_directory (no ..).",
275
+ "type": "string",
276
+ "minLength": 1,
277
+ "pattern": "^(?!.*\\.\\.)(?!/)[A-Za-z0-9._/-]+$",
278
+ "examples": ["goss.yaml", "tests/goss.yaml"]
279
+ }
280
+ }
281
+ }
282
+ },
283
+ "examples": [{
284
+ "trivy": { "severity": "HIGH,CRITICAL", "scanners": ["vuln", "misconfig"] },
285
+ "lynis": { "min_hardening_index": 50 },
286
+ "goss": { "spec": "goss.yaml" }
287
+ }],
288
+ "x-stax-types": ["packer"]
289
+ },
290
+ "image_resource_group_name": { "description": "Deprecated alias of azure.image_resource_group_name.", "type": "string", "minLength": 1 },
291
+ "gallery_name": { "description": "Deprecated alias of azure.gallery_name.", "type": "string", "minLength": 1 },
292
+ "image_definition_name": { "description": "Deprecated alias of azure.image_definition_name.", "type": "string", "minLength": 1 },
293
+ "image_version": { "description": "Deprecated alias of azure.image_version.", "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
294
+ "target_regions": { "description": "Deprecated alias of azure.target_regions.", "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
136
295
 
137
296
  "image_name": { "type": "string", "examples": ["my-app"], "x-stax-types": ["docker-build-push"] },
138
297
  "dockerfile_folder": { "description": "Build context containing the Dockerfile.", "type": "string", "examples": ["docker/my-app"], "x-stax-types": ["docker-build-push"] },
@@ -172,6 +331,20 @@
172
331
  "if": { "properties": { "type": { "const": "packer" } }, "required": ["type"] },
173
332
  "then": { "required": ["packer_directory", "packer_version"] }
174
333
  },
334
+ {
335
+ "if": {
336
+ "properties": { "type": { "const": "packer" }, "build_target": { "const": "hetzner" } },
337
+ "required": ["type", "build_target"]
338
+ },
339
+ "then": { "required": ["hetzner"] }
340
+ },
341
+ {
342
+ "if": {
343
+ "properties": { "type": { "const": "packer" }, "build_target": { "const": "aws" } },
344
+ "required": ["type", "build_target"]
345
+ },
346
+ "then": { "required": ["aws"] }
347
+ },
175
348
  {
176
349
  "if": { "properties": { "type": { "const": "s3-site-deploy" } }, "required": ["type"] },
177
350
  "then": { "required": ["location"] }