Skip to content

[WIP] fix(ssh): write allowed signers that OpenSSH reads back - #55

Draft
timweri wants to merge 3 commits into
fix/allowed-signer-parsefrom
fix/allowed-signer-write
Draft

timweri wants to merge 3 commits into
fix/allowed-signer-parsefrom
fix/allowed-signer-write

Conversation

@timweri

@timweri timweri commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Flagged by Opus 5.5. Display wrote space-separated options, unquoted values and raw UNIX timestamps, which OpenSSH rejects. It also copied the key comment, so a comment with a newline added another trusted entry.

This replaces it with AllowedSigner::to_line(), which writes what OpenSSH reads and fails on entries it can't write. from_string now rejects what to_line can't write back: a line feed or NUL in a principal or namespace, and certificate keys.

alice cert-authority namespaces=git valid-after=1714867200 ssh-ed25519 AAAA... comment   # before
alice cert-authority,namespaces="git",valid-after="20240505000000Z" ssh-ed25519 AAAA...  # after

Stacked on #54.

BREAKING CHANGE: AllowedSigner no longer implements Display; use to_line(). from_string rejects certificate keys, and line feeds or NULs in principals and namespaces. AllowedSignerParsingError is now #[non_exhaustive].

Replace AllowedSignerSplitter with a parser that follows OpenSSH's
parse_principals_key_and_options() and sshsigopt_parse() in sshsig.c.

Options are one comma-separated field with double-quoted values, as
OpenSSH requires. Space-separated options and unquoted values, which
OpenSSH rejects, are now rejected too. Like OpenSSH 10.2, option names
and the timestamp suffix (Z or UTC) are case-insensitive, valid-after
and valid-before must be after the epoch, and any text after the key
is a comment.

BREAKING CHANGE: lines with space-separated options or unquoted values
no longer parse, including lines written by the old Display.
AllowedSignerParsingError::UnexpectedEnd and InvalidTimestamp are
removed.
Display wrote space-separated options with unquoted values and raw
UNIX timestamps, which OpenSSH rejects. Replace it with
AllowedSigner::to_line(), which writes one comma-separated options
field with quoted values, timestamps as YYYYMMDDHHMMSSZ and the plain
key type, and quotes the principals when needed.

to_line() fails when OpenSSH would read a field back differently, such
as a comma inside a principal or a timestamp that isn't after the
epoch. It also fails for a certificate key, which PublicKey can't
encode.

The key's comment is left out. from_string() ignores it, and a line
break in it would add another entry to the file.

DateTime::from_timestamp() needs chrono 0.4.31.

BREAKING CHANGE: AllowedSigner no longer implements Display; use
to_line().
from_string() accepted a few entries that to_line() can't write, so
to_line() failed on them. Reject them when parsing instead:

- a line feed or NUL in a principal or namespace. OpenSSH would read a
  line feed as the start of a new entry, and reads a line as a C string.
- a certificate as the key. PublicKey reads the wrong bytes as the key.

Mark AllowedSignerParsingError as #[non_exhaustive], so fixes like
these can add a variant without another breaking change.

Add a test that checks lines written by to_line() with ssh-keygen -Y
verify. It's skipped when ssh-keygen isn't installed.

BREAKING CHANGE: from_string() rejects certificate keys, and line feeds
or NULs in principals and namespaces. AllowedSignerParsingError is
now #[non_exhaustive].
@timweri
timweri force-pushed the fix/allowed-signer-write branch from 4a76ab5 to ceaf028 Compare November 10, 2026 03:38

This branch has not been deployed

No deployments
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