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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
CPU that supports it; an older QEMU exits at startup on the unknown
`secure-tsc` property. Such a guest also needs a KMS and verifier of this
release. Apps with `secure_time: false` launch as before.
- **RTMR3 of KMS apps changes.** Guests of this release add an `app-epoch`
runtime event, so the runtime RTMR3 (PCR14 on TPM platforms) of every app with
KMS keys differs from earlier images. Boot-time measurements are unchanged.
- **Certificates follow the measured app epoch.** `SignCert` signs under the
app epoch the CVM's attestation records, so after an app epoch rotation a
running CVM of this release keeps getting certificates from the old epoch,
under that epoch's policy row, until it restarts; once that row is revoked,
its certificate renewals are denied until then. Where nothing records it
(older guests, Nitro Enclave) the current epoch is used as before.
- **SEV-SNP apps with KMS keys: upgrade the KMS, gateways and verifiers
first.** SEV-SNP has no runtime register, so the VMM now binds the app epoch
in MrConfigV3 at every launch, asking the KMS for the current one when no pin
is set, and the guest refuses to boot without it. Older KMS, gateways and
verifiers reject such a document, so upgrade them before the VMM and the
guest images. The VMM binds the epoch only for images whose `metadata.json`
sets `app_epoch_pin`, so older images launch as before. A new SEV-SNP image
does not boot under an older VMM, and the VMM must reach the VM's KMS URLs at
every cold start and automatic restart.

### Added

Expand All @@ -27,6 +45,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Secure TSC when `secure_time` is on, so the host cannot skew the guest
clock.
- `vmm-cli compose --init-script` sets `init_script` in the app compose file.
- **The app key epoch is measured.** A guest with KMS keys records its app
epoch in an `app-epoch` runtime event after `key-provider`, and certificates
from the KMS `SignCert` carry it in the `PHALA_RATLS_APP_EPOCH` extension. A
deployment can pin the app epoch with the MrConfigV3 field `app_epoch`
(`vmm-cli deploy --app-epoch` or the VMM web UI), and `GetSealedEnvPubKey`
takes an optional `app_epoch` to seal an env for such a VM. dstack-verifier
reports the measured epoch as `app_epoch`. Older guests refuse a document
with the field; on SEV-SNP, older KMS and verifiers do too. See
[Measurement](docs/app-key-epochs.md#measurement).
- **`allowed_envs` entries can constrain values.** An entry may be `NAME: spec`,
such as `PORT: int(1..=65535)` or `NETWORK: /mainnet|testnet/`, and the guest
refuses to boot when a value does not match. `dstack-util validate-env`
Expand Down
60 changes: 60 additions & 0 deletions docs/app-key-epochs.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,66 @@ image or restoring a compatible header backup. App rotation isolates future app
keys from an exposed old derived key, but cannot recover from compromise of the
KMS root or revoke already disclosed secrets.

Certificates issued by `SignCert` carry the app epoch they were issued under in
the `PHALA_RATLS_APP_EPOCH` extension (OID `1.3.6.1.4.1.62397.1.10`, a DER
OCTET STRING holding a 4-byte big-endian integer), which
`CertExt::get_app_epoch` reads. The root epoch needs no extension: the issuing
root CA identifies it. There is no revocation list:
certificates issued before a rotation stay valid until they expire, and the
requester chooses their `not_after`. A verifier that reads the current app epoch
from the policy can reject a peer certificate from an older one. Certificates
without the extension come from a local CA or a KMS predating it, so a verifier
enforcing epochs must reject them as well.

## Measurement

A guest with KMS keys measures the app epoch it booted with in an `app-epoch`
runtime event, right after `key-provider`, as a 4-byte big-endian integer. The
root epoch is already identified by the KMS root key in `key-provider`. The
event extends RTMR3 on TDX and PCR14 on TPM platforms. SEV-SNP and Nitro Enclave
have no runtime register, so there the event is only logged and proves nothing.
`SignCert` signs under the app epoch the attestation records: the boot-time
`app-epoch` event where a register replays it, or the MrConfigV3 pin on
SEV-SNP. The requester cannot choose it, and the certificate's
`PHALA_RATLS_APP_EPOCH` matches the measurement. Where nothing records it, on
older guests and Nitro Enclave, `SignCert` uses the current app epoch.

A deployment can pin the app epoch with the optional MrConfigV3 field
`app_epoch`, bound by TDX `MR_CONFIG_ID` or SEV-SNP `HOST_DATA`. The guest then
requests that app epoch instead of the current one and refuses to boot when the
KMS serves another. The pin requires the KMS key provider, and on TDX it requires
`use_mrconfigid`. Set it with `vmm-cli.py deploy --app-epoch N`, change it with
`update --app-epoch N`, and remove it with `update --no-app-epoch`; the VMM web
UI has an App Epoch field in its deploy and update dialogs. The VMM
refuses the pin for other key providers, for launches without MrConfigV3,
including `no_tee` and every simulator except SEV-SNP, and for images whose
`metadata.json` lacks `app_epoch_pin`. `ListImages` reports that flag, and
vmm-cli and the web UI offer the pin only for an image it marks, so a VMM
predating pins, which never sets the flag, is never sent a pin it would drop.

SEV-SNP has no runtime register, so there the document always carries the app
epoch for KMS keys: without a pin, the VMM asks the KMS for the current app
epoch at every launch and binds it, so a restart still moves to a new epoch. A
guest of this release refuses to boot on SEV-SNP with KMS keys when the
document has no `app_epoch`, so it needs a VMM of this release, and that VMM
must reach the KMS URLs of the VM itself. Older KMS, gateways and verifiers
reject a document carrying `app_epoch`, so upgrade them before the VMM and the
guest images.

The pin lets the host choose any app epoch whose policy row still allows the
instance, and the CVM then runs on that epoch's keys. Clear the rows of an epoch
whose keys may be exposed, and have relying parties check the `app-epoch` event
or, on SEV-SNP, the `app_epoch` in the document; dstack-verifier reports either
as `app_epoch`.

Boot fails when the disk header records an app epoch newer than the pin, like
any other request for an older epoch. The env of a pinned VM must be sealed at
the pinned epoch, since the guest rejects one sealed at a newer epoch than its
own: vmm-cli and the VMM web UI pass the pin to `GetSealedEnvPubKey`, which then
returns the key of that app epoch. For the same reason, lowering the pin of a VM
below the epoch of its existing env makes its next boot fail until a new env is
sealed.

## SDK selection

Both selectors are optional; specify zero explicitly to recover an old key.
Expand Down
2 changes: 1 addition & 1 deletion docs/aws-attested-instance-security-evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ NitroTPM path meets them today.
| P1 | Verifiable platform root of trust | TDX/SNP/Nitro quote verification against vendor root; debug rejected; TCB surfaced | NitroTPM Attestation Documents are verified against the AWS Nitro Attestation PKI, including document timestamp sanity. AWS exposes no TDX/SNP-style TCB advisory field, so a verified attestation is normalized to `tcbStatus = "UpToDate"` and passes the standard authorization gate unchanged. |
| P2 | Reproducible or independently computable base image measurement | meta-dstack rebuild plus `dstack-mr` computes `MRTD`/`RTMR0-2` | The unified `os/build.sh` flow emits the AWS image archive with `sha256sum.txt`, `digest.txt`, and `measurement.aws.cbor`; its output directory also contains the reference-PCR side-car `aws-pcrs.json`. `os_image_hash = sha256(sha256sum.txt)` is the same identity used on all platforms; the verifier recomputes it from the downloaded image directory (`dstack/verifier/src/verification.rs`). The hardening audit script `os/yocto/tools/aws/audit-aws-ec2-image-hardening.sh` checks the image for operator mutation channels. |
| P3 | Boot command line and root filesystem integrity are measured | `RTMR1/2`, rootfs hash, dm-verity, measured initrd/cmdline | The UKI commits kernel, initrd, and embedded cmdline into `PCR4`; the rootfs is dm-verity-protected. `VmConfig.aws_measurement` is required and must bind `boot_pcr_digest = sha256(PCR4||PCR7||PCR12)` to the attested PCRs, so `PCR12` (external cmdline) is always part of the bound digest — a missing-PCR12 bypass is not expressible. Enforced in guest quote generation (`dstack/dstack-attest/src/attestation.rs`), `verify_os_image_hash_for_aws_nitro_tpm` (`dstack/verifier/src/verification.rs`), and the KMS pipeline via the same verifier check. |
| P4 | Runtime application identity is cryptographically bound | RTMR3 `compose-hash`, `app-id`, `instance-id`, `key-provider`; event log replay | SHA384 `PCR14` event-log replay is the authoritative binding (RTMR3 analogue; non-resettable). Launch events: `system-preparing`, `app-id`, `compose-hash`, zero or more ordered `init-script-hash` events, `instance-id`, `boot-mr-done`, `key-provider`, `storage-fs`, `storage-encrypted`, `system-ready` (`dstack/dstack-util/src/system_setup.rs`). GPU launches also include `gpu-policy-hash` before `instance-id`, and `gpu-attestation` after `boot-mr-done` and before `key-provider`. `dstack-attest`, `dstack-verifier`, and KMS reject missing/mismatched PCR14 and bad replay. Optionally, the guest extends the raw `MrConfig` V2 `config_id` into `PCR8` once (`PCR8 = sha384(0^48 || config_id)`) so a lightweight third-party verifier can check compose hash + key provider without event-log replay; dstack's own verifier and KMS do not check PCR8. |
| P4 | Runtime application identity is cryptographically bound | RTMR3 `compose-hash`, `app-id`, `instance-id`, `key-provider`; event log replay | SHA384 `PCR14` event-log replay is the authoritative binding (RTMR3 analogue; non-resettable). Launch events: `system-preparing`, `app-id`, `compose-hash`, zero or more ordered `init-script-hash` events, `instance-id`, `boot-mr-done`, `key-provider`, `app-epoch` (KMS keys only), `storage-fs`, `storage-encrypted`, `system-ready` (`dstack/dstack-util/src/system_setup.rs`). GPU launches also include `gpu-policy-hash` before `instance-id`, and `gpu-attestation` after `boot-mr-done` and before `key-provider`. `dstack-attest`, `dstack-verifier`, and KMS reject missing/mismatched PCR14 and bad replay. Optionally, the guest extends the raw `MrConfig` V2 `config_id` into `PCR8` once (`PCR8 = sha384(0^48 || config_id)`) so a lightweight third-party verifier can check compose hash + key provider without event-log replay; dstack's own verifier and KMS do not check PCR8. |
| P5 | Challenge/liveness and caller key binding | `report_data` challenge or RA-TLS public key hash in quote | RA-TLS binds `report_data` to the TLS certificate public key. KMS key release is bound to the live RA-TLS handshake; external `/verify` callers supply and check their own `report_data` challenge. The low-level NitroTPM document verifier also rejects stale or far-future document timestamps. |
| P6 | Secret release only to attested code | dstack KMS verifies attestation, checks auth policy, derives per-app keys | dstack KMS verifies the NitroTPM attestation, runs the same `verify_os_image_hash_for_aws_nitro_tpm` binding check as the verifier, builds `BootInfo` from verified boot PCRs plus PCR14 launch events, and checks auth policy before deriving app keys (`dstack/kms/src/main_service.rs`). AWS NitroTPM key release is gated behind the opt-in `aws_nitro_tpm_key_release` flag (default false in `kms.toml`). |
| P7 | Key-release policy is not controlled by the untrusted account admin | KMS runs inside TEE; policy from auth API/contracts; KMS identity measured | Satisfied with dstack KMS or another verifiable secret authority outside the untrusted AWS account admin's control. A NitroTPM-backed dstack KMS keeps root material out of account-admin snapshots and clones. The policy backend (on-chain `DstackKms`/`DstackApp` or an equivalent service; dstack-auth is for development, testing and evaluation only) must be outside the workload account admin's control. Same-account AWS KMS fails this property if the admin can change key policy, create grants, or call secret-bearing operations through a policy they control. |
Expand Down
7 changes: 4 additions & 3 deletions docs/kms-emergency-key-rotation-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,10 @@ signing trust, wallets, and permissions by reading old keys with an explicit
`root_epoch` before releasing business services. The guest agent fetches an
older epoch's app root from the KMS the first time GetKey names it and keeps it
in memory; old roots are not stored in the keys file. The frozen v0 surface
always uses the current epoch. A per-app epoch, if added later, follows the same convention. SignCert
retains existing checks and signs under current roots; GetMeta is not a trust
anchor. Change CVM/gateway certificate trust in both directions. Public ACME
always uses the current epoch. The app epoch follows the same convention. SignCert
signs under the current root and the app epoch the CVM's attestation records, so a
running CVM keeps that app epoch's certificates, and needs its policy row, until it
restarts; GetMeta is not a trust anchor. Change CVM/gateway certificate trust in both directions. Public ACME
certificates remain separate. Orchestration gates all business activity, including
outbound workers, until readiness.

Expand Down
16 changes: 15 additions & 1 deletion docs/sealed-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ The guest still enforces the application's environment-name allowlist.
## Keys and signatures

`GetSealedEnvPubKey` is available on KMS and proxied by VMM. Its request contains
`app_id` (20 bytes) only and always selects the current active epochs. Historical
`app_id` (20 bytes) and an optional `app_epoch`. It always selects the current
root epoch, and the current app epoch unless `app_epoch` asks for an older one,
which a VM pinned to that app epoch needs; a future app epoch is refused. The KMS
signs the key of an older app epoch with the prefix
`dstack-sealed-env-pubkey-historical-v1` instead of `dstack-sealed-env-pubkey-v1`,
so a verifier expecting the current key rejects it even when the request was
altered in transit. Accept that prefix only for an app epoch the user chose,
never one the host reports. vmm-cli does: it accepts the prefix only for the
`--app-epoch` typed on the command line and refuses to seal at a pin only the
VMM reports. The VMM web UI verifies no signature; it trusts the key the VMM
returns over its own origin, and its update dialog prefills the pin the VMM
reports. The SDK verifiers accept only the current-epoch prefix. Historical
private keys for decryption and migration are obtained through `GetAppKey`, not
through either environment public-key endpoint. The response contains
`public_key`, `root_epoch`, `app_epoch`, `timestamp`, and `signature`.
Expand All @@ -54,6 +65,9 @@ The public-key response signs Keccak256 of this unambiguous byte sequence:
|| app_epoch[4, big-endian] || public_key[32] || timestamp[8, big-endian]
```

For an app epoch older than the current one, the prefix is
`"dstack-sealed-env-pubkey-historical-v1:"` and the rest is unchanged.

The signing key is the selected epoch's secp256k1 root. The signature is
`r[32] || s[32] || recovery_id[1]`. Clients must compare the recovered signer
against an independently trusted epoch root key or pin. Recovering a signer
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorials/attestation-verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ In the output, look for the **X509v3 extensions** section. You'll see custom ext
| `1.3.6.1.4.1.62397.1.2` | Event Log | Detailed event log for RTMR3 replay verification |
| `1.3.6.1.4.1.62397.1.3` | App ID / Compose Hash | Application identity and configuration hash |
| `1.3.6.1.4.1.62397.1.4` | Custom Claims | Optional application-defined claims |
| `1.3.6.1.4.1.62397.1.10` | App Epoch | App key epoch the KMS signed under, as an OCTET STRING holding a 4-byte big-endian integer |

### Verify the certificate chain

Expand Down Expand Up @@ -491,6 +492,7 @@ These are the standard events you'll see in the log:
| `os-image-hash` | Guest OS image hash | Should match `tcb_info.os_image_hash` |
| `gpu-attestation` | Verified GPU state, aggregate `dbgstat`/`secboot`, and digest of the boot-time `nvattest` JSON | Required for an attested GPU launch; verify as described below |
| `key-provider` | Key provider type | e.g., `kms` |
| `app-epoch` | KMS keys only: the app key epoch as a 4-byte big-endian integer | Should match the app epoch you expect |
| `storage-fs` | Storage filesystem type | Storage configuration |
| `storage-encrypted` | `1` when the data disk is LUKS-encrypted, `0` when it is not | `0` means the host can read the application's data at rest |
| `system-ready` | System ready marker | Always present at end |
Expand Down
1 change: 1 addition & 0 deletions docs/vmm-cli-user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ Deploy your application with the compose file:
- `--gateway-url`: Gateway server URL
- `--stopped`: Create VM in stopped state (requires dstack-vmm >= 0.5.4)
- `--launch-ticket-file`: File holding the launch ticket the guest presents to the KMS (see below)
- `--app-epoch`: Pin the app key epoch the guest requests from the KMS; `update --app-epoch N` changes the pin and `update --no-app-epoch` removes it (see [app key epochs](app-key-epochs.md#measurement))

#### Launch Tickets

Expand Down
4 changes: 2 additions & 2 deletions dstack/cert-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl CertRequestClient {
CertRequestClient::Local { ca } => {
let app_info = local_ca_app_info(&csr.attestation);
let cert = ca
.sign_csr(csr, app_info.as_ref(), "app:custom")
.sign_csr(csr, app_info.as_ref(), None, "app:custom")
.context("Failed to sign certificate")?;
Ok(vec![cert.pem(), ca.pem_cert.clone()])
}
Expand Down Expand Up @@ -506,7 +506,7 @@ mod tests {
let mut csr = csr_with(undecodable_attestation(), key.public_key_der());
csr.config.subject_alt_names = vec![domain.to_string()];
let leaf = app_ca
.sign_csr(&csr, Some(&app_info_for(app_id)), "app:custom")
.sign_csr(&csr, Some(&app_info_for(app_id)), None, "app:custom")
.expect("sign csr");
(
format!("{}\n{}\n{}", leaf.pem(), app_ca.pem_cert, root.pem_cert),
Expand Down
Loading
Loading