Compare commits

40 Commits
wizard ... main

Author SHA1 Message Date
John Lancaster
2bbf9b3f53 README tweaks 2026-01-03 09:20:46 -06:00
John Lancaster
86339f5115 default path updates 2026-01-03 00:50:17 -06:00
John Lancaster
5b55b02a76 readme updates 2026-01-03 00:46:48 -06:00
John Lancaster
d7cb02f506 fixes 2026-01-03 00:34:04 -06:00
John Lancaster
3ca2a092fd another rbac 2026-01-02 23:11:47 -06:00
John Lancaster
5e52facc5c tweak 2026-01-02 23:08:38 -06:00
John Lancaster
7914368111 more rbac 2026-01-02 23:08:29 -06:00
John Lancaster
586c4b47bc comments 2026-01-02 15:08:12 -06:00
John Lancaster
cb530aa864 comments 2026-01-02 14:49:10 -06:00
John Lancaster
a5d0b1cb2f comment 2026-01-02 14:37:26 -06:00
John Lancaster
b7537179c9 comments 2026-01-02 14:32:35 -06:00
John Lancaster
be29375bee comments 2026-01-02 14:24:51 -06:00
John Lancaster
454a6fe00c comments 2026-01-02 14:18:20 -06:00
John Lancaster
405e1fc05c ignore log files 2026-01-02 14:12:37 -06:00
John Lancaster
34898d9b11 access log for envoy 2026-01-02 14:12:30 -06:00
John Lancaster
be34df6324 envoy config tweaks 2026-01-02 14:12:22 -06:00
John Lancaster
f92924b74f added role-based access control (RBAC) 2026-01-02 13:32:42 -06:00
John Lancaster
cd190d2e3f converted to envoy for spiffe identity filtering 2026-01-02 09:10:27 -06:00
John Lancaster
13438044e6 caddyfile update 2026-01-01 21:05:11 -06:00
John Lancaster
ecda3d4369 fixed openssl call 2026-01-01 15:40:39 -06:00
John Lancaster
3d377634aa added spiffe identity 2026-01-01 15:29:14 -06:00
John Lancaster
eb37a1992a fixed 2025-12-30 00:40:43 -06:00
John Lancaster
d834a543ee again 2025-12-30 00:38:57 -06:00
John Lancaster
80a59bb0a8 again 2025-12-30 00:37:17 -06:00
John Lancaster
2bfdd5543f tweaked output 2025-12-30 00:35:46 -06:00
John Lancaster
39650c2122 tweaked output 2025-12-30 00:34:27 -06:00
John Lancaster
4fbf229c0d more file checks 2025-12-30 00:25:38 -06:00
John Lancaster
f9347eb2bc enabling both service and timer 2025-12-29 23:54:06 -06:00
John Lancaster
4123ac3c00 line break 2025-12-29 23:52:51 -06:00
John Lancaster
f3bd116e91 removed hostname question 2025-12-29 23:51:08 -06:00
John Lancaster
f6492a2c5f changed defaults 2025-12-29 23:50:41 -06:00
John Lancaster
8f60dad7f6 not changing directory 2025-12-29 23:48:48 -06:00
John Lancaster
b0f1ae358b wizard now bootstrapping cert if it doesn't exist 2025-12-29 23:45:42 -06:00
John Lancaster
487dfe2e45 listing unit files at the end 2025-12-29 23:43:19 -06:00
John Lancaster
d08c3c750e changed default filenames 2025-12-29 22:48:55 -06:00
John Lancaster
83fd98a29b changed default cert dir 2025-12-29 21:57:16 -06:00
John Lancaster
f62d110adc added overwrite protection 2025-12-29 18:45:14 -06:00
John Lancaster
cba3d0eab9 added step-ca installation part 2025-12-29 18:14:47 -06:00
John Lancaster
0fee09099a service tweaks 2025-12-29 01:01:05 -06:00
John Lancaster
8000b32cea checking for crt before setting up service 2025-12-28 23:49:28 -06:00
8 changed files with 265 additions and 69 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
certs/
*.log

View File

@@ -7,7 +7,9 @@
protocols tls1.3
client_auth {
mode require_and_verify
trusted_ca_cert_file /certs/root_ca.crt
trust_pool file {
pem_file /certs/root_ca.crt
}
}
}
reverse_proxy rest-server:8000

View File

@@ -16,7 +16,8 @@ Connect solely through wireguard to `192.168.1.142` and serve the REST server wi
## Restic Repos
`/etc/fstab` entry:
`/etc/fstab` entry on Proxmox host:
```
john-nas:/volume1/restic /mnt/nfs/restic nfs nofail,_netdev,x-systemd.automount,x-systemd.idle-timeout=600,timeo=14,retrans=3,hard,tcp,nfsvers=3 0 0
```
@@ -36,27 +37,41 @@ pct set 103 -mp0 /mnt/nfs/restic,mp=/mnt/restic
Generate a new private key and (public) certificate in the right places. This will use the `admin` provisioner.
```
step ca certificate soteria.john-stream.com certs/soteria.crt certs/soteria.key --provisioner admin
export HOSTNAME=$(hostname -s) && \
export DOMAIN="john-stream.com" && \
export CERT_DIR="/var/lib/tls" && \
export IP_ADDRESS=$(ip -4 addr show dev eth0 | awk '/inet /{print $2}' | cut -d/ -f1)
```
```
(umask 077; mkdir -p "$CERT_DIR") && cd "$CERT_DIR" && \
step ca root root_ca.crt && \
step ca certificate "$HOSTNAME" cert.pem key.pem \
--san "$HOSTNAME" \
--san "$HOSTNAME.$DOMAIN" \
--san "$IP_ADDRESS" \
--san spiffe://john-stream.com/role/docker-agent \
--provisioner admin
```
Convert the key for Envoy to use:
```
(umask 027; openssl pkcs8 -topk8 -nocrypt -in key.pem -out key_pkcs8.pem)
```
Check the resultant certificate:
```
openssl x509 -noout -subject -issuer -ext extendedKeyUsage -ext subjectAltName -in certs/soteria.crt
openssl x509 -noout -subject -issuer -ext extendedKeyUsage,subjectAltName -in /var/lib/tls/cert.pem
```
Set up renewal
## Envoy Proxy
```bash
sudo ./scripts/install_services.sh
```
Test renewal
```
systemctl start cert-renewer.service && \
systemctl status cert-renewer.service --no-pager && \
Validate config:
```shell
docker compose run -it --rm envoy --mode validate -c /etc/envoy/envoy.yaml
```
## Clients
@@ -71,30 +86,37 @@ curl -sL https://gitea.john-stream.com/john/soteria/raw/branch/main/scripts/setu
curl -sL https://gitea.john-stream.com/john/soteria/raw/branch/main/scripts/check_status.sh | bash
```
```bash
curl -sL https://gitea.john-stream.com/john/soteria/raw/branch/main/scripts/wizard_setup.sh | bash
```
### Manual Setup
Set up provisioner password by running this and pasting in the current JWK provisioner password for `admin`
```
read -s secret && (umask 077; echo "$secret" > $(step path)/certs/secret.txt)
```
Generate the client TLS private key and (public) certificate for mTLS. This will combine them both into a file called `restic.pem`, which can be used with the `--tls-client-cert` option with the restic CLI.
```
cd $(step path)/certs && \
step ca certificate \
--provisioner admin --password-file secret.txt \
$(hostnamectl hostname) restic.crt restic.key && \
(umask 077; cat restic.crt restic.key > restic.pem)
export HOSTNAME=$(hostname -s) && \
export DOMAIN="john-stream.com" && \
export CERT_DIR="/var/lib/tls" && \
export IP_ADDRESS=$(ip -4 addr show dev eth0 | awk '/inet /{print $2}' | cut -d/ -f1) && \
(umask 077; mkdir -p "$CERT_DIR" && cd "$CERT_DIR" && \
step ca root root_ca.crt && \
step ca certificate "$HOSTNAME" cert.pem key.pem \
--san "$HOSTNAME" \
--san "$HOSTNAME.$DOMAIN" \
--san "$IP_ADDRESS" \
--san spiffe://john-stream.com/role/docker-agent \
--provisioner admin && \
cat {cert,key}.pem > restic.pem) && \
chmod 644 cert.pem root_ca.crt
```
Need restic 0.16+ for the env vars `RESTIC_CACERT` and `RESTIC_TLS_CLIENT_CERT` to work.
```
export RESTIC_CACERT=$(step path)/certs/root_ca.crt
export RESTIC_TLS_CLIENT_CERT=$(step path)/certs/restic.pem
export RESTIC_REPOSITORY=rest:https://soteria.john-stream.com/john-ubuntu
export RESTIC_CACERT=$(step path)/certs/root_ca.crt && \
export RESTIC_TLS_CLIENT_CERT=$(step path)/certs/restic.pem && \
export RESTIC_REPOSITORY=rest:https://soteria.john-stream.com/john-ubuntu && \
export RESTIC_PASSWORD_FILE=$(readlink -f ~/.config/resticprofile/password.txt)
```
@@ -106,6 +128,8 @@ restic snapshots
### Installing Latest Binary
Do this in case the restic version from apt is too old.
```
curl -s https://api.github.com/repos/restic/restic/releases/latest | grep tag_name
```

View File

@@ -8,16 +8,16 @@ services:
environment:
OPTIONS: --no-auth
caddy:
image: caddy:alpine
container_name: caddy
envoy:
image: envoyproxy/envoy:v1.33-latest
user: root
container_name: envoy
restart: unless-stopped
ports:
- "443:443"
- "443:10000"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- ./certs/soteria.crt:/certs/soteria.crt:ro
- ./certs/soteria.key:/certs/soteria.key:ro
- ${HOME}/.step/certs/root_ca.crt:/certs/root_ca.crt:ro
- ./envoy.yaml:/etc/envoy/envoy.yaml:ro
- /var/lib/tls:/certs
- ./access.log:/var/log/envoy/access.log
depends_on:
- rest-server

122
envoy.yaml Normal file
View File

@@ -0,0 +1,122 @@
static_resources:
# --8<-- [start:listener]
listeners:
- name: listener_0
address:
socket_address:
address: 0.0.0.0
port_value: 10000
# --8<-- [end:listener]
filter_chains:
- filter_chain_match:
server_names: ["*.john-stream.com"]
# --8<-- [start:transport_socket]
- transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
require_client_certificate: true
common_tls_context:
tls_params:
tls_minimum_protocol_version: TLSv1_3 # (1)!
validation_context:
trusted_ca: { filename: /certs/root_ca.crt }
match_typed_subject_alt_names:
- san_type: URI
matcher:
prefix: spiffe://john-stream.com # (2)!
tls_certificates:
- certificate_chain: { filename: /certs/cert.pem }
private_key: { filename: /certs/key_pkcs8.pem } # (3)!
# --8<-- [end:transport_socket]
filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
use_remote_address: true
http2_protocol_options:
max_concurrent_streams: 100
# --8<-- [start:access_log]
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: "/var/log/envoy/access.log"
# --8<-- [end:access_log]
# --8<-- [start:cluster_route]
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: restic
# --8<-- [end:cluster_route]
http_filters:
# --8<-- [start:rbac]
- name: envoy.filters.http.rbac
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.rbac.v3.RBAC
rules:
action: ALLOW
policies:
"ubuntu-policy":
permissions:
- and_rules:
rules:
- header:
name: ":path"
string_match:
prefix: "/john-ubuntu"
principals:
- authenticated:
principal_name:
exact: "spiffe://john-stream.com/ubuntu"
"p14-policy":
permissions:
- and_rules:
rules:
- header:
name: ":path"
string_match:
prefix: "/john-p14s"
principals:
- authenticated:
principal_name:
exact: "spiffe://john-stream.com/john-p14s"
"gitea-policy":
permissions:
- and_rules:
rules:
- header:
name: ":path"
string_match:
prefix: "/gitea"
principals:
- authenticated:
principal_name:
exact: "spiffe://john-stream.com/gitea"
# --8<-- [end:rbac]
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
# --8<-- [start:cluster]
clusters:
- name: restic
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: restic
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: rest-server
port_value: 8000
# --8<-- [end:cluster]

View File

@@ -22,9 +22,9 @@ print_status() {
EXIT_CODE=0
CERTS_DIR="$(readlink -f ~/.step/certs)"
SERVER_CERT="$CERTS_DIR/restic.crt"
SERVER_KEY="$CERTS_DIR/restic.key"
CERTS_DIR="/var/lib/tls"
SERVER_CERT="$CERTS_DIR/cert.pem"
SERVER_KEY="$CERTS_DIR/key.pem"
TIMER_NAME="cert-renewer.timer"
# 1. Check Certificates Existence

View File

@@ -102,8 +102,15 @@ install_unit() {
local filename=$(basename "$template_url")
local dest_path=/etc/systemd/system/"$filename"
log_info "Installing $filename..."
if [ -e "$dest_path" ]; then
get_input "CONFIRM_OVERWRITE" "Overwrite $dest_path? (y/n)" "y" "false"
if [[ "${CONFIRM_OVERWRITE,,}" != "y" ]]; then
echo "Skipping overwrite of ${dest_path}."
return
fi
fi
log_info "Installing $filename..."
curl -sL $template_url | envsubst > "$dest_path"
log_success "$filename installed to $dest_path"
}
@@ -115,31 +122,75 @@ install_unit() {
echo "Starting Interactive Setup..."
echo "-----------------------------"
# 1. Collect Inputs
# Example:
get_input "HOST_NAME" "Enter Hostname" "$(hostname)" "false"
get_input "CERT_DIR" "Enter directory for certificates" "$(step path)/certs" "false"
get_input "CERT_LOCATION" "Enter specific path for cert" "${CERT_DIR}/${HOSTNAME}.crt" "false"
get_input "KEY_LOCATION" "Enter specific path for private key" "${CERT_DIR}/${HOSTNAME}.key" "false"
# Verify required external binaries
if ! command -v step >/dev/null 2>&1; then
# Prompt the user to install the step CLI
get_input "INSTALL_STEP" "The 'step' CLI was not found. Install now? (y/n)" "y" "false"
export CERT_LOCATION=$(readlink -f $CERT_LOCATION)
export KEY_LOCATION=$(readlink -f $KEY_LOCATION)
if [[ "${INSTALL_STEP,,}" == "y" ]]; then
apt-get update && apt-get install -y --no-install-recommends curl vim gpg ca-certificates
curl -fsSL https://packages.smallstep.com/keys/apt/repo-signing-key.gpg -o /etc/apt/trusted.gpg.d/smallstep.asc && \
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/smallstep.asc] https://packages.smallstep.com/stable/debian debs main' \
| tee /etc/apt/sources.list.d/smallstep.list
apt-get update && apt-get -y install step-cli step-ca
else
log_error "Cannot continue without 'step'. Aborting." >&2
exit 1
fi
else
log_success "Step CA installed\n"
fi
get_input "CERT_DIR" "Enter directory for certificates" "/var/lib/tls" "false"
get_input "CERT_FILENAME" "Name for cert file" "cert.pem" "false"
get_input "KEY_FILENAME" "Name for private key" "key.pem" "false"
get_input "SPIFFE" "SPIFFE identity" "node" "false"
if [ ! -e "$CERT_DIR" ]; then
(umask 077; mkdir -p "${CERT_DIR}")
log_info "Created ${CERT_DIR}"
fi
# These need to get set so that they get filled into the service correctly.
export CERT_LOCATION=$(readlink -f ${CERT_DIR}/$CERT_FILENAME)
export KEY_LOCATION=$(readlink -f ${CERT_DIR}/$KEY_FILENAME)
# 2. Confirm
confirm_inputs "CERT_LOCATION" "KEY_LOCATION"
# 3. Configure
REPO_URL_BASE=https://gitea.john-stream.com/john/soteria/raw/branch/main/
SERVICE_TEMPLATE_URL="${REPO_URL_BASE}systemd/cert-renewer.service"
TIMER_TEMPLATE_URL="${REPO_URL_BASE}systemd/cert-renewer.timer"
if [ ! -e "${CERT_DIR}/root_ca.crt" ]; then
step ca root "${CERT_DIR}/root_ca.crt"
fi
# 3. Execute
# echo "Configuring $HOST_NAME..."
if [ ! -f "$CERT_LOCATION" ] || [ ! -f "$KEY_LOCATION" ]; then
hostname=$(hostname -s)
ip_address=$(ip -4 addr show dev eth0 | awk '/inet /{print $2}' | cut -d/ -f1)
step ca certificate "$hostname" \
"${CERT_DIR}/cert.pem" "${CERT_DIR}/key.pem" \
--san "$hostname" \
--san "$hostname.john-stream.com" \
--san "$ip_address" \
--san "spiffe://john-stream.com/$SPIFFE" \
--provisioner admin
fi
echo "" >&2
echo -e "${GREEN}=== Cert information ===${NC}" >&2
openssl x509 -noout -subject -issuer -ext extendedKeyUsage,subjectAltName -enddate -in "$CERT_LOCATION"
SERVICE_FILE="cert-renewer.service"
TIMER_FILE="cert-renewer.timer"
REPO_URL_BASE=https://gitea.john-stream.com/john/soteria/raw/branch/main/
SERVICE_TEMPLATE_URL="${REPO_URL_BASE}systemd/${SERVICE_FILE}"
TIMER_TEMPLATE_URL="${REPO_URL_BASE}systemd/${TIMER_FILE}"
echo "" >&2
echo -e "${GREEN}=== Installing rotation services ===${NC}" >&2
install_unit ${SERVICE_TEMPLATE_URL}
install_unit ${TIMER_TEMPLATE_URL}
echo "" >&2
echo -e "${GREEN}=== Reloading services ===${NC}" >&2
systemctl daemon-reload
systemctl enable --now "$(basename "${TIMER_TEMPLATE_URL}")"
systemctl status "$(basename "${SERVICE_TEMPLATE_URL}")" --no-pager
systemctl status "$(basename "${TIMER_TEMPLATE_URL}")" --no-pager
systemctl enable --now "${TIMER_FILE}" "${SERVICE_FILE}"
systemctl list-unit-files $SERVICE_FILE $TIMER_FILE

View File

@@ -3,22 +3,18 @@ Description=Certificate renewal
After=network-online.target
Documentation=https://smallstep.com/docs/step-ca/certificate-authority-server-production
StartLimitIntervalSec=0
; PartOf=cert-renewer.target
[Service]
Type=oneshot
User=root
; ExecCondition checks if the certificate is ready for renewal,
; based on the exit status of the command.
; (In systemd <242, you can use ExecStartPre= here.)
ExecCondition=/usr/bin/step certificate needs-renewal ${CERT_LOCATION}
; ExecCondition checks if the certificate is ready for renewal.
; ExecCondition=/usr/bin/step certificate needs-renewal ${CERT_LOCATION}
; ExecStart renews the certificate, if ExecStartPre was successful.
; ExecStart renews the certificate, if ExecCondition was successful.
ExecStart=/usr/bin/step ca renew --force ${CERT_LOCATION} ${KEY_LOCATION}
; ExecStartPost=/usr/bin/openssl x509 -noout -enddate -in ${CERT_LOCATION}
; ExecStartPost=/usr/bin/docker exec caddy caddy reload --config /etc/caddy/Caddyfile
ExecStartPost=/usr/bin/openssl x509 -noout -subject -issuer -enddate -in ${CERT_LOCATION}
[Install]
WantedBy=multi-user.target