Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/configurator-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,97 @@ jobs:
LZC_STACKIT_REDIRECT_URI: https://app.landing-zone.runs.onstackit.cloud/auth/stackit/callback
LZC_EXECUTION_ENABLED: 'true'
LZC_APPLICATION_EXECUTION_ENABLED: 'true'
LZC_RETIREMENTS_ENABLED: ${{ vars.LZC_RETIREMENTS_ENABLED }}
LZC_RUNNER_POOL_SIZE: '2'
LZC_DEPLOYMENT_ARTIFACT_KEY: ${{ secrets.LZC_DEPLOYMENT_ARTIFACT_KEY }}
- name: Login with application-space deployer
env:
LZC_FEATURE_OPERATOR_PROJECT_ID: ${{ vars.LZC_PROJECT_ID }}
run: |
cf api "$CF_API_URL"
cf auth
cf target -o "$LZC_CF_ORG_NAME" -s configurator
test "$(cf space configurator --guid)" = "$LZC_CF_SPACE_ID"
# BEGIN GENERATED RUNTIME FEATURE POLICY
node --input-type=module <<'LZC_RUNTIME_FEATURES'
// Embedded into both deployment workflows so rollback of an older application
// still preserves the current operator policy. Regenerate with embed-runtime-features.mjs.
import { readFileSync, writeFileSync, lstatSync } from "node:fs";
import { spawnSync } from "node:child_process";
import { join } from "node:path";
import { pathToFileURL } from "node:url";

export const featureKeys = ["LZC_RETIREMENTS_ENABLED", "LZC_ASSISTANT_ENABLED", "LZC_MAILOUT_ENABLED"];
const uuid = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/;
function boolean(value) {
if (value !== "true" && value !== "false") throw new Error("Runtime feature values must be true or false");
return value;
}
function projectIds(value) {
const ids = JSON.parse(value ?? "[]");
if (!Array.isArray(ids) || ids.length > 32 || ids.some(id => typeof id !== "string" || !uuid.test(id)))
throw new Error("Invalid retirement control projects");
return ids;
}
export function featureVariables(requested, current, operatorProjectId) {
if (!uuid.test(operatorProjectId ?? "")) throw new Error("Runtime feature policy requires the operator project ID");
const result = { ...requested };
for (const key of featureKeys) result[key] = boolean(Object.hasOwn(current, key) ? current[key] : requested[key] ?? "false");
if (result.LZC_ASSISTANT_ENABLED === "true" && (result.LZC_AUTH_ENABLED !== "true" || !result.LZC_MODEL_SERVING_TOKEN))
throw new Error("Assistant runtime prerequisites unavailable");
if (result.LZC_MAILOUT_ENABLED === "true" && ["LZC_MAILOUT_HOST", "LZC_MAILOUT_PORT", "LZC_MAILOUT_USERNAME", "LZC_MAILOUT_PASSWORD", "LZC_MAILOUT_FROM", "LZC_DEPLOYMENT_ARTIFACT_KEY"].some(key => !result[key]))
throw new Error("MailOut runtime prerequisites unavailable");
if (result.LZC_RETIREMENTS_ENABLED === "true" && (result.LZC_EXECUTION_ENABLED !== "true" || result.LZC_APPLICATION_EXECUTION_ENABLED !== "true" || !result.LZC_DEPLOYMENT_ARTIFACT_KEY))
throw new Error("Retirement runtime prerequisites unavailable");
const controls = [...new Set([operatorProjectId, ...projectIds(requested.LZC_RETIREMENT_CONTROL_PROJECT_IDS), ...projectIds(current.LZC_RETIREMENT_CONTROL_PROJECT_IDS)])];
if (controls.length > 32) throw new Error("Too many retirement control projects");
result.LZC_RETIREMENT_CONTROL_PROJECT_IDS = JSON.stringify(controls);
return result;
}
export function preserveRuntimeFeatures({ directory, spaceId, operatorProjectId, cf }) {
if (!uuid.test(spaceId ?? "")) throw new Error("Invalid runtime feature target space");
const appFile = join(directory, "app-vars.json"), stageFile = join(directory, "app-stage-vars.json");
for (const file of [appFile, stageFile]) {
const stat = lstatSync(file);
if (!stat.isFile() || (stat.mode & 0o077) !== 0 || stat.uid !== process.getuid()) throw new Error("Private feature variable files required");
}
const requested = JSON.parse(readFileSync(appFile, "utf8"));
const stage = JSON.parse(readFileSync(stageFile, "utf8"));
const apps = cf(["curl", `/v3/apps?names=landing-zone-configurator&space_guids=${spaceId}`]);
if (!Array.isArray(apps.resources) || apps.resources.length > 1 || (apps.pagination?.total_results ?? apps.resources.length) !== apps.resources.length)
throw new Error("Runtime feature application lookup failed");
let current = {};
if (apps.resources.length) {
const app = apps.resources[0];
if (app.name !== "landing-zone-configurator" || !uuid.test(app.guid) || app.relationships?.space?.data?.guid !== spaceId) throw new Error("Runtime feature application target mismatch");
current = cf(["curl", `/v3/apps/${app.guid}/environment_variables`]).var;
if (!current || typeof current !== "object" || Array.isArray(current)) throw new Error("Runtime feature environment lookup failed");
}
const active = featureVariables(requested, current, operatorProjectId);
// Preserve only explicit feature choices and protected project IDs. Secrets,
// origins, authentication and execution permissions always use the reviewed release.
const suspended = { ...stage, LZC_EXECUTION_ENABLED: "false", LZC_APPLICATION_EXECUTION_ENABLED: "false", LZC_RUNNER_POOL_SIZE: "0" };
for (const key of featureKeys) suspended[key] = "false";
writeFileSync(appFile, JSON.stringify(active), { mode: 0o600 });
writeFileSync(stageFile, JSON.stringify(suspended), { mode: 0o600 });
return Object.fromEntries(featureKeys.map(key => [key, active[key]]));
}
if (process.argv[1] === "-" || (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)) {
try {
const flags = preserveRuntimeFeatures({ directory: process.env.LZC_PRIVATE, spaceId: process.env.LZC_CF_SPACE_ID, operatorProjectId: process.env.LZC_FEATURE_OPERATOR_PROJECT_ID, cf(args) {
const result = spawnSync("cf", args, { encoding: "utf8", timeout: 45_000, maxBuffer: 4 * 1024 * 1024 });
if (result.status !== 0) throw new Error("CF feature lookup failed");
return JSON.parse(result.stdout);
} });
console.log(JSON.stringify({ event: "runtime_features_preserved", flags }));
} catch {
// CF responses and private variable files can contain credentials. Never log them.
console.error("Runtime feature policy could not be verified; deployment stopped before staging.");
process.exitCode = 1;
}
}
LZC_RUNTIME_FEATURES
# END GENERATED RUNTIME FEATURE POLICY
- name: Stage runner, migration and application
run: node infra/ci/run-parallel.mjs runner 'bash infra/ci/stage-release-runner.sh' migration 'bash infra/ci/stage-release-migration.sh' application 'bash infra/ci/stage-release-application.sh'
- name: Activate verified droplet with rolling deployment
Expand Down
84 changes: 83 additions & 1 deletion .github/workflows/configurator-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
npm install --global npm@11.19.0
npm ci
npm run check
node --test ../infra/ci/prepare-release.test.mjs
node --test ../infra/ci/prepare-release.test.mjs ../infra/ci/runtime-features.test.mjs
node --test ../infra/ci/buildpack-source.test.mjs
node --test ../infra/ci/image-staging.test.mjs
node --test ../infra/ci/ubuntu-dependencies.test.mjs
Expand Down Expand Up @@ -340,12 +340,94 @@ jobs:
LZC_GITHUB_CLIENT_SECRET: ${{ secrets.LZC_GITHUB_CLIENT_SECRET }}
- name: CF login and target
if: steps.lifecycle.outputs.parallel == 'true'
env:
LZC_FEATURE_OPERATOR_PROJECT_ID: ${{ vars.LZC_PROJECT_ID }}
run: |
cf version
cf api "$CF_API_URL"
cf auth
cf target -o lzc-dev -s configurator
test "$(cf space configurator --guid)" = "$LZC_CF_SPACE_ID"
# BEGIN GENERATED RUNTIME FEATURE POLICY
node --input-type=module <<'LZC_RUNTIME_FEATURES'
// Embedded into both deployment workflows so rollback of an older application
// still preserves the current operator policy. Regenerate with embed-runtime-features.mjs.
import { readFileSync, writeFileSync, lstatSync } from "node:fs";
import { spawnSync } from "node:child_process";
import { join } from "node:path";
import { pathToFileURL } from "node:url";

export const featureKeys = ["LZC_RETIREMENTS_ENABLED", "LZC_ASSISTANT_ENABLED", "LZC_MAILOUT_ENABLED"];
const uuid = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/;
function boolean(value) {
if (value !== "true" && value !== "false") throw new Error("Runtime feature values must be true or false");
return value;
}
function projectIds(value) {
const ids = JSON.parse(value ?? "[]");
if (!Array.isArray(ids) || ids.length > 32 || ids.some(id => typeof id !== "string" || !uuid.test(id)))
throw new Error("Invalid retirement control projects");
return ids;
}
export function featureVariables(requested, current, operatorProjectId) {
if (!uuid.test(operatorProjectId ?? "")) throw new Error("Runtime feature policy requires the operator project ID");
const result = { ...requested };
for (const key of featureKeys) result[key] = boolean(Object.hasOwn(current, key) ? current[key] : requested[key] ?? "false");
if (result.LZC_ASSISTANT_ENABLED === "true" && (result.LZC_AUTH_ENABLED !== "true" || !result.LZC_MODEL_SERVING_TOKEN))
throw new Error("Assistant runtime prerequisites unavailable");
if (result.LZC_MAILOUT_ENABLED === "true" && ["LZC_MAILOUT_HOST", "LZC_MAILOUT_PORT", "LZC_MAILOUT_USERNAME", "LZC_MAILOUT_PASSWORD", "LZC_MAILOUT_FROM", "LZC_DEPLOYMENT_ARTIFACT_KEY"].some(key => !result[key]))
throw new Error("MailOut runtime prerequisites unavailable");
if (result.LZC_RETIREMENTS_ENABLED === "true" && (result.LZC_EXECUTION_ENABLED !== "true" || result.LZC_APPLICATION_EXECUTION_ENABLED !== "true" || !result.LZC_DEPLOYMENT_ARTIFACT_KEY))
throw new Error("Retirement runtime prerequisites unavailable");
const controls = [...new Set([operatorProjectId, ...projectIds(requested.LZC_RETIREMENT_CONTROL_PROJECT_IDS), ...projectIds(current.LZC_RETIREMENT_CONTROL_PROJECT_IDS)])];
if (controls.length > 32) throw new Error("Too many retirement control projects");
result.LZC_RETIREMENT_CONTROL_PROJECT_IDS = JSON.stringify(controls);
return result;
}
export function preserveRuntimeFeatures({ directory, spaceId, operatorProjectId, cf }) {
if (!uuid.test(spaceId ?? "")) throw new Error("Invalid runtime feature target space");
const appFile = join(directory, "app-vars.json"), stageFile = join(directory, "app-stage-vars.json");
for (const file of [appFile, stageFile]) {
const stat = lstatSync(file);
if (!stat.isFile() || (stat.mode & 0o077) !== 0 || stat.uid !== process.getuid()) throw new Error("Private feature variable files required");
}
const requested = JSON.parse(readFileSync(appFile, "utf8"));
const stage = JSON.parse(readFileSync(stageFile, "utf8"));
const apps = cf(["curl", `/v3/apps?names=landing-zone-configurator&space_guids=${spaceId}`]);
if (!Array.isArray(apps.resources) || apps.resources.length > 1 || (apps.pagination?.total_results ?? apps.resources.length) !== apps.resources.length)
throw new Error("Runtime feature application lookup failed");
let current = {};
if (apps.resources.length) {
const app = apps.resources[0];
if (app.name !== "landing-zone-configurator" || !uuid.test(app.guid) || app.relationships?.space?.data?.guid !== spaceId) throw new Error("Runtime feature application target mismatch");
current = cf(["curl", `/v3/apps/${app.guid}/environment_variables`]).var;
if (!current || typeof current !== "object" || Array.isArray(current)) throw new Error("Runtime feature environment lookup failed");
}
const active = featureVariables(requested, current, operatorProjectId);
// Preserve only explicit feature choices and protected project IDs. Secrets,
// origins, authentication and execution permissions always use the reviewed release.
const suspended = { ...stage, LZC_EXECUTION_ENABLED: "false", LZC_APPLICATION_EXECUTION_ENABLED: "false", LZC_RUNNER_POOL_SIZE: "0" };
for (const key of featureKeys) suspended[key] = "false";
writeFileSync(appFile, JSON.stringify(active), { mode: 0o600 });
writeFileSync(stageFile, JSON.stringify(suspended), { mode: 0o600 });
return Object.fromEntries(featureKeys.map(key => [key, active[key]]));
}
if (process.argv[1] === "-" || (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)) {
try {
const flags = preserveRuntimeFeatures({ directory: process.env.LZC_PRIVATE, spaceId: process.env.LZC_CF_SPACE_ID, operatorProjectId: process.env.LZC_FEATURE_OPERATOR_PROJECT_ID, cf(args) {
const result = spawnSync("cf", args, { encoding: "utf8", timeout: 45_000, maxBuffer: 4 * 1024 * 1024 });
if (result.status !== 0) throw new Error("CF feature lookup failed");
return JSON.parse(result.stdout);
} });
console.log(JSON.stringify({ event: "runtime_features_preserved", flags }));
} catch {
// CF responses and private variable files can contain credentials. Never log them.
console.error("Runtime feature policy could not be verified; deployment stopped before staging.");
process.exitCode = 1;
}
}
LZC_RUNTIME_FEATURES
# END GENERATED RUNTIME FEATURE POLICY
- name: Stage runner, migration and application in parallel
if: steps.lifecycle.outputs.parallel == 'true'
id: stage_runner
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/validate-configurator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ jobs:
- name: Lint, typecheck, build and test
run: npm run check
- name: Check release configuration with the built API validators
run: node --test ../infra/ci/prepare-release.test.mjs
run: node --test ../infra/ci/prepare-release.test.mjs ../infra/ci/runtime-features.test.mjs
- name: Check parallel release lifecycle and slim migration payload
run: node --test ../infra/ci/release-lifecycle.test.mjs ../infra/ci/production.test.mjs ../infra/ci/production-readiness.test.mjs
- name: Check release configuration under the explicit Dev exception
run: node --test ../infra/ci/prepare-release.test.mjs
run: node --test ../infra/ci/prepare-release.test.mjs ../infra/ci/runtime-features.test.mjs
env:
LZC_RELEASE_MODE: dev-skip-assistant-qualification
- name: Test first preparations and stateful platform Plan/Apply broker
Expand Down
62 changes: 62 additions & 0 deletions landing-zone-configurator/docs/production.de.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,68 @@ GitHub-Environments. Die öffentliche Origin lautet
`https://app.landing-zone.runs.onstackit.cloud`. Der native Accelerator in `src/`
bleibt unabhängig nutzbar.

## Feature-Toggles zur Laufzeit

Betreiber können bereitgestellte optionale Funktionen über CF-Umgebungsvariablen
der App schalten. Dafür sind weder ein neuer App-Build noch ein GitHub Release
oder eine Deployment-Pipeline nötig. Zulässige Werte sind die Zeichenfolgen
`true` und `false`.

| Variable | Funktion |
| --- | --- |
| `LZC_RETIREMENTS_ENABLED` | Gestufter Rückbau von Platform Landing Zones und seine authentifizierte API |
| `LZC_ASSISTANT_ENABLED` | Konfigurations-Assistant und Template-Beratung |
| `LZC_MAILOUT_ENABLED` | Ausgehende transaktionale E-Mails; Einstellungen und Posteingang bleiben verfügbar |

Beispiel für eine ruhende, vollständig ausgerollte Produktions-App:

```sh
cf target -o lzc-prod -s configurator
cf set-env landing-zone-configurator LZC_RETIREMENTS_ENABLED true
cf restart landing-zone-configurator --strategy rolling --max-in-flight 1
```

Mit `false` wird die Funktion deaktiviert. Geänderte CF-Variablen wirken erst beim
Neustart der Prozesse; sie werden nicht im laufenden Prozess neu geladen. Ein
Rolling Restart erhält die Verfügbarkeit. Vorher sicherstellen, dass keine
Release-Pipeline oder CF-Bereitstellung läuft und kein neueres, noch ungestagtes
Package ansteht: Die CF-CLI kann sonst dieses Package stagen, statt den bisherigen
Droplet neu zu starten. Im Zweifel den aktuellen Droplet ausdrücklich über eine
rollierende CF-V3-Bereitstellung angeben, wie im Release-Aktivator. Diese Aktion
aktiviert die Funktion; sie startet keinen Rückbau einer Landing Zone.

Rückbauvorhaben vor dem Abschalten beenden oder pausieren und alle laufenden Jobs
sowie State-Rückmeldungen vollständig abwickeln lassen. Pausieren allein belegt
keinen gestoppten Runner; der Schalter beendet keine gestarteten Cloud-Jobs.

Jedes Deployment übernimmt die drei bestehenden CF-Schalter nach dem gezielten
CF-Login und vor dem Staging. Ein ausdrückliches `false` bleibt ebenso erhalten
wie `true`. GitHub-Einstellungen liefern nur Initialwerte, wenn die betreffende
CF-Variable fehlt. Authentifizierung, Ausführungsberechtigungen, Origins und
Zugangsdaten stammen weiterhin aus dem geprüften Release. Aktivierte Funktionen
benötigen ihre bereitgestellten Abhängigkeiten; fehlende Voraussetzungen oder
ungültige Werte stoppen das Deployment vor dem Staging. Toggles nicht während
einer laufenden Release-Pipeline ändern.

Retirement benötigt außerdem `LZC_RETIREMENT_CONTROL_PROJECT_IDS`. Das Deployment
fügt das Operator-Projekt des Configurators immer dieser Schutzliste hinzu, auch
bei deaktiviertem Retirement, und erhält weitere geschützte Projekte. Beim
normalen Schalten einer Funktion dürfen diese Schutzwerte nicht entfernt werden.
Benutzerrollen, Organisationsnachweis und Plan-/Apply-Freigabe bleiben erforderlich.

Während des Stagings werden alle drei optionalen Funktionen und Cloud-Ausführungen
in der Staging-Konfiguration vorübergehend deaktiviert. Erst die freigegebene
Aktivierung stellt die übernommenen Betreiberwerte wieder her. Bestehende Prozesse
behalten bis dahin ihre laufenden Einstellungen. Die aktuelle Workflow-Version
enthält die Richtlinie direkt; dadurch bleiben CF-Entscheidungen auch beim
erneuten Deployment eines älteren kompatiblen App-Releases erhalten.

Maintainer ändern `infra/ci/runtime-features.mjs` und führen danach
`node infra/ci/embed-runtime-features.mjs` sowie
`node --test infra/ci/runtime-features.test.mjs` aus. Die Tests prüfen beide
Workflow-Kopien, Initialwerte, deaktivierte Funktionen, Geheimnis-Isolation und
das Abschalten während des Stagings.

## Bereitstellung und Verfügbarkeit

Die geprüfte Stage `lzc-prod` definiert drei Web/API-Instanzen, zwei gemeinsam
Expand Down
Loading
Loading