first commit

This commit is contained in:
2026-10-10 22:23:26 +03:00
commit 4bbcd31694
5 changed files with 271 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
FROM nginx:alpine
LABEL description="HTTP server for OpenPGP public keys"
RUN rm -f /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
RUN mkdir -p /usr/share/nginx/html/keys \
&& chown -R nginx:nginx /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
+186
View File
@@ -0,0 +1,186 @@
# GPG Public Key Server
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.
> **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.
## 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
```text
gpg-keyserver/
├── Dockerfile
├── docker-compose.yml
├── nginx.conf
└── keys/
└── .gitkeep
```
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
## Build and start
From the project directory, run:
```bash
docker compose up -d --build
```
Check the container and logs:
```bash
docker compose ps
docker compose logs -f gpg-keyserver
```
Check the health endpoint:
```bash
curl http://localhost:8088/healthz
```
Expected response:
```text
OK
```
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:
```bash
gpg --armor --export user@example.com > keys/user@example.com.asc
```
An ASCII-armored public key should begin with:
```text
-----BEGIN PGP PUBLIC KEY BLOCK-----
```
The key will be available at:
```text
http://localhost:8088/keys/user@example.com.asc
```
Test retrieval:
```bash
curl -f http://localhost:8088/keys/user@example.com.asc
```
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.
## Configuration
### Change the host port
In `docker-compose.yml`, change:
```yaml
ports:
- "8088:80"
```
For example, use `"8090:80"` to expose the service on host port 8090.
### Add keys
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.
## Useful commands
Stop the service:
```bash
docker compose down
```
Restart it:
```bash
docker compose restart
```
Rebuild after changing the Dockerfile or Nginx configuration:
```bash
docker compose up -d --build
```
Follow logs:
```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.
+32
View File
@@ -0,0 +1,32 @@
services:
gpg-keyserver:
build:
context: .
dockerfile: Dockerfile
container_name: ep-gpg-keyserver
restart: unless-stopped
ports:
- "8088:80"
volumes:
- ./keys:/usr/share/nginx/html/keys:ro
healthcheck:
test: ["CMD", "wget", "-q", "-O", "/dev/null",
"http://127.0.0.1/healthz"]
interval: 30s
timeout: 5s
retries: 3
read_only: true
tmpfs:
- /var/cache/nginx
- /var/run
- /tmp
security_opt:
- no-new-privileges:true
View File
+39
View File
@@ -0,0 +1,39 @@
```nginx
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
server_tokens off;
autoindex off;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Access-Control-Allow-Origin "*" always;
location = /healthz {
access_log off;
default_type text/plain;
return 200 "OK\n";
}
location /keys/ {
limit_except GET HEAD {
deny all;
}
types {
text/plain asc;
text/plain txt;
}
default_type application/octet-stream;
try_files $uri =404;
}
location / {
return 404;
}
}
```