@empire-builder-kit/nx 1.0.0-rc.46 → 1.0.0-rc.48
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 +14 -169
- package/executors.json +24 -79
- package/generators.json +18 -18
- package/package.json +13 -71
- package/src/aws/identity.d.ts +1 -1
- package/src/aws-authority/boundary-transforms.d.ts +9 -0
- package/src/aws-authority/boundary-transforms.js +78 -0
- package/src/aws-authority/contracts.d.ts +116 -0
- package/src/aws-authority/contracts.js +40 -0
- package/src/aws-authority/deployment-guardrails.d.ts +4 -0
- package/src/aws-authority/deployment-guardrails.js +543 -0
- package/src/aws-authority/deployment-policy-groups.d.ts +3 -0
- package/src/aws-authority/deployment-policy-groups.js +299 -0
- package/src/aws-authority/deployment-resources.d.ts +64 -0
- package/src/aws-authority/deployment-resources.js +265 -0
- package/src/aws-authority/deployment-services.d.ts +3 -0
- package/src/aws-authority/deployment-services.js +717 -0
- package/src/aws-authority/development-authority.d.ts +11 -0
- package/src/aws-authority/development-authority.js +160 -0
- package/src/aws-authority/guardrail-actions.d.ts +87 -0
- package/src/aws-authority/guardrail-actions.js +463 -0
- package/src/aws-authority/policy-document.d.ts +15 -0
- package/src/aws-authority/policy-document.js +264 -0
- package/src/aws-authority/runtime-boundary.d.ts +7 -0
- package/src/aws-authority/runtime-boundary.js +211 -0
- package/src/aws-authority/service-actions.d.ts +96 -0
- package/src/aws-authority/service-actions.js +512 -0
- package/src/aws-authority/stage-authority.d.ts +6 -244
- package/src/aws-authority/stage-authority.js +114 -3419
- package/src/aws-authority/stage-identity.d.ts +6 -0
- package/src/aws-authority/stage-identity.js +134 -0
- package/src/cli/bootstrap.d.ts +0 -20
- package/src/cli/bootstrap.js +2 -153
- package/src/cli/dev-command.d.ts +2 -4
- package/src/cli/dev-command.js +1 -19
- package/src/cli/main.d.ts +0 -4
- package/src/cli/main.js +22 -80
- package/src/cli/output.d.ts +2 -4
- package/src/cli/output.js +2 -8
- package/src/executors/deployment-plan/deployment-plan.d.ts +0 -2
- package/src/executors/deployment-plan/deployment-plan.js +5 -67
- package/src/executors/dev-doctor/dev-doctor.d.ts +25 -3
- package/src/executors/dev-doctor/dev-doctor.js +137 -50
- package/src/executors/dev-setup/dev-setup.d.ts +18 -1
- package/src/executors/dev-setup/dev-setup.js +320 -196
- package/src/executors/foundation-preflight/foundation-preflight.js +9 -1
- package/src/executors/foundation-remove-preflight/foundation-remove-preflight.js +2 -2
- package/src/executors/local-deploy/deployed-smoke.d.ts +12 -0
- package/src/executors/local-deploy/deployed-smoke.js +115 -0
- package/src/executors/local-deploy/deployment-authority.d.ts +24 -0
- package/src/executors/local-deploy/deployment-authority.js +81 -0
- package/src/executors/local-deploy/deployment-child.d.ts +18 -0
- package/src/executors/local-deploy/deployment-child.js +77 -0
- package/src/executors/local-deploy/deployment-contracts.d.ts +96 -0
- package/src/executors/local-deploy/deployment-contracts.js +3 -0
- package/src/executors/local-deploy/deployment-projects.d.ts +4 -0
- package/src/executors/local-deploy/deployment-projects.js +16 -0
- package/src/executors/local-deploy/deployment-receipt.d.ts +4 -0
- package/src/executors/local-deploy/deployment-receipt.js +55 -0
- package/src/executors/local-deploy/deployment-scope.d.ts +17 -0
- package/src/executors/local-deploy/deployment-scope.js +239 -0
- package/src/executors/local-deploy/deployment-source.d.ts +13 -0
- package/src/executors/local-deploy/deployment-source.js +86 -0
- package/src/executors/local-deploy/local-deploy.d.ts +5 -106
- package/src/executors/local-deploy/local-deploy.js +56 -855
- package/src/executors/sst-lifecycle/governed-child-process.d.ts +27 -0
- package/src/executors/sst-lifecycle/governed-child-process.js +277 -0
- package/src/executors/sst-lifecycle/governed-native-operation.js +4 -10
- package/src/executors/sst-lifecycle/run-sst-command.d.ts +4 -85
- package/src/executors/sst-lifecycle/run-sst-command.js +28 -788
- package/src/executors/sst-lifecycle/sst-contracts.d.ts +44 -0
- package/src/executors/sst-lifecycle/sst-contracts.js +3 -0
- package/src/executors/sst-lifecycle/sst-invocation.d.ts +17 -0
- package/src/executors/sst-lifecycle/sst-invocation.js +502 -0
- package/src/executors/sst-lifecycle/task-unlock.js +3 -3
- package/src/foundation/discovery.d.ts +1 -5
- package/src/foundation/discovery.js +0 -2
- package/src/foundation/identity-domain-parent-ready.d.ts +91 -0
- package/src/foundation/identity-domain-parent-ready.js +333 -0
- package/src/foundation/identity-domain.d.ts +94 -0
- package/src/foundation/identity-domain.js +115 -0
- package/src/foundation/index.d.ts +2 -2
- package/src/foundation/index.js +7 -9
- package/src/foundation/local-private-smoke-access.d.ts +6 -15
- package/src/foundation/local-private-smoke-access.js +8 -192
- package/src/foundation/observability.d.ts +16 -26
- package/src/foundation/observability.js +34 -135
- package/src/foundation/preflight.js +16 -14
- package/src/foundation/private-smoke-access.d.ts +7 -14
- package/src/foundation/private-smoke-access.js +4 -126
- package/src/foundation/root-site-workspace.d.ts +35 -0
- package/src/foundation/root-site-workspace.js +80 -0
- package/src/foundation/root-site.d.ts +82 -0
- package/src/foundation/root-site.js +276 -0
- package/src/generators/formatting.js +5 -4
- package/src/generators/framework-prerequisites.d.ts +2 -0
- package/src/generators/framework-prerequisites.js +34 -0
- package/src/generators/function/function.d.ts +20 -1
- package/src/generators/function/function.js +143 -90
- package/src/generators/function/schema.d.ts +1 -0
- package/src/generators/function/schema.json +8 -2
- package/src/generators/function-access/function-access.d.ts +8 -0
- package/src/generators/function-access/function-access.js +73 -0
- package/src/generators/function-access/schema.d.ts +6 -0
- package/src/generators/function-access/schema.json +25 -0
- package/src/generators/observability-policy.js +1 -2
- package/src/{supply-chain → generators}/pnpm-toolchain-authority.d.ts +3 -3
- package/src/{supply-chain → generators}/pnpm-toolchain-authority.js +12 -12
- package/src/generators/post-generation-install.d.ts +2 -9
- package/src/generators/post-generation-install.js +12 -140
- package/src/generators/preset/dependency-overrides.d.ts +14 -20
- package/src/generators/preset/dependency-overrides.js +13 -57
- package/src/generators/preset/generator.js +0 -3
- package/src/generators/preset/workspace-files-foundation-infra.d.ts +6 -0
- package/src/generators/preset/workspace-files-foundation-infra.js +586 -0
- package/src/generators/preset/workspace-files-foundation-readme.d.ts +5 -0
- package/src/generators/preset/workspace-files-foundation-readme.js +90 -0
- package/src/generators/preset/workspace-files-foundation.d.ts +3 -0
- package/src/generators/preset/workspace-files-foundation.js +170 -0
- package/src/generators/preset/workspace-files-ownership.d.ts +9 -0
- package/src/generators/preset/workspace-files-ownership.js +124 -0
- package/src/generators/preset/workspace-files-root-config.d.ts +32 -0
- package/src/generators/preset/workspace-files-root-config.js +356 -0
- package/src/generators/preset/workspace-files-root-docs.d.ts +5 -0
- package/src/generators/preset/workspace-files-root-docs.js +109 -0
- package/src/generators/preset/workspace-files-shared.d.ts +18 -0
- package/src/generators/preset/workspace-files-shared.js +7 -0
- package/src/generators/preset/workspace-files-workflows.d.ts +39 -0
- package/src/generators/preset/workspace-files-workflows.js +306 -0
- package/src/generators/preset/workspace-files-workspace-health.d.ts +6 -0
- package/src/generators/preset/workspace-files-workspace-health.js +148 -0
- package/src/generators/preset/workspace-files.d.ts +10 -24
- package/src/generators/preset/workspace-files.js +48 -10511
- package/src/generators/site/built-in-site-documentation-files.d.ts +3 -0
- package/src/generators/site/built-in-site-documentation-files.js +51 -0
- package/src/generators/site/built-in-site-files.d.ts +11 -0
- package/src/generators/site/built-in-site-files.js +41 -0
- package/src/generators/site/built-in-site-infrastructure-files.d.ts +3 -0
- package/src/generators/site/built-in-site-infrastructure-files.js +115 -0
- package/src/generators/site/built-in-site-plan.d.ts +23 -0
- package/src/generators/site/built-in-site-plan.js +67 -0
- package/src/generators/site/built-in-site-project-files.d.ts +11 -0
- package/src/generators/site/built-in-site-project-files.js +212 -0
- package/src/generators/site/built-in-site-script-files.d.ts +4 -0
- package/src/generators/site/built-in-site-script-files.js +102 -0
- package/src/generators/site/built-in-site-shared.d.ts +69 -0
- package/src/generators/site/built-in-site-shared.js +314 -0
- package/src/generators/site/built-in-site-sst-config-files.d.ts +3 -0
- package/src/generators/site/built-in-site-sst-config-files.js +107 -0
- package/src/generators/site/built-in-site-web-files.d.ts +3 -0
- package/src/generators/site/built-in-site-web-files.js +78 -0
- package/src/generators/site/schema.d.ts +9 -0
- package/src/generators/site/schema.json +26 -0
- package/src/generators/site/site.d.ts +5 -0
- package/src/generators/site/site.js +153 -0
- package/src/generators/slice/built-in-plan-api-files.d.ts +1 -2
- package/src/generators/slice/built-in-plan-api-files.js +30 -890
- package/src/generators/slice/built-in-plan-database-lifecycle-files.js +57 -1851
- package/src/generators/slice/built-in-plan-infrastructure-files.d.ts +5 -2
- package/src/generators/slice/built-in-plan-infrastructure-files.js +80 -3358
- package/src/generators/slice/built-in-plan-key-value-files.d.ts +3 -2
- package/src/generators/slice/built-in-plan-key-value-files.js +3 -21
- package/src/generators/slice/built-in-plan-project-files.d.ts +5 -3
- package/src/generators/slice/built-in-plan-project-files.js +79 -897
- package/src/generators/slice/built-in-plan-shared.d.ts +4 -19
- package/src/generators/slice/built-in-plan-shared.js +5 -58
- package/src/generators/slice/built-in-plan-sst-config.d.ts +49 -0
- package/src/generators/slice/built-in-plan-sst-config.js +160 -0
- package/src/generators/slice/built-in-plan-web-files.d.ts +1 -1
- package/src/generators/slice/built-in-plan-web-files.js +14 -475
- package/src/generators/slice/built-in-plan.d.ts +2 -3
- package/src/generators/slice/built-in-plan.js +79 -277
- package/src/{developer-agent/preview-changes.d.ts → generators/slice/generation-tree.d.ts} +1 -5
- package/src/generators/slice/generation-tree.js +161 -0
- package/src/generators/slice/persistence-contract.js +2 -2
- package/src/generators/slice/schema.json +12 -4
- package/src/generators/slice/slice-config.d.ts +7 -0
- package/src/generators/slice/slice-config.js +125 -0
- package/src/generators/slice/slice.js +52 -257
- package/src/generators/slice/sql-bootstrap.d.ts +1 -0
- package/src/generators/slice/sql-bootstrap.js +505 -0
- package/src/generators/slice/sql-client.d.ts +1 -0
- package/src/generators/slice/sql-client.js +107 -0
- package/src/generators/slice/sql-infrastructure.d.ts +1 -0
- package/src/generators/slice/sql-infrastructure.js +225 -0
- package/src/generators/slice/sql-logging.d.ts +1 -0
- package/src/generators/slice/sql-logging.js +266 -0
- package/src/generators/slice/sql-migration.d.ts +2 -0
- package/src/generators/slice/sql-migration.js +202 -0
- package/src/generators/slice/standard-slice-contract.d.ts +25 -0
- package/src/generators/slice/standard-slice-contract.js +64 -0
- package/src/generators/sql/schema.json +1 -1
- package/src/generators/sql/sql.d.ts +1 -1
- package/src/generators/sql/sql.js +13 -7
- package/src/generators/upgrade/framework-package-upgrade.d.ts +35 -0
- package/src/generators/upgrade/framework-package-upgrade.js +55 -0
- package/src/generators/upgrade/framework-packages.d.ts +25 -0
- package/src/generators/upgrade/framework-packages.js +138 -0
- package/src/generators/upgrade/function-authentication-notice.d.ts +21 -0
- package/src/generators/upgrade/function-authentication-notice.js +54 -0
- package/src/generators/upgrade/schema.d.ts +0 -3
- package/src/generators/upgrade/schema.json +7 -17
- package/src/generators/upgrade/slice-compositions.d.ts +20 -0
- package/src/generators/upgrade/slice-compositions.js +100 -0
- package/src/generators/upgrade/slice-upgrade-guidance.d.ts +19 -0
- package/src/generators/upgrade/slice-upgrade-guidance.js +50 -0
- package/src/generators/upgrade/slice-upgrade.d.ts +4 -0
- package/src/generators/upgrade/slice-upgrade.js +231 -0
- package/src/generators/upgrade/upgrade-plan.d.ts +49 -0
- package/src/generators/upgrade/upgrade-plan.js +242 -0
- package/src/generators/upgrade/upgrade-preflight.d.ts +20 -0
- package/src/generators/upgrade/upgrade-preflight.js +64 -0
- package/src/generators/upgrade/upgrade.d.ts +8 -87
- package/src/generators/upgrade/upgrade.js +27 -1909
- package/src/generators/workload/schema.json +2 -2
- package/src/generators/workload/workload.d.ts +11 -11
- package/src/generators/workload/workload.js +167 -1200
- package/src/index.d.ts +0 -5
- package/src/index.js +0 -5
- package/src/local-dev/browser-verification.d.ts +0 -7
- package/src/local-dev/browser-verification.js +0 -136
- package/src/local-dev/contracts.d.ts +6 -0
- package/src/local-dev/contracts.js +17 -9
- package/src/local-dev/environment-checks.d.ts +126 -0
- package/src/local-dev/environment-checks.js +81 -0
- package/src/local-dev/environment-inspector.d.ts +3 -124
- package/src/local-dev/environment-inspector.js +9 -148
- package/src/local-dev/fleet-process.d.ts +9 -2
- package/src/local-dev/fleet-process.js +27 -7
- package/src/local-dev/gateway-daemon.d.ts +1 -1
- package/src/local-dev/gateway-daemon.js +6 -4
- package/src/local-dev/portless.d.ts +5 -0
- package/src/local-dev/portless.js +5 -0
- package/src/local-dev/private-state.d.ts +1 -0
- package/src/local-dev/private-state.js +19 -23
- package/src/local-dev/process-group.d.ts +10 -0
- package/src/local-dev/process-group.js +33 -0
- package/src/local-dev/process-identity.js +4 -2
- package/src/local-dev/slice-runner-child.d.ts +37 -0
- package/src/local-dev/slice-runner-child.js +127 -0
- package/src/local-dev/slice-runner-recovery.d.ts +32 -0
- package/src/local-dev/slice-runner-recovery.js +216 -0
- package/src/local-dev/slice-runner-state.d.ts +82 -0
- package/src/local-dev/slice-runner-state.js +265 -0
- package/src/local-dev/slice-runner.d.ts +4 -117
- package/src/local-dev/slice-runner.js +59 -594
- package/src/local-dev/tls.js +39 -99
- package/src/local-dev/trust-store.d.ts +42 -0
- package/src/local-dev/trust-store.js +87 -0
- package/src/ownership/composition.d.ts +7 -0
- package/src/ownership/composition.js +64 -56
- package/src/ownership/index.d.ts +2 -0
- package/src/ownership/index.js +7 -0
- package/src/ownership/pnpm-workspace.d.ts +77 -0
- package/src/ownership/pnpm-workspace.js +225 -0
- package/src/ownership/record.d.ts +19 -0
- package/src/ownership/record.js +26 -2
- package/src/ownership/site-record.d.ts +26 -0
- package/src/ownership/site-record.js +120 -0
- package/src/repository-policy/capacity-migration.d.ts +1 -1
- package/src/repository-policy/capacity-migration.js +1 -1
- package/src/repository-policy/deployment-plan.d.ts +3 -0
- package/src/repository-policy/deployment-plan.js +33 -4
- package/src/repository-policy/foundation-router.d.ts +17 -0
- package/src/repository-policy/foundation-router.js +44 -0
- package/src/repository-policy/index.d.ts +3 -0
- package/src/repository-policy/index.js +3 -0
- package/src/repository-policy/policy-accounts.d.ts +22 -0
- package/src/repository-policy/policy-accounts.js +134 -0
- package/src/repository-policy/policy-files.d.ts +8 -0
- package/src/repository-policy/policy-files.js +201 -0
- package/src/repository-policy/policy-internal.d.ts +2 -0
- package/src/repository-policy/policy-internal.js +11 -0
- package/src/repository-policy/policy-model.d.ts +95 -0
- package/src/repository-policy/policy-model.js +42 -0
- package/src/repository-policy/policy-validation.d.ts +4 -0
- package/src/repository-policy/policy-validation.js +308 -0
- package/src/repository-policy/policy.d.ts +6 -109
- package/src/repository-policy/policy.js +52 -626
- package/src/repository-policy/public-dns.d.ts +69 -0
- package/src/repository-policy/public-dns.js +265 -0
- package/src/{generators/repository-policy → repository-policy}/tree-policy.d.ts +1 -1
- package/src/{generators/repository-policy → repository-policy}/tree-policy.js +5 -5
- package/src/schemas/generated-ownership-v2.json +6 -0
- package/src/schemas/repository-policy-v1.json +106 -3
- package/src/secrets/index.d.ts +0 -5
- package/src/secrets/index.js +0 -5
- package/src/slice-infra/index.d.ts +57 -0
- package/src/slice-infra/index.js +117 -0
- package/src/slice-scripts/build.d.ts +27 -0
- package/src/slice-scripts/build.js +120 -0
- package/src/slice-scripts/database.d.ts +87 -0
- package/src/slice-scripts/database.js +328 -0
- package/src/slice-scripts/index.d.ts +11 -0
- package/src/slice-scripts/index.js +23 -0
- package/src/slice-scripts/root-site-routes.d.ts +11 -0
- package/src/slice-scripts/root-site-routes.js +83 -0
- package/src/slice-scripts/sql-migration-engine.mjs +180 -0
- package/src/workload-roles/effective-policy.d.ts +0 -37
- package/src/workload-roles/effective-policy.js +1 -174
- package/src/workload-roles/standard-slice.d.ts +2 -19
- package/src/workload-roles/standard-slice.js +3 -129
- package/src/workspace-deployment/ownership.d.ts +15 -0
- package/src/workspace-deployment/ownership.js +19 -3
- package/src/api-contract/baseline-update.d.ts +0 -82
- package/src/api-contract/baseline-update.js +0 -225
- package/src/api-contract/compatibility.d.ts +0 -30
- package/src/api-contract/compatibility.js +0 -643
- package/src/api-contract/contract-graph.d.ts +0 -35
- package/src/api-contract/contract-graph.js +0 -141
- package/src/api-contract/evidence.d.ts +0 -23
- package/src/api-contract/evidence.js +0 -87
- package/src/api-contract/index.d.ts +0 -6
- package/src/api-contract/index.js +0 -10
- package/src/api-contract/model.d.ts +0 -144
- package/src/api-contract/model.js +0 -993
- package/src/api-contract/rollout.d.ts +0 -32
- package/src/api-contract/rollout.js +0 -88
- package/src/authorization/compatibility.d.ts +0 -62
- package/src/authorization/compatibility.js +0 -175
- package/src/authorization/index.d.ts +0 -1
- package/src/authorization/index.js +0 -5
- package/src/blueprints/execution.d.ts +0 -55
- package/src/blueprints/execution.js +0 -329
- package/src/blueprints/external-sandbox.d.ts +0 -53
- package/src/blueprints/external-sandbox.js +0 -1194
- package/src/blueprints/index.d.ts +0 -5
- package/src/blueprints/index.js +0 -9
- package/src/blueprints/inputs.d.ts +0 -43
- package/src/blueprints/inputs.js +0 -103
- package/src/blueprints/manifest.d.ts +0 -281
- package/src/blueprints/manifest.js +0 -424
- package/src/blueprints/resolver.d.ts +0 -37
- package/src/blueprints/resolver.js +0 -387
- package/src/blueprints/transitions.d.ts +0 -20
- package/src/blueprints/transitions.js +0 -61
- package/src/cli/agent-command.d.ts +0 -30
- package/src/cli/agent-command.js +0 -204
- package/src/cli/agent-runtime.d.ts +0 -25
- package/src/cli/agent-runtime.js +0 -498
- package/src/cli/blueprint-authority.d.ts +0 -9
- package/src/cli/blueprint-authority.js +0 -43
- package/src/cli/blueprint-command.d.ts +0 -24
- package/src/cli/blueprint-command.js +0 -63
- package/src/data-lifecycle/index.d.ts +0 -3
- package/src/data-lifecycle/index.js +0 -7
- package/src/data-lifecycle/model.d.ts +0 -172
- package/src/data-lifecycle/model.js +0 -95
- package/src/data-lifecycle/sensitive-artifacts.d.ts +0 -28
- package/src/data-lifecycle/sensitive-artifacts.js +0 -146
- package/src/data-lifecycle/validation.d.ts +0 -32
- package/src/data-lifecycle/validation.js +0 -837
- package/src/database-retirement/contract.d.ts +0 -68
- package/src/database-retirement/contract.js +0 -166
- package/src/database-retirement/index.d.ts +0 -1
- package/src/database-retirement/index.js +0 -5
- package/src/developer-agent/context.d.ts +0 -57
- package/src/developer-agent/context.js +0 -662
- package/src/developer-agent/generator-planning.d.ts +0 -34
- package/src/developer-agent/generator-planning.js +0 -666
- package/src/developer-agent/generator-preview.d.ts +0 -8
- package/src/developer-agent/generator-preview.js +0 -650
- package/src/developer-agent/git-inspection.d.ts +0 -112
- package/src/developer-agent/git-inspection.js +0 -887
- package/src/developer-agent/handoff.d.ts +0 -43
- package/src/developer-agent/handoff.js +0 -713
- package/src/developer-agent/index.d.ts +0 -10
- package/src/developer-agent/index.js +0 -14
- package/src/developer-agent/model.d.ts +0 -493
- package/src/developer-agent/model.js +0 -143
- package/src/developer-agent/operation-registry.d.ts +0 -60
- package/src/developer-agent/operation-registry.js +0 -1550
- package/src/developer-agent/ordering.d.ts +0 -9
- package/src/developer-agent/ordering.js +0 -15
- package/src/developer-agent/planning.d.ts +0 -25
- package/src/developer-agent/planning.js +0 -478
- package/src/developer-agent/preview-changes.js +0 -215
- package/src/developer-agent/preview-source.d.ts +0 -2
- package/src/developer-agent/preview-source.js +0 -19
- package/src/developer-agent/validation.d.ts +0 -30
- package/src/developer-agent/validation.js +0 -2725
- package/src/developer-agent/workspace-inspection.d.ts +0 -20
- package/src/developer-agent/workspace-inspection.js +0 -1189
- package/src/developer-agent/workspace-path.d.ts +0 -6
- package/src/developer-agent/workspace-path.js +0 -22
- package/src/executors/blueprint-trust/blueprint-trust.d.ts +0 -29
- package/src/executors/blueprint-trust/blueprint-trust.js +0 -121
- package/src/executors/blueprint-trust/schema.json +0 -27
- package/src/executors/blueprint-verification/blueprint-verification.d.ts +0 -13
- package/src/executors/blueprint-verification/blueprint-verification.js +0 -110
- package/src/executors/blueprint-verification/schema.json +0 -44
- package/src/executors/developer-context/developer-context.d.ts +0 -38
- package/src/executors/developer-context/developer-context.js +0 -78
- package/src/executors/developer-context/schema.json +0 -87
- package/src/executors/foundation-profile-preflight/foundation-profile-preflight.d.ts +0 -19
- package/src/executors/foundation-profile-preflight/foundation-profile-preflight.js +0 -105
- package/src/executors/foundation-profile-preflight/schema.json +0 -32
- package/src/executors/github-bootstrap/github-bootstrap.d.ts +0 -13
- package/src/executors/github-bootstrap/github-bootstrap.js +0 -62
- package/src/executors/github-bootstrap/schema.json +0 -50
- package/src/executors/infrastructure-plan/infrastructure-plan.d.ts +0 -37
- package/src/executors/infrastructure-plan/infrastructure-plan.js +0 -268
- package/src/executors/infrastructure-plan/schema.json +0 -38
- package/src/executors/router-waf-rehearsal/router-waf-rehearsal.d.ts +0 -42
- package/src/executors/router-waf-rehearsal/router-waf-rehearsal.js +0 -1229
- package/src/executors/router-waf-rehearsal/schema.json +0 -29
- package/src/executors/secret-guardrails/schema.json +0 -6
- package/src/executors/secret-guardrails/secret-guardrails.d.ts +0 -3
- package/src/executors/secret-guardrails/secret-guardrails.js +0 -44
- package/src/executors/secret-initialize/schema.json +0 -42
- package/src/executors/secret-initialize/secret-initialize.d.ts +0 -34
- package/src/executors/secret-initialize/secret-initialize.js +0 -297
- package/src/executors/secret-metadata/schema.json +0 -36
- package/src/executors/secret-metadata/secret-metadata.d.ts +0 -46
- package/src/executors/secret-metadata/secret-metadata.js +0 -230
- package/src/executors/sst-lifecycle/generated-secret-retirement.d.ts +0 -53
- package/src/executors/sst-lifecycle/generated-secret-retirement.js +0 -192
- package/src/executors/sst-lifecycle/logging-preflight.d.ts +0 -22
- package/src/executors/sst-lifecycle/logging-preflight.js +0 -206
- package/src/executors/sst-lifecycle/secret-preflight.d.ts +0 -27
- package/src/executors/sst-lifecycle/secret-preflight.js +0 -125
- package/src/executors/work-markers/schema.json +0 -14
- package/src/executors/work-markers/work-markers.d.ts +0 -6
- package/src/executors/work-markers/work-markers.js +0 -20
- package/src/foundation/cost-estimate.d.ts +0 -175
- package/src/foundation/cost-estimate.js +0 -706
- package/src/foundation/private-smoke-admission.d.ts +0 -45
- package/src/foundation/private-smoke-admission.js +0 -180
- package/src/foundation/private-smoke-control-plane.d.ts +0 -18
- package/src/foundation/private-smoke-control-plane.js +0 -184
- package/src/foundation/router-waf-rate-rehearsal.d.ts +0 -97
- package/src/foundation/router-waf-rate-rehearsal.js +0 -210
- package/src/foundation/router-waf.d.ts +0 -149
- package/src/foundation/router-waf.js +0 -809
- package/src/frontend-security/index.d.ts +0 -1
- package/src/frontend-security/index.js +0 -5
- package/src/frontend-security/security-headers.d.ts +0 -50
- package/src/frontend-security/security-headers.js +0 -418
- package/src/generators/blueprint/blueprint.d.ts +0 -5
- package/src/generators/blueprint/blueprint.js +0 -102
- package/src/generators/blueprint/files.d.ts +0 -6
- package/src/generators/blueprint/files.js +0 -217
- package/src/generators/blueprint/schema.d.ts +0 -4
- package/src/generators/blueprint/schema.json +0 -18
- package/src/generators/feature-registry.d.ts +0 -13
- package/src/generators/feature-registry.js +0 -73
- package/src/generators/observability-infrastructure.d.ts +0 -2
- package/src/generators/observability-infrastructure.js +0 -31
- package/src/generators/preset/workspace-files-adopter-skills.d.ts +0 -7
- package/src/generators/preset/workspace-files-adopter-skills.js +0 -345
- package/src/generators/preset/workspace-files-agent-development.d.ts +0 -9
- package/src/generators/preset/workspace-files-agent-development.js +0 -42
- package/src/generators/preset/workspace-files-ci-acceptance.d.ts +0 -1
- package/src/generators/preset/workspace-files-ci-acceptance.js +0 -791
- package/src/generators/preset/workspace-files-ci-install.d.ts +0 -2
- package/src/generators/preset/workspace-files-ci-install.js +0 -196
- package/src/generators/preset/workspace-files-developer-agent.d.ts +0 -16
- package/src/generators/preset/workspace-files-developer-agent.js +0 -638
- package/src/generators/preset/workspace-files-ecr-inspector.d.ts +0 -18
- package/src/generators/preset/workspace-files-ecr-inspector.js +0 -298
- package/src/generators/preset/workspace-files-foundation-workload-roles.d.ts +0 -6
- package/src/generators/preset/workspace-files-foundation-workload-roles.js +0 -409
- package/src/generators/preset/workspace-files-performance-cost.d.ts +0 -66
- package/src/generators/preset/workspace-files-performance-cost.js +0 -866
- package/src/generators/preset/workspace-files-performance-load.d.ts +0 -73
- package/src/generators/preset/workspace-files-performance-load.js +0 -815
- package/src/generators/preset/workspace-files-shared-operation-claims.d.ts +0 -10
- package/src/generators/preset/workspace-files-shared-operation-claims.js +0 -59
- package/src/generators/preset/workspace-files-stage-authority.d.ts +0 -6
- package/src/generators/preset/workspace-files-stage-authority.js +0 -529
- package/src/generators/preset/workspace-files-thin-deploy.d.ts +0 -65
- package/src/generators/preset/workspace-files-thin-deploy.js +0 -2520
- package/src/generators/preset/workspace-files-thin-docs.d.ts +0 -7
- package/src/generators/preset/workspace-files-thin-docs.js +0 -358
- package/src/generators/preset/workspace-files-thin-release.d.ts +0 -14
- package/src/generators/preset/workspace-files-thin-release.js +0 -26
- package/src/generators/preset/workspace-files-workload-role-baseline.d.ts +0 -9
- package/src/generators/preset/workspace-files-workload-role-baseline.js +0 -1314
- package/src/generators/repository-policy/repository-policy.d.ts +0 -4
- package/src/generators/repository-policy/repository-policy.js +0 -293
- package/src/generators/repository-policy/schema.d.ts +0 -28
- package/src/generators/repository-policy/schema.json +0 -122
- package/src/generators/slice/built-in-plan-alarm-identity.d.ts +0 -173
- package/src/generators/slice/built-in-plan-alarm-identity.js +0 -202
- package/src/generators/slice/built-in-plan-api-contract-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-api-contract-files.js +0 -2830
- package/src/generators/slice/built-in-plan-async-work-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-async-work-files.js +0 -6100
- package/src/generators/slice/built-in-plan-authorization-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-authorization-files.js +0 -2082
- package/src/generators/slice/built-in-plan-authorization-infrastructure-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-authorization-infrastructure-files.js +0 -1301
- package/src/generators/slice/built-in-plan-authorization-storage.d.ts +0 -3
- package/src/generators/slice/built-in-plan-authorization-storage.js +0 -119
- package/src/generators/slice/built-in-plan-background-work-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-background-work-files.js +0 -99
- package/src/generators/slice/built-in-plan-data-deletion-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-data-deletion-files.js +0 -273
- package/src/generators/slice/built-in-plan-data-export-infrastructure-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-data-export-infrastructure-files.js +0 -223
- package/src/generators/slice/built-in-plan-data-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-data-files.js +0 -513
- package/src/generators/slice/built-in-plan-data-lifecycle-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-data-lifecycle-files.js +0 -775
- package/src/generators/slice/built-in-plan-data-lifecycle-runtime-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-data-lifecycle-runtime-files.js +0 -863
- package/src/generators/slice/built-in-plan-data-retention-job-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-data-retention-job-files.js +0 -169
- package/src/generators/slice/built-in-plan-data-retention-launcher-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-data-retention-launcher-files.js +0 -186
- package/src/generators/slice/built-in-plan-data-rights-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-data-rights-files.js +0 -152
- package/src/generators/slice/built-in-plan-database-retirement-rehearsal-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-database-retirement-rehearsal-files.js +0 -508
- package/src/generators/slice/built-in-plan-event-contract-literal.d.ts +0 -6
- package/src/generators/slice/built-in-plan-event-contract-literal.js +0 -52
- package/src/generators/slice/built-in-plan-foundation-files.d.ts +0 -3
- package/src/generators/slice/built-in-plan-foundation-files.js +0 -205
- package/src/generators/slice/built-in-plan-frontend-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-frontend-files.js +0 -2244
- package/src/generators/slice/built-in-plan-infrastructure-safety-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-infrastructure-safety-files.js +0 -373
- package/src/generators/slice/built-in-plan-key-value-cleanup.d.ts +0 -4
- package/src/generators/slice/built-in-plan-key-value-cleanup.js +0 -100
- package/src/generators/slice/built-in-plan-key-value-consumer.d.ts +0 -4
- package/src/generators/slice/built-in-plan-key-value-consumer.js +0 -151
- package/src/generators/slice/built-in-plan-key-value-deletion.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-deletion.js +0 -377
- package/src/generators/slice/built-in-plan-key-value-delivery.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-delivery.js +0 -137
- package/src/generators/slice/built-in-plan-key-value-export.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-export.js +0 -595
- package/src/generators/slice/built-in-plan-key-value-holds.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-holds.js +0 -189
- package/src/generators/slice/built-in-plan-key-value-infrastructure.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-infrastructure.js +0 -102
- package/src/generators/slice/built-in-plan-key-value-performance.d.ts +0 -5
- package/src/generators/slice/built-in-plan-key-value-performance.js +0 -530
- package/src/generators/slice/built-in-plan-key-value-provider.d.ts +0 -4
- package/src/generators/slice/built-in-plan-key-value-provider.js +0 -366
- package/src/generators/slice/built-in-plan-key-value-records.d.ts +0 -3
- package/src/generators/slice/built-in-plan-key-value-records.js +0 -232
- package/src/generators/slice/built-in-plan-key-value-retention-infrastructure.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-retention-infrastructure.js +0 -103
- package/src/generators/slice/built-in-plan-key-value-retention-job-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-retention-job-files.js +0 -160
- package/src/generators/slice/built-in-plan-key-value-retention-maintenance.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-retention-maintenance.js +0 -329
- package/src/generators/slice/built-in-plan-key-value-retention-worker.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-retention-worker.js +0 -477
- package/src/generators/slice/built-in-plan-key-value-retention.d.ts +0 -2
- package/src/generators/slice/built-in-plan-key-value-retention.js +0 -184
- package/src/generators/slice/built-in-plan-metadata-files.d.ts +0 -3
- package/src/generators/slice/built-in-plan-metadata-files.js +0 -384
- package/src/generators/slice/built-in-plan-native-runtime-authority-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-native-runtime-authority-files.js +0 -324
- package/src/generators/slice/built-in-plan-operations-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-operations-files.js +0 -1218
- package/src/generators/slice/built-in-plan-performance-files.d.ts +0 -4
- package/src/generators/slice/built-in-plan-performance-files.js +0 -2439
- package/src/generators/slice/built-in-plan-release-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-release-files.js +0 -6585
- package/src/generators/slice/built-in-plan-reliability-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-reliability-files.js +0 -4724
- package/src/generators/slice/built-in-plan-secret-runtime-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-secret-runtime-files.js +0 -1015
- package/src/generators/slice/built-in-plan-sql-events.d.ts +0 -2
- package/src/generators/slice/built-in-plan-sql-events.js +0 -276
- package/src/generators/slice/built-in-plan-testing-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-testing-files.js +0 -2575
- package/src/generators/slice/built-in-plan-testing-persistence-event-files.d.ts +0 -7
- package/src/generators/slice/built-in-plan-testing-persistence-event-files.js +0 -487
- package/src/generators/slice/built-in-plan-testing-persistence-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-testing-persistence-files.js +0 -180
- package/src/generators/slice/built-in-plan-thin-release-files.d.ts +0 -11
- package/src/generators/slice/built-in-plan-thin-release-files.js +0 -162
- package/src/generators/slice/built-in-plan-verification-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-verification-files.js +0 -431
- package/src/generators/slice/built-in-plan-workload-role-files.d.ts +0 -2
- package/src/generators/slice/built-in-plan-workload-role-files.js +0 -2220
- package/src/generators/slice/data-policy-review-seed.d.ts +0 -2
- package/src/generators/slice/data-policy-review-seed.js +0 -22
- package/src/generators/slice/deployed-smoke-readiness.d.ts +0 -2
- package/src/generators/slice/deployed-smoke-readiness.js +0 -214
- package/src/generators/slice/local-source-identity.d.ts +0 -2
- package/src/generators/slice/local-source-identity.js +0 -31
- package/src/generators/upgrade/sql-seeded-reconciliation.d.ts +0 -2
- package/src/generators/upgrade/sql-seeded-reconciliation.js +0 -170
- package/src/generators/workload/performance-registration.d.ts +0 -33
- package/src/generators/workload/performance-registration.js +0 -224
- package/src/generators/workload/reliability-registration.d.ts +0 -16
- package/src/generators/workload/reliability-registration.js +0 -150
- package/src/generators/workload/service-performance-files.d.ts +0 -5
- package/src/generators/workload/service-performance-files.js +0 -1883
- package/src/git-policy/action-pins.d.ts +0 -43
- package/src/git-policy/action-pins.js +0 -50
- package/src/git-policy/github-bootstrap.d.ts +0 -94
- package/src/git-policy/github-bootstrap.js +0 -1248
- package/src/git-policy/index.d.ts +0 -3
- package/src/git-policy/index.js +0 -7
- package/src/git-policy/routing.d.ts +0 -21
- package/src/git-policy/routing.js +0 -138
- package/src/infrastructure-change/convergence.d.ts +0 -13
- package/src/infrastructure-change/convergence.js +0 -85
- package/src/infrastructure-change/drift.d.ts +0 -13
- package/src/infrastructure-change/drift.js +0 -112
- package/src/infrastructure-change/index.d.ts +0 -7
- package/src/infrastructure-change/index.js +0 -11
- package/src/infrastructure-change/local-capability.d.ts +0 -73
- package/src/infrastructure-change/local-capability.js +0 -114
- package/src/infrastructure-change/model.d.ts +0 -274
- package/src/infrastructure-change/model.js +0 -29
- package/src/infrastructure-change/normalize.d.ts +0 -16
- package/src/infrastructure-change/normalize.js +0 -285
- package/src/infrastructure-change/plan.d.ts +0 -67
- package/src/infrastructure-change/plan.js +0 -671
- package/src/infrastructure-change/risk.d.ts +0 -9
- package/src/infrastructure-change/risk.js +0 -349
- package/src/infrastructure-change/summary.d.ts +0 -20
- package/src/infrastructure-change/summary.js +0 -130
- package/src/performance/cost-collection.d.ts +0 -225
- package/src/performance/cost-collection.js +0 -827
- package/src/performance/cost-controls.d.ts +0 -135
- package/src/performance/cost-controls.js +0 -347
- package/src/performance/evidence.d.ts +0 -140
- package/src/performance/evidence.js +0 -601
- package/src/performance/index.d.ts +0 -10
- package/src/performance/index.js +0 -14
- package/src/performance/load-safety.d.ts +0 -84
- package/src/performance/load-safety.js +0 -348
- package/src/performance/model.d.ts +0 -129
- package/src/performance/model.js +0 -451
- package/src/performance/pr-artifact-budget.d.ts +0 -42
- package/src/performance/pr-artifact-budget.js +0 -151
- package/src/performance/runner.d.ts +0 -75
- package/src/performance/runner.js +0 -227
- package/src/performance/scenario-endpoint.d.ts +0 -1
- package/src/performance/scenario-endpoint.js +0 -5
- package/src/performance/scenario.d.ts +0 -215
- package/src/performance/scenario.js +0 -744
- package/src/performance/unit-cost.d.ts +0 -105
- package/src/performance/unit-cost.js +0 -364
- package/src/release/index.d.ts +0 -2
- package/src/release/index.js +0 -6
- package/src/release/lifecycle.d.ts +0 -132
- package/src/release/lifecycle.js +0 -411
- package/src/release/manifest.d.ts +0 -148
- package/src/release/manifest.js +0 -503
- package/src/release/rollout.d.ts +0 -170
- package/src/release/rollout.js +0 -578
- package/src/release/source-authority.d.ts +0 -19
- package/src/release/source-authority.js +0 -212
- package/src/schemas/aggregate-count-evidence-v1.json +0 -135
- package/src/schemas/api-contract-baseline-v1.json +0 -674
- package/src/schemas/api-contract-compatibility-report-v1.json +0 -126
- package/src/schemas/aws-billing-actual-evidence-v1.json +0 -407
- package/src/schemas/blueprint-input-schema-v1.json +0 -23
- package/src/schemas/blueprint-v1.json +0 -188
- package/src/schemas/data-lifecycle-policy-v1.json +0 -517
- package/src/schemas/performance-policy-v1.json +0 -335
- package/src/schemas/testing-evidence-quarantine-v1.json +0 -168
- package/src/schemas/testing-evidence-result-v1.json +0 -319
- package/src/secrets/aws-control-plane.d.ts +0 -29
- package/src/secrets/aws-control-plane.js +0 -322
- package/src/secrets/generated-aws-control-plane.d.ts +0 -33
- package/src/secrets/generated-aws-control-plane.js +0 -322
- package/src/secrets/guardrails.d.ts +0 -26
- package/src/secrets/guardrails.js +0 -328
- package/src/secrets/metadata.d.ts +0 -48
- package/src/secrets/metadata.js +0 -199
- package/src/secrets/operator.d.ts +0 -190
- package/src/secrets/operator.js +0 -701
- package/src/secrets/verification.d.ts +0 -18
- package/src/secrets/verification.js +0 -152
- package/src/supply-chain/action-pins.d.ts +0 -26
- package/src/supply-chain/action-pins.js +0 -262
- package/src/supply-chain/blueprint-trust-git.d.ts +0 -130
- package/src/supply-chain/blueprint-trust-git.js +0 -1642
- package/src/supply-chain/blueprint-trust-process.d.ts +0 -4
- package/src/supply-chain/blueprint-trust-process.js +0 -88
- package/src/supply-chain/blueprint-trust.d.ts +0 -354
- package/src/supply-chain/blueprint-trust.js +0 -1558
- package/src/supply-chain/blueprint-verification-authority.d.ts +0 -62
- package/src/supply-chain/blueprint-verification-authority.js +0 -661
- package/src/supply-chain/blueprint-verification-execution.d.ts +0 -68
- package/src/supply-chain/blueprint-verification-execution.js +0 -639
- package/src/supply-chain/build-output-bounds.d.ts +0 -2
- package/src/supply-chain/build-output-bounds.js +0 -12
- package/src/supply-chain/build-output.d.ts +0 -41
- package/src/supply-chain/build-output.js +0 -551
- package/src/supply-chain/common.d.ts +0 -21
- package/src/supply-chain/common.js +0 -107
- package/src/supply-chain/container-artifact-contract.d.ts +0 -23
- package/src/supply-chain/container-artifact-contract.js +0 -208
- package/src/supply-chain/container-release.d.ts +0 -119
- package/src/supply-chain/container-release.js +0 -496
- package/src/supply-chain/ecr-applicability.d.ts +0 -19
- package/src/supply-chain/ecr-applicability.js +0 -103
- package/src/supply-chain/ecr-scanning.d.ts +0 -85
- package/src/supply-chain/ecr-scanning.js +0 -325
- package/src/supply-chain/ecs-deployed-image.d.ts +0 -87
- package/src/supply-chain/ecs-deployed-image.js +0 -302
- package/src/supply-chain/errors.d.ts +0 -6
- package/src/supply-chain/errors.js +0 -15
- package/src/supply-chain/generated-blueprint-trust-command.d.ts +0 -4
- package/src/supply-chain/generated-blueprint-trust-command.js +0 -1379
- package/src/supply-chain/generated-command.d.ts +0 -1
- package/src/supply-chain/generated-command.js +0 -775
- package/src/supply-chain/generated-container-release-command.d.ts +0 -16
- package/src/supply-chain/generated-container-release-command.js +0 -3248
- package/src/supply-chain/generated-ecr-collector-command.d.ts +0 -20
- package/src/supply-chain/generated-ecr-collector-command.js +0 -1445
- package/src/supply-chain/generated-files.d.ts +0 -13
- package/src/supply-chain/generated-files.js +0 -421
- package/src/supply-chain/generated-scanner-command.d.ts +0 -1
- package/src/supply-chain/generated-scanner-command.js +0 -778
- package/src/supply-chain/index.d.ts +0 -28
- package/src/supply-chain/index.js +0 -36
- package/src/supply-chain/inventory.d.ts +0 -96
- package/src/supply-chain/inventory.js +0 -828
- package/src/supply-chain/license-expression.d.ts +0 -7
- package/src/supply-chain/license-expression.js +0 -128
- package/src/supply-chain/policy.d.ts +0 -105
- package/src/supply-chain/policy.js +0 -304
- package/src/supply-chain/publication.d.ts +0 -48
- package/src/supply-chain/publication.js +0 -85
- package/src/supply-chain/sbom.d.ts +0 -228
- package/src/supply-chain/sbom.js +0 -913
- package/src/supply-chain/scanner.d.ts +0 -77
- package/src/supply-chain/scanner.js +0 -514
- package/src/supply-chain/vendored-source.d.ts +0 -95
- package/src/supply-chain/vendored-source.js +0 -315
- package/src/testing-evidence/fixture-scope.d.ts +0 -53
- package/src/testing-evidence/fixture-scope.js +0 -142
- package/src/testing-evidence/index.d.ts +0 -5
- package/src/testing-evidence/index.js +0 -9
- package/src/testing-evidence/quarantine.d.ts +0 -48
- package/src/testing-evidence/quarantine.js +0 -253
- package/src/testing-evidence/result.d.ts +0 -109
- package/src/testing-evidence/result.js +0 -585
- package/src/testing-evidence/runner-adapter.d.ts +0 -51
- package/src/testing-evidence/runner-adapter.js +0 -288
- package/src/testing-evidence/sensitive-artifacts.d.ts +0 -13
- package/src/testing-evidence/sensitive-artifacts.js +0 -93
- package/src/work-markers/index.d.ts +0 -1
- package/src/work-markers/index.js +0 -5
- package/src/work-markers/work-markers.d.ts +0 -39
- package/src/work-markers/work-markers.js +0 -360
- package/src/workload-roles/account-baseline.d.ts +0 -143
- package/src/workload-roles/account-baseline.js +0 -980
- package/src/workload-roles/authority.d.ts +0 -40
- package/src/workload-roles/authority.js +0 -202
- package/src/workload-roles/aws-adapter.d.ts +0 -99
- package/src/workload-roles/aws-adapter.js +0 -416
- package/src/workload-roles/aws-internal-handler.d.ts +0 -27
- package/src/workload-roles/aws-internal-handler.js +0 -58
- package/src/workload-roles/aws-s3-state.d.ts +0 -52
- package/src/workload-roles/aws-s3-state.js +0 -191
- package/src/workload-roles/aws-sdk-control-plane.d.ts +0 -12
- package/src/workload-roles/aws-sdk-control-plane.js +0 -291
- package/src/workload-roles/boundary.d.ts +0 -34
- package/src/workload-roles/boundary.js +0 -137
- package/src/workload-roles/convergence.d.ts +0 -66
- package/src/workload-roles/convergence.js +0 -186
- package/src/workload-roles/handler.d.ts +0 -43
- package/src/workload-roles/handler.js +0 -158
- package/src/workload-roles/history.d.ts +0 -47
- package/src/workload-roles/history.js +0 -324
- package/src/workload-roles/injection.d.ts +0 -119
- package/src/workload-roles/injection.js +0 -495
- package/src/workload-roles/manifest.d.ts +0 -54
- package/src/workload-roles/manifest.js +0 -343
- package/src/workload-roles/provisioner.d.ts +0 -70
- package/src/workload-roles/provisioner.js +0 -239
- package/src/workload-roles/registration.d.ts +0 -102
- package/src/workload-roles/registration.js +0 -462
- package/src/workload-roles/stage-boundary.d.ts +0 -31
- package/src/workload-roles/stage-boundary.js +0 -208
- /package/src/executors/{foundation-profile-preflight → local-deploy}/production-database-safeguard.d.ts +0 -0
- /package/src/executors/{foundation-profile-preflight → local-deploy}/production-database-safeguard.js +0 -0
|
@@ -1,2082 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renderProductAuthorizationFiles = renderProductAuthorizationFiles;
|
|
4
|
-
const built_in_plan_shared_js_1 = require("./built-in-plan-shared.js");
|
|
5
|
-
const built_in_plan_authorization_storage_js_1 = require("./built-in-plan-authorization-storage.js");
|
|
6
|
-
/** @internal */
|
|
7
|
-
function renderProductAuthorizationFiles(name, pascalName) {
|
|
8
|
-
const identifierPrefix = (0, built_in_plan_shared_js_1.lowerCamelIdentifier)(pascalName);
|
|
9
|
-
return {
|
|
10
|
-
'authorization/record-store.ts': (0, built_in_plan_authorization_storage_js_1.renderAuthorizationRecordStore)(),
|
|
11
|
-
'authorization/policy.ts': `import {
|
|
12
|
-
defineAuthorizationPolicy,
|
|
13
|
-
defineCoarseAdmission,
|
|
14
|
-
type AuthorizationContext,
|
|
15
|
-
type AuthorizationInput,
|
|
16
|
-
type AuthorizationResource,
|
|
17
|
-
} from '@empire-builder-kit/runtime/authorization';
|
|
18
|
-
|
|
19
|
-
export const ${identifierPrefix}AuthorizationActions = {
|
|
20
|
-
approvalReview: '${name}:approval-review',
|
|
21
|
-
dataExportCleanup: '${name}:data-export-cleanup',
|
|
22
|
-
databaseRead: '${name}:database-read',
|
|
23
|
-
eventPublish: '${name}:event-publish',
|
|
24
|
-
lifecycleConsume: '${name}:lifecycle-consume',
|
|
25
|
-
machineProofRead: '${name}:machine-proof-read',
|
|
26
|
-
protectedRead: '${name}:protected-read',
|
|
27
|
-
recordDelegationIssue: '${name}:record-delegation-issue',
|
|
28
|
-
recordDelegationRevoke: '${name}:record-delegation-revoke',
|
|
29
|
-
recordDelegationUse: '${name}:record-delegation-use',
|
|
30
|
-
recordDelete: '${name}:record-delete',
|
|
31
|
-
recordExport: '${name}:record-export',
|
|
32
|
-
recordExportCleanup: '${name}:record-export-cleanup',
|
|
33
|
-
recordHoldManage: '${name}:record-hold-manage',
|
|
34
|
-
recordRead: '${name}:record-read',
|
|
35
|
-
recordWrite: '${name}:record-write',
|
|
36
|
-
retentionApply: '${name}:retention-apply',
|
|
37
|
-
retentionMaintenance: '${name}:retention-maintenance',
|
|
38
|
-
retentionReport: '${name}:retention-report',
|
|
39
|
-
retentionReview: '${name}:retention-review',
|
|
40
|
-
} as const;
|
|
41
|
-
|
|
42
|
-
export type ${pascalName}AuthorizationAction =
|
|
43
|
-
(typeof ${identifierPrefix}AuthorizationActions)[keyof typeof ${identifierPrefix}AuthorizationActions];
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Cognito resource-server scopes are not application action identifiers.
|
|
47
|
-
* Keep this mapping explicit so adding an action never grants it to the
|
|
48
|
-
* Standard confidential client implicitly.
|
|
49
|
-
*/
|
|
50
|
-
export function ${identifierPrefix}MachineScopes(stage: string) {
|
|
51
|
-
if (!/^[a-z][a-z0-9-]{0,62}$/.test(stage)) {
|
|
52
|
-
throw new Error('Machine authorization requires a safe deployed stage.');
|
|
53
|
-
}
|
|
54
|
-
const resourceServer = '${name}-' + stage;
|
|
55
|
-
return {
|
|
56
|
-
delegationUse: resourceServer + '/delegation-use',
|
|
57
|
-
proofReader: resourceServer + '/proof-read',
|
|
58
|
-
} as const;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function ${identifierPrefix}MachineScopeForAction(
|
|
62
|
-
action: ${pascalName}AuthorizationAction,
|
|
63
|
-
stage: string,
|
|
64
|
-
): string | undefined {
|
|
65
|
-
const scopes = ${identifierPrefix}MachineScopes(stage);
|
|
66
|
-
switch (action) {
|
|
67
|
-
case ${identifierPrefix}AuthorizationActions.machineProofRead:
|
|
68
|
-
return scopes.proofReader;
|
|
69
|
-
case ${identifierPrefix}AuthorizationActions.recordDelegationUse:
|
|
70
|
-
return scopes.delegationUse;
|
|
71
|
-
default:
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface ${pascalName}ResourceAttributes {
|
|
77
|
-
collection?: boolean;
|
|
78
|
-
ownerId?: string;
|
|
79
|
-
syntheticTestData?: boolean;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type ${pascalName}AuthorizationResource = AuthorizationResource<
|
|
83
|
-
'record' | 'slice',
|
|
84
|
-
Readonly<${pascalName}ResourceAttributes>
|
|
85
|
-
>;
|
|
86
|
-
|
|
87
|
-
export type ${pascalName}AuthorizationInput = AuthorizationInput<
|
|
88
|
-
${pascalName}AuthorizationAction,
|
|
89
|
-
${pascalName}AuthorizationResource,
|
|
90
|
-
AuthorizationContext<Readonly<{ operationId: string }>>
|
|
91
|
-
>;
|
|
92
|
-
|
|
93
|
-
const recordActions = new Set<${pascalName}AuthorizationAction>([
|
|
94
|
-
${identifierPrefix}AuthorizationActions.recordDelegationIssue,
|
|
95
|
-
${identifierPrefix}AuthorizationActions.recordDelegationRevoke,
|
|
96
|
-
${identifierPrefix}AuthorizationActions.recordDelegationUse,
|
|
97
|
-
${identifierPrefix}AuthorizationActions.recordDelete,
|
|
98
|
-
${identifierPrefix}AuthorizationActions.recordExport,
|
|
99
|
-
${identifierPrefix}AuthorizationActions.recordExportCleanup,
|
|
100
|
-
${identifierPrefix}AuthorizationActions.recordHoldManage,
|
|
101
|
-
${identifierPrefix}AuthorizationActions.recordRead,
|
|
102
|
-
${identifierPrefix}AuthorizationActions.recordWrite,
|
|
103
|
-
]);
|
|
104
|
-
|
|
105
|
-
export function ${identifierPrefix}InternalWorkloadIdentityForAction(
|
|
106
|
-
action: ${pascalName}AuthorizationAction,
|
|
107
|
-
): string | undefined {
|
|
108
|
-
switch (action) {
|
|
109
|
-
case ${identifierPrefix}AuthorizationActions.lifecycleConsume:
|
|
110
|
-
return '${name}:event-consumer';
|
|
111
|
-
case ${identifierPrefix}AuthorizationActions.dataExportCleanup:
|
|
112
|
-
return '${name}:data-export-cleanup';
|
|
113
|
-
case ${identifierPrefix}AuthorizationActions.retentionApply:
|
|
114
|
-
case ${identifierPrefix}AuthorizationActions.retentionMaintenance:
|
|
115
|
-
case ${identifierPrefix}AuthorizationActions.retentionReport:
|
|
116
|
-
return '${name}:data-retention-job';
|
|
117
|
-
default:
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function create${pascalName}CoarseAdmission(stage: string) {
|
|
123
|
-
return defineCoarseAdmission({
|
|
124
|
-
anyOf: [
|
|
125
|
-
{
|
|
126
|
-
kinds: ['admin', 'customer'],
|
|
127
|
-
subjectTypes: ['user'],
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
anyScope: Object.values(${identifierPrefix}MachineScopes(stage)),
|
|
131
|
-
kinds: ['agent'],
|
|
132
|
-
subjectTypes: ['service'],
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Product actions and rules are seeded and Slice-owned. Keep policy inputs
|
|
140
|
-
* minimal and advance the version whenever observable allow/deny behavior
|
|
141
|
-
* changes.
|
|
142
|
-
*/
|
|
143
|
-
export const ${identifierPrefix}AuthorizationPolicy =
|
|
144
|
-
defineAuthorizationPolicy<${pascalName}AuthorizationInput>({
|
|
145
|
-
version: '1.0.0',
|
|
146
|
-
evaluate(input) {
|
|
147
|
-
const { action, principal, resource } = input;
|
|
148
|
-
|
|
149
|
-
const internalWorkloadIdentity =
|
|
150
|
-
${identifierPrefix}InternalWorkloadIdentityForAction(action);
|
|
151
|
-
if (internalWorkloadIdentity !== undefined) {
|
|
152
|
-
return principal.kind === 'agent' &&
|
|
153
|
-
principal.actor.type === 'service' &&
|
|
154
|
-
principal.actor.id === internalWorkloadIdentity &&
|
|
155
|
-
principal.subject.id === internalWorkloadIdentity &&
|
|
156
|
-
principal.authority.mode === 'machine' &&
|
|
157
|
-
principal.authority.machineIdentityId === internalWorkloadIdentity &&
|
|
158
|
-
principal.scopes.length === 0 &&
|
|
159
|
-
resource.type === 'slice' &&
|
|
160
|
-
resource.attributes.collection === true
|
|
161
|
-
? { decision: 'allow' }
|
|
162
|
-
: { decision: 'deny' };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
action ===
|
|
167
|
-
${identifierPrefix}AuthorizationActions.machineProofRead &&
|
|
168
|
-
(principal.kind !== 'agent' ||
|
|
169
|
-
principal.actor.type !== 'service' ||
|
|
170
|
-
principal.subject.type !== 'service' ||
|
|
171
|
-
principal.authority.mode !== 'machine')
|
|
172
|
-
) {
|
|
173
|
-
return { decision: 'deny' };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const directHuman =
|
|
177
|
-
principal.actor.type === 'user' &&
|
|
178
|
-
principal.subject.type === 'user' &&
|
|
179
|
-
principal.authority.mode === 'direct';
|
|
180
|
-
if (
|
|
181
|
-
action === ${identifierPrefix}AuthorizationActions.recordWrite &&
|
|
182
|
-
resource.attributes.syntheticTestData === true &&
|
|
183
|
-
(!directHuman ||
|
|
184
|
-
!principal.roles.includes('${name}-test-writer'))
|
|
185
|
-
) {
|
|
186
|
-
return { decision: 'deny' };
|
|
187
|
-
}
|
|
188
|
-
if (
|
|
189
|
-
action === ${identifierPrefix}AuthorizationActions.recordExport
|
|
190
|
-
) {
|
|
191
|
-
return directHuman &&
|
|
192
|
-
resource.type === 'record' &&
|
|
193
|
-
resource.attributes.ownerId === principal.actor.id
|
|
194
|
-
? { decision: 'allow' }
|
|
195
|
-
: { decision: 'deny' };
|
|
196
|
-
}
|
|
197
|
-
if (
|
|
198
|
-
action ===
|
|
199
|
-
${identifierPrefix}AuthorizationActions.recordExportCleanup ||
|
|
200
|
-
action === ${identifierPrefix}AuthorizationActions.recordHoldManage
|
|
201
|
-
) {
|
|
202
|
-
return directHuman && principal.kind === 'admin'
|
|
203
|
-
? { decision: 'allow' }
|
|
204
|
-
: { decision: 'deny' };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// A direct, authenticated admin remains an independently testable
|
|
208
|
-
// recovery authority. No generated universal break-glass role exists.
|
|
209
|
-
if (
|
|
210
|
-
principal.kind === 'admin' &&
|
|
211
|
-
principal.actor.type === 'user' &&
|
|
212
|
-
principal.authority.mode === 'direct'
|
|
213
|
-
) {
|
|
214
|
-
return { decision: 'allow' };
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (
|
|
218
|
-
action === ${identifierPrefix}AuthorizationActions.approvalReview ||
|
|
219
|
-
action === ${identifierPrefix}AuthorizationActions.retentionReview
|
|
220
|
-
) {
|
|
221
|
-
return { decision: 'deny' };
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Cognito client-credentials callers are admitted only for an exact
|
|
225
|
-
// action scope; an audience match alone never authorizes.
|
|
226
|
-
if (
|
|
227
|
-
principal.kind === 'agent' &&
|
|
228
|
-
principal.actor.type === 'service' &&
|
|
229
|
-
principal.authority.mode === 'machine'
|
|
230
|
-
) {
|
|
231
|
-
const requiredScope = ${identifierPrefix}MachineScopeForAction(
|
|
232
|
-
action,
|
|
233
|
-
input.context.stage,
|
|
234
|
-
);
|
|
235
|
-
return requiredScope !== undefined &&
|
|
236
|
-
principal.scopes.includes(requiredScope)
|
|
237
|
-
? { decision: 'allow' }
|
|
238
|
-
: { decision: 'deny' };
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (!recordActions.has(action)) {
|
|
242
|
-
return principal.actor.type === 'user' &&
|
|
243
|
-
principal.authority.mode === 'direct'
|
|
244
|
-
? { decision: 'allow' }
|
|
245
|
-
: { decision: 'deny' };
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// The use endpoint is admitted only for the generated machine scope.
|
|
249
|
-
// Its second decision is evaluated below under delegated authority.
|
|
250
|
-
if (
|
|
251
|
-
action === ${identifierPrefix}AuthorizationActions.recordDelegationUse
|
|
252
|
-
) {
|
|
253
|
-
return { decision: 'deny' };
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const effectiveOwner =
|
|
257
|
-
principal.authority.mode === 'delegated'
|
|
258
|
-
? principal.authority.delegatedBy.id
|
|
259
|
-
: principal.actor.type === 'user' &&
|
|
260
|
-
principal.authority.mode === 'direct'
|
|
261
|
-
? principal.actor.id
|
|
262
|
-
: undefined;
|
|
263
|
-
return resource.type === 'record' &&
|
|
264
|
-
effectiveOwner !== undefined &&
|
|
265
|
-
resource.attributes.ownerId === effectiveOwner
|
|
266
|
-
? { decision: 'allow' }
|
|
267
|
-
: { decision: 'deny' };
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
`,
|
|
271
|
-
'authorization/runtime.ts': `import { createHash } from 'node:crypto';
|
|
272
|
-
import { sliceAuthorizationGroupNames, sliceAuthorizationRoles } from './groups.mjs';
|
|
273
|
-
import type { RuntimeHttpEvent } from '@empire-builder-kit/runtime';
|
|
274
|
-
import {
|
|
275
|
-
createBetterAuthConfig,
|
|
276
|
-
AuthError,
|
|
277
|
-
authErrorCodes,
|
|
278
|
-
type Principal,
|
|
279
|
-
} from '@empire-builder-kit/runtime/auth';
|
|
280
|
-
import { createAuthGuard } from '@empire-builder-kit/runtime/auth-backend';
|
|
281
|
-
import type { ApiAuthorizationInput } from '@empire-builder-kit/runtime/api-server';
|
|
282
|
-
import type { ApiOperationDefinition } from '@empire-builder-kit/runtime/api-contract';
|
|
283
|
-
import { ${identifierPrefix}GetRecord, ${identifierPrefix}PutRecord } from '../api/contracts/protected.js';
|
|
284
|
-
import {
|
|
285
|
-
createAuthorizationEvaluator,
|
|
286
|
-
composeAuthorizationPrincipal,
|
|
287
|
-
createDirectAuthorizationPrincipal,
|
|
288
|
-
createMachineAuthorizationPrincipal,
|
|
289
|
-
defineCoarseAdmission,
|
|
290
|
-
toAuthorizationAuditRecord,
|
|
291
|
-
type AuthorizationDecision,
|
|
292
|
-
type AuthorizationDecisionSinkInput,
|
|
293
|
-
type AuthorizationObligation,
|
|
294
|
-
type AuthorizationPrincipal,
|
|
295
|
-
} from '@empire-builder-kit/runtime/authorization';
|
|
296
|
-
import { isBoundedSafeReference } from '@empire-builder-kit/runtime/safe-reference';
|
|
297
|
-
import { readAuthorizationRecord, writeAuthorizationAudit${', readRecordDeletionApproval'} } from './record-store.js';
|
|
298
|
-
import { ${''}create${pascalName}DelegationStore } from './store.js';
|
|
299
|
-
import {
|
|
300
|
-
${identifierPrefix}AuthorizationActions,
|
|
301
|
-
${identifierPrefix}MachineScopes,
|
|
302
|
-
${identifierPrefix}AuthorizationPolicy,
|
|
303
|
-
create${pascalName}CoarseAdmission,
|
|
304
|
-
type ${pascalName}AuthorizationAction,
|
|
305
|
-
type ${pascalName}AuthorizationInput,
|
|
306
|
-
type ${pascalName}AuthorizationResource,
|
|
307
|
-
} from './policy.js';
|
|
308
|
-
|
|
309
|
-
let guard: ReturnType<typeof createAuthGuard> | undefined;
|
|
310
|
-
|
|
311
|
-
function acceptedMachineClientIds(): readonly string[] {
|
|
312
|
-
const current = process.env.AUTH_MACHINE_CLIENT_ID;
|
|
313
|
-
const encoded = process.env.AUTH_MACHINE_ACCEPTED_CLIENT_IDS;
|
|
314
|
-
if (current === undefined && encoded === undefined) return [];
|
|
315
|
-
if (!current || !encoded || !isBoundedSafeReference(current)) {
|
|
316
|
-
throw new Error('Machine authorization client configuration is invalid.');
|
|
317
|
-
}
|
|
318
|
-
let candidate: unknown;
|
|
319
|
-
try {
|
|
320
|
-
candidate = JSON.parse(encoded);
|
|
321
|
-
} catch {
|
|
322
|
-
throw new Error('Machine authorization client configuration is invalid.');
|
|
323
|
-
}
|
|
324
|
-
if (
|
|
325
|
-
!Array.isArray(candidate) ||
|
|
326
|
-
candidate.length < 1 ||
|
|
327
|
-
candidate.length > 2 ||
|
|
328
|
-
new Set(candidate).size !== candidate.length ||
|
|
329
|
-
candidate.some(
|
|
330
|
-
(clientId) =>
|
|
331
|
-
typeof clientId !== 'string' ||
|
|
332
|
-
!isBoundedSafeReference(clientId),
|
|
333
|
-
) ||
|
|
334
|
-
!candidate.includes(current)
|
|
335
|
-
) {
|
|
336
|
-
throw new Error('Machine authorization client configuration is invalid.');
|
|
337
|
-
}
|
|
338
|
-
return Object.freeze([...candidate] as string[]);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
function getGuard() {
|
|
342
|
-
const stage = process.env.EBK_STAGE ?? '';
|
|
343
|
-
const webClientId = process.env.AUTH_CLIENT_ID ?? '';
|
|
344
|
-
const machineClientIds = acceptedMachineClientIds();
|
|
345
|
-
return guard ??= createAuthGuard({
|
|
346
|
-
config: createBetterAuthConfig({
|
|
347
|
-
clientId: webClientId,
|
|
348
|
-
region: process.env.AWS_REGION ?? '',
|
|
349
|
-
userPoolId: process.env.AUTH_USER_POOL_ID ?? '',
|
|
350
|
-
}),
|
|
351
|
-
verifierOptions: {
|
|
352
|
-
acceptedClientIds: [webClientId, ...machineClientIds],
|
|
353
|
-
},
|
|
354
|
-
policy: {
|
|
355
|
-
admin: { groups: [sliceAuthorizationGroupNames(stage).admin] },
|
|
356
|
-
agent: {
|
|
357
|
-
scopes: Object.values(${identifierPrefix}MachineScopes(stage)),
|
|
358
|
-
},
|
|
359
|
-
defaultKind: 'customer',
|
|
360
|
-
},
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function operationAction(
|
|
365
|
-
operation: ApiOperationDefinition,
|
|
366
|
-
): ${pascalName}AuthorizationAction {
|
|
367
|
-
if (operation.authorizationActions.length !== 1) {
|
|
368
|
-
throw new Error(
|
|
369
|
-
'Standard protected operations require exactly one Slice-owned authorization action.',
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
const action = operation.authorizationActions[0];
|
|
373
|
-
if (
|
|
374
|
-
!Object.values(${identifierPrefix}AuthorizationActions).includes(
|
|
375
|
-
action as ${pascalName}AuthorizationAction,
|
|
376
|
-
)
|
|
377
|
-
) {
|
|
378
|
-
throw new Error('The API operation declares an unknown authorization action.');
|
|
379
|
-
}
|
|
380
|
-
return action as ${pascalName}AuthorizationAction;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
async function operationResource(
|
|
384
|
-
operation: ApiOperationDefinition,
|
|
385
|
-
request: unknown,
|
|
386
|
-
ownerId: string,
|
|
387
|
-
correlationId: string,
|
|
388
|
-
): Promise<${pascalName}AuthorizationResource> {
|
|
389
|
-
const candidate = request as {
|
|
390
|
-
body?: { testExpiresAt?: unknown };
|
|
391
|
-
path?: { delegationId?: unknown; recordId?: unknown };
|
|
392
|
-
query?: { approvalRequestId?: unknown };
|
|
393
|
-
};
|
|
394
|
-
const recordId = candidate.path?.recordId;
|
|
395
|
-
const recordAction = operation.authorizationActions[0]?.includes(':record-');
|
|
396
|
-
if (recordAction) {
|
|
397
|
-
if (typeof recordId !== 'string') {
|
|
398
|
-
throw new Error(
|
|
399
|
-
'A record authorization action requires its validated record path.',
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
const existing = await (async () => {
|
|
403
|
-
const record = await readAuthorizationRecord(correlationId, recordId);
|
|
404
|
-
if (record) return record;
|
|
405
|
-
const delegationId = candidate.path?.delegationId;
|
|
406
|
-
if (
|
|
407
|
-
operation.authorizationActions[0] ===
|
|
408
|
-
${identifierPrefix}AuthorizationActions.recordDelegationRevoke &&
|
|
409
|
-
typeof delegationId === 'string'
|
|
410
|
-
) {
|
|
411
|
-
const grant = await create${pascalName}DelegationStore(correlationId).read(delegationId);
|
|
412
|
-
if (
|
|
413
|
-
grant?.resourceBoundary?.kind === 'exact' &&
|
|
414
|
-
grant.resourceBoundary.resourceType === 'record' &&
|
|
415
|
-
Array.isArray(grant.resourceBoundary.resourceIds) &&
|
|
416
|
-
grant.resourceBoundary.resourceIds.includes(recordId) &&
|
|
417
|
-
typeof grant.delegator?.id === 'string'
|
|
418
|
-
) {
|
|
419
|
-
return { ownerId: grant.delegator.id };
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// A deletion retry may run after primary deletion committed. Only its
|
|
424
|
-
// exact durable approval can recover the original owner boundary; a
|
|
425
|
-
// bare missing row remains unauthorized.
|
|
426
|
-
const approvalRequestId = candidate.query?.approvalRequestId;
|
|
427
|
-
if (
|
|
428
|
-
operation.authorizationActions[0] !==
|
|
429
|
-
${identifierPrefix}AuthorizationActions.recordDelete ||
|
|
430
|
-
typeof approvalRequestId !== 'string'
|
|
431
|
-
) {
|
|
432
|
-
return undefined;
|
|
433
|
-
}
|
|
434
|
-
const approval = await ${`readRecordDeletionApproval(approvalRequestId, recordId, ${identifierPrefix}AuthorizationActions.recordDelete)`};
|
|
435
|
-
return approval?.resource.id === recordId && approval.action === ${identifierPrefix}AuthorizationActions.recordDelete
|
|
436
|
-
? { ownerId: approval.author.effectiveHumanId ?? approval.author.actorId }
|
|
437
|
-
: undefined;
|
|
438
|
-
})();
|
|
439
|
-
const missingOwnerId =
|
|
440
|
-
operation.authorizationActions[0] ===
|
|
441
|
-
${identifierPrefix}AuthorizationActions.recordWrite
|
|
442
|
-
? ownerId
|
|
443
|
-
: 'missing-resource-owner';
|
|
444
|
-
return {
|
|
445
|
-
// PUT may authorize creation against the caller's owner boundary.
|
|
446
|
-
// Read/deletion misses use a non-owner sentinel so missing and adjacent
|
|
447
|
-
// protected identifiers produce the same denial class.
|
|
448
|
-
attributes: {
|
|
449
|
-
ownerId: existing?.ownerId ?? missingOwnerId,
|
|
450
|
-
syntheticTestData: candidate.body?.testExpiresAt !== undefined,
|
|
451
|
-
},
|
|
452
|
-
id: recordId,
|
|
453
|
-
type: 'record',
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
return { attributes: { collection: true }, type: 'slice' };
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
function pseudonymousSubjectId(subjectId: string): string {
|
|
460
|
-
return createHash('sha256').update('${name}\\0' + subjectId).digest('hex');
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
function pseudonymousResourceReference(
|
|
464
|
-
resourceId: string | undefined,
|
|
465
|
-
): string | undefined {
|
|
466
|
-
return resourceId === undefined
|
|
467
|
-
? undefined
|
|
468
|
-
: 'sha256:' +
|
|
469
|
-
createHash('sha256')
|
|
470
|
-
.update('${name}\\0resource\\0' + resourceId)
|
|
471
|
-
.digest('hex');
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
export type ${pascalName}AuthorizationDecisionSink = (
|
|
475
|
-
input: AuthorizationDecisionSinkInput<${pascalName}AuthorizationInput, never>,
|
|
476
|
-
) => Promise<void> | void;
|
|
477
|
-
|
|
478
|
-
async function persistAuthorizationDecision<
|
|
479
|
-
Obligation extends AuthorizationObligation,
|
|
480
|
-
>(
|
|
481
|
-
decisionInput: ${pascalName}AuthorizationInput,
|
|
482
|
-
decision: AuthorizationDecision<Obligation>,
|
|
483
|
-
correlationId: string,
|
|
484
|
-
workload:
|
|
485
|
-
| 'api-database-records'
|
|
486
|
-
| 'data-export-cleanup'
|
|
487
|
-
| 'data-retention-job'
|
|
488
|
-
| 'event-consumer',
|
|
489
|
-
) {
|
|
490
|
-
const audit = toAuthorizationAuditRecord(decisionInput, decision, {
|
|
491
|
-
correlationId,
|
|
492
|
-
pseudonymousSubjectId: pseudonymousSubjectId(
|
|
493
|
-
decisionInput.principal.actor.id,
|
|
494
|
-
),
|
|
495
|
-
resourceReference: pseudonymousResourceReference(
|
|
496
|
-
decisionInput.resource.id,
|
|
497
|
-
),
|
|
498
|
-
slice: '${name}',
|
|
499
|
-
stage: decisionInput.context.stage,
|
|
500
|
-
timestamp: decisionInput.context.now,
|
|
501
|
-
});
|
|
502
|
-
await writeAuthorizationAudit({
|
|
503
|
-
...audit,
|
|
504
|
-
...(decisionInput.principal.authority.mode === 'delegated'
|
|
505
|
-
? { delegationReference: decisionInput.principal.authority.delegationId }
|
|
506
|
-
: {}),
|
|
507
|
-
}, workload);
|
|
508
|
-
return audit;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
export async function authorize${pascalName}InternalOperation(input: {
|
|
512
|
-
action:
|
|
513
|
-
| typeof ${identifierPrefix}AuthorizationActions.dataExportCleanup
|
|
514
|
-
| typeof ${identifierPrefix}AuthorizationActions.lifecycleConsume
|
|
515
|
-
| typeof ${identifierPrefix}AuthorizationActions.retentionApply
|
|
516
|
-
| typeof ${identifierPrefix}AuthorizationActions.retentionMaintenance
|
|
517
|
-
| typeof ${identifierPrefix}AuthorizationActions.retentionReport;
|
|
518
|
-
correlationId: string;
|
|
519
|
-
operationId: string;
|
|
520
|
-
workloadIdentity: string;
|
|
521
|
-
}): Promise<void> {
|
|
522
|
-
const principal: AuthorizationPrincipal = {
|
|
523
|
-
actor: { id: input.workloadIdentity, type: 'service' },
|
|
524
|
-
audience: input.workloadIdentity,
|
|
525
|
-
authority: {
|
|
526
|
-
machineIdentityId: input.workloadIdentity,
|
|
527
|
-
mode: 'machine',
|
|
528
|
-
},
|
|
529
|
-
kind: 'agent',
|
|
530
|
-
roles: [],
|
|
531
|
-
scopes: [],
|
|
532
|
-
subject: { id: input.workloadIdentity, type: 'service' },
|
|
533
|
-
};
|
|
534
|
-
const authorizationInput: ${pascalName}AuthorizationInput = {
|
|
535
|
-
action: input.action,
|
|
536
|
-
context: {
|
|
537
|
-
facts: { operationId: input.operationId },
|
|
538
|
-
now: new Date().toISOString(),
|
|
539
|
-
stage: process.env.EBK_STAGE ?? 'development',
|
|
540
|
-
},
|
|
541
|
-
principal,
|
|
542
|
-
resource: { attributes: { collection: true }, type: 'slice' },
|
|
543
|
-
};
|
|
544
|
-
const evaluator = createAuthorizationEvaluator({
|
|
545
|
-
admission: defineCoarseAdmission({
|
|
546
|
-
anyOf: [{ kinds: ['agent'], subjectTypes: ['service'] }],
|
|
547
|
-
}),
|
|
548
|
-
policy: ${identifierPrefix}AuthorizationPolicy,
|
|
549
|
-
decisionSink: async ({ decision, input: decisionInput }) => {
|
|
550
|
-
await persistAuthorizationDecision(
|
|
551
|
-
decisionInput,
|
|
552
|
-
decision,
|
|
553
|
-
input.correlationId,
|
|
554
|
-
input.action ===
|
|
555
|
-
${identifierPrefix}AuthorizationActions.lifecycleConsume
|
|
556
|
-
? 'event-consumer'
|
|
557
|
-
: input.action ===
|
|
558
|
-
${identifierPrefix}AuthorizationActions.dataExportCleanup
|
|
559
|
-
? 'data-export-cleanup'
|
|
560
|
-
: 'data-retention-job',
|
|
561
|
-
);
|
|
562
|
-
},
|
|
563
|
-
});
|
|
564
|
-
await evaluator.authorize(authorizationInput);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
type ${pascalName}AuthorizedOperationInput<Operation extends ApiOperationDefinition> = Pick<
|
|
568
|
-
ApiAuthorizationInput<Operation, RuntimeHttpEvent>,
|
|
569
|
-
'context' | 'logger' | 'operation' | 'request'
|
|
570
|
-
>;
|
|
571
|
-
|
|
572
|
-
async function evaluate${pascalName}AuthenticatedOperation<
|
|
573
|
-
Operation extends ApiOperationDefinition,
|
|
574
|
-
>(
|
|
575
|
-
input: ${pascalName}AuthorizedOperationInput<Operation>,
|
|
576
|
-
verified: Principal,
|
|
577
|
-
): Promise<{
|
|
578
|
-
authenticated: Principal;
|
|
579
|
-
principal: AuthorizationPrincipal;
|
|
580
|
-
}> {
|
|
581
|
-
const authenticated = {
|
|
582
|
-
...verified,
|
|
583
|
-
roles: sliceAuthorizationRoles(process.env.EBK_STAGE ?? '', verified.roles),
|
|
584
|
-
};
|
|
585
|
-
const action = operationAction(input.operation);
|
|
586
|
-
const recognizedMachineScopes = Object.values(
|
|
587
|
-
${identifierPrefix}MachineScopes(process.env.EBK_STAGE ?? ''),
|
|
588
|
-
).filter((scope) => authenticated.scopes.includes(scope));
|
|
589
|
-
const principal =
|
|
590
|
-
authenticated.session.subject.type === 'service'
|
|
591
|
-
? recognizedMachineScopes.length > 0
|
|
592
|
-
? createMachineAuthorizationPrincipal(authenticated, {
|
|
593
|
-
audience: authenticated.audience ?? '',
|
|
594
|
-
capability: action,
|
|
595
|
-
machineIdentityId: authenticated.id,
|
|
596
|
-
requiredScopes: recognizedMachineScopes,
|
|
597
|
-
slice: '${name}',
|
|
598
|
-
})
|
|
599
|
-
: composeAuthorizationPrincipal(authenticated, {
|
|
600
|
-
machineIdentityId: authenticated.id,
|
|
601
|
-
mode: 'machine',
|
|
602
|
-
})
|
|
603
|
-
: createDirectAuthorizationPrincipal(authenticated);
|
|
604
|
-
const effectiveOwnerId =
|
|
605
|
-
principal.authority.mode === 'delegated'
|
|
606
|
-
? principal.authority.delegatedBy.id
|
|
607
|
-
: authenticated.id;
|
|
608
|
-
const authorizationInput: ${pascalName}AuthorizationInput = {
|
|
609
|
-
action,
|
|
610
|
-
context: {
|
|
611
|
-
facts: { operationId: input.operation.operationId },
|
|
612
|
-
now: new Date().toISOString(),
|
|
613
|
-
stage: process.env.EBK_STAGE ?? 'development',
|
|
614
|
-
},
|
|
615
|
-
principal,
|
|
616
|
-
resource: await operationResource(
|
|
617
|
-
input.operation,
|
|
618
|
-
input.request,
|
|
619
|
-
effectiveOwnerId,
|
|
620
|
-
input.context.correlationId,
|
|
621
|
-
),
|
|
622
|
-
};
|
|
623
|
-
const evaluator = createAuthorizationEvaluator({
|
|
624
|
-
admission: create${pascalName}CoarseAdmission(
|
|
625
|
-
authorizationInput.context.stage,
|
|
626
|
-
),
|
|
627
|
-
policy: ${identifierPrefix}AuthorizationPolicy,
|
|
628
|
-
decisionSink: async ({ decision, input: decisionInput }) => {
|
|
629
|
-
const audit = await persistAuthorizationDecision(
|
|
630
|
-
decisionInput,
|
|
631
|
-
decision,
|
|
632
|
-
input.context.correlationId,
|
|
633
|
-
'api-database-records',
|
|
634
|
-
);
|
|
635
|
-
input.logger.info('Authorization decision evaluated', {
|
|
636
|
-
attributes: {
|
|
637
|
-
action: audit.action,
|
|
638
|
-
authorityMode: audit.authorityMode,
|
|
639
|
-
decision: audit.decision,
|
|
640
|
-
policyVersion: audit.policyVersion,
|
|
641
|
-
reasonCategory: audit.reasonCategory,
|
|
642
|
-
resourceType: audit.resourceType,
|
|
643
|
-
},
|
|
644
|
-
outcome: decision.decision === 'allow' ? 'success' : 'failure',
|
|
645
|
-
});
|
|
646
|
-
},
|
|
647
|
-
});
|
|
648
|
-
await evaluator.authorize(authorizationInput);
|
|
649
|
-
return { authenticated, principal };
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
async function evaluate${pascalName}Operation<
|
|
653
|
-
Operation extends ApiOperationDefinition,
|
|
654
|
-
>(input: ApiAuthorizationInput<Operation, RuntimeHttpEvent>): Promise<{
|
|
655
|
-
authenticated: Principal;
|
|
656
|
-
principal: AuthorizationPrincipal;
|
|
657
|
-
}> {
|
|
658
|
-
const verified = await getGuard().authorize(input.event, {
|
|
659
|
-
logger: input.logger,
|
|
660
|
-
});
|
|
661
|
-
return evaluate${pascalName}AuthenticatedOperation(input, verified);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
/** Fleet-only native Next transport; Lambda continues using the same evaluator. */
|
|
665
|
-
export async function authorize${pascalName}FleetRecordOperation<
|
|
666
|
-
Operation extends ApiOperationDefinition,
|
|
667
|
-
>(input: ${pascalName}AuthorizedOperationInput<Operation> & { accessToken: string | null }): Promise<AuthorizationPrincipal> {
|
|
668
|
-
if (!Object.is(input.operation, ${identifierPrefix}GetRecord) &&
|
|
669
|
-
!Object.is(input.operation, ${identifierPrefix}PutRecord))
|
|
670
|
-
throw new Error('Fleet record authorization requires the exact generated record operation.');
|
|
671
|
-
const verified = await getGuard().authorizeToken(input.accessToken, { logger: input.logger });
|
|
672
|
-
const webClientId = process.env.AUTH_CLIENT_ID;
|
|
673
|
-
if (!webClientId || verified.audience !== webClientId ||
|
|
674
|
-
verified.session.subject.type !== 'user' || verified.kind !== 'customer')
|
|
675
|
-
throw new AuthError({ code: authErrorCodes.invalidToken,
|
|
676
|
-
message: 'The access token is not a task web-client human token.', status: 401 });
|
|
677
|
-
return (await evaluate${pascalName}AuthenticatedOperation(input, verified)).principal;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
export async function authorize${pascalName}Operation<
|
|
681
|
-
Operation extends ApiOperationDefinition,
|
|
682
|
-
>(
|
|
683
|
-
input: ApiAuthorizationInput<Operation, RuntimeHttpEvent>,
|
|
684
|
-
): Promise<Principal> {
|
|
685
|
-
return (await evaluate${pascalName}Operation(input)).authenticated;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* Data-rights services receive the exact rich principal that was evaluated,
|
|
690
|
-
* rather than reconstructing authority from the transport principal.
|
|
691
|
-
*/
|
|
692
|
-
export async function authorize${pascalName}DataRightsOperation<
|
|
693
|
-
Operation extends ApiOperationDefinition,
|
|
694
|
-
>(
|
|
695
|
-
input: ApiAuthorizationInput<Operation, RuntimeHttpEvent>,
|
|
696
|
-
): Promise<AuthorizationPrincipal> {
|
|
697
|
-
return (await evaluate${pascalName}Operation(input)).principal;
|
|
698
|
-
}
|
|
699
|
-
`,
|
|
700
|
-
'authorization/store.ts': (0, built_in_plan_authorization_storage_js_1.renderDynamoAuthorizationStore)(pascalName),
|
|
701
|
-
'authorization/workflows.ts': `import { createHash } from 'node:crypto';
|
|
702
|
-
import type { Principal } from '@empire-builder-kit/runtime/auth';
|
|
703
|
-
import {
|
|
704
|
-
assertAuthorizationAllowed,
|
|
705
|
-
createAuthorizationEvaluator,
|
|
706
|
-
createDirectAuthorizationPrincipal,
|
|
707
|
-
createMachineAuthorizationPrincipal,
|
|
708
|
-
issueDelegation,
|
|
709
|
-
revokeDelegation,
|
|
710
|
-
useDelegation,
|
|
711
|
-
type AuthorizationDecision,
|
|
712
|
-
type AuthorizationPrincipal,
|
|
713
|
-
type DelegationGrant,
|
|
714
|
-
type IssuedDelegation,
|
|
715
|
-
} from '@empire-builder-kit/runtime/authorization';
|
|
716
|
-
import { RuntimeError } from '@empire-builder-kit/runtime/response';
|
|
717
|
-
import { isBoundedSafeReference } from '@empire-builder-kit/runtime/safe-reference';
|
|
718
|
-
import { readAuthorizationRecord, writeAuthorizationAudit } from './record-store.js';
|
|
719
|
-
import {
|
|
720
|
-
${identifierPrefix}AuthorizationActions,
|
|
721
|
-
${identifierPrefix}AuthorizationPolicy,
|
|
722
|
-
${identifierPrefix}MachineScopes,
|
|
723
|
-
create${pascalName}CoarseAdmission,
|
|
724
|
-
type ${pascalName}AuthorizationAction,
|
|
725
|
-
type ${pascalName}AuthorizationInput,
|
|
726
|
-
} from './policy.js';
|
|
727
|
-
import { create${pascalName}DelegationStore } from './store.js';
|
|
728
|
-
|
|
729
|
-
const POLICY_VERSION = ${identifierPrefix}AuthorizationPolicy.version;
|
|
730
|
-
|
|
731
|
-
interface RecordResult {
|
|
732
|
-
id: string;
|
|
733
|
-
name: string;
|
|
734
|
-
runScope: string;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
function stage(): string {
|
|
738
|
-
return process.env.EBK_STAGE ?? 'development';
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
function acceptedMachineClientIds(): readonly string[] {
|
|
742
|
-
const current = process.env.AUTH_MACHINE_CLIENT_ID ?? '';
|
|
743
|
-
const encoded = process.env.AUTH_MACHINE_ACCEPTED_CLIENT_IDS ?? '';
|
|
744
|
-
let candidate: unknown;
|
|
745
|
-
try {
|
|
746
|
-
candidate = JSON.parse(encoded);
|
|
747
|
-
} catch {
|
|
748
|
-
unavailable();
|
|
749
|
-
}
|
|
750
|
-
if (
|
|
751
|
-
!Array.isArray(candidate) ||
|
|
752
|
-
candidate.length < 1 ||
|
|
753
|
-
candidate.length > 2 ||
|
|
754
|
-
new Set(candidate).size !== candidate.length ||
|
|
755
|
-
candidate.some(
|
|
756
|
-
(clientId) =>
|
|
757
|
-
!isBoundedSafeReference(clientId),
|
|
758
|
-
) ||
|
|
759
|
-
!isBoundedSafeReference(current) ||
|
|
760
|
-
!candidate.includes(current)
|
|
761
|
-
) {
|
|
762
|
-
unavailable();
|
|
763
|
-
}
|
|
764
|
-
return candidate as string[];
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
function machineClientId(): string {
|
|
768
|
-
const value = process.env.AUTH_MACHINE_CLIENT_ID ?? '';
|
|
769
|
-
if (
|
|
770
|
-
!isBoundedSafeReference(value) ||
|
|
771
|
-
!acceptedMachineClientIds().includes(value)
|
|
772
|
-
) {
|
|
773
|
-
unavailable();
|
|
774
|
-
}
|
|
775
|
-
return value;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
function authenticatedMachineClientId(principal: Principal): string {
|
|
779
|
-
const value = principal.audience;
|
|
780
|
-
if (
|
|
781
|
-
principal.kind !== 'agent' ||
|
|
782
|
-
principal.session.subject.type !== 'service' ||
|
|
783
|
-
typeof value !== 'string' ||
|
|
784
|
-
principal.id !== value ||
|
|
785
|
-
!acceptedMachineClientIds().includes(value)
|
|
786
|
-
) {
|
|
787
|
-
denied();
|
|
788
|
-
}
|
|
789
|
-
return value;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
function pseudonymousReference(namespace: string, value: string): string {
|
|
793
|
-
return (
|
|
794
|
-
'sha256:' +
|
|
795
|
-
createHash('sha256')
|
|
796
|
-
.update('${name}\\0' + namespace + '\\0' + value)
|
|
797
|
-
.digest('hex')
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
function invalidInput(): never {
|
|
802
|
-
throw new RuntimeError({
|
|
803
|
-
code: 'authorization_input_invalid',
|
|
804
|
-
message: 'Authorization input is invalid.',
|
|
805
|
-
retryable: false,
|
|
806
|
-
status: 403,
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
function denied(): never {
|
|
811
|
-
throw new RuntimeError({
|
|
812
|
-
code: 'authorization_denied',
|
|
813
|
-
message: 'Authorization denied.',
|
|
814
|
-
retryable: false,
|
|
815
|
-
status: 403,
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
function notFound(): never {
|
|
820
|
-
throw new RuntimeError({
|
|
821
|
-
code: 'record_not_found',
|
|
822
|
-
message: 'The record was not found.',
|
|
823
|
-
retryable: false,
|
|
824
|
-
status: 404,
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
function unavailable(): never {
|
|
829
|
-
throw new RuntimeError({
|
|
830
|
-
code: 'authorization_unavailable',
|
|
831
|
-
message: 'Authorization is temporarily unavailable.',
|
|
832
|
-
retryable: true,
|
|
833
|
-
status: 503,
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
function targetMachinePrincipal(): AuthorizationPrincipal {
|
|
838
|
-
const clientId = machineClientId();
|
|
839
|
-
return {
|
|
840
|
-
actor: { id: clientId, type: 'service' },
|
|
841
|
-
audience: clientId,
|
|
842
|
-
authority: { machineIdentityId: clientId, mode: 'machine' },
|
|
843
|
-
kind: 'agent',
|
|
844
|
-
roles: [],
|
|
845
|
-
scopes: [${identifierPrefix}MachineScopes(stage()).delegationUse],
|
|
846
|
-
subject: { id: clientId, type: 'service' },
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
async function writeDelegationAudit(input: {
|
|
851
|
-
action: ${pascalName}AuthorizationAction;
|
|
852
|
-
correlationId: string;
|
|
853
|
-
decision: AuthorizationDecision;
|
|
854
|
-
delegationId: string;
|
|
855
|
-
principal: AuthorizationPrincipal;
|
|
856
|
-
recordId: string;
|
|
857
|
-
reasonCategory: string;
|
|
858
|
-
}): Promise<void> {
|
|
859
|
-
await writeAuthorizationAudit({
|
|
860
|
-
action: input.action,
|
|
861
|
-
authorityMode: input.principal.authority.mode,
|
|
862
|
-
correlationId: input.correlationId,
|
|
863
|
-
decision: input.decision.decision,
|
|
864
|
-
delegationReference: pseudonymousReference('delegation', input.delegationId),
|
|
865
|
-
policyVersion: input.decision.policyVersion,
|
|
866
|
-
principalKind: input.principal.kind,
|
|
867
|
-
pseudonymousSubjectId: pseudonymousReference('subject', input.principal.actor.id),
|
|
868
|
-
reasonCategory: input.reasonCategory,
|
|
869
|
-
resourceReference: pseudonymousReference('record', input.recordId),
|
|
870
|
-
resourceType: 'record',
|
|
871
|
-
slice: '${name}',
|
|
872
|
-
stage: stage(),
|
|
873
|
-
subjectType: input.principal.actor.type,
|
|
874
|
-
timestamp: new Date().toISOString(),
|
|
875
|
-
}, 'api-database-records');
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
export async function issue${pascalName}RecordDelegation(input: {
|
|
879
|
-
correlationId: string;
|
|
880
|
-
expiresAt: string;
|
|
881
|
-
principal: Principal;
|
|
882
|
-
purposeReference: string;
|
|
883
|
-
recordId: string;
|
|
884
|
-
}): Promise<IssuedDelegation<${pascalName}AuthorizationAction>> {
|
|
885
|
-
const now = new Date();
|
|
886
|
-
const expiresAt = Date.parse(input.expiresAt);
|
|
887
|
-
if (
|
|
888
|
-
!isBoundedSafeReference(input.purposeReference) ||
|
|
889
|
-
!Number.isFinite(expiresAt) ||
|
|
890
|
-
expiresAt <= now.getTime() ||
|
|
891
|
-
expiresAt - now.getTime() > 60 * 60 * 1_000
|
|
892
|
-
) {
|
|
893
|
-
invalidInput();
|
|
894
|
-
}
|
|
895
|
-
const ownership = await readAuthorizationRecord(input.correlationId, input.recordId);
|
|
896
|
-
if (ownership?.ownerId !== input.principal.id) denied();
|
|
897
|
-
const delegator = createDirectAuthorizationPrincipal(input.principal);
|
|
898
|
-
let issued: IssuedDelegation<${pascalName}AuthorizationAction>;
|
|
899
|
-
try {
|
|
900
|
-
issued = await issueDelegation(
|
|
901
|
-
create${pascalName}DelegationStore(input.correlationId),
|
|
902
|
-
{
|
|
903
|
-
actions: [${identifierPrefix}AuthorizationActions.recordRead],
|
|
904
|
-
agent: targetMachinePrincipal(),
|
|
905
|
-
audience: machineClientId(),
|
|
906
|
-
capabilityScopes: [
|
|
907
|
-
${identifierPrefix}MachineScopes(stage()).delegationUse,
|
|
908
|
-
],
|
|
909
|
-
delegator,
|
|
910
|
-
expiresAt: new Date(expiresAt).toISOString(),
|
|
911
|
-
issuedUnderPolicyVersion: POLICY_VERSION,
|
|
912
|
-
maxUses: 20,
|
|
913
|
-
now: now.toISOString(),
|
|
914
|
-
purposeReference: input.purposeReference,
|
|
915
|
-
rateLimit: { maximumUses: 5, windowSeconds: 60 },
|
|
916
|
-
resourceBoundary: {
|
|
917
|
-
kind: 'exact',
|
|
918
|
-
resourceIds: [input.recordId],
|
|
919
|
-
resourceType: 'record',
|
|
920
|
-
},
|
|
921
|
-
slice: '${name}',
|
|
922
|
-
},
|
|
923
|
-
);
|
|
924
|
-
} catch {
|
|
925
|
-
unavailable();
|
|
926
|
-
}
|
|
927
|
-
const decision = {
|
|
928
|
-
decision: 'allow',
|
|
929
|
-
obligations: [],
|
|
930
|
-
policyVersion: POLICY_VERSION,
|
|
931
|
-
} as const;
|
|
932
|
-
await writeDelegationAudit({
|
|
933
|
-
action: ${identifierPrefix}AuthorizationActions.recordDelegationIssue,
|
|
934
|
-
correlationId: input.correlationId,
|
|
935
|
-
decision,
|
|
936
|
-
delegationId: issued.grant.id,
|
|
937
|
-
principal: delegator,
|
|
938
|
-
recordId: input.recordId,
|
|
939
|
-
reasonCategory: 'delegation-issued',
|
|
940
|
-
});
|
|
941
|
-
return issued;
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
export async function use${pascalName}RecordDelegation(input: {
|
|
945
|
-
capability: string;
|
|
946
|
-
correlationId: string;
|
|
947
|
-
delegationId: string;
|
|
948
|
-
principal: Principal;
|
|
949
|
-
recordId: string;
|
|
950
|
-
}): Promise<RecordResult> {
|
|
951
|
-
const currentStage = stage();
|
|
952
|
-
const requiredScope =
|
|
953
|
-
${identifierPrefix}MachineScopes(currentStage).delegationUse;
|
|
954
|
-
const authenticatedClientId = authenticatedMachineClientId(input.principal);
|
|
955
|
-
let machine: AuthorizationPrincipal;
|
|
956
|
-
try {
|
|
957
|
-
machine = createMachineAuthorizationPrincipal(input.principal, {
|
|
958
|
-
audience: authenticatedClientId,
|
|
959
|
-
capability:
|
|
960
|
-
${identifierPrefix}AuthorizationActions.recordDelegationUse,
|
|
961
|
-
machineIdentityId: authenticatedClientId,
|
|
962
|
-
requiredScopes: [requiredScope],
|
|
963
|
-
slice: '${name}',
|
|
964
|
-
});
|
|
965
|
-
} catch {
|
|
966
|
-
denied();
|
|
967
|
-
}
|
|
968
|
-
const owner = await readAuthorizationRecord(input.correlationId, input.recordId);
|
|
969
|
-
const resource = {
|
|
970
|
-
attributes: {
|
|
971
|
-
ownerId: owner?.ownerId ?? 'missing-resource-owner',
|
|
972
|
-
},
|
|
973
|
-
id: input.recordId,
|
|
974
|
-
type: 'record' as const,
|
|
975
|
-
};
|
|
976
|
-
const context = {
|
|
977
|
-
facts: { operationId: '${name}.use-record-delegation' },
|
|
978
|
-
now: new Date().toISOString(),
|
|
979
|
-
stage: currentStage,
|
|
980
|
-
};
|
|
981
|
-
const result = await useDelegation({
|
|
982
|
-
action: ${identifierPrefix}AuthorizationActions.recordRead,
|
|
983
|
-
agent: machine,
|
|
984
|
-
audience: authenticatedClientId,
|
|
985
|
-
capability: input.capability,
|
|
986
|
-
context,
|
|
987
|
-
delegationId: input.delegationId,
|
|
988
|
-
evaluator: createAuthorizationEvaluator<${pascalName}AuthorizationInput>({
|
|
989
|
-
admission: create${pascalName}CoarseAdmission(currentStage),
|
|
990
|
-
policy: ${identifierPrefix}AuthorizationPolicy,
|
|
991
|
-
}),
|
|
992
|
-
resolveDelegator: ({ delegator, resource: currentResource }) =>
|
|
993
|
-
currentResource.attributes.ownerId === delegator.id
|
|
994
|
-
? {
|
|
995
|
-
actor: delegator,
|
|
996
|
-
authority: { mode: 'direct' },
|
|
997
|
-
kind: 'customer',
|
|
998
|
-
roles: [],
|
|
999
|
-
scopes: [],
|
|
1000
|
-
subject: delegator,
|
|
1001
|
-
}
|
|
1002
|
-
: undefined,
|
|
1003
|
-
requiredCapabilityScopes: [requiredScope],
|
|
1004
|
-
resource,
|
|
1005
|
-
store: create${pascalName}DelegationStore(input.correlationId),
|
|
1006
|
-
});
|
|
1007
|
-
const auditPrincipal = result.principal ?? machine;
|
|
1008
|
-
await writeDelegationAudit({
|
|
1009
|
-
action: ${identifierPrefix}AuthorizationActions.recordRead,
|
|
1010
|
-
correlationId: input.correlationId,
|
|
1011
|
-
decision: result.decision,
|
|
1012
|
-
delegationId: input.delegationId,
|
|
1013
|
-
principal: auditPrincipal,
|
|
1014
|
-
recordId: input.recordId,
|
|
1015
|
-
reasonCategory:
|
|
1016
|
-
result.decision.decision === 'allow'
|
|
1017
|
-
? 'delegation-used'
|
|
1018
|
-
: result.decision.category,
|
|
1019
|
-
});
|
|
1020
|
-
assertAuthorizationAllowed(result.decision);
|
|
1021
|
-
if (!result.grant || !owner) notFound();
|
|
1022
|
-
|
|
1023
|
-
const record = await readAuthorizationRecord(input.correlationId, input.recordId, result.grant.delegator.id);
|
|
1024
|
-
if (!record) notFound();
|
|
1025
|
-
return { id: record.id, name: record.name, runScope: record.runScope };
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
function grantMatchesRecord(
|
|
1029
|
-
grant: DelegationGrant<${pascalName}AuthorizationAction>,
|
|
1030
|
-
recordId: string,
|
|
1031
|
-
): boolean {
|
|
1032
|
-
return (
|
|
1033
|
-
grant.resourceBoundary.kind === 'exact' &&
|
|
1034
|
-
grant.resourceBoundary.resourceType === 'record' &&
|
|
1035
|
-
grant.resourceBoundary.resourceIds.includes(recordId)
|
|
1036
|
-
);
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
export async function revoke${pascalName}RecordDelegation(input: {
|
|
1040
|
-
correlationId: string;
|
|
1041
|
-
delegationId: string;
|
|
1042
|
-
principal: Principal;
|
|
1043
|
-
recordId: string;
|
|
1044
|
-
}): Promise<DelegationGrant<${pascalName}AuthorizationAction>> {
|
|
1045
|
-
const store = create${pascalName}DelegationStore(input.correlationId);
|
|
1046
|
-
const grant = await store.read(input.delegationId);
|
|
1047
|
-
const revoker = createDirectAuthorizationPrincipal(input.principal);
|
|
1048
|
-
if (
|
|
1049
|
-
!grant ||
|
|
1050
|
-
!grantMatchesRecord(grant, input.recordId) ||
|
|
1051
|
-
(input.principal.kind !== 'admin' &&
|
|
1052
|
-
grant.delegator.id !== input.principal.id)
|
|
1053
|
-
) {
|
|
1054
|
-
denied();
|
|
1055
|
-
}
|
|
1056
|
-
const revoked = await revokeDelegation(store, {
|
|
1057
|
-
delegationId: input.delegationId,
|
|
1058
|
-
now: new Date().toISOString(),
|
|
1059
|
-
revokedBy: revoker,
|
|
1060
|
-
});
|
|
1061
|
-
if (!revoked) denied();
|
|
1062
|
-
const decision = {
|
|
1063
|
-
decision: 'allow',
|
|
1064
|
-
obligations: [],
|
|
1065
|
-
policyVersion: POLICY_VERSION,
|
|
1066
|
-
} as const;
|
|
1067
|
-
await writeDelegationAudit({
|
|
1068
|
-
action: ${identifierPrefix}AuthorizationActions.recordDelegationRevoke,
|
|
1069
|
-
correlationId: input.correlationId,
|
|
1070
|
-
decision,
|
|
1071
|
-
delegationId: revoked.id,
|
|
1072
|
-
principal: revoker,
|
|
1073
|
-
recordId: input.recordId,
|
|
1074
|
-
reasonCategory: 'delegation-revoked',
|
|
1075
|
-
});
|
|
1076
|
-
return revoked;
|
|
1077
|
-
}
|
|
1078
|
-
`,
|
|
1079
|
-
'authorization/machine-authorization-proof.ts': `import {
|
|
1080
|
-
createMachineTokenProvider,
|
|
1081
|
-
type MachineTokenExchangeResult,
|
|
1082
|
-
} from '@empire-builder-kit/runtime/authorization';
|
|
1083
|
-
import {
|
|
1084
|
-
bindServerSecretRuntime,
|
|
1085
|
-
createAwsSecretsManagerSource,
|
|
1086
|
-
createServerSecretResolver,
|
|
1087
|
-
defineSecrets,
|
|
1088
|
-
secret,
|
|
1089
|
-
} from '@empire-builder-kit/runtime/secrets';
|
|
1090
|
-
|
|
1091
|
-
interface MachineCredentialDocument {
|
|
1092
|
-
clientId: string;
|
|
1093
|
-
clientSecret: string;
|
|
1094
|
-
generation: string;
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
const MachineAuthorizationSecrets = defineSecrets({
|
|
1098
|
-
${pascalName}MachineClientCredential: {
|
|
1099
|
-
cache: { freshTtlMs: 0, staleTtlMs: 0 },
|
|
1100
|
-
owner: '${name}',
|
|
1101
|
-
requiredStages: ['development', 'staging', 'production'],
|
|
1102
|
-
retention: { mode: 'retain' },
|
|
1103
|
-
rotation: {
|
|
1104
|
-
mode: 'manual',
|
|
1105
|
-
runbook: 'docs/runbooks/rotate-machine-authorization.md',
|
|
1106
|
-
},
|
|
1107
|
-
source: 'aws-managed',
|
|
1108
|
-
value: secret.json<MachineCredentialDocument>({
|
|
1109
|
-
validate(value): value is MachineCredentialDocument {
|
|
1110
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1111
|
-
return false;
|
|
1112
|
-
}
|
|
1113
|
-
const candidate = value as Partial<MachineCredentialDocument>;
|
|
1114
|
-
return (
|
|
1115
|
-
typeof candidate.clientId === 'string' &&
|
|
1116
|
-
typeof candidate.clientSecret === 'string' &&
|
|
1117
|
-
typeof candidate.generation === 'string' &&
|
|
1118
|
-
candidate.clientSecret.length >= 1 &&
|
|
1119
|
-
candidate.clientSecret.length <= 4_096 &&
|
|
1120
|
-
/^(?:blue|green)-[1-9][0-9]{0,11}$/.test(candidate.generation)
|
|
1121
|
-
);
|
|
1122
|
-
},
|
|
1123
|
-
}),
|
|
1124
|
-
},
|
|
1125
|
-
});
|
|
1126
|
-
|
|
1127
|
-
function requiredEnvironment(name: string): string {
|
|
1128
|
-
const value = process.env[name]?.trim();
|
|
1129
|
-
if (!value || value.length > 2_048 || /[\\r\\n]/.test(value)) {
|
|
1130
|
-
throw new Error('Machine authorization proof configuration is invalid.');
|
|
1131
|
-
}
|
|
1132
|
-
return value;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
function credentialDocument(
|
|
1136
|
-
candidate: MachineCredentialDocument,
|
|
1137
|
-
): MachineCredentialDocument {
|
|
1138
|
-
if (
|
|
1139
|
-
candidate.clientId !== requiredEnvironment('AUTH_MACHINE_CLIENT_ID')
|
|
1140
|
-
) {
|
|
1141
|
-
throw new Error('Machine authorization credential is invalid.');
|
|
1142
|
-
}
|
|
1143
|
-
return candidate;
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
function machineCredentialResolver() {
|
|
1147
|
-
return createServerSecretResolver({
|
|
1148
|
-
binding: bindServerSecretRuntime({
|
|
1149
|
-
stage: requiredEnvironment('EBK_STAGE'),
|
|
1150
|
-
workload: '${name}:machine-authorization-proof',
|
|
1151
|
-
}),
|
|
1152
|
-
cache: { freshTtlMs: 0, staleTtlMs: 0 },
|
|
1153
|
-
source: createAwsSecretsManagerSource(),
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
async function exchange(input: {
|
|
1158
|
-
audience: string;
|
|
1159
|
-
clientId: string;
|
|
1160
|
-
clientSecret: string;
|
|
1161
|
-
scopes: readonly string[];
|
|
1162
|
-
}): Promise<MachineTokenExchangeResult> {
|
|
1163
|
-
const response = await fetch(
|
|
1164
|
-
requiredEnvironment('AUTH_MACHINE_TOKEN_ENDPOINT'),
|
|
1165
|
-
{
|
|
1166
|
-
body: new URLSearchParams({
|
|
1167
|
-
grant_type: 'client_credentials',
|
|
1168
|
-
scope: input.scopes.join(' '),
|
|
1169
|
-
}),
|
|
1170
|
-
headers: {
|
|
1171
|
-
authorization:
|
|
1172
|
-
'Basic ' +
|
|
1173
|
-
Buffer.from(input.clientId + ':' + input.clientSecret).toString(
|
|
1174
|
-
'base64',
|
|
1175
|
-
),
|
|
1176
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
1177
|
-
},
|
|
1178
|
-
method: 'POST',
|
|
1179
|
-
signal: AbortSignal.timeout(10_000),
|
|
1180
|
-
},
|
|
1181
|
-
);
|
|
1182
|
-
if (!response.ok) {
|
|
1183
|
-
throw new Error('Machine token exchange was denied.');
|
|
1184
|
-
}
|
|
1185
|
-
const value = (await response.json()) as {
|
|
1186
|
-
access_token?: unknown;
|
|
1187
|
-
expires_in?: unknown;
|
|
1188
|
-
scope?: unknown;
|
|
1189
|
-
token_type?: unknown;
|
|
1190
|
-
};
|
|
1191
|
-
const expiresIn = Number(value.expires_in);
|
|
1192
|
-
if (
|
|
1193
|
-
typeof value.access_token !== 'string' ||
|
|
1194
|
-
value.token_type !== 'Bearer' ||
|
|
1195
|
-
!Number.isFinite(expiresIn) ||
|
|
1196
|
-
expiresIn < 1 ||
|
|
1197
|
-
(value.scope !== undefined && typeof value.scope !== 'string')
|
|
1198
|
-
) {
|
|
1199
|
-
throw new Error('Machine token exchange returned an invalid response.');
|
|
1200
|
-
}
|
|
1201
|
-
// RFC 6749 section 5.1: an omitted scope is identical to the requested
|
|
1202
|
-
// scope. Amazon Cognito omits it from client_credentials responses and
|
|
1203
|
-
// rejects, never narrows, a scope the client may not use. A returned scope
|
|
1204
|
-
// is still parsed, and createMachineTokenProvider requires the exact set.
|
|
1205
|
-
const scopes =
|
|
1206
|
-
value.scope === undefined
|
|
1207
|
-
? [...input.scopes]
|
|
1208
|
-
: value.scope.split(/\\s+/).filter(Boolean);
|
|
1209
|
-
return {
|
|
1210
|
-
accessToken: value.access_token,
|
|
1211
|
-
audience: input.audience,
|
|
1212
|
-
expiresAt: Date.now() / 1_000 + expiresIn,
|
|
1213
|
-
scopes,
|
|
1214
|
-
tokenType: 'Bearer',
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
export async function handler() {
|
|
1219
|
-
const clientId = requiredEnvironment('AUTH_MACHINE_CLIENT_ID');
|
|
1220
|
-
const scope = requiredEnvironment('AUTH_MACHINE_PROOF_SCOPE');
|
|
1221
|
-
let generation = 'unresolved';
|
|
1222
|
-
const provider = createMachineTokenProvider({
|
|
1223
|
-
audience: requiredEnvironment('AUTH_MACHINE_RESOURCE_SERVER'),
|
|
1224
|
-
clientId,
|
|
1225
|
-
exchange,
|
|
1226
|
-
machineIdentityId: clientId,
|
|
1227
|
-
resolveClientSecret: async () => {
|
|
1228
|
-
const credential = credentialDocument(
|
|
1229
|
-
await machineCredentialResolver().get(
|
|
1230
|
-
MachineAuthorizationSecrets.${pascalName}MachineClientCredential,
|
|
1231
|
-
{
|
|
1232
|
-
logicalName:
|
|
1233
|
-
MachineAuthorizationSecrets.${pascalName}MachineClientCredential
|
|
1234
|
-
.logicalName,
|
|
1235
|
-
provider: 'aws-secrets-manager',
|
|
1236
|
-
secretArn: requiredEnvironment(
|
|
1237
|
-
'AUTH_MACHINE_CLIENT_SECRET_ARN',
|
|
1238
|
-
),
|
|
1239
|
-
},
|
|
1240
|
-
),
|
|
1241
|
-
);
|
|
1242
|
-
generation = credential.generation;
|
|
1243
|
-
return { value: credential.clientSecret };
|
|
1244
|
-
},
|
|
1245
|
-
scopes: [scope],
|
|
1246
|
-
});
|
|
1247
|
-
const token = await provider.getToken();
|
|
1248
|
-
const response = await fetch(
|
|
1249
|
-
requiredEnvironment('AUTH_MACHINE_PROBE_URL'),
|
|
1250
|
-
{
|
|
1251
|
-
headers: { authorization: token.tokenType + ' ' + token.accessToken },
|
|
1252
|
-
method: 'GET',
|
|
1253
|
-
signal: AbortSignal.timeout(10_000),
|
|
1254
|
-
},
|
|
1255
|
-
);
|
|
1256
|
-
if (response.status !== 200) {
|
|
1257
|
-
throw new Error('Machine authorization allow probe was denied.');
|
|
1258
|
-
}
|
|
1259
|
-
return {
|
|
1260
|
-
audit: provider.auditSnapshot(),
|
|
1261
|
-
clientId,
|
|
1262
|
-
credentialGeneration: generation,
|
|
1263
|
-
outcome: 'success' as const,
|
|
1264
|
-
probeStatus: response.status,
|
|
1265
|
-
scope,
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
`,
|
|
1269
|
-
'authorization/policy.spec.ts': `import {
|
|
1270
|
-
createAuthorizationEvaluator,
|
|
1271
|
-
defineCoarseAdmission,
|
|
1272
|
-
type AuthorizationPrincipal,
|
|
1273
|
-
} from '@empire-builder-kit/runtime/authorization';
|
|
1274
|
-
import { describe, expect, it } from 'vitest';
|
|
1275
|
-
import {
|
|
1276
|
-
${identifierPrefix}AuthorizationActions,
|
|
1277
|
-
${identifierPrefix}MachineScopes,
|
|
1278
|
-
${identifierPrefix}AuthorizationPolicy,
|
|
1279
|
-
create${pascalName}CoarseAdmission,
|
|
1280
|
-
type ${pascalName}AuthorizationAction,
|
|
1281
|
-
type ${pascalName}AuthorizationInput,
|
|
1282
|
-
} from './policy.js';
|
|
1283
|
-
|
|
1284
|
-
function principal(
|
|
1285
|
-
overrides: Partial<AuthorizationPrincipal> = {},
|
|
1286
|
-
): AuthorizationPrincipal {
|
|
1287
|
-
return {
|
|
1288
|
-
actor: { id: 'subject-owner', type: 'user' },
|
|
1289
|
-
authority: { mode: 'direct' },
|
|
1290
|
-
kind: 'customer',
|
|
1291
|
-
roles: [],
|
|
1292
|
-
scopes: [],
|
|
1293
|
-
subject: { id: 'subject-owner', type: 'user' },
|
|
1294
|
-
...overrides,
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
function input(
|
|
1299
|
-
overrides: Partial<${pascalName}AuthorizationInput> = {},
|
|
1300
|
-
): ${pascalName}AuthorizationInput {
|
|
1301
|
-
return {
|
|
1302
|
-
action: ${identifierPrefix}AuthorizationActions.recordRead,
|
|
1303
|
-
context: {
|
|
1304
|
-
facts: { operationId: '${name}.get-record' },
|
|
1305
|
-
now: '2026-07-27T12:00:00.000Z',
|
|
1306
|
-
stage: 'development',
|
|
1307
|
-
},
|
|
1308
|
-
principal: principal(),
|
|
1309
|
-
resource: {
|
|
1310
|
-
attributes: { ownerId: 'subject-owner' },
|
|
1311
|
-
id: '00000000-0000-4000-8000-000000000001',
|
|
1312
|
-
type: 'record',
|
|
1313
|
-
},
|
|
1314
|
-
...overrides,
|
|
1315
|
-
};
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
describe('${pascalName} authorization policy', () => {
|
|
1319
|
-
const evaluator = createAuthorizationEvaluator({
|
|
1320
|
-
admission: create${pascalName}CoarseAdmission('development'),
|
|
1321
|
-
policy: ${identifierPrefix}AuthorizationPolicy,
|
|
1322
|
-
});
|
|
1323
|
-
|
|
1324
|
-
it('allows an owner and denies an adjacent resource', async () => {
|
|
1325
|
-
await expect(evaluator.evaluate(input())).resolves.toMatchObject({
|
|
1326
|
-
decision: 'allow',
|
|
1327
|
-
});
|
|
1328
|
-
await expect(
|
|
1329
|
-
evaluator.evaluate(
|
|
1330
|
-
input({
|
|
1331
|
-
resource: {
|
|
1332
|
-
attributes: { ownerId: 'subject-adjacent' },
|
|
1333
|
-
id: '00000000-0000-4000-8000-000000000002',
|
|
1334
|
-
type: 'record',
|
|
1335
|
-
},
|
|
1336
|
-
}),
|
|
1337
|
-
),
|
|
1338
|
-
).resolves.toMatchObject({
|
|
1339
|
-
category: 'domain-authorization-denied',
|
|
1340
|
-
decision: 'deny',
|
|
1341
|
-
});
|
|
1342
|
-
});
|
|
1343
|
-
|
|
1344
|
-
it('limits TTL-bearing synthetic records to the generated test-writer role', async () => {
|
|
1345
|
-
const syntheticResource = {
|
|
1346
|
-
attributes: {
|
|
1347
|
-
ownerId: 'subject-owner',
|
|
1348
|
-
syntheticTestData: true,
|
|
1349
|
-
},
|
|
1350
|
-
id: '00000000-0000-4000-8000-000000000001',
|
|
1351
|
-
type: 'record' as const,
|
|
1352
|
-
};
|
|
1353
|
-
await expect(
|
|
1354
|
-
evaluator.evaluate(
|
|
1355
|
-
input({
|
|
1356
|
-
action: ${identifierPrefix}AuthorizationActions.recordWrite,
|
|
1357
|
-
resource: syntheticResource,
|
|
1358
|
-
}),
|
|
1359
|
-
),
|
|
1360
|
-
).resolves.toMatchObject({
|
|
1361
|
-
category: 'domain-authorization-denied',
|
|
1362
|
-
decision: 'deny',
|
|
1363
|
-
});
|
|
1364
|
-
await expect(
|
|
1365
|
-
evaluator.evaluate(
|
|
1366
|
-
input({
|
|
1367
|
-
action: ${identifierPrefix}AuthorizationActions.recordWrite,
|
|
1368
|
-
principal: principal({ roles: ['${name}-test-writer'] }),
|
|
1369
|
-
resource: syntheticResource,
|
|
1370
|
-
}),
|
|
1371
|
-
),
|
|
1372
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1373
|
-
});
|
|
1374
|
-
|
|
1375
|
-
it('separates owner export from direct-admin cleanup and hold authority', async () => {
|
|
1376
|
-
await expect(
|
|
1377
|
-
evaluator.evaluate(
|
|
1378
|
-
input({
|
|
1379
|
-
action: ${identifierPrefix}AuthorizationActions.recordExport,
|
|
1380
|
-
}),
|
|
1381
|
-
),
|
|
1382
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1383
|
-
const admin = principal({
|
|
1384
|
-
actor: { id: 'admin-reviewer', type: 'user' },
|
|
1385
|
-
kind: 'admin',
|
|
1386
|
-
roles: ['${name}-admin'],
|
|
1387
|
-
subject: { id: 'admin-reviewer', type: 'user' },
|
|
1388
|
-
});
|
|
1389
|
-
await expect(
|
|
1390
|
-
evaluator.evaluate(
|
|
1391
|
-
input({
|
|
1392
|
-
action: ${identifierPrefix}AuthorizationActions.recordExport,
|
|
1393
|
-
principal: admin,
|
|
1394
|
-
}),
|
|
1395
|
-
),
|
|
1396
|
-
).resolves.toMatchObject({ decision: 'deny' });
|
|
1397
|
-
await expect(
|
|
1398
|
-
evaluator.evaluate(
|
|
1399
|
-
input({
|
|
1400
|
-
action:
|
|
1401
|
-
${identifierPrefix}AuthorizationActions.recordExportCleanup,
|
|
1402
|
-
}),
|
|
1403
|
-
),
|
|
1404
|
-
).resolves.toMatchObject({ decision: 'deny' });
|
|
1405
|
-
for (const action of [
|
|
1406
|
-
${identifierPrefix}AuthorizationActions.recordExportCleanup,
|
|
1407
|
-
${identifierPrefix}AuthorizationActions.recordHoldManage,
|
|
1408
|
-
]) {
|
|
1409
|
-
await expect(
|
|
1410
|
-
evaluator.evaluate(input({ action, principal: admin })),
|
|
1411
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1412
|
-
}
|
|
1413
|
-
});
|
|
1414
|
-
|
|
1415
|
-
it('requires an exact action scope for a machine principal', async () => {
|
|
1416
|
-
const machine = principal({
|
|
1417
|
-
actor: { id: 'machine-client', type: 'service' },
|
|
1418
|
-
audience: 'machine-client',
|
|
1419
|
-
authority: {
|
|
1420
|
-
machineIdentityId: 'machine-client',
|
|
1421
|
-
mode: 'machine',
|
|
1422
|
-
},
|
|
1423
|
-
kind: 'agent',
|
|
1424
|
-
scopes: [
|
|
1425
|
-
${identifierPrefix}MachineScopes('development').delegationUse,
|
|
1426
|
-
],
|
|
1427
|
-
subject: { id: 'machine-client', type: 'service' },
|
|
1428
|
-
});
|
|
1429
|
-
await expect(
|
|
1430
|
-
evaluator.evaluate(input({ principal: machine })),
|
|
1431
|
-
).resolves.toMatchObject({
|
|
1432
|
-
category: 'domain-authorization-denied',
|
|
1433
|
-
decision: 'deny',
|
|
1434
|
-
});
|
|
1435
|
-
await expect(
|
|
1436
|
-
evaluator.evaluate(
|
|
1437
|
-
input({
|
|
1438
|
-
action: ${identifierPrefix}AuthorizationActions.machineProofRead,
|
|
1439
|
-
principal: {
|
|
1440
|
-
...machine,
|
|
1441
|
-
scopes: [
|
|
1442
|
-
${identifierPrefix}MachineScopes('development').proofReader,
|
|
1443
|
-
],
|
|
1444
|
-
},
|
|
1445
|
-
}),
|
|
1446
|
-
),
|
|
1447
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1448
|
-
await expect(
|
|
1449
|
-
evaluator.evaluate(
|
|
1450
|
-
input({
|
|
1451
|
-
principal: {
|
|
1452
|
-
...machine,
|
|
1453
|
-
scopes: ['${name}-development/record-read'],
|
|
1454
|
-
},
|
|
1455
|
-
}),
|
|
1456
|
-
),
|
|
1457
|
-
).resolves.toMatchObject({
|
|
1458
|
-
category: 'admission-scope-denied',
|
|
1459
|
-
decision: 'deny',
|
|
1460
|
-
});
|
|
1461
|
-
});
|
|
1462
|
-
|
|
1463
|
-
it('fails closed for system and non-agent service principals', async () => {
|
|
1464
|
-
for (const unsupported of [
|
|
1465
|
-
principal({
|
|
1466
|
-
actor: { id: 'system-subject', type: 'system' },
|
|
1467
|
-
audience: 'system-subject',
|
|
1468
|
-
authority: {
|
|
1469
|
-
machineIdentityId: 'system-subject',
|
|
1470
|
-
mode: 'machine',
|
|
1471
|
-
},
|
|
1472
|
-
kind: 'agent',
|
|
1473
|
-
subject: { id: 'system-subject', type: 'system' },
|
|
1474
|
-
}),
|
|
1475
|
-
principal({
|
|
1476
|
-
actor: { id: 'service-member', type: 'service' },
|
|
1477
|
-
kind: 'customer',
|
|
1478
|
-
subject: { id: 'service-member', type: 'service' },
|
|
1479
|
-
}),
|
|
1480
|
-
]) {
|
|
1481
|
-
await expect(
|
|
1482
|
-
evaluator.evaluate(input({ principal: unsupported })),
|
|
1483
|
-
).resolves.toMatchObject({ decision: 'deny' });
|
|
1484
|
-
}
|
|
1485
|
-
});
|
|
1486
|
-
|
|
1487
|
-
it('keeps the machine proof action unavailable to direct humans', async () => {
|
|
1488
|
-
for (const directHuman of [
|
|
1489
|
-
principal(),
|
|
1490
|
-
principal({
|
|
1491
|
-
actor: { id: 'admin-reviewer', type: 'user' },
|
|
1492
|
-
kind: 'admin',
|
|
1493
|
-
roles: ['${name}-admin'],
|
|
1494
|
-
subject: { id: 'admin-reviewer', type: 'user' },
|
|
1495
|
-
}),
|
|
1496
|
-
]) {
|
|
1497
|
-
await expect(
|
|
1498
|
-
evaluator.evaluate(
|
|
1499
|
-
input({
|
|
1500
|
-
action: ${identifierPrefix}AuthorizationActions.machineProofRead,
|
|
1501
|
-
principal: directHuman,
|
|
1502
|
-
resource: { attributes: { collection: true }, type: 'slice' },
|
|
1503
|
-
}),
|
|
1504
|
-
),
|
|
1505
|
-
).resolves.toMatchObject({
|
|
1506
|
-
category: 'domain-authorization-denied',
|
|
1507
|
-
decision: 'deny',
|
|
1508
|
-
});
|
|
1509
|
-
}
|
|
1510
|
-
});
|
|
1511
|
-
|
|
1512
|
-
it('allows only exact internal workload action and identity pairs', async () => {
|
|
1513
|
-
const internalEvaluator = createAuthorizationEvaluator({
|
|
1514
|
-
admission: defineCoarseAdmission({
|
|
1515
|
-
anyOf: [{ kinds: ['agent'], subjectTypes: ['service'] }],
|
|
1516
|
-
}),
|
|
1517
|
-
policy: ${identifierPrefix}AuthorizationPolicy,
|
|
1518
|
-
});
|
|
1519
|
-
const service = (identity: string): AuthorizationPrincipal =>
|
|
1520
|
-
principal({
|
|
1521
|
-
actor: { id: identity, type: 'service' },
|
|
1522
|
-
audience: identity,
|
|
1523
|
-
authority: { machineIdentityId: identity, mode: 'machine' },
|
|
1524
|
-
kind: 'agent',
|
|
1525
|
-
scopes: [],
|
|
1526
|
-
subject: { id: identity, type: 'service' },
|
|
1527
|
-
});
|
|
1528
|
-
const internalInput = (
|
|
1529
|
-
action: ${pascalName}AuthorizationAction,
|
|
1530
|
-
identity: string,
|
|
1531
|
-
): ${pascalName}AuthorizationInput =>
|
|
1532
|
-
input({
|
|
1533
|
-
action,
|
|
1534
|
-
principal: service(identity),
|
|
1535
|
-
resource: { attributes: { collection: true }, type: 'slice' },
|
|
1536
|
-
});
|
|
1537
|
-
|
|
1538
|
-
await expect(
|
|
1539
|
-
internalEvaluator.evaluate(
|
|
1540
|
-
internalInput(
|
|
1541
|
-
${identifierPrefix}AuthorizationActions.lifecycleConsume,
|
|
1542
|
-
'${name}:event-consumer',
|
|
1543
|
-
),
|
|
1544
|
-
),
|
|
1545
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1546
|
-
await expect(
|
|
1547
|
-
internalEvaluator.evaluate(
|
|
1548
|
-
internalInput(
|
|
1549
|
-
${identifierPrefix}AuthorizationActions.retentionApply,
|
|
1550
|
-
'${name}:data-retention-job',
|
|
1551
|
-
),
|
|
1552
|
-
),
|
|
1553
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1554
|
-
await expect(
|
|
1555
|
-
internalEvaluator.evaluate(
|
|
1556
|
-
internalInput(
|
|
1557
|
-
${identifierPrefix}AuthorizationActions.retentionReport,
|
|
1558
|
-
'${name}:data-retention-job',
|
|
1559
|
-
),
|
|
1560
|
-
),
|
|
1561
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1562
|
-
await expect(
|
|
1563
|
-
internalEvaluator.evaluate(
|
|
1564
|
-
internalInput(
|
|
1565
|
-
${identifierPrefix}AuthorizationActions.retentionMaintenance,
|
|
1566
|
-
'${name}:data-retention-job',
|
|
1567
|
-
),
|
|
1568
|
-
),
|
|
1569
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1570
|
-
await expect(
|
|
1571
|
-
internalEvaluator.evaluate(
|
|
1572
|
-
internalInput(
|
|
1573
|
-
${identifierPrefix}AuthorizationActions.dataExportCleanup,
|
|
1574
|
-
'${name}:data-export-cleanup',
|
|
1575
|
-
),
|
|
1576
|
-
),
|
|
1577
|
-
).resolves.toMatchObject({ decision: 'allow' });
|
|
1578
|
-
for (const rejected of [
|
|
1579
|
-
internalInput(
|
|
1580
|
-
${identifierPrefix}AuthorizationActions.dataExportCleanup,
|
|
1581
|
-
'${name}:data-retention-job',
|
|
1582
|
-
),
|
|
1583
|
-
internalInput(
|
|
1584
|
-
${identifierPrefix}AuthorizationActions.retentionApply,
|
|
1585
|
-
'${name}:event-consumer',
|
|
1586
|
-
),
|
|
1587
|
-
internalInput(
|
|
1588
|
-
${identifierPrefix}AuthorizationActions.retentionReport,
|
|
1589
|
-
'${name}:event-consumer',
|
|
1590
|
-
),
|
|
1591
|
-
internalInput(
|
|
1592
|
-
${identifierPrefix}AuthorizationActions.retentionMaintenance,
|
|
1593
|
-
'${name}:event-consumer',
|
|
1594
|
-
),
|
|
1595
|
-
internalInput(
|
|
1596
|
-
${identifierPrefix}AuthorizationActions.lifecycleConsume,
|
|
1597
|
-
'ordinary-machine-client',
|
|
1598
|
-
),
|
|
1599
|
-
input({
|
|
1600
|
-
action: ${identifierPrefix}AuthorizationActions.lifecycleConsume,
|
|
1601
|
-
principal: principal(),
|
|
1602
|
-
resource: { attributes: { collection: true }, type: 'slice' },
|
|
1603
|
-
}),
|
|
1604
|
-
]) {
|
|
1605
|
-
await expect(
|
|
1606
|
-
internalEvaluator.evaluate(rejected),
|
|
1607
|
-
).resolves.toMatchObject({ decision: 'deny' });
|
|
1608
|
-
}
|
|
1609
|
-
});
|
|
1610
|
-
|
|
1611
|
-
it('fails closed when the policy evaluator is unavailable', async () => {
|
|
1612
|
-
const unavailable = createAuthorizationEvaluator<${pascalName}AuthorizationInput>({
|
|
1613
|
-
admission: create${pascalName}CoarseAdmission('development'),
|
|
1614
|
-
policy: {
|
|
1615
|
-
evaluate() {
|
|
1616
|
-
throw new Error('provider unavailable');
|
|
1617
|
-
},
|
|
1618
|
-
version: '1.0.0',
|
|
1619
|
-
},
|
|
1620
|
-
});
|
|
1621
|
-
await expect(unavailable.evaluate(input())).resolves.toMatchObject({
|
|
1622
|
-
category: 'authorization-unavailable',
|
|
1623
|
-
decision: 'deny',
|
|
1624
|
-
});
|
|
1625
|
-
});
|
|
1626
|
-
});
|
|
1627
|
-
`,
|
|
1628
|
-
'authorization/workflows.spec.ts': `import {
|
|
1629
|
-
authorizeApprovalExecution,
|
|
1630
|
-
beginApprovalExecution,
|
|
1631
|
-
createApprovalRequest,
|
|
1632
|
-
createAuthorizationEvaluator,
|
|
1633
|
-
decideApprovalRequest,
|
|
1634
|
-
issueDelegation,
|
|
1635
|
-
revokeDelegation,
|
|
1636
|
-
useDelegation,
|
|
1637
|
-
type AuthorizationPrincipal,
|
|
1638
|
-
type DelegationGrant,
|
|
1639
|
-
type DelegationStore,
|
|
1640
|
-
} from '@empire-builder-kit/runtime/authorization';
|
|
1641
|
-
import { describe, expect, it } from 'vitest';
|
|
1642
|
-
import {
|
|
1643
|
-
${identifierPrefix}AuthorizationActions,
|
|
1644
|
-
${identifierPrefix}AuthorizationPolicy,
|
|
1645
|
-
${identifierPrefix}MachineScopes,
|
|
1646
|
-
create${pascalName}CoarseAdmission,
|
|
1647
|
-
type ${pascalName}AuthorizationAction,
|
|
1648
|
-
} from './policy.js';
|
|
1649
|
-
|
|
1650
|
-
class MemoryDelegationStore
|
|
1651
|
-
implements DelegationStore<${pascalName}AuthorizationAction>
|
|
1652
|
-
{
|
|
1653
|
-
readonly grants = new Map<
|
|
1654
|
-
string,
|
|
1655
|
-
DelegationGrant<${pascalName}AuthorizationAction>
|
|
1656
|
-
>();
|
|
1657
|
-
|
|
1658
|
-
create(grant: DelegationGrant<${pascalName}AuthorizationAction>) {
|
|
1659
|
-
if (this.grants.has(grant.id)) return false;
|
|
1660
|
-
this.grants.set(grant.id, structuredClone(grant));
|
|
1661
|
-
return true;
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
read(id: string) {
|
|
1665
|
-
const grant = this.grants.get(id);
|
|
1666
|
-
return grant ? structuredClone(grant) : undefined;
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
write(
|
|
1670
|
-
id: string,
|
|
1671
|
-
expectedRevision: number,
|
|
1672
|
-
grant: DelegationGrant<${pascalName}AuthorizationAction>,
|
|
1673
|
-
) {
|
|
1674
|
-
const current = this.grants.get(id);
|
|
1675
|
-
if (!current || current.revision !== expectedRevision) return false;
|
|
1676
|
-
this.grants.set(id, structuredClone(grant));
|
|
1677
|
-
return true;
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
function human(id: string, kind: 'admin' | 'customer' = 'customer') {
|
|
1682
|
-
return {
|
|
1683
|
-
actor: { id, type: 'user' as const },
|
|
1684
|
-
authority: { mode: 'direct' as const },
|
|
1685
|
-
kind,
|
|
1686
|
-
roles: kind === 'admin' ? ['${name}-admin'] : [],
|
|
1687
|
-
scopes: [],
|
|
1688
|
-
subject: { id, type: 'user' as const },
|
|
1689
|
-
} satisfies AuthorizationPrincipal;
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
function agent(): AuthorizationPrincipal {
|
|
1693
|
-
return {
|
|
1694
|
-
actor: { id: '${name}-agent-api', type: 'service' },
|
|
1695
|
-
audience: '${name}-agent-api',
|
|
1696
|
-
authority: {
|
|
1697
|
-
machineIdentityId: '${name}-attended-agent',
|
|
1698
|
-
mode: 'machine',
|
|
1699
|
-
},
|
|
1700
|
-
kind: 'agent',
|
|
1701
|
-
roles: [],
|
|
1702
|
-
scopes: [
|
|
1703
|
-
${identifierPrefix}MachineScopes('development').delegationUse,
|
|
1704
|
-
],
|
|
1705
|
-
subject: { id: '${name}-agent-api', type: 'service' },
|
|
1706
|
-
};
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
const recordId = '00000000-0000-4000-8000-000000000001';
|
|
1710
|
-
const context = {
|
|
1711
|
-
facts: { operationId: '${name}.get-record' },
|
|
1712
|
-
now: '2026-07-27T12:01:00.000Z',
|
|
1713
|
-
stage: 'development',
|
|
1714
|
-
};
|
|
1715
|
-
const resource = {
|
|
1716
|
-
attributes: { ownerId: 'record-owner' },
|
|
1717
|
-
id: recordId,
|
|
1718
|
-
type: 'record' as const,
|
|
1719
|
-
};
|
|
1720
|
-
|
|
1721
|
-
describe('${pascalName} delegated authorization and approvals', () => {
|
|
1722
|
-
it('uses online delegation within exact bounds and denies rate/revocation', async () => {
|
|
1723
|
-
const store = new MemoryDelegationStore();
|
|
1724
|
-
const actingAgent = agent();
|
|
1725
|
-
const issued = await issueDelegation(store, {
|
|
1726
|
-
actions: [${identifierPrefix}AuthorizationActions.recordRead],
|
|
1727
|
-
agent: actingAgent,
|
|
1728
|
-
audience: '${name}-agent-api',
|
|
1729
|
-
capabilityScopes: [
|
|
1730
|
-
${identifierPrefix}MachineScopes('development').delegationUse,
|
|
1731
|
-
],
|
|
1732
|
-
delegator: human('record-owner'),
|
|
1733
|
-
expiresAt: '2026-07-27T12:30:00.000Z',
|
|
1734
|
-
issuedUnderPolicyVersion: '1.0.0',
|
|
1735
|
-
now: '2026-07-27T12:00:00.000Z',
|
|
1736
|
-
purposeReference: 'work-item-123',
|
|
1737
|
-
rateLimit: { maximumUses: 1, windowSeconds: 60 },
|
|
1738
|
-
resourceBoundary: {
|
|
1739
|
-
kind: 'exact',
|
|
1740
|
-
resourceIds: [recordId],
|
|
1741
|
-
resourceType: 'record',
|
|
1742
|
-
},
|
|
1743
|
-
slice: '${name}',
|
|
1744
|
-
});
|
|
1745
|
-
const evaluator = createAuthorizationEvaluator({
|
|
1746
|
-
admission: create${pascalName}CoarseAdmission('development'),
|
|
1747
|
-
policy: ${identifierPrefix}AuthorizationPolicy,
|
|
1748
|
-
});
|
|
1749
|
-
const use = () =>
|
|
1750
|
-
useDelegation({
|
|
1751
|
-
action: ${identifierPrefix}AuthorizationActions.recordRead,
|
|
1752
|
-
agent: actingAgent,
|
|
1753
|
-
audience: '${name}-agent-api',
|
|
1754
|
-
capability: issued.capability,
|
|
1755
|
-
context,
|
|
1756
|
-
delegationId: issued.grant.id,
|
|
1757
|
-
evaluator,
|
|
1758
|
-
resolveDelegator: ({ delegator }) => human(delegator.id),
|
|
1759
|
-
requiredCapabilityScopes: [
|
|
1760
|
-
${identifierPrefix}MachineScopes('development').delegationUse,
|
|
1761
|
-
],
|
|
1762
|
-
resource,
|
|
1763
|
-
store,
|
|
1764
|
-
});
|
|
1765
|
-
|
|
1766
|
-
await expect(use()).resolves.toMatchObject({
|
|
1767
|
-
decision: { decision: 'allow' },
|
|
1768
|
-
grant: { usage: { totalUses: 1 } },
|
|
1769
|
-
});
|
|
1770
|
-
await expect(use()).resolves.toMatchObject({
|
|
1771
|
-
decision: {
|
|
1772
|
-
category: 'delegation-rate-limited',
|
|
1773
|
-
decision: 'deny',
|
|
1774
|
-
},
|
|
1775
|
-
});
|
|
1776
|
-
await revokeDelegation(store, {
|
|
1777
|
-
delegationId: issued.grant.id,
|
|
1778
|
-
now: '2026-07-27T12:02:00.000Z',
|
|
1779
|
-
revokedBy: human('record-owner'),
|
|
1780
|
-
});
|
|
1781
|
-
await expect(use()).resolves.toMatchObject({
|
|
1782
|
-
decision: { category: 'delegation-revoked', decision: 'deny' },
|
|
1783
|
-
});
|
|
1784
|
-
});
|
|
1785
|
-
|
|
1786
|
-
it('denies attended use when the delegator no longer owns the resource', async () => {
|
|
1787
|
-
const store = new MemoryDelegationStore();
|
|
1788
|
-
const actingAgent = agent();
|
|
1789
|
-
const issued = await issueDelegation(store, {
|
|
1790
|
-
actions: [${identifierPrefix}AuthorizationActions.recordRead],
|
|
1791
|
-
agent: actingAgent,
|
|
1792
|
-
audience: '${name}-agent-api',
|
|
1793
|
-
capabilityScopes: [
|
|
1794
|
-
${identifierPrefix}MachineScopes('development').delegationUse,
|
|
1795
|
-
],
|
|
1796
|
-
delegator: human('former-owner'),
|
|
1797
|
-
expiresAt: '2026-07-27T12:30:00.000Z',
|
|
1798
|
-
issuedUnderPolicyVersion: '1.0.0',
|
|
1799
|
-
now: '2026-07-27T12:00:00.000Z',
|
|
1800
|
-
purposeReference: 'work-item-delegator-ceiling',
|
|
1801
|
-
resourceBoundary: {
|
|
1802
|
-
kind: 'exact',
|
|
1803
|
-
resourceIds: [recordId],
|
|
1804
|
-
resourceType: 'record',
|
|
1805
|
-
},
|
|
1806
|
-
slice: '${name}',
|
|
1807
|
-
});
|
|
1808
|
-
await expect(
|
|
1809
|
-
useDelegation({
|
|
1810
|
-
action: ${identifierPrefix}AuthorizationActions.recordRead,
|
|
1811
|
-
agent: actingAgent,
|
|
1812
|
-
audience: '${name}-agent-api',
|
|
1813
|
-
capability: issued.capability,
|
|
1814
|
-
context,
|
|
1815
|
-
delegationId: issued.grant.id,
|
|
1816
|
-
evaluator: createAuthorizationEvaluator({
|
|
1817
|
-
admission: create${pascalName}CoarseAdmission('development'),
|
|
1818
|
-
policy: ${identifierPrefix}AuthorizationPolicy,
|
|
1819
|
-
}),
|
|
1820
|
-
resolveDelegator: ({ delegator }) => human(delegator.id),
|
|
1821
|
-
requiredCapabilityScopes: [
|
|
1822
|
-
${identifierPrefix}MachineScopes('development').delegationUse,
|
|
1823
|
-
],
|
|
1824
|
-
resource,
|
|
1825
|
-
store,
|
|
1826
|
-
}),
|
|
1827
|
-
).resolves.toMatchObject({
|
|
1828
|
-
decision: {
|
|
1829
|
-
category: 'delegation-out-of-bounds',
|
|
1830
|
-
decision: 'deny',
|
|
1831
|
-
},
|
|
1832
|
-
});
|
|
1833
|
-
expect(store.read(issued.grant.id)?.usage.totalUses).toBe(0);
|
|
1834
|
-
});
|
|
1835
|
-
|
|
1836
|
-
it('denies attended use when the issuing policy version is stale', async () => {
|
|
1837
|
-
const store = new MemoryDelegationStore();
|
|
1838
|
-
const actingAgent = agent();
|
|
1839
|
-
const issued = await issueDelegation(store, {
|
|
1840
|
-
actions: [${identifierPrefix}AuthorizationActions.recordRead],
|
|
1841
|
-
agent: actingAgent,
|
|
1842
|
-
audience: '${name}-agent-api',
|
|
1843
|
-
capabilityScopes: [
|
|
1844
|
-
${identifierPrefix}MachineScopes('development').delegationUse,
|
|
1845
|
-
],
|
|
1846
|
-
delegator: human('record-owner'),
|
|
1847
|
-
expiresAt: '2026-07-27T12:30:00.000Z',
|
|
1848
|
-
issuedUnderPolicyVersion: '1.0.0',
|
|
1849
|
-
now: '2026-07-27T12:00:00.000Z',
|
|
1850
|
-
purposeReference: 'work-item-policy-version',
|
|
1851
|
-
resourceBoundary: {
|
|
1852
|
-
kind: 'exact',
|
|
1853
|
-
resourceIds: [recordId],
|
|
1854
|
-
resourceType: 'record',
|
|
1855
|
-
},
|
|
1856
|
-
slice: '${name}',
|
|
1857
|
-
});
|
|
1858
|
-
const evaluator = createAuthorizationEvaluator({
|
|
1859
|
-
admission: create${pascalName}CoarseAdmission('development'),
|
|
1860
|
-
policy: {
|
|
1861
|
-
...${identifierPrefix}AuthorizationPolicy,
|
|
1862
|
-
version: '2.0.0',
|
|
1863
|
-
},
|
|
1864
|
-
});
|
|
1865
|
-
|
|
1866
|
-
await expect(
|
|
1867
|
-
useDelegation({
|
|
1868
|
-
action: ${identifierPrefix}AuthorizationActions.recordRead,
|
|
1869
|
-
agent: actingAgent,
|
|
1870
|
-
audience: '${name}-agent-api',
|
|
1871
|
-
capability: issued.capability,
|
|
1872
|
-
context,
|
|
1873
|
-
delegationId: issued.grant.id,
|
|
1874
|
-
evaluator,
|
|
1875
|
-
resolveDelegator: ({ delegator }) => human(delegator.id),
|
|
1876
|
-
requiredCapabilityScopes: [
|
|
1877
|
-
${identifierPrefix}MachineScopes('development').delegationUse,
|
|
1878
|
-
],
|
|
1879
|
-
resource,
|
|
1880
|
-
store,
|
|
1881
|
-
}),
|
|
1882
|
-
).resolves.toMatchObject({
|
|
1883
|
-
decision: {
|
|
1884
|
-
category: 'policy-stale',
|
|
1885
|
-
decision: 'deny',
|
|
1886
|
-
policyVersion: '2.0.0',
|
|
1887
|
-
},
|
|
1888
|
-
});
|
|
1889
|
-
expect(store.read(issued.grant.id)?.usage.totalUses).toBe(0);
|
|
1890
|
-
});
|
|
1891
|
-
|
|
1892
|
-
it('denies an expired attended capability online', async () => {
|
|
1893
|
-
const store = new MemoryDelegationStore();
|
|
1894
|
-
const actingAgent = agent();
|
|
1895
|
-
const issued = await issueDelegation(store, {
|
|
1896
|
-
actions: [${identifierPrefix}AuthorizationActions.recordRead],
|
|
1897
|
-
agent: actingAgent,
|
|
1898
|
-
audience: '${name}-agent-api',
|
|
1899
|
-
delegator: human('record-owner'),
|
|
1900
|
-
expiresAt: '2026-07-27T12:02:00.000Z',
|
|
1901
|
-
issuedUnderPolicyVersion: '1.0.0',
|
|
1902
|
-
now: '2026-07-27T12:00:00.000Z',
|
|
1903
|
-
purposeReference: 'work-item-124',
|
|
1904
|
-
resourceBoundary: {
|
|
1905
|
-
kind: 'exact',
|
|
1906
|
-
resourceIds: [recordId],
|
|
1907
|
-
resourceType: 'record',
|
|
1908
|
-
},
|
|
1909
|
-
slice: '${name}',
|
|
1910
|
-
});
|
|
1911
|
-
await expect(
|
|
1912
|
-
useDelegation({
|
|
1913
|
-
action: ${identifierPrefix}AuthorizationActions.recordRead,
|
|
1914
|
-
agent: actingAgent,
|
|
1915
|
-
audience: '${name}-agent-api',
|
|
1916
|
-
capability: issued.capability,
|
|
1917
|
-
context: { ...context, now: '2026-07-27T12:03:00.000Z' },
|
|
1918
|
-
delegationId: issued.grant.id,
|
|
1919
|
-
evaluator: createAuthorizationEvaluator({
|
|
1920
|
-
admission: create${pascalName}CoarseAdmission('development'),
|
|
1921
|
-
policy: ${identifierPrefix}AuthorizationPolicy,
|
|
1922
|
-
}),
|
|
1923
|
-
resolveDelegator: ({ delegator }) => human(delegator.id),
|
|
1924
|
-
resource,
|
|
1925
|
-
store,
|
|
1926
|
-
}),
|
|
1927
|
-
).resolves.toMatchObject({
|
|
1928
|
-
decision: { category: 'delegation-expired', decision: 'deny' },
|
|
1929
|
-
});
|
|
1930
|
-
});
|
|
1931
|
-
|
|
1932
|
-
it('keeps a high-impact record deletion pending until non-author approval', () => {
|
|
1933
|
-
const command = { reasonCode: 'subject-request', recordId };
|
|
1934
|
-
const pending = createApprovalRequest({
|
|
1935
|
-
action: ${identifierPrefix}AuthorizationActions.recordDelete,
|
|
1936
|
-
author: agent(),
|
|
1937
|
-
command,
|
|
1938
|
-
expiresAt: '2026-07-27T13:00:00.000Z',
|
|
1939
|
-
now: '2026-07-27T12:00:00.000Z',
|
|
1940
|
-
policyVersion: '1.0.0',
|
|
1941
|
-
resource: { id: recordId, type: 'record' },
|
|
1942
|
-
slice: '${name}',
|
|
1943
|
-
});
|
|
1944
|
-
expect(
|
|
1945
|
-
authorizeApprovalExecution(pending, {
|
|
1946
|
-
action: ${identifierPrefix}AuthorizationActions.recordDelete,
|
|
1947
|
-
command,
|
|
1948
|
-
now: '2026-07-27T12:05:00.000Z',
|
|
1949
|
-
requiredPolicyVersion: '1.0.0',
|
|
1950
|
-
resource: { id: recordId, type: 'record' },
|
|
1951
|
-
}),
|
|
1952
|
-
).toMatchObject({
|
|
1953
|
-
category: 'approval-pending',
|
|
1954
|
-
decision: 'deny',
|
|
1955
|
-
});
|
|
1956
|
-
const approved = decideApprovalRequest(pending, {
|
|
1957
|
-
approver: human('privacy-reviewer', 'admin'),
|
|
1958
|
-
expectedRequestDigest: pending.requestDigest,
|
|
1959
|
-
now: '2026-07-27T12:10:00.000Z',
|
|
1960
|
-
outcome: 'approved',
|
|
1961
|
-
reasonReference: 'review-123',
|
|
1962
|
-
requiredPolicyVersion: '1.0.0',
|
|
1963
|
-
});
|
|
1964
|
-
expect(approved.decision.decision).toBe('allow');
|
|
1965
|
-
expect(
|
|
1966
|
-
beginApprovalExecution(approved.request, {
|
|
1967
|
-
action: ${identifierPrefix}AuthorizationActions.recordDelete,
|
|
1968
|
-
command,
|
|
1969
|
-
executionId: 'deletion-execution-stale',
|
|
1970
|
-
now: '2026-07-27T12:11:00.000Z',
|
|
1971
|
-
requiredPolicyVersion: '2.0.0',
|
|
1972
|
-
resource: { id: recordId, type: 'record' },
|
|
1973
|
-
}),
|
|
1974
|
-
).toMatchObject({
|
|
1975
|
-
decision: {
|
|
1976
|
-
category: 'policy-stale',
|
|
1977
|
-
decision: 'deny',
|
|
1978
|
-
policyVersion: '2.0.0',
|
|
1979
|
-
},
|
|
1980
|
-
request: { status: 'approved' },
|
|
1981
|
-
});
|
|
1982
|
-
expect(
|
|
1983
|
-
beginApprovalExecution(approved.request, {
|
|
1984
|
-
action: ${identifierPrefix}AuthorizationActions.recordDelete,
|
|
1985
|
-
command,
|
|
1986
|
-
executionId: 'deletion-execution-123',
|
|
1987
|
-
now: '2026-07-27T12:11:00.000Z',
|
|
1988
|
-
requiredPolicyVersion: '1.0.0',
|
|
1989
|
-
resource: { id: recordId, type: 'record' },
|
|
1990
|
-
}),
|
|
1991
|
-
).toMatchObject({
|
|
1992
|
-
decision: { decision: 'allow' },
|
|
1993
|
-
request: { status: 'executing' },
|
|
1994
|
-
});
|
|
1995
|
-
expect(
|
|
1996
|
-
authorizeApprovalExecution(approved.request, {
|
|
1997
|
-
action: ${identifierPrefix}AuthorizationActions.recordDelete,
|
|
1998
|
-
command: { ...command, recordId: recordId.replace(/1$/, '2') },
|
|
1999
|
-
now: '2026-07-27T12:11:00.000Z',
|
|
2000
|
-
requiredPolicyVersion: '1.0.0',
|
|
2001
|
-
resource: { id: recordId, type: 'record' },
|
|
2002
|
-
}),
|
|
2003
|
-
).toMatchObject({
|
|
2004
|
-
category: 'approval-invalid',
|
|
2005
|
-
decision: 'deny',
|
|
2006
|
-
});
|
|
2007
|
-
});
|
|
2008
|
-
|
|
2009
|
-
it('denies direct self-review of the exact request digest', () => {
|
|
2010
|
-
const author = human('record-owner');
|
|
2011
|
-
const pending = createApprovalRequest({
|
|
2012
|
-
action: ${identifierPrefix}AuthorizationActions.recordDelete,
|
|
2013
|
-
author,
|
|
2014
|
-
command: { recordId },
|
|
2015
|
-
expiresAt: '2026-07-27T13:00:00.000Z',
|
|
2016
|
-
now: '2026-07-27T12:00:00.000Z',
|
|
2017
|
-
policyVersion: '1.0.0',
|
|
2018
|
-
resource: { id: recordId, type: 'record' },
|
|
2019
|
-
slice: '${name}',
|
|
2020
|
-
});
|
|
2021
|
-
expect(
|
|
2022
|
-
decideApprovalRequest(pending, {
|
|
2023
|
-
approver: author,
|
|
2024
|
-
expectedRequestDigest: pending.requestDigest,
|
|
2025
|
-
now: '2026-07-27T12:10:00.000Z',
|
|
2026
|
-
outcome: 'approved',
|
|
2027
|
-
reasonReference: 'self-review',
|
|
2028
|
-
requiredPolicyVersion: '1.0.0',
|
|
2029
|
-
}),
|
|
2030
|
-
).toMatchObject({
|
|
2031
|
-
decision: { category: 'approval-invalid', decision: 'deny' },
|
|
2032
|
-
request: { status: 'pending' },
|
|
2033
|
-
});
|
|
2034
|
-
});
|
|
2035
|
-
});
|
|
2036
|
-
`,
|
|
2037
|
-
'docs/runbooks/authorization.md': `# Authorization
|
|
2038
|
-
|
|
2039
|
-
Every protected operation declares one Slice-owned action and passes through
|
|
2040
|
-
the generated authentication-plus-domain-authorization adapter before business
|
|
2041
|
-
logic. The seeded policy in \`authorization/policy.ts\` is deny by default.
|
|
2042
|
-
Roles and OAuth scopes are coarse admission only; resource/action policy still
|
|
2043
|
-
decides each operation.
|
|
2044
|
-
|
|
2045
|
-
Advance the policy version when observable behavior changes. Run
|
|
2046
|
-
\`pnpm nx run ${name}:authorization-check\` and review policy compatibility before
|
|
2047
|
-
deployment. Permission broadening requires explicit security review; a
|
|
2048
|
-
reduction is breaking until callers and recovery authority are reconciled.
|
|
2049
|
-
|
|
2050
|
-
The Standard machine client exposes only the exact \`proof-read\` and
|
|
2051
|
-
\`delegation-use\` Cognito scopes. It cannot read a product record directly;
|
|
2052
|
-
resource access requires the attended, server-side delegation decision.
|
|
2053
|
-
Attended delegation uses an audience-bound opaque capability and never exposes
|
|
2054
|
-
the delegator's token. Every use resolves the delegator from current
|
|
2055
|
-
Slice-owned state and requires both the direct delegator and delegated agent
|
|
2056
|
-
policy decisions to allow the exact action and resource. High-impact actions
|
|
2057
|
-
use a digest-bound approval from a different direct human. Neither agents nor
|
|
2058
|
-
machines may approve their own grant or action.
|
|
2059
|
-
|
|
2060
|
-
Deployment provisions the empty \`${name}-admin\` Cognito group used for direct
|
|
2061
|
-
human recovery, deletion approval, and retention review. Add or remove group
|
|
2062
|
-
membership only through a reviewed identity-administration action; never seed a
|
|
2063
|
-
member, reuse the group for machines, or treat group admission as the final
|
|
2064
|
-
domain decision.
|
|
2065
|
-
|
|
2066
|
-
The generated event consumer and data-retention Job use internal-only
|
|
2067
|
-
\`${name}:event-consumer\` and \`${name}:data-retention-job\` workload identities.
|
|
2068
|
-
They are not Cognito clients or scopes. Each is accepted only for its exact
|
|
2069
|
-
Slice-collection action, and the internal helper must run before the protected
|
|
2070
|
-
effect so a missing, swapped, or externally supplied identity fails closed.
|
|
2071
|
-
These workloads are represented as \`kind: agent\`, \`subject.type: service\`.
|
|
2072
|
-
System subjects and non-agent service principals are intentionally unsupported
|
|
2073
|
-
in the Standard v1 policy and receive a default-deny decision.
|
|
2074
|
-
|
|
2075
|
-
Audit output contains only pseudonymous subject, action, resource type/safe
|
|
2076
|
-
reference, authority mode, decision category, policy version, correlation,
|
|
2077
|
-
Slice, stage, and timestamp. Never add tokens, claims, email, record content,
|
|
2078
|
-
policy input, roles, or scopes.
|
|
2079
|
-
`,
|
|
2080
|
-
};
|
|
2081
|
-
}
|
|
2082
|
-
//# sourceMappingURL=built-in-plan-authorization-files.js.map
|