Add Web Key Directory (WKD)
This commit is contained in:
@@ -1,186 +1,123 @@
|
||||
# GPG Public Key Server
|
||||
# GPG Public Key Server with Web Key Directory (WKD)
|
||||
|
||||
A lightweight Dockerized Nginx service for publishing **OpenPGP/GPG public keys** over HTTP. It provides a simple, read-only directory of downloadable public-key files and can run behind an existing HTTPS reverse proxy.
|
||||
A small Docker/Nginx service that publishes OpenPGP public keys as static files. It supports the **WKD direct method** as well as optional human-downloadable armored keys. WKD lets compatible OpenPGP clients discover a public key from an email address and its domain.
|
||||
|
||||
> **Scope:** This project serves static files. It is not a full HKP/HKPS OpenPGP keyserver and does not implement Web Key Directory (WKD), key submission, key search, or key synchronization.
|
||||
> This is a static WKD publisher, not a full HKP/HKPS keyserver or a key-submission service. It does not automatically verify ownership of email addresses or update/revoke published keys.
|
||||
|
||||
## Features
|
||||
|
||||
- Nginx-based Docker image
|
||||
- Read-only mount for published key files
|
||||
- Serves keys from `/keys/`
|
||||
- Directory listing disabled
|
||||
- Health-check endpoint at `/healthz`
|
||||
- Basic security headers
|
||||
- Read-only container filesystem
|
||||
|
||||
## Project structure
|
||||
## Files
|
||||
|
||||
```text
|
||||
gpg-keyserver/
|
||||
gpg-keyserver-wkd/
|
||||
├── Dockerfile
|
||||
├── docker-compose.yml
|
||||
├── nginx.conf
|
||||
└── keys/
|
||||
└── .gitkeep
|
||||
├── publish-wkd-key.sh
|
||||
├── README.md
|
||||
├── keys/ # Optional ASCII-armored downloads
|
||||
└── wkd/
|
||||
├── policy # WKD policy marker (created by script)
|
||||
└── hu/ # Binary public keys named by WKD hash
|
||||
```
|
||||
|
||||
Create the `keys/` directory if it does not already exist.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Docker Engine
|
||||
- Docker Compose v2 (`docker compose`)
|
||||
- GPG installed on the machine where you export keys
|
||||
- Docker Engine and Docker Compose v2
|
||||
- GnuPG installed on the host for key export
|
||||
- A domain you control and HTTPS for production
|
||||
|
||||
## Build and start
|
||||
## Start the container
|
||||
|
||||
From the project directory, run:
|
||||
From this directory:
|
||||
|
||||
```bash
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
Check the container and logs:
|
||||
|
||||
```bash
|
||||
docker compose ps
|
||||
docker compose logs -f gpg-keyserver
|
||||
curl -f http://localhost:8088/healthz
|
||||
```
|
||||
|
||||
Check the health endpoint:
|
||||
Expected health response: `OK`. The service is available locally on port `8088`.
|
||||
|
||||
## Publish a WKD key
|
||||
|
||||
First ensure the public key for the target email address is in your local GPG keyring. Export **public keys only**; never export secret/private keys to this service.
|
||||
|
||||
On Linux, macOS, or WSL, run from this project directory:
|
||||
|
||||
```bash
|
||||
curl http://localhost:8088/healthz
|
||||
./publish-wkd-key.sh user@example.com
|
||||
```
|
||||
|
||||
Expected response:
|
||||
The script uses `gpg-wks-client --print-wkd-hash` to compute the WKD filename, exports a binary public key into `wkd/hu/<hash>`, creates the `wkd/policy` marker, and exports an optional ASCII-armored copy into `keys/user@example.com.asc`.
|
||||
|
||||
```text
|
||||
OK
|
||||
```
|
||||
The Docker container mounts `wkd/` and `keys/` read-only. Files added or updated on the host are served without rebuilding the image.
|
||||
|
||||
The sample Compose configuration maps host port `8088` to container port `80`, making the service available locally at `http://localhost:8088`.
|
||||
|
||||
## Export and publish a public key
|
||||
|
||||
Export only the public key. Replace the example address with the email address associated with your key:
|
||||
### Manual export (if you prefer)
|
||||
|
||||
```bash
|
||||
gpg --armor --export user@example.com > keys/user@example.com.asc
|
||||
HASH="$(gpg-wks-client --print-wkd-hash user@example.com | awk 'NR==1 {print $1}')"
|
||||
mkdir -p wkd/hu
|
||||
: > wkd/policy
|
||||
gpg --batch --export user@example.com > "wkd/hu/$HASH"
|
||||
```
|
||||
|
||||
An ASCII-armored public key should begin with:
|
||||
The WKD object should be a binary OpenPGP export. The public key must contain the intended email address in a user ID, and you should verify its fingerprint independently before publishing.
|
||||
|
||||
## URL layout and DNS/HTTPS
|
||||
|
||||
This configuration implements the **direct method**. For `user@example.com`, the path is:
|
||||
|
||||
```text
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
https://example.com/.well-known/openpgpkey/hu/<WKD_HASH>?l=user
|
||||
```
|
||||
|
||||
The key will be available at:
|
||||
The policy marker must be available at:
|
||||
|
||||
```text
|
||||
http://localhost:8088/keys/user@example.com.asc
|
||||
https://example.com/.well-known/openpgpkey/policy
|
||||
```
|
||||
|
||||
Test retrieval:
|
||||
Replace `example.com` with your actual email domain. The Nginx container itself only speaks HTTP on port 80; put it behind your existing HTTPS reverse proxy and route the domain's requests to this service. The certificate must be valid for the email domain. WKD requires HTTPS; do not treat plain HTTP testing as production validation.
|
||||
|
||||
For the direct method, the email domain itself must serve `/.well-known/openpgpkey/`. If your main website already owns that domain, configure its reverse proxy to route that path to this service, or merge the WKD files and Nginx location into the existing web server. Do not simply point the whole domain at this container if that would replace your existing website.
|
||||
|
||||
The alternative **advanced method** uses `https://openpgpkey.example.com/.well-known/openpgpkey/example.com/...` and requires a dedicated `openpgpkey` subdomain with HTTPS. This sample is configured for the direct method only.
|
||||
|
||||
## Test WKD
|
||||
|
||||
After configuring DNS and HTTPS, use GnuPG from a client machine:
|
||||
|
||||
```bash
|
||||
curl -f http://localhost:8088/keys/user@example.com.asc
|
||||
gpg --locate-keys --auto-key-locate clear,nodefault,wkd user@example.com
|
||||
```
|
||||
|
||||
The `keys/` directory is bind-mounted read-only into the container. Add, replace, or remove files on the host; a container rebuild is not required for file changes.
|
||||
You can also check the raw key URL locally after publishing. Substitute the hash printed by the script:
|
||||
|
||||
## Configuration
|
||||
|
||||
### Change the host port
|
||||
|
||||
In `docker-compose.yml`, change:
|
||||
|
||||
```yaml
|
||||
ports:
|
||||
- "8088:80"
|
||||
```bash
|
||||
curl -f http://localhost:8088/.well-known/openpgpkey/hu/<WKD_HASH>
|
||||
```
|
||||
|
||||
For example, use `"8090:80"` to expose the service on host port 8090.
|
||||
A successful local HTTP request verifies file serving only; final validation must use the public HTTPS URL and your real email domain.
|
||||
|
||||
### Add keys
|
||||
## Security and maintenance
|
||||
|
||||
Place exported public-key files in `./keys/`. The URL path after `/keys/` matches the filename, for example `keys/user@example.com.asc` is served at `/keys/user@example.com.asc`.
|
||||
|
||||
### HTTPS and production deployment
|
||||
|
||||
The sample Nginx configuration listens on HTTP inside the container. For production, put the service behind your existing HTTPS reverse proxy and publish it under a domain you control, such as `keys.example.com`.
|
||||
|
||||
1. Configure TLS certificates and renewal at the reverse proxy.
|
||||
2. Route requests to the container on port 80 over a trusted Docker network.
|
||||
3. Verify key fingerprints through a trusted, separate channel before relying on a key.
|
||||
4. Keep private keys out of `keys/`, out of the Docker image, and out of source control.
|
||||
|
||||
If your reverse proxy runs in Docker, connect both services to a shared Docker network and route to the `gpg-keyserver` service on port 80. Adapt the Compose file to your proxy architecture.
|
||||
|
||||
## Security notes
|
||||
|
||||
- **Never publish private keys.** Do not use `gpg --export-secret-keys` for this service.
|
||||
- Public-key files are not secret, but hosting a key does not prove that it belongs to the email address in its filename.
|
||||
- Verify fingerprints independently before using a key to encrypt sensitive email.
|
||||
- Nginx directory listings are disabled, and the Compose configuration mounts `./keys` as read-only.
|
||||
- The Compose configuration enables a read-only container filesystem.
|
||||
- The sample `Access-Control-Allow-Origin: *` header permits browser-based cross-origin reads. Remove it from `nginx.conf` if browser clients do not need cross-origin access.
|
||||
- This service has no upload endpoint, key validation, revocation processing, or key-management interface.
|
||||
- Never put private keys, secret-key exports, passwords, or private key backups in `keys/` or `wkd/`.
|
||||
- Public keys are public, but their association with an email address should be verified before publication.
|
||||
- Directory listing is disabled; only GET and HEAD are allowed for key paths.
|
||||
- WKD does not itself prove a key is safe or current. Publish updates and revocations when appropriate, and verify fingerprints through a separate trusted channel.
|
||||
- The sample grants `Access-Control-Allow-Origin: *` only for WKD paths because browser-based clients may need cross-origin reads.
|
||||
- Keep the reverse proxy and TLS certificates correctly configured and renewed.
|
||||
|
||||
## Useful commands
|
||||
|
||||
Stop the service:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
```
|
||||
|
||||
Restart it:
|
||||
|
||||
```bash
|
||||
docker compose logs -f gpg-keyserver
|
||||
docker compose restart
|
||||
```
|
||||
|
||||
Rebuild after changing the Dockerfile or Nginx configuration:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
Follow logs:
|
||||
## References
|
||||
|
||||
```bash
|
||||
docker compose logs -f gpg-keyserver
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### `404 Not Found`
|
||||
|
||||
- Confirm the key file exists under `./keys/`.
|
||||
- Check the filename and URL spelling, including the `.asc` suffix.
|
||||
- Inspect logs with `docker compose logs gpg-keyserver`.
|
||||
|
||||
### Port already in use
|
||||
|
||||
Change the host-side port in `docker-compose.yml`, for example from `"8088:80"` to `"8090:80"`, then run:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### Health check fails
|
||||
|
||||
Check the container state and logs:
|
||||
|
||||
```bash
|
||||
docker compose ps
|
||||
docker compose logs gpg-keyserver
|
||||
```
|
||||
|
||||
Confirm that `nginx.conf` contains the `/healthz` endpoint and that Nginx starts successfully.
|
||||
|
||||
## Possible next step: Web Key Directory (WKD)
|
||||
|
||||
If you need automatic email-address-based public-key discovery, implement **OpenPGP Web Key Directory (WKD)** rather than relying on arbitrary static URLs. If you need keyserver-protocol lookup and submission, deploy an HKP/HKPS-compatible keyserver. Neither capability is provided by this static Nginx service.
|
||||
- [GnuPG Wiki: WKD](https://wiki.gnupg.org/WKD)
|
||||
- [GnuPG Wiki: WKD hosting](https://wiki.gnupg.org/WKDHosting)
|
||||
- [OpenPGP Web Key Directory specification draft](https://datatracker.ietf.org/doc/draft-koch-openpgp-webkey-service/)
|
||||
|
||||
Reference in New Issue
Block a user