From 7c614ae8ff52f916759240fa6c809899048058fb Mon Sep 17 00:00:00 2001 From: Santeri Kainulainen Date: Tue, 9 Dec 2025 15:33:36 +0200 Subject: [PATCH] Install newest Caddy version with role nvjacobo.caddy and update template and pre-generated certs This commit will also allow Caddy to properly generate certs with longer lifetimes than 12 hours, and by default it has been set to 1 month. This commit removes the pre-generated certs for safety reasons. This commit also updates the README.md thoroughly with some guides about the certs and how to use the role in general. --- README.MD | 22 +++++++++++++++------- files/certs/intermediate.crt | 12 ------------ files/certs/intermediate.key | 5 ----- files/certs/root.crt | 11 ----------- files/certs/root.key | 5 ----- meta/main.yml | 3 ++- tasks/main.yml | 5 ----- templates/Caddyfile.j2 | 5 +++-- 8 files changed, 20 insertions(+), 48 deletions(-) delete mode 100644 files/certs/intermediate.crt delete mode 100644 files/certs/intermediate.key delete mode 100644 files/certs/root.crt delete mode 100644 files/certs/root.key diff --git a/README.MD b/README.MD index c112245..d606807 100644 --- a/README.MD +++ b/README.MD @@ -1,13 +1,17 @@ # Kifi Caddy -Installs and configures Caddy for use as a local ACME CA server allowing certificates to be issued in testing. -This role should function as of now, but for example certificate lifetime changes don't work (defaults to 12h). +Installs and configures Caddy for use as a local ACME CA server allowing certificates to be issued in testing.\ +By default, the Caddyfile defaults to 1 month for the leaf certificates and 1 year for the intermediate certificate.\ +To use the same certificates for all VM's that use this role, create directory `./files/certs` in the root of the repo, and using for example scp or sshfs move the certificates from one your VM's to the directory.\ +The location of the certs is usually `/var/lib/caddy/.local/share/caddy/pki/authorities/local`. Simple copy-paste everything from there to your host machine and into the role directory.\ +This is for mostly convenience, as multiple VM's might use this role so you only need to import the `root.crt` to your browser once. + ## Example usage -In your playbook, define the role and config paths. Most likely the defaults are fine, so you can just simply add the role. Remember to add this before any certbot role. The ACME server is hosted at port 8443. You can also change the `templates/Caddyfile.j2` to fit your own needs. - -Example for tilastot.kirjastot.fi.local: +In your playbook, define the role and config paths. Most likely the defaults are fine, so you can just simply add the role. Remember to add this before any certbot role. The ACME server is hosted at port 8443. You can also change the `templates/Caddyfile.j2` to fit your own needs.\ +\ +Example: ``` - role: kifi.caddy caddy_config_path: /etc/caddy/Caddyfile @@ -15,7 +19,7 @@ Example for tilastot.kirjastot.fi.local: caddy_service_name: caddy ``` -Another example of how to use this in combination with the kifi.certbot role: +Another example of how to use this in combination with the kifi.certbot role on domain tilastot.kirjastot.fi.local: ``` tasks: - name: Run Certbot role @@ -41,4 +45,8 @@ tasks: ``` Note that the domains get looped over, so you can have multiple of them. -Certificates for domains can be found in the folder /etc/letsencrypt/live/domainname though it might be wise to change this \ No newline at end of file +Certificates for domains can be found in the folder /etc/letsencrypt/live/domainname though it might be wise to change this + +# Dependencies + +[nvjacobo.caddy](https://github.com/nvjacobo/caddy.git) - Used for installing Caddy diff --git a/files/certs/intermediate.crt b/files/certs/intermediate.crt deleted file mode 100644 index 5ef5a67..0000000 --- a/files/certs/intermediate.crt +++ /dev/null @@ -1,12 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIBtDCCAVqgAwIBAgIRAMHp+q/ddqH+S9fE5V7QhhkwCgYIKoZIzj0EAwIwJjEk -MCIGA1UEAxMbTXkgTG9jYWwgQ0EgLSAyMDI1IEVDQyBSb290MB4XDTI1MTIwMTEz -MTg1M1oXDTI1MTIwODEzMTg1M1owKTEnMCUGA1UEAxMeTXkgTG9jYWwgQ0EgLSBF -Q0MgSW50ZXJtZWRpYXRlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZL83Hyar -iIsBkRtRNxRtHoiW7KEUuxq4gVyNrJjtdYZwlfZE+qOCYo5I6E99zZiVD2SZNe1x -uVXYV6mcERDnC6NmMGQwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8C -AQAwHQYDVR0OBBYEFJII7wjwySNFSJWt700GYE1JfsGxMB8GA1UdIwQYMBaAFHCv -EafSET7wyiMUOd3eZrQx3lw8MAoGCCqGSM49BAMCA0gAMEUCIQCCj54nwceSHHJ+ -RCN2CyEByqMh/RdDd/FijJ800x3J6gIgemnp9J3CrKN/Fzy3JOhetVCRkVqjDNLc -ZH4K1pYnDBA= ------END CERTIFICATE----- diff --git a/files/certs/intermediate.key b/files/certs/intermediate.key deleted file mode 100644 index 4c6898d..0000000 --- a/files/certs/intermediate.key +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -MHcCAQEEIDLfKjCXLIseInlVmkL1dx6K/Iv6uxjhJjRmI4xr9kXNoAoGCCqGSM49 -AwEHoUQDQgAEZL83HyariIsBkRtRNxRtHoiW7KEUuxq4gVyNrJjtdYZwlfZE+qOC -Yo5I6E99zZiVD2SZNe1xuVXYV6mcERDnCw== ------END EC PRIVATE KEY----- diff --git a/files/certs/root.crt b/files/certs/root.crt deleted file mode 100644 index 55ab77e..0000000 --- a/files/certs/root.crt +++ /dev/null @@ -1,11 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIBjzCCATWgAwIBAgIQMNAFWqphrzOxuSOWVbSr4jAKBggqhkjOPQQDAjAmMSQw -IgYDVQQDExtNeSBMb2NhbCBDQSAtIDIwMjUgRUNDIFJvb3QwHhcNMjUxMjAxMTMx -ODUzWhcNMzUxMDEwMTMxODUzWjAmMSQwIgYDVQQDExtNeSBMb2NhbCBDQSAtIDIw -MjUgRUNDIFJvb3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASD2byYNpauRUOg -LggkyrY/ZRMZIQMT+rXlQMctxnV77VOdaXccTC2vfpOS2tqwcwySyP1NYg1DqvD0 -L4VjUb/To0UwQzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd -BgNVHQ4EFgQUcK8Rp9IRPvDKIxQ53d5mtDHeXDwwCgYIKoZIzj0EAwIDSAAwRQIh -AI4rOGX/GNjlUnwixzcXM1FFrBrarzRZd/6+z99I+1yhAiAqxxK69h4ae0nylgVO -pKlmiO5bk38ZfwjN6qAIqMaCcg== ------END CERTIFICATE----- diff --git a/files/certs/root.key b/files/certs/root.key deleted file mode 100644 index 173930c..0000000 --- a/files/certs/root.key +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -MHcCAQEEICFWtuowkCW/82uhRaJUuisuQFQ3kQc6WH2xopi6aID8oAoGCCqGSM49 -AwEHoUQDQgAEg9m8mDaWrkVDoC4IJMq2P2UTGSEDE/q15UDHLcZ1e+1TnWl3HEwt -r36TktrasHMMksj9TWINQ6rw9C+FY1G/0w== ------END EC PRIVATE KEY----- diff --git a/meta/main.yml b/meta/main.yml index d960394..6a2a7f0 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -9,4 +9,5 @@ galaxy_info: - caddy - tls - localca -dependencies: [] +dependencies: + - role: nvjacobo.caddy diff --git a/tasks/main.yml b/tasks/main.yml index 34238b2..1187f95 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,3 @@ -- name: Ensure Caddy is installed - ansible.builtin.package: - name: caddy - state: present - - name: Create Caddy configuration directory become: yes ansible.builtin.file: diff --git a/templates/Caddyfile.j2 b/templates/Caddyfile.j2 index 0ed25e9..6faef42 100644 --- a/templates/Caddyfile.j2 +++ b/templates/Caddyfile.j2 @@ -2,6 +2,7 @@ pki { ca local { name "My Local CA" + intermediate_lifetime 365d } } http_port 8080 @@ -11,6 +12,6 @@ localhost:8443 { acme_server { ca local - lifetime 720h + lifetime 30d } -} \ No newline at end of file +}