412. Signing keys and trust
A KDOS machine decides whom to believe with directories of public keys, one directory for each kind of thing it accepts from elsewhere: prebuilt host packages, application packs, and the ports tree that kdos update fetch installs. TLS certificate authorities are a separate store again. This page covers where each keyring is, what the image puts in it, how to make a key and sign with it, how to trust or stop trusting one, and how to read a refusal.
Installation
The keys are files; the programs that read and write them are on every image:
| Program | Provided by | Uses |
|---|---|---|
kpkg keygen, sign, index --sign, verify-index, verify-pkg, binhost |
kpkg, compiled by 10_bootstrap; see kpkg |
/etc/kdos/keys |
kdos-pack keygen, sign, index --sign, verify |
kdos-pack | /etc/kdos/keys/packs |
kdos-packd, which checks a pack before it is installed |
kdos-packd | /etc/kdos/keys/packs |
kdos update fetch |
kdos-tools | /etc/kdos/keys/tree |
update-ca-certificates, the p11-kit trust module |
ca-certificates, p11-kit | /etc/ca-certificates/trust-source/anchors |
Signatures are Ed25519, made and checked by KDOS’s own libksig; see Signing.
What the image ships in each ring:
| Ring | Shipped key | From |
|---|---|---|
/etc/kdos/keys |
kdos-binhost.pub and kdos-release.pub, the image’s own build’s, when the build found them; otherwise none |
70_image’s 105_ports.sh; fs/etc/kdos/keys/ holds only the README |
/etc/kdos/keys/packs |
kdos-packs.pub |
fs/etc/kdos/keys/packs/ |
/etc/kdos/keys/tree |
kdos-release.pub, when the build had a release key; otherwise none |
70_image’s 105_ports.sh |
The live medium and an installed system carry the same rings; the installer copies them with the rest of the root.
Configuration
/etc/kdos/keys/
The host ring, for a binary host’s index and for a package’s own .sig file. Its README, from fs/etc/kdos/keys/README, states the policy:
Trusted package-signing keys.
Every `*.pub` in this directory is a key this machine will accept a signature
from — for the binhost index (PACKAGES.sig) and for a package's own `.sig`
sidecar. Adding a key is copying a file in; removing trust is deleting one.
There is no revocation list and no online check: the directory IS the policy.
kpkg keygen builder # on the machine that builds
cp builder.pub /etc/kdos/keys/ # on every machine that should trust it
A key id (16 hex characters, printed by kpkg) identifies a key. It is NOT a
credential: a signature file names the id so a person can be told which key
signed, and verification always uses the key from THIS directory.
THE IMAGE SHIPS ITS OWN BUILD'S TWO KEYS HERE: kdos-binhost.pub, which signs
its release's binhost, and kdos-release.pub, which signs the release index
and the slot image. Both come from the same build that made this image, so
trusting them is trusting whoever built the image, which booting the image
already is. They verify the release index, the binhost index (PACKAGES.sig),
each prebuilt package's .sig and the slot image's manifest, and nothing from
another builder. Delete them and this machine takes no prebuilt package and
no slot image; it still builds every port from source, whose integrity comes
from the `sha256 =` lines of its recipe. Add another builder's .pub to trust
that binhost too.
`packs/` IS SHIPPED WITH A KEY, and it is a different question. kdos-packd
checks an application pack's own signature, or a signed pack index (PACKAGES)
beside the packs being imported, against it. Nothing the build makes is signed
with that key and the build does not hold its secret half, so on a fresh system
it verifies nothing; add the `.pub` from `kdos-pack keygen` to trust packs you
sign yourself. It is a subdirectory because a keyring is a flat read of
`*.pub`: a key that vouches for a pack must not thereby vouch for a package
repository.
`tree/` holds the key that signs a published ports tree, which
`kdos update fetch` installs as /ports. The build puts its release key's public
half there; tree/README says how. It is a subdirectory for the same reason.
The image step that fills it, from script/phases/70_image/105_ports.sh, empties it of keys and installs each of the build’s two public keys it finds:
rm -f /etc/kdos/keys/*.pub
for pub in "$RELEASE_PUB" /kdos/build/binhost-key/kdos-binhost.pub; do
if [ -f "$pub" ]; then
install -m 0644 "$pub" "/etc/kdos/keys/${pub##*/}"
echo " /etc/kdos/keys trusts ${pub#/kdos/}"
else
echo " no ${pub#/kdos/}: /etc/kdos/keys does not trust it"
fi
done
script/phases/70_image/105_ports.sh, lines 195–203
Every *.pub directly in the directory is trusted; the loader does not descend into packs/ or tree/, which is what keeps the three rings apart. KPKG_KEYRING names another directory for one kpkg command. Every ring, this one and the two below, is read in name order and holds at most sixteen keys: each .pub past the sixteenth is not trusted, and the loader names it on stderr (DIR: a keyring holds at most 16 keys; NAME.pub is not trusted).
/etc/kdos/keys/packs/
The ring kdos-packd and kdos-pack verify check application packs and pack indexes against. kdos-pack verify --keys DIR, or KDOS_KEYS, points kdos-pack at another; kdos-packd checks against this directory only. The shipped key, from fs/etc/kdos/keys/packs/kdos-packs.pub:
kdos-pubkey-1 0f0a92d672dda877584148b6b03ef7e0c4b3be956a11c3f402db0ffe45a82e2f kdos-packs
fs/etc/kdos/keys/packs/kdos-packs.pub
A public key file is one line: kdos-pubkey-1, the key in hex, and a name. What this key asserts is in Signing and trust.
/etc/kdos/keys/tree/
The ring kdos update fetch checks a published ports tree’s kdos-ports.tar.xz.sig against. Its README, from fs/etc/kdos/keys/tree/README:
Trusted keys for the ports tree.
`kdos update fetch` replaces /ports with a published recipe tree only when
its signature (kdos-ports.tar.xz.sig) verifies against a `*.pub` here. The
build puts the public half of its release key here as kdos-release.pub:
the key `ports/publish --release` signs each system release with, kept in
build/keys/ on the machine that builds and never in git. An image built
without that key carries none, and fetches no tree.
A ring of its own, for the reason packs/ is one: a key that vouches for
recipes must not thereby vouch for packages or packs, and the reverse.
Adding a key is copying a file in; removing trust is deleting one.
The image step that fills it, from script/phases/70_image/105_ports.sh:
RELEASE_PUB=/kdos/build/keys/kdos-release.pub
TREE_RING=/etc/kdos/keys/tree
mkdir -p "$TREE_RING"
rm -f "$TREE_RING"/*.pub
if [ -f "$RELEASE_PUB" ]; then
install -m 0644 "$RELEASE_PUB" "$TREE_RING/kdos-release.pub"
echo " $TREE_RING trusts build/keys/kdos-release.pub"
else
echo " no build/keys/kdos-release.pub: $TREE_RING is empty and this image fetches no tree"
fi
script/phases/70_image/105_ports.sh, lines 185–194
Where fetch looks for the tree is /etc/kdos/update.conf, which is not shipped; see /etc/kdos/update.conf.
Environment variables
| Variable | Read by | Does |
|---|---|---|
KPKG_REQUIRE_SIG=1 |
kpkg (kpkgadd) |
Refuses to install a package with no valid .sig beside it |
KPKG_KEYRING |
kpkg |
Replaces /etc/kdos/keys |
KDOS_REQUIRE_SIG |
kdos-pack verify, from the caller; kdos-packd, from its own environment |
Treats an unsigned pack as a failure |
KDOS_KEYS |
kdos-pack |
Replaces /etc/kdos/keys/packs. kdos-packd reads it only for its status listing; its checks before a mount or an install always use /etc/kdos/keys/packs |
KDOS_TREE_KEYS |
kdos update fetch |
Replaces /etc/kdos/keys/tree |
kdos-packd is started by /etc/init.d/59_packd.sh, which sets no variable before its supervise line:
echo "[KDOS] Starting $NAME..."
supervise "$NAME" "$DAEMON"
fs/etc/init.d/59_packd.sh, lines 25–26
TLS trust anchors
Certificate authorities for TLS are not in any of these rings. The Mozilla bundle is /usr/share/ca-certificates/mozilla.pem, your own roots go in /etc/ca-certificates/trust-source/anchors/, and update-ca-certificates writes the combined /etc/ssl/cert.pem. Which library reads which file is in TLS trust anchors.
Usage
Listing what this machine trusts
ls /etc/kdos/keys /etc/kdos/keys/packs /etc/kdos/keys/tree
cat /etc/kdos/keys/packs/*.pub
Each .pub is one trusted key. kpkg and kdos-pack print a key’s 16-character id when they make or verify with it; the id names a key for a person and grants nothing.
Trusting a binary host
On the machine that builds:
Make a key pair, once:
kpkg keygen builderIt writes
builder.key, the secret half, mode 0600, andbuilder.pub, and prints the key’s id (==> Key <id>). An existingbuilder.keyis never overwritten: a secondkeygen builderendsERROR: cannot write builder.key (it must not already exist).Index and sign a directory of packages:
kpkg index /repo --sign builder.keyIt writes
PACKAGES,PACKAGES.sig, and a.sigbeside every package, and reportsIndexed N package(s) and M delta(s) into /repo/PACKAGES,Signed with key <id>andWrote N package signature(s). A secret key that group or others can read is refused:ERROR: builder.key is readable by other users — refusing to sign with it.
On every machine that should use it:
Copy the public half in:
sudo cp builder.pub /etc/kdos/keys/Check the index, then install from it:
kpkg verify-index /repo sudo kpkg binhost /repo zlibverify-indexprintssignature good (key <id>)and the id of the key that verified, which may differ from the id the signature names. The three testsbinhostmakes before it uses a package are in The binary host; building one with the image is on The binary host.
Signing one package
For a package that travels without an index:
kpkg sign <package>.tar.xz builder.key # writes <package>.tar.xz.sig
kpkg verify-pkg <package>.tar.xz
verify-pkg prints signature good (key <id>), or, for a file changed after it was signed, a key not in the ring, an empty ring or no .sig at all, ERROR: <package>.tar.xz: NO trusted signature and exit status 1.
kpkgadd checks the .sig when it finds one and /etc/kdos/keys holds a key, and refuses the package when it does not verify. A package with no .sig is installed, and so is one with a .sig on a machine whose ring is empty, as an image built without the keys ships it; KPKG_REQUIRE_SIG=1 refuses both.
Signing packs with your own key
Make a pack key, on the machine that makes packs:
kdos-pack keygen mypacksIt writes
mypacks.key(0600) andmypacks.pub, and prints the key’s id beside the public file’s name (mypacks.pub <id>).Sign a pack, or a directory of packs and its index:
kdos-pack sign app.kpack mypacks.key kdos-pack index ./packs --sign mypacks.keysignprintsapp.kpack signed, andindexprints./packs/PACKAGES N entries, signed. A secret key that group or others can read is refused by both:kdos-pack: mypacks.key is readable by other users — refusing to sign with it.On every machine that should accept them, put the public half in the pack ring. To trust only your packs, remove the shipped key as well. No pack the build makes is signed with it, including the optional KDOS base pack on the medium, so removing it refuses nothing the image carries:
sudo cp mypacks.pub /etc/kdos/keys/packs/ sudo rm /etc/kdos/keys/packs/kdos-packs.pubCheck a pack against the ring:
kdos-pack verify app.kpackIt prints
<pack id>: signed by <key id>,<pack id>: unsigned, or the reason the signature failed. A signature by a key that is not in the ring readsbad signature, the same as a pack changed after it was signed, and exits 2;--keys DIRorKDOS_KEYSnames a directory to try instead. With an empty ring a signed pack readssigned, but this machine has no key to check it withand exits 2. WithKDOS_REQUIRE_SIG=1an unsigned pack readsunsigned, and KDOS_REQUIRE_SIG is setand exits 2.
How packs are built and composed is in Building a pack.
Refusing unsigned packs
- As root, edit
/etc/init.d/59_packd.shand addexport KDOS_REQUIRE_SIG=1on the line beforesupervise "$NAME" "$DAEMON". - Restart the daemon:
sudo service restart packd. - From then on
kdos-packdrefuses an unsigned pack at install. A pack mounted straight from a medium is not covered; see How an application is verified.
To see what the daemon would decide about a pack before you import it, run KDOS_REQUIRE_SIG=1 kdos-pack verify <pack>, which makes the same check.
Following a ports tree you publish
A tree is signed with a kpkg key. Make one with kpkg keygen mytree, and sign the archive with kpkg sign kdos-ports.tar.xz mytree.key. ports/publish --release <tag>, which publishes a whole system release, signs the tree it uploads itself, with the key --key names, else $KDOS_RELEASE_KEY, else build/keys/kdos-release.key, and signs the release index kdos-update.idx with the same key and with build/binhost-key/kdos-binhost.key as well, so a machine whose /etc/kdos/keys/ holds either .pub reads the index its binhost and slot image are found through. The archive must hold the tree’s TREE stamp, core/ and sources.idx, or fetch refuses it after the signature has verified.
Replace the tree ring’s key with the public half of the key you sign trees with:
sudo rm /etc/kdos/keys/tree/*.pub sudo cp mytree.pub /etc/kdos/keys/tree/Point
fetchat where you publish, withtree =in/etc/kdos/update.conf, or once:sudo kdos update fetch --from /media/stick/releaseA directory or URL must hold
kdos-ports.tar.xzandkdos-ports.tar.xz.sig.
No published, signed tree has been followed this way yet; treat a refusal as a possible fault in the procedure as well as in the tree.
Trusting a local certificate authority
sudo cp root.crt /etc/ca-certificates/trust-source/anchors/ # PEM only
sudo update-ca-certificates
Firefox, LibreWolf and Thunderbird keep their own store and need the root added in their own settings.
Removing trust
Delete the key’s .pub from its ring. There is no revocation list and no cache: every verification reads the ring afresh, so the next one does not try the deleted key.
Tips
- Keep every
.keyfile off the machines that only verify. A secret key is needed only where you sign. - A build keeps its release key,
kdos-release.key, and the kernel’s module-signing key inbuild/keys/, and the binary host’s key inbuild/binhost-key/;make cleanandmake cleanbuildleave both directories in place. Lose the release key and images already written keep trusting a key nobody can sign trees with. The binary host’s key is made only when it is missing, so deletingbuild/binhost-key/by hand is what makes a new one: the nextKDOS_MAKE_BINHOST=1build signs with it, and every machine holding the oldkdos-binhost.pubrefuses the new index until it is given the new one. - A key placed in the wrong ring is trusted only for that ring’s kind of file. A pack key copied into
/etc/kdos/keyswould make its holder a trusted source of host packages. kdos explain libksigprints the design note on why a key id is not a key; see kdos explain.
Troubleshooting
kpkg verify-index or kpkg binhost prints no trusted keys in /etc/kdos/keys. The ring is empty: the image was built without its build’s keys, or they were deleted. Copy the builder’s .pub in. kpkg binhost exits 2 for this, for a missing index, and for a failed verification.
kpkg binhost prints no trusted signature — refusing to use it. PACKAGES.sig was made by a key that is not in /etc/kdos/keys, or the index changed after it was signed; binhost exits 2. Run kpkg verify-index <dir> to see which. Re-index with --sign on the build machine after changing anything in the directory.
kpkg binhost exits 1 and says build from source. The binhost has no such package, or its architecture, build configuration or recipe hash differs from this machine’s; the message says which. That is a match failure, not a trust failure, and binhost installs nothing: build the port with kpkg install. The build configuration is read from CC and its version, CFLAGS, CXXFLAGS, LDFLAGS and KDOS_TARGET, so different build config usually means the client’s environment is not the one the index was written under; see The binary host.
kdos update check reports no-key or fetch-failed. Run sudo kdos update fetch to see the reason. The ring is read first: an image built without a release key has an empty /etc/kdos/keys/tree, and fetch stops there, before any download, with no trusted tree key in /etc/kdos/keys/tree and the state no-key. With a key, and no /etc/kdos/update.conf, it downloads from the project’s latest release, and a release that carries no tree ends kdos update: https://github.com/kunaldawn/kdos/releases/latest/download/kdos-ports.tar.xz could not be downloaded, after curl’s The requested URL returned error: 404. A tree whose signature does not verify, or whose TREE stamp is older than the installed one, is refused. The states are in kdos update.
A pack import is refused. Read the daemon’s log, /run/kdos-svc.kdos-packd.log. A bad payload hash, a bad signature, or a signature by a key that is not in /etc/kdos/keys/packs is refused; kdos-pack verify <pack> reports the same state without installing.
curl accepts a local root and a GnuTLS program does not, or the reverse. The two sides read different files. update-ca-certificates updates OpenSSL’s /etc/ssl/cert.pem and reports /etc/ssl/cert.pem: the Mozilla bundle and N local anchor file(s); GnuTLS reads the anchors directory through p11-kit at once, so trust list shows a new root before update-ca-certificates has run. A DER file is skipped by update-ca-certificates, which says <file> holds no PEM certificate, skipped; convert it with openssl x509 -in root.der -inform der -out root.crt.
Known gaps
- No published release’s update has been applied to an installed machine
- Secure Boot is not supported: the boot loader is unsigned
- Unsigned packs and unenforced module signatures, among the points in Security
See also
- Signing and trust: the three rings and what each key asserts
- Signing and The binary host: the package side
- How an application is verified: the checks
kdos-packdmakes - Module signing: the kernel’s own key
- /etc/kdos/keys/: the reference
- The binary host, The recipe tree and the source offer, kpkg, Packs, Updating