Install the CA chain on client machines to trust certificates from this authority.
Manual Installation
Linux (Debian/Ubuntu)
sudo cp ca-chain.crt /usr/local/share/ca-certificates/certauth.crt
sudo update-ca-certificates
macOS
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca-chain.crt
Windows
Double-click ca-chain.crt, then:
1. Click "Install Certificate"
2. Select "Local Machine" → Next
3. Select "Place all certificates in the following store"
4. Browse → "Trusted Root Certification Authorities"
5. OK → Next → Finish
Docker
COPY ca-chain.crt /usr/local/share/ca-certificates/certauth.crt
RUN update-ca-certificates
{% endblock %}
TPL_SETUP.HTML_EOF
chown -R "$ADMIN_USER:$ADMIN_USER" /opt/certauth
# Initialize database
cd /opt/certauth/api
sudo -u "$ADMIN_USER" python3 -c "from models import init_db; init_db()" 2>/dev/null || true
success "API installed"
}
# ===================== STEP 8: SERVICES =====================
setup_services() {
info "=== Step 8: Configure Services ==="
# Caddy
cat > /etc/caddy/Caddyfile << 'CADDYEOF'
:80 {
encode gzip
reverse_proxy 127.0.0.1:8000 {
header_up Host {host}
header_up X-Real-IP {remote}
}
}
CADDYEOF
# Systemd service for API
cat > /etc/systemd/system/certauth-api.service << SVCCEOF
[Unit]
Description=CertAuth Certificate Management API
After=network.target pcscd.service
[Service]
Type=simple
User=$ADMIN_USER
Group=$ADMIN_USER
WorkingDirectory=/opt/certauth/api
Environment=PYTHONUNBUFFERED=1
ExecStart=/usr/bin/python3 -m uvicorn main:app --host 127.0.0.1 --port 8000
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
SVCCEOF
systemctl daemon-reload
systemctl enable caddy certauth-api pcscd
systemctl start caddy certauth-api
success "Services configured and started"
}
# ===================== STEP 9: VERIFY =====================
verify_setup() {
info "=== Step 9: Verification ==="
sleep 3
# Check services
for svc in certauth-api caddy pcscd; do
STATUS=$(systemctl is-active "$svc")
if [[ "$STATUS" == "active" ]]; then
success "$svc: active"
else
warn "$svc: $STATUS"
fi
done
# Test API
HEALTH=$(curl -s http://localhost:8000/api/health 2>/dev/null || echo "FAILED")
if echo "$HEALTH" | grep -q "ok"; then
success "API health check: OK"
else
warn "API health check: $HEALTH"
fi
# Verify CA chain
openssl verify -CAfile /etc/ssl/ca/root/root-ca.crt \
/etc/ssl/ca/intermediate/intermediate-ca.crt 2>&1 | while read line; do
if echo "$line" | grep -q "OK"; then
success "CA chain verification: OK"
else
warn "CA chain: $line"
fi
done
echo ""
echo "============================================================"
echo " SETUP COMPLETE"
echo "============================================================"
echo ""
echo " Access the Key Vault UI at:"
echo " http://$(hostname -I | awk '{print $1}')/"
echo ""
echo " Admin login:"
echo " Username: $ADMIN_USER"
echo " Password: $ADMIN_PASS"
echo ""
echo " API endpoints:"
echo " POST /api/token - Login (returns JWT)"
echo " GET /api/domains - List domains"
echo " POST /api/domains - Register domain"
echo " GET /api/certs - List certificates"
echo " POST /api/certs/request - Request certificate"
echo " POST /api/certs/{id}/sign - Sign certificate (requires YK2)"
echo " GET /api/certs/{id}/download - Download cert"
echo " GET /api/certs/{id}/key - Download private key"
echo " GET /api/ca-chain - Download CA chain"
echo ""
echo " IMPORTANT: Change the admin password after first login!"
echo "============================================================"
}
# ===================== MAIN =====================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo ""
echo "============================================================"
echo " CertAuth Setup"
echo "============================================================"
echo ""
check_prerequisites
setup_system
setup_user
setup_firewall
detect_yubikeys
configure_yubikeys
generate_ca_certs
install_api
setup_services
verify_setup
echo ""
success "All done!"