feat: enhance user account management during VM creation with automatic user creation and metadata preservation

This commit is contained in:
2026-09-22 00:07:37 +05:30
parent c75c7d9baf
commit 71425a98e3
7 changed files with 347 additions and 22 deletions
+19 -7
View File
@@ -526,18 +526,28 @@ make recovery convenient. Proven-gone legacy processes can be cleaned up.
### Template Contract
`images/ubuntu.ext4` is a template only. Each create operation copies it into
the VM runtime directory before UVM modifies the requested existing account's
shadow entry and OpenSSH password policy with `debugfs`. Firecracker only sees
the VM runtime directory before UVM provisions the requested account, its
shadow entry, and OpenSSH password policy with `debugfs`. Firecracker only sees
the resulting private copy. Never change that to a shared writable rootfs.
Copies use coreutils `cp --reflink=auto --sparse=always`; the new disk is resized
to the requested capacity before credential provisioning. Existing disk resizes
do not reprovision credentials or host keys.
Guest images must provide `/etc/passwd`, `/etc/shadow`, OpenSSH's
`/etc/ssh/sshd_config`, and the requested account. UVM does not create missing
users. It replaces conventional RSA, ECDSA, and Ed25519 host keys in each
private disk and removes the known public login key from Firecracker's bionic
image. A VM must never rely on reusable SSH private keys from a shared template.
Guest images must provide `/etc/passwd`, `/etc/shadow`, and OpenSSH's
`/etc/ssh/sshd_config`. Existing accounts retain their identity, groups, home,
shell, and password-aging policy. Missing custom users are created offline,
using `/etc/group` and an available `/bin/sh` login shell. UVM allocates unused
UIDs/GIDs from 1000-60000, accounting for primary GIDs in passwd as well as
group entries, and reuses a same-named group when present. New group entries
also update `/etc/gshadow` if it exists. Account-file metadata is preserved.
The new `/home/USERNAME` directory is mode `0700`, owned by the new UID/GID;
`/home` is created if absent and existing home paths are not overwritten.
Directory ownership/modes and account-file writes are read back before the
disk can be marked ready. The default `root` account must already exist.
UVM replaces conventional RSA, ECDSA, and Ed25519 host keys in each private
disk and removes the known public login key from Firecracker's bionic image.
A VM must never rely on reusable SSH private keys from a shared template.
### Integrity Model
@@ -880,6 +890,8 @@ exercise the kernel packet path.
`test_storage.py` also exercises real e2fsprogs against temporary unmounted,
sparse ext4 images when the tools are installed: default 30 GiB creation,
growth, shrinking, geometry, and retained data/password-hash/host-key fixtures.
`test_images.py` uses temporary ext4 images to verify custom-user creation,
UID/GID allocation, account/home metadata, existing accounts, and password hashes.
Lifecycle resize tests use fake processes/networking to verify ordering,
single-lock ownership, identity preservation, pending intent, and failure recovery.