Profpatsch/users/Profpatsch/passkey-gate
- db.go 4.2 KiB
- default.nix 674 B
- gate.go 19.6 KiB
- gate_test.go 14.3 KiB
- go.mod 1.0 KiB
- go.sum 4.0 KiB
- main.go 5.3 KiB
- nixos-module.nix 5.4 KiB
- pages.go 11.5 KiB
- passkey-gate.1 6.8 KiB
passkey-gate(1)
NAME
passkey-gate - guard a website with passkeys, for nginx's auth_request
SYNOPSIS
passkey-gate
serve
--origin url
[--db path]
[--listen addr]
[--title text]
passkey-gate
enroll
--origin url
[--db path]
passkey-gate
passkey list
[--db path]
passkey-gate
passkey remove
[--db path]
id
passkey-gate
token create
--name name
[--db path]
passkey-gate
token list
[--db path]
passkey-gate
token revoke
--name name
[--db path]
passkey-gate
logout-all
[--db path]
DESCRIPTION
passkey-gate
stands in front of one website and lets in whoever holds one of its passkeys.
nginx asks it before every request it protects, with
auth_request,
and it answers 204 or 401; the application behind it is not told anything and
needs no change.
There is one owner. Every enrolled passkey is theirs, and any of them logs in; the gate knows nobody by name. A person typically has one passkey per device: the phone's, unlocked by fingerprint, and one kept by a password manager such as KeePassXC on the laptop.
A passkey is bound to the host in --origin and works there and nowhere else, including other subdomains. Changing the host makes every passkey useless.
Logging in sets a session cookie for 30 days. Clients without a browser send a bearer token instead; see TOKENS.
COMMANDS
serve
Serve the gate. --origin is the site's address as the browser names it,
https://host; WebAuthn refuses anything else but localhost. --listen isunix:/path (the default is /run/passkey-gate/gate.sock) for a socket created mode 0660, so that nginx gets in through the group and nobody else does, or a TCP address. --title is what the pages call the site; the host by default.
enroll
Print a link that adds a passkey, valid once and for 15 minutes. Open it on the device that is to hold the passkey. This is how the first passkey comes to exist, and the way back in when every device is lost. Adding a passkey also logs that browser in.
passkey list
The enrolled passkeys, with their ids, names, when they were added and last used, and how many sessions each has open.
passkey remove id
Remove a passkey and end every session it opened. Unlike the web page, this removes the last one too.
token create --name name
Make a bearer token and print it, once; only its hash is kept.
token list
token revoke --name name
logout-all
End every session. Passkeys and tokens stay.
--db defaults to /var/lib/passkey-gate/gate.db. The commands work while serve runs.
ROUTES
/.gate/auth
For nginx: 204 if the request carries a live session cookie or a known bearer token, 401 otherwise. No body.
/.gate/denied
For nginx, as the
error_pageof a 401: a browser asking for a page is redirected to the login page and, after logging in, back to where it was going, as passed in theX-Gate-Nextheader; any other client gets the 401, with what to do in the body.
/.gate/login
The login page: one button, which asks the browser for any passkey of this site, with user verification – the fingerprint, the PIN, the password manager's prompt. No name is typed.
/.gate/enroll/secret
Add a passkey, from a link enroll printed.
/.gate/passkeys
List, rename and remove passkeys and revoke tokens, and add a passkey on the device in hand. Needs a session; a token does not open it.
POST /.gate/logout
Every POST is refused unless the browser says it came from the gate's own
pages
(Sec-Fetch-Site, Origin).
The pages run one inline script, permitted by its hash in the
Content-Security-Policy, and nothing else.
NGINX
The gate's locations are mounted into the protected site's own vhost, so that the session cookie is the site's and the login page is on the site's host. The NixOS module nixos-module.nix beside the sources runs one gate per site and exports them, for the site's module to merge into its vhost:
profpatsch.passkeyGate.campusweb.origin = "https://campusweb.example.org";
services.nginx.virtualHosts."campusweb.example.org".locations =
config.profpatsch.passkeyGate.campusweb.nginxLocations // {
"/" = {
proxyPass = "http://unix:/run/campusweb/campusweb.sock:";
extraConfig = ''
auth_request /.gate/auth;
error_page 401 = @gate-denied;
proxy_set_header Authorization "";
proxy_set_header Cookie "";
'';
};
};
A location without
auth_request
is not protected; that is how a site leaves out what must be public.
Removing
Authorization
and
Cookie
before the application keeps the gate's credentials away from it.
The module also installs passkey-gate-name, which runs the commands as the gate's user against its database:
# passkey-gate-campusweb enroll
# passkey-gate-campusweb token create --name rolery-llm
TOKENS
A token is for a program reading the site, such as curl(1) or a language model's tool, from wherever it runs:
$ curl -H "Authorization: Bearer $TOKEN" https://campusweb.example.org/
It is accepted wherever a session is, except on the gate's own pages, and it does not expire; revoke it when the program that holds it is done.
FILES
/var/lib/passkey-gate/gate.db
SQLite: the passkeys' public keys, and SHA-256 of every session, token and enrollment link, which are only ever shown to their holder. Losing it loses nothing secret, and locks everybody out until a new passkey is enrolled.
SEE ALSO
campusweb(1)
WebAuthn: https://www.w3.org/TR/webauthn-3/
AUTHORS
Profpatsch <mail@profpatsch.de>
CAVEATS
The session lives server-side, and that is the point
The cookie is a random value; the gate looks it up. Removing a passkey ends the sessions it opened, and logout-all ends all of them, at once.
Attestation is not asked for
The gate does not ask an authenticator to prove what it is, and accepts any that does WebAuthn with user verification. It is protecting one person's site from everybody else, not choosing which hardware that person may use.
A ceremony in progress does not survive a restart
The challenge sent to the browser is kept in memory for five minutes. After a restart in between, the button has to be pressed again.
Signature counters are not enforced
Synced passkeys, which is what a phone and a password manager hold, report a counter of zero every time, and a gate that insisted on it rising would refuse them.
Some authenticators may not verify the user
The gate requires user verification. An authenticator that cannot do it – a security key without a PIN set – is refused, at enrollment and at login.