From cac3f3dc5fa8a83a8559750fc3f1c5054c08948e Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Mon, 7 Sep 2026 04:28:26 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8B=F0=9F=94=A7=EF=BC=9Awrite=20out=20?= =?UTF-8?q?the=20one=20key,=20not=20everything=20offered?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found reviewing the port of this file into the portal, where it landed as 86ecc82. The count and the thing written were not the same list. `count` is how many of `ssh-add -L`'s lines look like a key type this accepts. The file was then written from `identities`, which is every line the agent offered. An agent forwarding a certificate alongside the key it belongs to prints two lines and matches one -- the certificate is `ssh-ed25519-cert-v01@openssh.com`, deliberately not an accepted type -- so the guard passed and wrote both. Two keys in that file breaks both readers of it. `ssh-keygen -Y sign -f` wants one public key, and allowed_signers takes its second field from `awk '{print $1, $2}'` over the whole file, which becomes a second line in a grammar that has room for none. The matching lines are kept now and the count taken from those, so what is counted is what is written. Checked against a single key, a key plus its certificate, two real keys, an ECDSA key, and "The agent has no identities.": one line written in the first, second and fourth, and a refusal in the others. The file is byte-identical to the portal's again with this. Signed-off-by: Derek Lewis Assisted-by: Claude-Code:claude-opus-5 --- .devcontainer/post-start.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.devcontainer/post-start.sh b/.devcontainer/post-start.sh index a89b687a..0dfa9e67 100755 --- a/.devcontainer/post-start.sh +++ b/.devcontainer/post-start.sh @@ -31,16 +31,25 @@ if [ "$(git config --global gpg.format 2>/dev/null || true)" = "ssh" ]; then # Matched by key type. `^ssh-` misses ECDSA and security keys; counting # non-blank lines instead would read "The agent has no identities." as an # identity and write that sentence out as the key. - count="$(printf '%s\n' "${identities}" | - grep -cE '^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp[0-9]+|sk-(ssh-ed25519|ecdsa-sha2-nistp[0-9]+)@openssh\.com) ' || + # + # Kept rather than counted, because the two are not the same list. An + # agent forwarding a certificate alongside the key it belongs to offers + # `ssh-ed25519-cert-v01@openssh.com`, which is deliberately not a type + # this accepts -- so the count is one while `ssh-add -L` printed two + # lines. Writing the unfiltered output would put two keys in a file + # `ssh-keygen -Y sign -f` reads one from, and give allowed_signers a + # second line where its grammar has room for none. + matched="$(printf '%s\n' "${identities}" | + grep -E '^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp[0-9]+|sk-(ssh-ed25519|ecdsa-sha2-nistp[0-9]+)@openssh\.com) ' || true)" + count="$(printf '%s\n' "${matched}" | grep -c . || true)" if [ "${count}" -eq 1 ]; then # Split because -m applies only to the deepest directory (SC2174), and # unconditional because ssh refuses a world-writable ~/.ssh. mkdir -p "$(dirname "${container_signingkey}")" chmod 700 "$(dirname "${container_signingkey}")" - printf '%s\n' "${identities}" >"${container_signingkey}" + printf '%s\n' "${matched}" >"${container_signingkey}" chmod 644 "${container_signingkey}" if [ "${signingkey}" != "${container_signingkey}" ]; then