Repository navigation
Code review fixes: bind all claims into the KEK, fail-closed attestation, demo layer scan, symlink escape - #8
Merged
Conversation
The v1 KEK context covered only version, license and customer id, product, payload id, policy, issued_at and not_after. Edition, entitlements, revocation_url, binding.server/max/fingerprint_hashes and signing_key_id were protected only by the signature, so a loader with the signature check patched out would run a license with revocation_url removed. Format v2 binds "cryptship/kek-ctx/v2" NUL SHA-256(canonical claims), where the canonical claims are the encoding/json form of Claims with wrapped_keys and unbound_secret cleared. The context is selected by claims.v: 1 keeps the byte-identical v1 layout (golden vector), 2 uses the new hash, anything else is an error. Parse now also rejects negative versions. cryptship issue writes v2 by default; --license-version 1 is available for fleets still running older loaders. wrapPerFingerprint now records every fingerprint hash before wrapping, since v2 covers those hashes. Tests: golden vectors for v1 and v2 (v2 cross-checked outside Go), every claim changes the v2 context, edited revocation_url / entitlements / edition / signing_key_id / binding.max do not unwrap a v2 license with the signature bypassed, v1 still unwraps, v1<->v2 rewrites do not unwrap, and pool licenses unwrap with every fingerprint under both versions. Fixes #1
--require-attestation accepted any non-empty evidence, so an operator who turned it on got no protection. There is no SEV-SNP/TDX verifier yet, so the server now refuses to start with the flag and says why. Add pkg/attest with a Verifier interface (Verify(evidence, nonce) (Measurement, error)) and replace licenseserver.Server.Verify with a Verifier field. Evidence must commit to online.AttestationNonce(license_id, nonce), so evidence for another request nonce or another license is rejected; the attested provider now obtains evidence after choosing the nonce. pkg/attest/attesttest holds the only implementation, for tests: its evidence proves nothing about the runtime. keyprovider.MockAttester, which returned fixed evidence, is replaced by attesttest.Attester. Docs: describe the fail-closed flag, that a non-verifying server with the same master key releases attested secrets, and that the client-chosen nonce still allows replay of a captured request (needs a server challenge, left for the real verifier work). Part of #3
The opacity check grepped the docker save output without unpacking each layer, so source inside a gzip-compressed layer blob would not be found and the check would pass falsely. scripts/check-image-opacity.sh now streams the save into a throwaway container, unpacks every layer blob (tar or gzip, legacy and OCI layouts) and fails on any blob it cannot unpack, including zstd. As a positive control it requires /cryptship/payload.enc in the unpacked layers. The demo app now carries a unique marker string that the scan looks for, and demo-compiled.sh uses the same scan. The tamper step ran python3 on the host although the README says only docker is needed. It now runs in the runtime image's Python over stdin/stdout. Fixes #6
None of the example Dockerfiles set USER, so the loader and the app ran as container root. Add USER 65532:65532 (with a state dir owned by that uid) to all three, and --user 65532:65532 plus a tmpfs owned by that uid to the hardened docker run in deploy/README.md. Note that --read-only leaves no writable state dir unless one is mounted. Part of #5
checkLink only checked that a link target was lexically inside dest. A target that passes through another symlink resolves against that symlink's target, so the pair s -> "." and t -> "s/.." created t pointing at the parent of dest, in either entry order. Writes stayed inside dest (os.Root), but the extracted tree handed the app a link out of the extract directory. Symlink targets may now use ".." only as leading components, climbing no higher than the link's own depth; ".." after an ordinary component is refused. Every accepted link then resolves inside dest whatever the entry order. TarDir applies the same rule and refuses unsupported file types at pack time, so a bad tree fails on the vendor's machine instead of on every customer's. It also closes each file as soon as it is copied; the deferred Close inside the walk callback kept every file open until the walk ended.
…e gaps - prepareDir deleted the contents of whatever CRYPTSHIP_EXTRACT named, so a typo such as /home/user emptied that directory. It now empties only a directory that is empty or carries the marker an earlier run left (.cryptship-extract-dir, or the manifest written by older loaders). - The revocation state file was named "revocation-"+license_id, so an id containing "/" could place it outside CRYPTSHIP_STATE_DIR. The id is now path-escaped (plain ids keep their old file names). - grace:<dur> treated a last-success time in the future (clock set back, or a hand-edited file) as within grace. Such times are now ignored. - The manifest was written with os.WriteFile, which follows a symlink the payload placed at that name. It is now created with O_EXCL, and a failure is reported as a warning instead of being dropped.
…nses An unedited expired license kept running if the system clock was set back. For licenses with not_after, the loader now records the latest start time in CRYPTSHIP_STATE_DIR, sealed with AES-GCM under a key derived from the content key and license id, and refuses to start when the clock is more than 24h behind that record. The tolerance absorbs NTP corrections and restored snapshots. This is best effort and documented as such: deleting the state file resets it, and an unwritable state dir disables it with a warning rather than blocking startup. Hard expiry still needs the online provider. Part of #2
cryptship master-key overwrote master.key unconditionally. The server derives every online/attested license secret from it, so rerunning the command (for example a copied demo script) silently broke every license issued under the old key. Require --force, as keygen already does for the signing key.
The server answers 410 for a revoked license and 403 when it rejects attestation evidence, but the provider mapped both to ErrRevoked, so a failed attestation told the operator the license was revoked. Map 403 to a new ErrDenied.
skalvinnathan
force-pushed
the
fix/code-review-2026-11
branch
from
November 15, 2026 17:23
c38ccf2 to
77bc5aa
Compare
skalvinnathan
added a commit
that referenced
this pull request
Nov 15, 2026
Code review fixes: bind all claims into the KEK, fail-closed attestation, demo layer scan, symlink escape
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a code review of the whole repository. It fixes the open issues that could be fixed safely, plus the bugs the review found. Each change is in its own commit.
Issues
go.modis nowgithub.com/AI2TH/cryptship, every import is rewritten, and the README has ago installline.kek-ctx/v2). The context is"cryptship/kek-ctx/v2" NUL SHA-256(canonical claims). The canonical claims are theencoding/jsonform ofClaimswithwrapped_keysandunbound_secretcleared.claims.vpicks the context: 1 keeps the v1 layout byte for byte, 2 uses the new hash, and any other value is an error with no fallback.vis inside both contexts, so rewriting a v2 license as v1 breaks the unwrap.cryptship issuewrites v2 by default.--license-version 1is kept for fleets that still run older loaders, which reject v2.Parsenow rejects negative versions.wrapPerFingerprintadded each fingerprint hash after wrapping with it. Under v2 that gave every pool key a wrong context. It now records all hashes first.--require-attestationfails closed. The server refuses to start with the flag, because there is no verifier yet.attest.Verifierinterface:Verify(evidence, nonce) (Measurement, error).licenseserver.Server.Verifierreplaces the oldVerifyfunc.online.AttestationNonce(license_id, nonce), so evidence made for another request nonce or another license is rejected.pkg/attest/attesttestholds the only implementation, for tests. It replaceskeyprovider.MockAttester.scripts/check-image-opacity.shrunsdocker saveand unpacks every layer blob in a container (tar or gzip, legacy and OCI layouts). It fails on a blob it cannot unpack, including zstd. As a positive control, the unpacked layers must contain/cryptship/payload.enc.demo-compiled.shuses the same scan.USER 65532:65532and create a state dir that user owns. The hardeneddocker runindeploy/README.mdgets--user 65532:65532and a tmpfs owned by that uid.not_after, the loader records the latest start time. The record is sealed with AES-GCM under a key derived from the content key and license id. The loader refuses to start if the clock is more than 24h behind that record. This is best effort and documented as such: deleting the state resets it, and a state dir it cannot write disables it with a warning.Other bugs found in review
s -> "."andt -> "s/.."createdtpointing at the parent of the extract dir, in either entry order. Targets may now use..only as leading components, and no higher than the link's own depth.TarDirapplies the same rule at pack time and now closes each file right away (the deferredCloseinside the walk kept every file open).prepareDiremptied whateverCRYPTSHIP_EXTRACTnamed, so a typo like/home/userwiped that directory. It now only empties an empty dir, or one marked by an earlier run.license_idraw, so an id containing/could put it outside the state dir. The id is now escaped.grace:treated a future last-success time as within grace.O_EXCL.master-keyoverwrote an existing master key, which breaks every online/attested license issued under it. It now needs--force, askeygenalready does.ErrDenied.Fixes #7
Fixes #1
Fixes #6
Part of #3
Part of #5
Part of #2
Testing
All runs used Docker (colima, Docker 29.5.2) with
golang:1.24(go1.24.13 linux/arm64).gofmt -l .(empty), thengo vet ./...,go build ./...,go build -tags cryptship_devfp ./cmd/cryptship-loaderandgo test -race -count=1 ./.... Result: pass, 8 packages with tests, 0 failures.revocation_url, entitlements, edition,signing_key_idorbinding.maxstops a v2 license from unwrapping. The same edits still unwrap a v1 license.vfrom 1 to 2 or from 2 to 1 does not unwrap.--require-attestationwith no verifier returns an error.prepareDir, manifest, state-file name, grace and clock tests.TestV2EditedClaimsDoNotUnwrapfail. Restoring the old wrap order makesTestWrapIntoPoolEveryFingerprintUnwrapsfail.mainCLI all run.node-aandnode-band is refused onnode-c.master-keyis refused.cryptship-server --require-attestationexits 1.bash scripts/demo.sh,bash scripts/demo-compiled.shandbash scripts/demo-online.shall exit 0. The images run as uid 65532, and the hardeneddocker runfromdeploy/README.md(with seccomp) runs the demo.Not fixed (and why)
memfd_create/fexecve,PR_SET_DUMPABLEhelpers): not small, so not done here.revocation_url(an on-path attacker, a captive portal) counts as "not revoked", even withCRYPTSHIP_REVOCATION=closed. The grace state file is plain text, so anyone who can write the state dir can extend grace. Fixing this needs a signed response, which is a protocol change.--expires YYYY-MM-DDexpires at 00:00 UTC at the start of that day. Changing it would change existing behaviour, so it is left as is.scripts/check-mermaid.sh's docker fallback fails on a Linux host: itsmktemp -ddir is 0700, so the mermaid-cli container user cannot read it. CI usesmmdcand is not affected.Claims.BindingContext()now returns([]byte, error),licenseserver.Server.Verifyis nowVerifier, andkeyprovider.MockAttesteris removed.