@wildo-ai/platform-config-lib 1.1.12 → 1.1.13

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.
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { PlatformAdminEnvKey, PlatformDocumentationSiteEnvKey, PlatformEmailEnvKey, PlatformInfrastructureEnvKey, PlatformIngressEnvKey, PlatformKubernetesEnvKey, PlatformLoggingEnvKey, PlatformObservabilityEnvKey, PlatformOwnershipDnsEnvKey, PlatformProcessEnvKey, PlatformProviderSelectionEnvKey, PlatformSecurityEnvKey, PlatformServiceUrlEnvKey, } from '../../bootstrap/platform-runtime-env.contracts.js';
3
+ import { AGENT_CONTENT_GUARDRAILS_ENV_VAR } from '@wildo-ai/saas-models';
3
4
  import { BackingServiceSource } from './backing-services.schemas.js';
4
5
  /** @wildo_source:part:start platform.config.platform-key-management facet:layer:platform facet:family:infra facet:audience:app-developer */
5
6
  /**
@@ -65,11 +66,14 @@ import { BackingServiceSource } from './backing-services.schemas.js';
65
66
  * - Azure Key Vault (a vault in the Azure RBAC permission model): two user-assigned managed identities on apps-manager,
66
67
  * each with a CUSTOM role on the vault. The built-in roles do not fit: "Key Vault Crypto User" can update and back up a
67
68
  * key, and "Key Vault Crypto Officer" holds `vaults/keys/*`, signing included.
68
- * - Signer: `Microsoft.KeyVault/vaults/keys/read`, `…/keys/versions/read`, `…/keys/sign/action`,
69
+ * - Signer: `Microsoft.KeyVault/vaults/keys/read`, `…/keys/sign/action`,
69
70
  * `…/keys/encrypt/action`, `…/keys/decrypt/action` (a data key is wrapped with A256GCM under an `oct-HSM` key, which
70
71
  * a Premium vault offers in preview; a Standard vault cannot hold one and serves signing only).
71
- * - Operator: `…/keys/read`, `…/keys/versions/read`, `…/keys/create/action`, `…/keys/update/action` (disable),
72
+ * - Operator: `…/keys/read`, `…/keys/create/action`, `…/keys/update/action` (disable),
72
73
  * `…/keys/delete`, `…/keys/purge/action`.
74
+ * Azure has no `keys/versions/read` data action: `keys/read` reads every version. Measured 2026-11-12 (#3697) with two
75
+ * user-assigned managed identities holding exactly these roles: each verb succeeded as its own identity and answered
76
+ * 403 as the other one.
73
77
  * The vault's recovery level decides whether a destroyed key is purged at once or kept until retention ends.
74
78
  * - Azure Managed HSM (`*.managedhsm.azure.net`): the same two identities, with custom roles in the HSM's LOCAL RBAC
75
79
  * (the built-in "Managed HSM Crypto User" can sign and back up, and cannot purge). Signer:
@@ -265,6 +269,8 @@ const WILDO_OWNED_PLATFORM_ENV_KEYS = new Set([
265
269
  PlatformKubernetesEnvKey, PlatformIngressEnvKey, PlatformLoggingEnvKey, PlatformObservabilityEnvKey, PlatformProviderSelectionEnvKey,
266
270
  PlatformEmailEnvKey, PlatformOwnershipDnsEnvKey, PlatformDocumentationSiteEnvKey,
267
271
  ].flatMap((vocabulary) => Object.values(vocabulary)),
272
+ // An application runtime's guardrail posture (`WildoInfraEnvConfig.agentContentGuardrails`), named by saas-models.
273
+ AGENT_CONTENT_GUARDRAILS_ENV_VAR,
268
274
  // Set literally by the deployment templates rather than through the env contract.
269
275
  'PLATFORM_SERVICE', 'NODE_OPTIONS', 'NODE_ENV',
270
276
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"platform-key-management.schemas.js","sourceRoot":"","sources":["../../../../src/project-config/shared/platform-key-management.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,+BAA+B,EAC/B,mBAAmB,EACnB,4BAA4B,EAC5B,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,EACrB,+BAA+B,EAC/B,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,4IAA4I;AAC5I;;;;;;;;;;;;;;;;;;;;;;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AC,MAAM,EAAE,EAAE,CAAC,CAAC;QACpD,OAAO,MAAM,CAAC,UAAU,KAAK,SAAS,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC;IAC1F,CAAC,CAAC,CAAC;AACL,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,+BAA+B,CAAC,MAA6B,EAAE,eAAwB;IACrG,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC5E,OAAO,GAAG,eAAe,CAAC,CAAC,CAAC,gBAAgB,eAAe,KAAK,CAAC,CAAC,CAAC,EAAE,4CAA4C,MAAM,CAAC,UAAU,IAAI;UAClI,0DAA0D,yCAAyC,sBAAsB;UACzH,6DAA6D,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,KAAK;UACzH,2HAA2H;UAC3H,wFAAwF,CAAC;AAC/F,CAAC;AAED,uHAAuH;AACvH,MAAM,UAAU,yBAAyB,CAAC,qBAAmE;IAC3G,OAAO,qBAAqB,EAAE,KAAK,EAAE,MAAM,KAAK,oBAAoB,CAAC,IAAI,CAAC;AAC5E,CAAC","sourcesContent":["import { z } from 'zod';\n\nimport {\n PlatformAdminEnvKey,\n PlatformDocumentationSiteEnvKey,\n PlatformEmailEnvKey,\n PlatformInfrastructureEnvKey,\n PlatformIngressEnvKey,\n PlatformKubernetesEnvKey,\n PlatformLoggingEnvKey,\n PlatformObservabilityEnvKey,\n PlatformOwnershipDnsEnvKey,\n PlatformProcessEnvKey,\n PlatformProviderSelectionEnvKey,\n PlatformSecurityEnvKey,\n PlatformServiceUrlEnvKey,\n} from '../../bootstrap/platform-runtime-env.contracts';\nimport { BackingServiceSource } from './backing-services.schemas';\n\n/** @wildo_source:part:start platform.config.platform-key-management facet:layer:platform facet:family:infra facet:audience:app-developer */\n/**\n * # Where the platform keeps the keys it holds for applications (#2933)\n *\n * apps-manager is the custodian of every platform-held key (approval seals, signature requests, and the wrapping keys\n * of an application's sealed secrets, #2894). Without this block it\n * seals them under its own key-encryption root (the LOCAL provider). With it, apps-manager also serves the\n * `vault-transit` and `vault-kv` key providers, and an application's key binding may name one of them.\n *\n * This is a PLATFORM-tier declaration, like `platformStorage`: one apps-manager holds one Vault, whatever application\n * an environment file belongs to. It is deliberately not a `backingServices` kind. A backing service is something an\n * application runtime dials, with credentials minted per application; no application runtime ever reaches this Vault,\n * and nothing is minted per application in it.\n *\n * - `{ vault: { source: 'self' } }` — the CLI renders a single-node OpenBao (the MPL-licensed Vault fork, API\n * compatible for everything used) beside apps-manager, in docker compose and in Kubernetes. It unseals itself from a\n * framework-managed key and configures itself on its first start: the Transit and KV mounts, the two least-privilege\n * policies, and the two tokens apps-manager speaks with. Good for development and for a small self-hosted platform;\n * its protection is SOFTWARE, as every Vault's is. Its self-initialization runs only on EMPTY storage, so an OpenBao\n * first started before a policy changed keeps the older policy: one started before #2894 cannot wrap data keys\n * (`transit/encrypt` and `transit/decrypt` answer 403) until the signer policy is written again (`bao policy write`\n * with `vaultSignerPolicy`) or its storage is recreated.\n * - `{ vault: { source: 'managed', address, … } }` — the operator's own Vault or OpenBao. The operator configures the\n * mounts and policies (`vaultSignerPolicy` / `vaultOperatorPolicy` in the key-management contracts) and puts the two\n * tokens in `secrets.json` under `platformKeyVaultManaged`.\n *\n * Absent, apps-manager serves no Vault provider, and a binding that names one is refused PROVIDER_UNAVAILABLE.\n *\n * ## Cloud KMS (#2896)\n *\n * `awsKms`, `googleCloudKms` and `azureKeyVault` make apps-manager serve the `aws-kms`, `google-cloud-kms` and\n * `azure-key-vault` providers: the key is generated inside the vendor's HSM, never leaves it, and the vendor signs. They\n * are always the operator's own account, so they carry no `source`. apps-manager authenticates with its WORKLOAD\n * identity (an IAM role for its service account, GKE workload identity, an Azure managed identity): nothing here is a\n * secret, and `secrets.json` holds nothing for them.\n *\n * Each provider acts as two identities, as Vault does with two tokens. The SIGNER may only read keys, sign, and wrap and\n * unwrap data keys under a wrapping key (#2894); the OPERATOR creates, disables and destroys keys and may never sign, wrap\n * or unwrap. Every wrap is authenticated encryption under a key only the vendor holds. Neither vendor's broad built-in role keeps to that, so\n * grant, per vendor:\n * - AWS: apps-manager's identity may only `sts:AssumeRole` the two roles. Every key apps-manager creates carries the tag\n * `wildo:key-ref`, and the policies are scoped by it:\n * - Signer, on `arn:aws:kms:<region>:<account>:key/*`: `kms:Sign`, `kms:Encrypt` and `kms:Decrypt` only where\n * `aws:ResourceTag/wildo:key-ref` is present (`\"Null\": { … \"false\" }`), so it cannot sign with, or decrypt under,\n * another key in the account; `kms:GetPublicKey` and `kms:DescribeKey` unconditioned (both read-only).\n * - Operator: `kms:CreateKey` and `kms:TagResource` on `\"Resource\": \"*\"` (CreateKey names no key yet), only where\n * `aws:RequestTag/wildo:key-ref` is present and `aws:TagKeys` is exactly `[\"wildo:key-ref\"]`; on `key/*`,\n * `kms:DisableKey` and `kms:ScheduleKeyDeletion` only where `aws:ResourceTag/wildo:key-ref` is present, and\n * `kms:DescribeKey`; never `kms:Sign`, `kms:Encrypt`, `kms:Decrypt` nor `kms:UntagResource`.\n * - The tag is what admits a key to the signer, so whoever may tag may admit: the operator's `kms:TagResource` lets it\n * put `wildo:key-ref` on ANY key in the account, which the signer could then sign with. AWS warns of exactly this\n * (\"Be cautious about giving principals the `kms:TagResource` … permissions\"). Keep the operator role to apps-manager\n * alone, and consider a permissions boundary or SCP denying `kms:TagResource` on keys outside the custodian's.\n * - KMS applies a tag to authorization up to five minutes after it is set, so a NEW version may be refused `kms:Sign`\n * for those minutes: the first ACTIVE version of every new keyring (made at its first signature request), and one\n * made by an emergency rotation. The signature fails as a provider fault and the caller retries it; so does the first\n * wrap under a new wrapping key, which the application's data-key ring asks for again on its own retry.\n * - Google: apps-manager's identity holds `roles/iam.serviceAccountTokenCreator` on the two service accounts only.\n * Signer: `roles/cloudkms.signer`, `roles/cloudkms.cryptoKeyEncrypterDecrypter`, `roles/cloudkms.publicKeyViewer` and\n * `roles/cloudkms.viewer` on the key ring (sign, wrap and unwrap data keys, read the public key, read a version's state). Operator: `roles/cloudkms.admin` on the key ring, which contains no\n * cryptographic operation.\n * - Azure Key Vault (a vault in the Azure RBAC permission model): two user-assigned managed identities on apps-manager,\n * each with a CUSTOM role on the vault. The built-in roles do not fit: \"Key Vault Crypto User\" can update and back up a\n * key, and \"Key Vault Crypto Officer\" holds `vaults/keys/*`, signing included.\n * - Signer: `Microsoft.KeyVault/vaults/keys/read`, `…/keys/versions/read`, `…/keys/sign/action`,\n * `…/keys/encrypt/action`, `…/keys/decrypt/action` (a data key is wrapped with A256GCM under an `oct-HSM` key, which\n * a Premium vault offers in preview; a Standard vault cannot hold one and serves signing only).\n * - Operator: `…/keys/read`, `…/keys/versions/read`, `…/keys/create/action`, `…/keys/update/action` (disable),\n * `…/keys/delete`, `…/keys/purge/action`.\n * The vault's recovery level decides whether a destroyed key is purged at once or kept until retention ends.\n * - Azure Managed HSM (`*.managedhsm.azure.net`): the same two identities, with custom roles in the HSM's LOCAL RBAC\n * (the built-in \"Managed HSM Crypto User\" can sign and back up, and cannot purge). Signer:\n * `Microsoft.KeyVault/managedHsm/keys/read/action`, `…/keys/sign/action`, `…/keys/encrypt/action`, `…/keys/decrypt/action`.\n * Operator: `…/keys/read/action`,\n * `…/keys/create`, `…/keys/write/action`, `…/keys/delete`, `…/keys/deletedKeys/read/action`,\n * `…/keys/deletedKeys/delete` (purge).\n *\n * spec-cite: AWS KMS developer guide, \"Use tags to control access to KMS keys\" (`aws:ResourceTag`, the five-minute\n * delay, limiting `kms:TagResource` with `aws:RequestTag` / `aws:TagKeys`),\n * https://docs.aws.amazon.com/kms/latest/developerguide/tag-authorization.html; AWS KMS permissions reference\n * (`CreateKey`'s resource is `*`), https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html; Azure built-in roles, Security (Key\n * Vault Crypto Officer DataActions `Microsoft.KeyVault/vaults/keys/*`) and Azure permissions, Microsoft.KeyVault (the\n * `vaults/keys/*` data actions), https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/security;\n * Managed HSM local RBAC built-in roles (the data-action table),\n * https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/built-in-roles.\n *\n * When a provider registers at startup, apps-manager logs the vendor's quota and per-request cost. It also holds its own\n * signing under 80% of the vendor's per-second quota, per process.\n *\n * ## Corroboration\n *\n * Every ten minutes, apps-manager compares, per key version and closed hour, the signatures its signing log records with\n * the ones the vendor's own audit log records, and writes one audit row per provider and hour:\n * - UNACCOUNTED (CRITICAL) the moment the vendor shows more signatures than apps-manager can account for: a key was used\n * outside the custodian, or a signature went unrecorded;\n * - otherwise, once the hour is six hours old (vendor logs arrive late): UNCORROBORATED (the vendor recorded fewer, or its\n * log could not be read) or CORROBORATED.\n * It reads as the OPERATOR identity, which therefore also needs:\n * - AWS: `cloudtrail:LookupEvents` (KMS `Sign` is a CloudTrail management event; nothing to enable).\n * - Google: `roles/logging.privateLogViewer` on the project, and Cloud KMS Data Access audit logs ENABLED (they are off by\n * default, and until they are on, every hour is uncorroborated).\n * - Azure: Log Analytics Reader on the workspace named by `logAnalyticsWorkspaceId`, which the vault's diagnostic setting\n * sends `AuditEvent` to.\n */\nexport const PlatformKeyVaultSelfHostedSchema = z.strictObject({\n source: z.literal(BackingServiceSource.SELF),\n});\n\n/** The operator's own Vault or OpenBao. Mounts and prefix default to the provider defaults (`transit`, `secret`, `wildo-`). */\nexport const PlatformKeyVaultManagedSchema = z.strictObject({\n source: z.literal(BackingServiceSource.MANAGED),\n /** The Vault API address apps-manager dials, e.g. `https://vault.internal:8200`. */\n address: z.url(),\n /** Vault Enterprise namespace (`team/keys/`); absent on open-source Vault and OpenBao's root namespace. */\n namespace: z.string().min(1).optional(),\n transitMount: z.string().min(1).optional(),\n kvMount: z.string().min(1).optional(),\n keyNamePrefix: z.string().min(1).optional(),\n});\n\nexport const PlatformKeyVaultConfigSchema = z.discriminatedUnion('source', [PlatformKeyVaultSelfHostedSchema, PlatformKeyVaultManagedSchema]);\nexport type PlatformKeyVaultConfig = z.infer<typeof PlatformKeyVaultConfigSchema>;\n\n/** The protection level apps-manager creates Google Cloud KMS keys at. */\nexport enum PlatformGoogleKmsKeyProtection {\n /** In Cloud HSM (FIPS 140-2 Level 3): the key's attestation is HARDWARE. */\n HSM = 'HSM',\n /** In Cloud KMS software: the key's attestation is SOFTWARE, and a HARDWARE floor refuses it. */\n SOFTWARE = 'SOFTWARE',\n}\n\n/** AWS KMS in the operator's account. */\nexport const PlatformKeyAwsKmsConfigSchema = z.strictObject({\n region: z.string().regex(/^[a-z]{2}(-[a-z]+)+-\\d$/),\n /** The role apps-manager assumes to read keys and sign. */\n signerRoleArn: z.string().regex(/^arn:aws[a-z-]*:iam::\\d{12}:role\\/.+$/),\n /** The role apps-manager assumes to create, disable and schedule the deletion of keys. */\n operatorRoleArn: z.string().regex(/^arn:aws[a-z-]*:iam::\\d{12}:role\\/.+$/),\n /** A KMS endpoint other than the region's public one (a VPC interface endpoint). */\n endpoint: z.url().optional(),\n});\n\n/** Google Cloud KMS in the operator's project. */\nexport const PlatformKeyGoogleCloudKmsConfigSchema = z.strictObject({\n /** `projects/<project>/locations/<location>/keyRings/<ring>`; created by the operator, since a key ring cannot be deleted. */\n keyRing: z.string().regex(/^projects\\/[^/]+\\/locations\\/[^/]+\\/keyRings\\/[^/]+$/),\n signerServiceAccount: z.email(),\n operatorServiceAccount: z.email(),\n protectionLevel: z.enum(PlatformGoogleKmsKeyProtection).default(PlatformGoogleKmsKeyProtection.HSM),\n});\n\n/** Azure Key Vault (Premium) or Managed HSM in the operator's subscription. */\nexport const PlatformKeyAzureKeyVaultConfigSchema = z.strictObject({\n /** `https://<vault>.vault.azure.net` or `https://<hsm>.managedhsm.azure.net`. */\n vaultUrl: z.url(),\n /** The client id of the signer's user-assigned managed identity. */\n signerClientId: z.uuid(),\n /** The client id of the operator's user-assigned managed identity. */\n operatorClientId: z.uuid(),\n /** HSM-protected keys (`EC-HSM`, a Premium vault or Managed HSM); `false` makes software `EC` keys. */\n hsm: z.boolean().default(true),\n /**\n * The Log Analytics workspace (its GUID) the vault's diagnostic setting sends `AuditEvent` to, in the `AzureDiagnostics`\n * destination mode. apps-manager reads it hourly to corroborate its signatures; absent, no Azure hour is compared.\n */\n logAnalyticsWorkspaceId: z.uuid().optional(),\n});\n\n/** The SoftHSM2 module the platform image carries: the one PKCS#11 module a containerised apps-manager has without a mount. */\nexport const PLATFORM_IMAGE_BUNDLED_PKCS11_MODULE_PATH = '/usr/lib/softhsm/libsofthsm2.so';\n\n/** An absolute path with no `.` or `..` segment, so \"is this path inside that mount\" is a plain prefix question. */\nconst AbsoluteNormalPathSchema = z\n .string()\n .regex(/^\\//, 'an absolute path')\n .refine((path) => !/(^|\\/)\\.{1,2}(\\/|$)/.test(path), 'a path with no `.` or `..` segment');\n\n/** Where the platform image keeps apps-manager itself: a mount here (or over `/`) would hide the service it serves. */\nconst PLATFORM_IMAGE_APPLICATION_ROOT = '/app';\n\n/**\n * One file or directory of the HSM vendor's PKCS#11 client, mounted READ-ONLY into apps-manager's container (#3019): the\n * module, its configuration, the client certificates. `hostPath` is on the docker host (compose) or on every node that\n * may run apps-manager (Kubernetes, a `hostPath` volume); `containerPath` is where apps-manager sees it.\n */\nexport const PlatformKeyPkcs11ClientFileSchema = z.strictObject({\n hostPath: AbsoluteNormalPathSchema,\n containerPath: AbsoluteNormalPathSchema.refine(\n (path) => path !== '/' && path.replace(/\\/+$/, '') !== PLATFORM_IMAGE_APPLICATION_ROOT && !path.startsWith(`${PLATFORM_IMAGE_APPLICATION_ROOT}/`),\n `a path outside \\`/\\` and \\`${PLATFORM_IMAGE_APPLICATION_ROOT}\\` (the platform image keeps apps-manager there)`,\n ),\n});\nexport type PlatformKeyPkcs11ClientFile = z.infer<typeof PlatformKeyPkcs11ClientFileSchema>;\n\n/**\n * A dedicated HSM reached over PKCS#11 (#2934): Thales Luna, Entrust nShield, AWS CloudHSM, Azure Cloud HSM, an\n * on-premises appliance, or SoftHSM2. apps-manager loads the vendor's PKCS#11 module, logs in to one token with a user PIN\n * (operator-typed in `secrets.json` under `platformKeyPkcs11: { pin }`, never here) and serves the `pkcs11` provider.\n *\n * Protection is read from the token, not declared: a key counts as HARDWARE only when the slot reports a hardware slot\n * AND the token's model is listed in `hardwareTokenModels`, which is your statement that this model is the hardware you\n * run. SoftHSM2 is always SOFTWARE. The binding (`pkcs11js`) is compiled by `pnpm setup:pkcs11`; an apps-manager that\n * cannot load it says so at boot and refuses every signature on this provider.\n *\n * ## A real HSM in a containerised platform (#3019)\n *\n * The platform image carries only SoftHSM2. A real HSM's client comes from the host, and every vendor documents the same\n * containerised shape: mount the client library and its configuration READ-ONLY, and point the client at its\n * configuration with the vendor's own variable. So:\n * - `clientFiles` lists what to mount, each `{ hostPath, containerPath }`. compose renders a read-only bind mount and refuses\n * to start the service when the host path is missing; Kubernetes renders a read-only `hostPath` volume, which it mounts\n * unchecked, so the files must exist on every node that may run apps-manager (a missing one shows as a token that cannot\n * be opened, logged at boot). Both apps-manager services get them (INIT and serving).\n * - `environment` carries the vendor's variables (`ChrystokiConfigurationPath` for a Thales Luna client, …). It is\n * rendered in plain text beside the service, so it may hold paths and settings, never a credential; it may not name a\n * variable Wildo sets itself. The token PIN stays in `secrets.json`.\n * - In a container, `modulePath` must be the bundled SoftHSM2 or lie under a `containerPath`. Declaring `clientFiles` says\n * apps-manager runs in a container, so that is refused here; without `clientFiles` it is refused when compose or\n * Kubernetes renders apps-manager, because a framework developer's NATIVE apps-manager loads a host path legitimately\n * (Homebrew's SoftHSM2, `/opt/homebrew/lib/softhsm/libsofthsm2.so`).\n * - Both are for the CONTAINER lanes. A framework developer's native apps-manager runs on the host, where the client is\n * installed and configured as the vendor documents, and receives neither.\n *\n * Example, a Thales Luna client installed under `/usr/safenet/lunaclient` on the host:\n * `{ modulePath: '/usr/safenet/lunaclient/lib/libCryptoki2_64.so', tokenLabel: 'wildo', hardwareTokenModels: ['Luna K7'],\n * clientFiles: [{ hostPath: '/usr/safenet/lunaclient', containerPath: '/usr/safenet/lunaclient' },\n * { hostPath: '/etc/Chrystoki.conf', containerPath: '/etc/Chrystoki.conf' }],\n * environment: { ChrystokiConfigurationPath: '/etc' } }`.\n */\nexport const PlatformKeyPkcs11ConfigSchema = z\n .strictObject({\n /**\n * The vendor's PKCS#11 module, as an absolute path in apps-manager's filesystem: in the platform image, the bundled\n * `/usr/lib/softhsm/libsofthsm2.so` or a path under a `clientFiles[].containerPath`.\n */\n modulePath: z.string().regex(/^\\//, 'an absolute path'),\n /** The token's label, as the module reports it. */\n tokenLabel: z.string().min(1).max(32),\n /** Token models (`CK_TOKEN_INFO.model`) you state are hardware. Empty: every key reports SOFTWARE. */\n hardwareTokenModels: z.array(z.string().min(1)).default([]),\n /** The vendor client's files, mounted read-only into apps-manager's container (#3019). */\n clientFiles: z.array(PlatformKeyPkcs11ClientFileSchema).optional(),\n /** The vendor client's own environment variables (no credential, and no variable Wildo sets). */\n environment: z.record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/, 'an environment variable name'), z.string()).optional(),\n })\n .superRefine((pkcs11, context) => {\n const containerPaths = (pkcs11.clientFiles ?? []).map((file) => file.containerPath.replace(/\\/+$/, ''));\n containerPaths.forEach((containerPath, index) => {\n if (containerPaths.indexOf(containerPath) !== index) {\n context.addIssue({ code: 'custom', path: ['clientFiles', index, 'containerPath'], message: `\"${containerPath}\" is mounted twice` });\n }\n });\n for (const name of Object.keys(pkcs11.environment ?? {})) {\n if (WILDO_OWNED_PLATFORM_ENV_KEYS.has(name)) {\n context.addIssue({ code: 'custom', path: ['environment', name], message: `\"${name}\" is a variable Wildo sets on apps-manager itself` });\n }\n }\n if (containerPaths.length > 0 && !pkcs11ModuleIsReachableInPlatformContainer(pkcs11)) {\n context.addIssue({ code: 'custom', path: ['modulePath'], message: describeUnreachablePkcs11Module(pkcs11) });\n }\n });\nexport type PlatformKeyPkcs11Config = z.infer<typeof PlatformKeyPkcs11ConfigSchema>;\n\nexport const WildoPlatformKeyManagementConfigSchema = z.strictObject({\n vault: PlatformKeyVaultConfigSchema.optional(),\n awsKms: PlatformKeyAwsKmsConfigSchema.optional(),\n googleCloudKms: PlatformKeyGoogleCloudKmsConfigSchema.optional(),\n azureKeyVault: PlatformKeyAzureKeyVaultConfigSchema.optional(),\n pkcs11: PlatformKeyPkcs11ConfigSchema.optional(),\n});\nexport type WildoPlatformKeyManagementConfig = z.infer<typeof WildoPlatformKeyManagementConfigSchema>;\n\n/** @wildo_source:part:end platform.config.platform-key-management */\n\n/** What deciding a module's reachability needs: the module, and where the client files are mounted. */\nexport interface Pkcs11ModuleMountView {\n readonly modulePath: string;\n readonly clientFiles?: readonly { readonly containerPath: string }[];\n}\n\n/**\n * Every environment variable Wildo itself sets on a platform process. A vendor `environment` entry may name none of them:\n * it would overwrite the platform's own value (a PIN, a connection string, the service's mode), and the vendor block is\n * rendered in plain text beside the service, never into a Secret.\n */\nconst WILDO_OWNED_PLATFORM_ENV_KEYS: ReadonlySet<string> = new Set<string>([\n ...[\n PlatformProcessEnvKey, PlatformServiceUrlEnvKey, PlatformInfrastructureEnvKey, PlatformSecurityEnvKey, PlatformAdminEnvKey,\n PlatformKubernetesEnvKey, PlatformIngressEnvKey, PlatformLoggingEnvKey, PlatformObservabilityEnvKey, PlatformProviderSelectionEnvKey,\n PlatformEmailEnvKey, PlatformOwnershipDnsEnvKey, PlatformDocumentationSiteEnvKey,\n ].flatMap((vocabulary) => Object.values(vocabulary) as string[]),\n // Set literally by the deployment templates rather than through the env contract.\n 'PLATFORM_SERVICE', 'NODE_OPTIONS', 'NODE_ENV',\n]);\n\n/**\n * Whether apps-manager, running in the PLATFORM IMAGE, can load `modulePath`: it is the bundled SoftHSM2, or it lies at or\n * under one of the declared `clientFiles[].containerPath`. Nothing else exists in that container.\n */\nexport function pkcs11ModuleIsReachableInPlatformContainer(pkcs11: Pkcs11ModuleMountView): boolean {\n if (pkcs11.modulePath === PLATFORM_IMAGE_BUNDLED_PKCS11_MODULE_PATH) return true;\n return (pkcs11.clientFiles ?? []).some(({ containerPath }) => {\n const mountRoot = containerPath.replace(/\\/+$/, '');\n return pkcs11.modulePath === mountRoot || pkcs11.modulePath.startsWith(`${mountRoot}/`);\n });\n}\n\n/** The refusal both container lanes (compose, Kubernetes) raise for an unreachable module, naming the declaration. */\nexport function describeUnreachablePkcs11Module(pkcs11: Pkcs11ModuleMountView, environmentName?: string): string {\n const mounts = (pkcs11.clientFiles ?? []).map((file) => file.containerPath);\n return `${environmentName ? `Environment \"${environmentName}\": ` : ''}platformKeyManagement.pkcs11.modulePath \"${pkcs11.modulePath}\" `\n + `is not the SoftHSM2 module the platform image carries (${PLATFORM_IMAGE_BUNDLED_PKCS11_MODULE_PATH}) and lies under no `\n + `platformKeyManagement.pkcs11.clientFiles[].containerPath (${mounts.length > 0 ? mounts.join(', ') : 'none declared'}). `\n + 'apps-manager runs in the platform image, where nothing else exists: declare the vendor\\'s module (and its configuration) '\n + 'in clientFiles as { hostPath, containerPath } and point modulePath inside one of them.';\n}\n\n/** Whether the platform runs its own Vault (OpenBao) in this environment: the one predicate both lanes render from. */\nexport function selfHostsPlatformKeyVault(platformKeyManagement: WildoPlatformKeyManagementConfig | undefined): boolean {\n return platformKeyManagement?.vault?.source === BackingServiceSource.SELF;\n}\n"]}
1
+ {"version":3,"file":"platform-key-management.schemas.js","sourceRoot":"","sources":["../../../../src/project-config/shared/platform-key-management.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,mBAAmB,EACnB,+BAA+B,EAC/B,mBAAmB,EACnB,4BAA4B,EAC5B,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,2BAA2B,EAC3B,0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EnvKey,\n PlatformInfrastructureEnvKey,\n PlatformIngressEnvKey,\n PlatformKubernetesEnvKey,\n PlatformLoggingEnvKey,\n PlatformObservabilityEnvKey,\n PlatformOwnershipDnsEnvKey,\n PlatformProcessEnvKey,\n PlatformProviderSelectionEnvKey,\n PlatformSecurityEnvKey,\n PlatformServiceUrlEnvKey,\n} from '../../bootstrap/platform-runtime-env.contracts';\nimport { AGENT_CONTENT_GUARDRAILS_ENV_VAR } from '@wildo-ai/saas-models';\nimport { BackingServiceSource } from './backing-services.schemas';\n\n/** @wildo_source:part:start platform.config.platform-key-management facet:layer:platform facet:family:infra facet:audience:app-developer */\n/**\n * # Where the platform keeps the keys it holds for applications (#2933)\n *\n * apps-manager is the custodian of every platform-held key (approval seals, signature requests, and the wrapping keys\n * of an application's sealed secrets, #2894). Without this block it\n * seals them under its own key-encryption root (the LOCAL provider). With it, apps-manager also serves the\n * `vault-transit` and `vault-kv` key providers, and an application's key binding may name one of them.\n *\n * This is a PLATFORM-tier declaration, like `platformStorage`: one apps-manager holds one Vault, whatever application\n * an environment file belongs to. It is deliberately not a `backingServices` kind. A backing service is something an\n * application runtime dials, with credentials minted per application; no application runtime ever reaches this Vault,\n * and nothing is minted per application in it.\n *\n * - `{ vault: { source: 'self' } }` — the CLI renders a single-node OpenBao (the MPL-licensed Vault fork, API\n * compatible for everything used) beside apps-manager, in docker compose and in Kubernetes. It unseals itself from a\n * framework-managed key and configures itself on its first start: the Transit and KV mounts, the two least-privilege\n * policies, and the two tokens apps-manager speaks with. Good for development and for a small self-hosted platform;\n * its protection is SOFTWARE, as every Vault's is. Its self-initialization runs only on EMPTY storage, so an OpenBao\n * first started before a policy changed keeps the older policy: one started before #2894 cannot wrap data keys\n * (`transit/encrypt` and `transit/decrypt` answer 403) until the signer policy is written again (`bao policy write`\n * with `vaultSignerPolicy`) or its storage is recreated.\n * - `{ vault: { source: 'managed', address, … } }` — the operator's own Vault or OpenBao. The operator configures the\n * mounts and policies (`vaultSignerPolicy` / `vaultOperatorPolicy` in the key-management contracts) and puts the two\n * tokens in `secrets.json` under `platformKeyVaultManaged`.\n *\n * Absent, apps-manager serves no Vault provider, and a binding that names one is refused PROVIDER_UNAVAILABLE.\n *\n * ## Cloud KMS (#2896)\n *\n * `awsKms`, `googleCloudKms` and `azureKeyVault` make apps-manager serve the `aws-kms`, `google-cloud-kms` and\n * `azure-key-vault` providers: the key is generated inside the vendor's HSM, never leaves it, and the vendor signs. They\n * are always the operator's own account, so they carry no `source`. apps-manager authenticates with its WORKLOAD\n * identity (an IAM role for its service account, GKE workload identity, an Azure managed identity): nothing here is a\n * secret, and `secrets.json` holds nothing for them.\n *\n * Each provider acts as two identities, as Vault does with two tokens. The SIGNER may only read keys, sign, and wrap and\n * unwrap data keys under a wrapping key (#2894); the OPERATOR creates, disables and destroys keys and may never sign, wrap\n * or unwrap. Every wrap is authenticated encryption under a key only the vendor holds. Neither vendor's broad built-in role keeps to that, so\n * grant, per vendor:\n * - AWS: apps-manager's identity may only `sts:AssumeRole` the two roles. Every key apps-manager creates carries the tag\n * `wildo:key-ref`, and the policies are scoped by it:\n * - Signer, on `arn:aws:kms:<region>:<account>:key/*`: `kms:Sign`, `kms:Encrypt` and `kms:Decrypt` only where\n * `aws:ResourceTag/wildo:key-ref` is present (`\"Null\": { … \"false\" }`), so it cannot sign with, or decrypt under,\n * another key in the account; `kms:GetPublicKey` and `kms:DescribeKey` unconditioned (both read-only).\n * - Operator: `kms:CreateKey` and `kms:TagResource` on `\"Resource\": \"*\"` (CreateKey names no key yet), only where\n * `aws:RequestTag/wildo:key-ref` is present and `aws:TagKeys` is exactly `[\"wildo:key-ref\"]`; on `key/*`,\n * `kms:DisableKey` and `kms:ScheduleKeyDeletion` only where `aws:ResourceTag/wildo:key-ref` is present, and\n * `kms:DescribeKey`; never `kms:Sign`, `kms:Encrypt`, `kms:Decrypt` nor `kms:UntagResource`.\n * - The tag is what admits a key to the signer, so whoever may tag may admit: the operator's `kms:TagResource` lets it\n * put `wildo:key-ref` on ANY key in the account, which the signer could then sign with. AWS warns of exactly this\n * (\"Be cautious about giving principals the `kms:TagResource` … permissions\"). Keep the operator role to apps-manager\n * alone, and consider a permissions boundary or SCP denying `kms:TagResource` on keys outside the custodian's.\n * - KMS applies a tag to authorization up to five minutes after it is set, so a NEW version may be refused `kms:Sign`\n * for those minutes: the first ACTIVE version of every new keyring (made at its first signature request), and one\n * made by an emergency rotation. The signature fails as a provider fault and the caller retries it; so does the first\n * wrap under a new wrapping key, which the application's data-key ring asks for again on its own retry.\n * - Google: apps-manager's identity holds `roles/iam.serviceAccountTokenCreator` on the two service accounts only.\n * Signer: `roles/cloudkms.signer`, `roles/cloudkms.cryptoKeyEncrypterDecrypter`, `roles/cloudkms.publicKeyViewer` and\n * `roles/cloudkms.viewer` on the key ring (sign, wrap and unwrap data keys, read the public key, read a version's state). Operator: `roles/cloudkms.admin` on the key ring, which contains no\n * cryptographic operation.\n * - Azure Key Vault (a vault in the Azure RBAC permission model): two user-assigned managed identities on apps-manager,\n * each with a CUSTOM role on the vault. The built-in roles do not fit: \"Key Vault Crypto User\" can update and back up a\n * key, and \"Key Vault Crypto Officer\" holds `vaults/keys/*`, signing included.\n * - Signer: `Microsoft.KeyVault/vaults/keys/read`, `…/keys/sign/action`,\n * `…/keys/encrypt/action`, `…/keys/decrypt/action` (a data key is wrapped with A256GCM under an `oct-HSM` key, which\n * a Premium vault offers in preview; a Standard vault cannot hold one and serves signing only).\n * - Operator: `…/keys/read`, `…/keys/create/action`, `…/keys/update/action` (disable),\n * `…/keys/delete`, `…/keys/purge/action`.\n * Azure has no `keys/versions/read` data action: `keys/read` reads every version. Measured 2026-11-12 (#3697) with two\n * user-assigned managed identities holding exactly these roles: each verb succeeded as its own identity and answered\n * 403 as the other one.\n * The vault's recovery level decides whether a destroyed key is purged at once or kept until retention ends.\n * - Azure Managed HSM (`*.managedhsm.azure.net`): the same two identities, with custom roles in the HSM's LOCAL RBAC\n * (the built-in \"Managed HSM Crypto User\" can sign and back up, and cannot purge). Signer:\n * `Microsoft.KeyVault/managedHsm/keys/read/action`, `…/keys/sign/action`, `…/keys/encrypt/action`, `…/keys/decrypt/action`.\n * Operator: `…/keys/read/action`,\n * `…/keys/create`, `…/keys/write/action`, `…/keys/delete`, `…/keys/deletedKeys/read/action`,\n * `…/keys/deletedKeys/delete` (purge).\n *\n * spec-cite: AWS KMS developer guide, \"Use tags to control access to KMS keys\" (`aws:ResourceTag`, the five-minute\n * delay, limiting `kms:TagResource` with `aws:RequestTag` / `aws:TagKeys`),\n * https://docs.aws.amazon.com/kms/latest/developerguide/tag-authorization.html; AWS KMS permissions reference\n * (`CreateKey`'s resource is `*`), https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html; Azure built-in roles, Security (Key\n * Vault Crypto Officer DataActions `Microsoft.KeyVault/vaults/keys/*`) and Azure permissions, Microsoft.KeyVault (the\n * `vaults/keys/*` data actions), https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/security;\n * Managed HSM local RBAC built-in roles (the data-action table),\n * https://learn.microsoft.com/en-us/azure/key-vault/managed-hsm/built-in-roles.\n *\n * When a provider registers at startup, apps-manager logs the vendor's quota and per-request cost. It also holds its own\n * signing under 80% of the vendor's per-second quota, per process.\n *\n * ## Corroboration\n *\n * Every ten minutes, apps-manager compares, per key version and closed hour, the signatures its signing log records with\n * the ones the vendor's own audit log records, and writes one audit row per provider and hour:\n * - UNACCOUNTED (CRITICAL) the moment the vendor shows more signatures than apps-manager can account for: a key was used\n * outside the custodian, or a signature went unrecorded;\n * - otherwise, once the hour is six hours old (vendor logs arrive late): UNCORROBORATED (the vendor recorded fewer, or its\n * log could not be read) or CORROBORATED.\n * It reads as the OPERATOR identity, which therefore also needs:\n * - AWS: `cloudtrail:LookupEvents` (KMS `Sign` is a CloudTrail management event; nothing to enable).\n * - Google: `roles/logging.privateLogViewer` on the project, and Cloud KMS Data Access audit logs ENABLED (they are off by\n * default, and until they are on, every hour is uncorroborated).\n * - Azure: Log Analytics Reader on the workspace named by `logAnalyticsWorkspaceId`, which the vault's diagnostic setting\n * sends `AuditEvent` to.\n */\nexport const PlatformKeyVaultSelfHostedSchema = z.strictObject({\n source: z.literal(BackingServiceSource.SELF),\n});\n\n/** The operator's own Vault or OpenBao. Mounts and prefix default to the provider defaults (`transit`, `secret`, `wildo-`). */\nexport const PlatformKeyVaultManagedSchema = z.strictObject({\n source: z.literal(BackingServiceSource.MANAGED),\n /** The Vault API address apps-manager dials, e.g. `https://vault.internal:8200`. */\n address: z.url(),\n /** Vault Enterprise namespace (`team/keys/`); absent on open-source Vault and OpenBao's root namespace. */\n namespace: z.string().min(1).optional(),\n transitMount: z.string().min(1).optional(),\n kvMount: z.string().min(1).optional(),\n keyNamePrefix: z.string().min(1).optional(),\n});\n\nexport const PlatformKeyVaultConfigSchema = z.discriminatedUnion('source', [PlatformKeyVaultSelfHostedSchema, PlatformKeyVaultManagedSchema]);\nexport type PlatformKeyVaultConfig = z.infer<typeof PlatformKeyVaultConfigSchema>;\n\n/** The protection level apps-manager creates Google Cloud KMS keys at. */\nexport enum PlatformGoogleKmsKeyProtection {\n /** In Cloud HSM (FIPS 140-2 Level 3): the key's attestation is HARDWARE. */\n HSM = 'HSM',\n /** In Cloud KMS software: the key's attestation is SOFTWARE, and a HARDWARE floor refuses it. */\n SOFTWARE = 'SOFTWARE',\n}\n\n/** AWS KMS in the operator's account. */\nexport const PlatformKeyAwsKmsConfigSchema = z.strictObject({\n region: z.string().regex(/^[a-z]{2}(-[a-z]+)+-\\d$/),\n /** The role apps-manager assumes to read keys and sign. */\n signerRoleArn: z.string().regex(/^arn:aws[a-z-]*:iam::\\d{12}:role\\/.+$/),\n /** The role apps-manager assumes to create, disable and schedule the deletion of keys. */\n operatorRoleArn: z.string().regex(/^arn:aws[a-z-]*:iam::\\d{12}:role\\/.+$/),\n /** A KMS endpoint other than the region's public one (a VPC interface endpoint). */\n endpoint: z.url().optional(),\n});\n\n/** Google Cloud KMS in the operator's project. */\nexport const PlatformKeyGoogleCloudKmsConfigSchema = z.strictObject({\n /** `projects/<project>/locations/<location>/keyRings/<ring>`; created by the operator, since a key ring cannot be deleted. */\n keyRing: z.string().regex(/^projects\\/[^/]+\\/locations\\/[^/]+\\/keyRings\\/[^/]+$/),\n signerServiceAccount: z.email(),\n operatorServiceAccount: z.email(),\n protectionLevel: z.enum(PlatformGoogleKmsKeyProtection).default(PlatformGoogleKmsKeyProtection.HSM),\n});\n\n/** Azure Key Vault (Premium) or Managed HSM in the operator's subscription. */\nexport const PlatformKeyAzureKeyVaultConfigSchema = z.strictObject({\n /** `https://<vault>.vault.azure.net` or `https://<hsm>.managedhsm.azure.net`. */\n vaultUrl: z.url(),\n /** The client id of the signer's user-assigned managed identity. */\n signerClientId: z.uuid(),\n /** The client id of the operator's user-assigned managed identity. */\n operatorClientId: z.uuid(),\n /** HSM-protected keys (`EC-HSM`, a Premium vault or Managed HSM); `false` makes software `EC` keys. */\n hsm: z.boolean().default(true),\n /**\n * The Log Analytics workspace (its GUID) the vault's diagnostic setting sends `AuditEvent` to, in the `AzureDiagnostics`\n * destination mode. apps-manager reads it hourly to corroborate its signatures; absent, no Azure hour is compared.\n */\n logAnalyticsWorkspaceId: z.uuid().optional(),\n});\n\n/** The SoftHSM2 module the platform image carries: the one PKCS#11 module a containerised apps-manager has without a mount. */\nexport const PLATFORM_IMAGE_BUNDLED_PKCS11_MODULE_PATH = '/usr/lib/softhsm/libsofthsm2.so';\n\n/** An absolute path with no `.` or `..` segment, so \"is this path inside that mount\" is a plain prefix question. */\nconst AbsoluteNormalPathSchema = z\n .string()\n .regex(/^\\//, 'an absolute path')\n .refine((path) => !/(^|\\/)\\.{1,2}(\\/|$)/.test(path), 'a path with no `.` or `..` segment');\n\n/** Where the platform image keeps apps-manager itself: a mount here (or over `/`) would hide the service it serves. */\nconst PLATFORM_IMAGE_APPLICATION_ROOT = '/app';\n\n/**\n * One file or directory of the HSM vendor's PKCS#11 client, mounted READ-ONLY into apps-manager's container (#3019): the\n * module, its configuration, the client certificates. `hostPath` is on the docker host (compose) or on every node that\n * may run apps-manager (Kubernetes, a `hostPath` volume); `containerPath` is where apps-manager sees it.\n */\nexport const PlatformKeyPkcs11ClientFileSchema = z.strictObject({\n hostPath: AbsoluteNormalPathSchema,\n containerPath: AbsoluteNormalPathSchema.refine(\n (path) => path !== '/' && path.replace(/\\/+$/, '') !== PLATFORM_IMAGE_APPLICATION_ROOT && !path.startsWith(`${PLATFORM_IMAGE_APPLICATION_ROOT}/`),\n `a path outside \\`/\\` and \\`${PLATFORM_IMAGE_APPLICATION_ROOT}\\` (the platform image keeps apps-manager there)`,\n ),\n});\nexport type PlatformKeyPkcs11ClientFile = z.infer<typeof PlatformKeyPkcs11ClientFileSchema>;\n\n/**\n * A dedicated HSM reached over PKCS#11 (#2934): Thales Luna, Entrust nShield, AWS CloudHSM, Azure Cloud HSM, an\n * on-premises appliance, or SoftHSM2. apps-manager loads the vendor's PKCS#11 module, logs in to one token with a user PIN\n * (operator-typed in `secrets.json` under `platformKeyPkcs11: { pin }`, never here) and serves the `pkcs11` provider.\n *\n * Protection is read from the token, not declared: a key counts as HARDWARE only when the slot reports a hardware slot\n * AND the token's model is listed in `hardwareTokenModels`, which is your statement that this model is the hardware you\n * run. SoftHSM2 is always SOFTWARE. The binding (`pkcs11js`) is compiled by `pnpm setup:pkcs11`; an apps-manager that\n * cannot load it says so at boot and refuses every signature on this provider.\n *\n * ## A real HSM in a containerised platform (#3019)\n *\n * The platform image carries only SoftHSM2. A real HSM's client comes from the host, and every vendor documents the same\n * containerised shape: mount the client library and its configuration READ-ONLY, and point the client at its\n * configuration with the vendor's own variable. So:\n * - `clientFiles` lists what to mount, each `{ hostPath, containerPath }`. compose renders a read-only bind mount and refuses\n * to start the service when the host path is missing; Kubernetes renders a read-only `hostPath` volume, which it mounts\n * unchecked, so the files must exist on every node that may run apps-manager (a missing one shows as a token that cannot\n * be opened, logged at boot). Both apps-manager services get them (INIT and serving).\n * - `environment` carries the vendor's variables (`ChrystokiConfigurationPath` for a Thales Luna client, …). It is\n * rendered in plain text beside the service, so it may hold paths and settings, never a credential; it may not name a\n * variable Wildo sets itself. The token PIN stays in `secrets.json`.\n * - In a container, `modulePath` must be the bundled SoftHSM2 or lie under a `containerPath`. Declaring `clientFiles` says\n * apps-manager runs in a container, so that is refused here; without `clientFiles` it is refused when compose or\n * Kubernetes renders apps-manager, because a framework developer's NATIVE apps-manager loads a host path legitimately\n * (Homebrew's SoftHSM2, `/opt/homebrew/lib/softhsm/libsofthsm2.so`).\n * - Both are for the CONTAINER lanes. A framework developer's native apps-manager runs on the host, where the client is\n * installed and configured as the vendor documents, and receives neither.\n *\n * Example, a Thales Luna client installed under `/usr/safenet/lunaclient` on the host:\n * `{ modulePath: '/usr/safenet/lunaclient/lib/libCryptoki2_64.so', tokenLabel: 'wildo', hardwareTokenModels: ['Luna K7'],\n * clientFiles: [{ hostPath: '/usr/safenet/lunaclient', containerPath: '/usr/safenet/lunaclient' },\n * { hostPath: '/etc/Chrystoki.conf', containerPath: '/etc/Chrystoki.conf' }],\n * environment: { ChrystokiConfigurationPath: '/etc' } }`.\n */\nexport const PlatformKeyPkcs11ConfigSchema = z\n .strictObject({\n /**\n * The vendor's PKCS#11 module, as an absolute path in apps-manager's filesystem: in the platform image, the bundled\n * `/usr/lib/softhsm/libsofthsm2.so` or a path under a `clientFiles[].containerPath`.\n */\n modulePath: z.string().regex(/^\\//, 'an absolute path'),\n /** The token's label, as the module reports it. */\n tokenLabel: z.string().min(1).max(32),\n /** Token models (`CK_TOKEN_INFO.model`) you state are hardware. Empty: every key reports SOFTWARE. */\n hardwareTokenModels: z.array(z.string().min(1)).default([]),\n /** The vendor client's files, mounted read-only into apps-manager's container (#3019). */\n clientFiles: z.array(PlatformKeyPkcs11ClientFileSchema).optional(),\n /** The vendor client's own environment variables (no credential, and no variable Wildo sets). */\n environment: z.record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/, 'an environment variable name'), z.string()).optional(),\n })\n .superRefine((pkcs11, context) => {\n const containerPaths = (pkcs11.clientFiles ?? []).map((file) => file.containerPath.replace(/\\/+$/, ''));\n containerPaths.forEach((containerPath, index) => {\n if (containerPaths.indexOf(containerPath) !== index) {\n context.addIssue({ code: 'custom', path: ['clientFiles', index, 'containerPath'], message: `\"${containerPath}\" is mounted twice` });\n }\n });\n for (const name of Object.keys(pkcs11.environment ?? {})) {\n if (WILDO_OWNED_PLATFORM_ENV_KEYS.has(name)) {\n context.addIssue({ code: 'custom', path: ['environment', name], message: `\"${name}\" is a variable Wildo sets on apps-manager itself` });\n }\n }\n if (containerPaths.length > 0 && !pkcs11ModuleIsReachableInPlatformContainer(pkcs11)) {\n context.addIssue({ code: 'custom', path: ['modulePath'], message: describeUnreachablePkcs11Module(pkcs11) });\n }\n });\nexport type PlatformKeyPkcs11Config = z.infer<typeof PlatformKeyPkcs11ConfigSchema>;\n\nexport const WildoPlatformKeyManagementConfigSchema = z.strictObject({\n vault: PlatformKeyVaultConfigSchema.optional(),\n awsKms: PlatformKeyAwsKmsConfigSchema.optional(),\n googleCloudKms: PlatformKeyGoogleCloudKmsConfigSchema.optional(),\n azureKeyVault: PlatformKeyAzureKeyVaultConfigSchema.optional(),\n pkcs11: PlatformKeyPkcs11ConfigSchema.optional(),\n});\nexport type WildoPlatformKeyManagementConfig = z.infer<typeof WildoPlatformKeyManagementConfigSchema>;\n\n/** @wildo_source:part:end platform.config.platform-key-management */\n\n/** What deciding a module's reachability needs: the module, and where the client files are mounted. */\nexport interface Pkcs11ModuleMountView {\n readonly modulePath: string;\n readonly clientFiles?: readonly { readonly containerPath: string }[];\n}\n\n/**\n * Every environment variable Wildo itself sets on a platform process. A vendor `environment` entry may name none of them:\n * it would overwrite the platform's own value (a PIN, a connection string, the service's mode), and the vendor block is\n * rendered in plain text beside the service, never into a Secret.\n */\nconst WILDO_OWNED_PLATFORM_ENV_KEYS: ReadonlySet<string> = new Set<string>([\n ...[\n PlatformProcessEnvKey, PlatformServiceUrlEnvKey, PlatformInfrastructureEnvKey, PlatformSecurityEnvKey, PlatformAdminEnvKey,\n PlatformKubernetesEnvKey, PlatformIngressEnvKey, PlatformLoggingEnvKey, PlatformObservabilityEnvKey, PlatformProviderSelectionEnvKey,\n PlatformEmailEnvKey, PlatformOwnershipDnsEnvKey, PlatformDocumentationSiteEnvKey,\n ].flatMap((vocabulary) => Object.values(vocabulary) as string[]),\n // An application runtime's guardrail posture (`WildoInfraEnvConfig.agentContentGuardrails`), named by saas-models.\n AGENT_CONTENT_GUARDRAILS_ENV_VAR,\n // Set literally by the deployment templates rather than through the env contract.\n 'PLATFORM_SERVICE', 'NODE_OPTIONS', 'NODE_ENV',\n]);\n\n/**\n * Whether apps-manager, running in the PLATFORM IMAGE, can load `modulePath`: it is the bundled SoftHSM2, or it lies at or\n * under one of the declared `clientFiles[].containerPath`. Nothing else exists in that container.\n */\nexport function pkcs11ModuleIsReachableInPlatformContainer(pkcs11: Pkcs11ModuleMountView): boolean {\n if (pkcs11.modulePath === PLATFORM_IMAGE_BUNDLED_PKCS11_MODULE_PATH) return true;\n return (pkcs11.clientFiles ?? []).some(({ containerPath }) => {\n const mountRoot = containerPath.replace(/\\/+$/, '');\n return pkcs11.modulePath === mountRoot || pkcs11.modulePath.startsWith(`${mountRoot}/`);\n });\n}\n\n/** The refusal both container lanes (compose, Kubernetes) raise for an unreachable module, naming the declaration. */\nexport function describeUnreachablePkcs11Module(pkcs11: Pkcs11ModuleMountView, environmentName?: string): string {\n const mounts = (pkcs11.clientFiles ?? []).map((file) => file.containerPath);\n return `${environmentName ? `Environment \"${environmentName}\": ` : ''}platformKeyManagement.pkcs11.modulePath \"${pkcs11.modulePath}\" `\n + `is not the SoftHSM2 module the platform image carries (${PLATFORM_IMAGE_BUNDLED_PKCS11_MODULE_PATH}) and lies under no `\n + `platformKeyManagement.pkcs11.clientFiles[].containerPath (${mounts.length > 0 ? mounts.join(', ') : 'none declared'}). `\n + 'apps-manager runs in the platform image, where nothing else exists: declare the vendor\\'s module (and its configuration) '\n + 'in clientFiles as { hostPath, containerPath } and point modulePath inside one of them.';\n}\n\n/** Whether the platform runs its own Vault (OpenBao) in this environment: the one predicate both lanes render from. */\nexport function selfHostsPlatformKeyVault(platformKeyManagement: WildoPlatformKeyManagementConfig | undefined): boolean {\n return platformKeyManagement?.vault?.source === BackingServiceSource.SELF;\n}\n"]}