Skip to content

fix(prelaunch): v0.0.22 - stop installing user_config SSH keys as root - #177

Draft
kvinwang wants to merge 1 commit into
mainfrom
fix/prelaunch-drop-user-config-ssh
Draft

kvinwang wants to merge 1 commit into
mainfrom
fix/prelaunch-drop-user-config-ssh

Conversation

@kvinwang

@kvinwang kvinwang commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Draft: needs a Phala Cloud owner's decision. This changes product behaviour. Workspace SSH keys that Phala Cloud delivers through user_config stop working for apps that run this pre-launch script. The Phala Cloud owner should decide whether to ship this. They also need to assign the version number (v0.0.22 here) and register the new script hash as official.

Problem

prelaunch.sh appends user_config.ssh_authorized_keys to root's authorized_keys. The host supplies user_config. It is not measured, not authenticated and not filtered by allowed_envs. On any image that ships sshd, which means every dstack 0.5.x dev image, whoever runs the host can give itself root SSH.

This combines with an integer manifest_version and with a KMS that admits dev images. A host can then start an extra instance of the app that the owner does not know about, log in as root, and read the app keys.

DSTACK_AUTHORIZED_KEYS / DSTACK_ROOT_PUBLIC_KEY / DSTACK_ROOT_PASSWORD from the encrypted env have the same problem in a weaker form. Encrypted env is HPKE base mode sealed to a public key, so anyone can forge it. This PR leaves those variables in place and documents the risk.

Fix

  • The user_config.ssh_authorized_keys branch no longer writes anything. It logs Ignoring ssh_authorized_keys from user_config (host-supplied, unauthenticated).
  • The key count and fingerprint log (v0.0.19) now run on whatever the env vars installed. The boot log still lists every authorized key.
  • Version banner: v0.0.21 → v0.0.22. Everything else in the script is unchanged.
  • README: new "SSH access" section. It covers the env-var channel and why it is unauthenticated, links to the dstack mitigations (APP_LAUNCH_TOKEN, KMS launch tickets), and explains migration.

Why remove the branch instead of limiting it to dev images: only dev images ship sshd, so a dev-only rule would keep the hole exactly where it exists. The script also has no reliable signal for the image flavour. Build flavour is not written to /etc/os-release, and user_config and host-shared files are host-controlled.

Migration

  • Apps that got SSH access from Phala Cloud workspace keys (user_config) need to put those keys in the DSTACK_AUTHORIZED_KEYS encrypted env, with the risk documented in the README.
  • The pre-launch script is part of app-compose.json. Switching to v0.0.22 changes the compose hash, so for apps governed on chain the new hash must be whitelisted first.
  • /home is a tmpfs overlay in the guest. Keys that an older version installed from user_config are gone after the first boot with v0.0.22.

Verification

  • bash -n passes.
  • shellcheck: same 5 warnings before and after, all pre-existing (SC2034 comment, SC2155 export). Nothing new.
  • I extracted the SSH block from the old and new scripts and ran each against temp paths, with one env key and one different user_config key:
    • v0.0.21 installed both keys.
    • v0.0.22 installs only the env key, logs the ignore line, and prints that key's fingerprint.
    • With only a user_config key, v0.0.22 creates no authorized_keys.
  • New script sha256: c5b4e3b9b5f30fed24118fbe37545c6dabfd09586d74baf08a9d4ae60abba601. It is not in the official hash list yet.

Not done: no boot test on a real CVM.

Open questions

  1. Does Phala Cloud accept losing user_config SSH delivery? If it does, the dashboard needs a different way to deliver workspace keys, and v0.0.22 needs an entry in the official script hash list.
  2. dev-box/entrypoint.sh (dstack 0.6) reads user_config.ssh_authorized_keys itself, and its README states that trust boundary. This PR does not change it. It needs the same decision.
  3. default_gateway_domain is still read from user_config, ahead of app-compose.json. That is host-controlled, but it only sets DSTACK_GATEWAY_DOMAIN/DSTACK_APP_DOMAIN, so this PR leaves it unchanged.
  4. The underlying exposure is KMS admitting dev images for production apps. This script change only removes one easy path to root.

The script appended user_config.ssh_authorized_keys to root's
authorized_keys. The host supplies user_config: it is not measured, not
authenticated and not filtered by allowed_envs. On any image with sshd,
which means every dstack 0.5.x dev image, whoever ran the host could
therefore log in as root.

v0.0.22 ignores that key and logs that it did. The key count and
fingerprint log now cover whatever the encrypted env installed, so the
boot log still lists every authorized key.

The README documents the remaining channel, DSTACK_AUTHORIZED_KEYS,
DSTACK_ROOT_PUBLIC_KEY and DSTACK_ROOT_PASSWORD from the encrypted env.
Anyone can produce a valid encrypted env, because it is sealed to a
public key, so these are for dev images on trusted hosts only. The
README also covers migration for apps that used user_config keys.

Signed-off-by: Kevin Wang <wy721@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant