diff --git a/README.md b/README.md index 343510a..ba2a417 100644 --- a/README.md +++ b/README.md @@ -353,30 +353,34 @@ service unifi start ### Revoke a certificate ```bash -vault write pki_dnet_int/revoke serial_number= -vault write pki_dnet_int/tidy tidy_cert_store=true tidy_revoked_certs=true +export PKI_PATH=dnet_inter + +vault write $PKI_PATH/revoke serial_number= +vault write $PKI_PATH/tidy tidy_cert_store=true tidy_revoked_certs=true ``` ### Use with cert-manager ```bash -vault policy write pki_dnet_int - < cert-manager/vault-clusterissuer.yaml < cert-manager/pikube-vault-clusterissuer.yaml <> /etc/ssh/sshd_config +``` + +Restart the SSH service + +```bash +service ssh restart +``` + +Add signing role + +```bash +vault write ssh-client-signer/roles/ducoterra -<<"EOH" +{ + "allow_user_certificates": true, + "allowed_users": "*", + "allowed_extensions": "permit-pty,permit-port-forwarding", + "default_extensions": [ + { "permit-pty": "" } + ], + "key_type": "ca", + "default_user": "ducoterra", + "ttl": "30m0s" +} +EOH +``` + +```bash +vault write ssh-client-signer/roles/pi -<<"EOH" +{ + "allow_user_certificates": true, + "allowed_users": "*", + "allowed_extensions": "permit-pty,permit-port-forwarding", + "default_extensions": [ + { "permit-pty": "" } + ], + "key_type": "ca", + "default_user": "pi", + "ttl": "30m0s" +} +EOH +``` + +```bash +vault write ssh-client-signer/roles/rancher -<<"EOH" +{ + "allow_user_certificates": true, + "allowed_users": "*", + "allowed_extensions": "permit-pty,permit-port-forwarding", + "default_extensions": [ + { "permit-pty": "" } + ], + "key_type": "ca", + "default_user": "rancher", + "ttl": "30m0s" +} +EOH +``` + +Sign a key + +```bash +export SSHUSER=pi; vault write -field=signed_key ssh-client-signer/sign/$SSHUSER public_key=@$HOME/.ssh/test_rsa.pub > ~/.ssh/test_rsa-cert.pub +``` + +SSH using the signed key + +```bash +# If you saved the signed pub as key_name"-cert.pub" then you don't need to specify the signed-cert.pub part. +ssh -i signed-cert.pub -i ~/.ssh/test_rsa client + +# or without the cert (using default client) +ssh -i ~/.ssh/test_rsa client +``` + +#### Server Host Signing + +Enable secrets engine + +```bash +vault secrets enable -path=ssh-host-signer ssh +``` + +Generate keys: + +```bash +vault write ssh-host-signer/config/ca generate_signing_key=true +``` + +Extend host key's TTL + +```bash +vault secrets tune -max-lease-ttl=87600h ssh-host-signer +``` + +Create host role + +```bash +vault write ssh-host-signer/roles/hostrole \ + key_type=ca \ + ttl=87600h \ + allow_host_certificates=true \ + allowed_domains="localdomains,dnet,hole,ducoterra.net" \ + allow_subdomains=true +``` + +Sign the host's public key + +```bash +vault write ssh-host-signer/sign/hostrole \ + cert_type=host \ + public_key=@$HOME/.ssh/id_rsa.pub +``` + +Write the signed certificate to the ssh config on the host + +```bash +vault write -field=signed_key ssh-host-signer/sign/hostrole \ + cert_type=host \ + public_key=@$HOME/.ssh/id_rsa.pub > /etc/ssh/ssh_host_rsa_key-cert.pub +``` + +Assign correct permissions + +```bash +chmod 0640 /etc/ssh/ssh_host_rsa_key-cert.pub +``` + +Add to sshd_config + +```bash +echo HostKey /etc/ssh/ssh_host_rsa_key >> /etc/ssh/sshd_config +echo HostCertificate /etc/ssh/ssh_host_rsa_key-cert.pub >> /etc/ssh/sshd_config +``` + +Restart the ssh service + +```bash +service ssh restart +``` + +Add certificate to client + +```bash +echo '@cert-authority *.ducoterra.net '$(vault read -field=public_key ssh-host-signer/config/ca) >> ~/.ssh/known_hosts +```