Homelab: server certificates
In previous log I have introduced my homelab infrastructure.
One of the thing I'm the most bothered with, is the lack of ciphering between my desktop computer (Looping) and my server (Barracuda).
The easiest thing is to generate and expose a server certificate (which will be used to "authenticate" the server and cipher exchanges).
In order to do that we should first create a certificate authority (CA):
##!/usr/bin/env bash
CA_DIR=server/ca
REQ_DIR=server/requests
|
Note: in order to generate the configuration files for openssl
(I mean, [libressl
(https://www.libressl.org/)]),
I used dhall-openssl
.
It's a genius project which abstract the tedious and mysterious world of OpenSSL configuration files you end up copy-pasting
from the internet (even if you do it professionally for years).
Which gives:
let openssl =
https://raw.githubusercontent.com/jvanbruegge/dhall-openssl/master/package.dhall
in \(caDir : Text) ->
openssl.mkCaConfig
openssl.CaConfig::{
, distinguishedName = openssl.DistinguishedName::{
, commonName = "Barracuda Root Certificate Authority"
}
, allowedHosts = [ "barracuda.local" ]
, caDir
}
Simple, straight-to-the-point, genius.
Then, we have to create and sign server certificates:
#!/usr/bin/env bash
if [;
then
fi
SERVICE=
CRT_DIR=server/services/
CA_DIR=server/ca
REQ_DIR=server/requests
|
# Create a new certificate
# Sign it with our CA
# TODO add -days 1
TARGET_DIR=/etc/nixos/certificates/servers/
TARGET_LOGIN=black@192.168.0.4
and the configuration file:
let openssl =
https://raw.githubusercontent.com/jvanbruegge/dhall-openssl/master/package.dhall
in \(service : Text) ->
openssl.mkConfig
openssl.Config::{
, distinguishedName = openssl.DistinguishedName::{
, commonName = "${service}.barracuda.local"
}
, altNames = [] : List Text
}
Then we have to update Barracuda (nginx), configuration:
"withings.barracuda.local" = {
enableACME = false;
serverAliases = [ ];
forceSSL = true;
sslCertificate = "/etc/nixos/certificates/servers/withings/server.crt";
sslCertificateKey = "/etc/nixos/certificates/servers/withings/server.key";
locations."/" = {
proxyPass = "http://127.0.0.1:5555/";
};
};
we should have everything working, except, we have to explicitly disable certificate authority check. In order to do that, we should modify Looping (and all clients' configuration) to and the CA to the list of trusted CAs.
security.pki.certificateFiles = [ ./certificates/barracuda/ca.pem ];