-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from freifunkMUC/freifunk-net-domains
- Loading branch information
Showing
15 changed files
with
344 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/python | ||
"""WIP module to get virtual machine data from netbox, e.g. to get all VMs with a certain tag.. | ||
""" | ||
|
||
import requests | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def get_vms_by_filter(netbox_api, netbox_token, filter): | ||
# Example filter: 'tag=authorative-dns' | ||
headers = { | ||
"Authorization": "Token {}".format(netbox_token), | ||
"Accept": "application/json", | ||
} | ||
url = f"{netbox_api}/virtualization/virtual-machines/?{filter}" | ||
auth_servers = [] | ||
try: | ||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() | ||
response = response.json() | ||
log.info(response) | ||
for auth in response["results"]: | ||
auth_servers.append(auth["name"]) | ||
except Exception as e: | ||
log.error(str(e)) | ||
__context__["retcode"] = 1 | ||
return e | ||
return auth_servers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
# Script to nsupdate all our authoritative servers, supposed to be run by certbot. | ||
# Requires bind9-utils installed. | ||
|
||
# The following environment variables are passed to the script by certbot: | ||
# CERTBOT_DOMAIN, CERTBOT_VALIDATION, CERTBOT_TOKEN (HTTP-01 only), CERTBOT_REMAINING_CHALLENGES, CERTBOT_ALL_DOMAINS, CERTBOT_AUTH_OUTPUT | ||
|
||
HOST="_acme-challenge" | ||
|
||
{%- set update_key = salt['pillar.get']('netbox:config_context:dns_zones:update_keys:letsencrypt:key') %} | ||
UPDATE_KEY="{{ update_key }}" | ||
|
||
AUTH_SERVERS=("webfrontend03.ov.ffmuc.net" "webfrontend04.ov.ffmuc.net" "webfrontend05.ov.ffmuc.net" "webfrontend06.ov.ffmuc.net") | ||
|
||
for AUTH in ${AUTH_SERVERS[@]}; do | ||
nsupdate -y "hmac-sha512:letsencrypt:${UPDATE_KEY}" << EOM | ||
server ${AUTH} 553 | ||
zone ${CERTBOT_DOMAIN} | ||
update delete ${HOST}.${CERTBOT_DOMAIN} TXT "${CERTBOT_VALIDATION}" | ||
send | ||
EOM | ||
echo "" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dns_cloudflare_api_token = {{ cloudflare_token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
# Script to nsupdate all our authoritative servers, supposed to be run by certbot. | ||
# Requires bind-tools installed. | ||
|
||
# The following environment variables are passed to the script by certbot: | ||
# CERTBOT_DOMAIN, CERTBOT_VALIDATION, CERTBOT_TOKEN (HTTP-01 only), CERTBOT_REMAINING_CHALLENGES, CERTBOT_ALL_DOMAINS | ||
|
||
HOST="_acme-challenge" | ||
|
||
{%- set update_key = salt['pillar.get']('netbox:config_context:dns_zones:update_keys:letsencrypt:key') %} | ||
UPDATE_KEY="{{ update_key }}" | ||
|
||
{#- TODO: use netbox_vms:get_vms_by_filter to get authoritative DNS servers | ||
{%- set auth_servers = salt['netbox_vms:get_vms_by_filter']( | ||
salt['pillar.get']('netbox:config_context:netbox:api_url'), | ||
salt['pillar.get']('netbox:config_context:dns_zones:netbox_token'), | ||
'tag=authorative-dns' | ||
) %} | ||
AUTH_SERVERS=({{ auth_servers | join(" ") }}) | ||
#} | ||
|
||
AUTH_SERVERS=("webfrontend03.ov.ffmuc.net" "webfrontend04.ov.ffmuc.net" "webfrontend05.ov.ffmuc.net" "webfrontend06.ov.ffmuc.net") | ||
|
||
for AUTH in ${AUTH_SERVERS[@]}; do | ||
nsupdate -y "hmac-sha512:letsencrypt:${UPDATE_KEY}" << EOM | ||
server ${AUTH} 553 | ||
zone ${CERTBOT_DOMAIN} | ||
{#- Don't delete existing records as they might be of other webfrontends renewing simultaneously. #} | ||
update add ${HOST}.${CERTBOT_DOMAIN} 5 TXT "${CERTBOT_VALIDATION}" | ||
send | ||
EOM | ||
echo "" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ update_ca_certificates: | |
|
||
generate-dhparam: | ||
cmd.run: | ||
- name: openssl dhparam -out /etc/ssl/dhparam.pem 2048 | ||
- name: openssl dhparam -out /etc/ssl/dhparam.pem 4096 | ||
- creates: /etc/ssl/dhparam.pem | ||
|
||
# Install FFMUC internal CA into Debian CA certificate mangling mechanism so | ||
|
@@ -129,9 +129,12 @@ certbot-dns-cloudflare: | |
dns_credentials: | ||
file.managed: | ||
- name: /var/lib/cache/salt/dns_plugin_credentials.ini | ||
- source: salt://certs/files/dns_plugin_credentials.ini | ||
- makedirs: True | ||
- contents: "dns_cloudflare_api_token = {{ cloudflare_token }}" | ||
- mode: "0600" | ||
- template: jinja | ||
- defaults: | ||
cloudflare_token: {{ cloudflare_token }} | ||
|
||
ffmuc-wildcard-cert: | ||
acme.cert: | ||
|
@@ -173,6 +176,49 @@ ffmuc-wildcard-cert: | |
- pip: acme-client | ||
- file: dns_credentials | ||
|
||
|
||
{% if "webserver-external" in role %} | ||
# Required for running nsupdate with certbot | ||
bind9-utils: | ||
pkg.installed | ||
|
||
update-dns.sh: | ||
file.managed: | ||
- name: /var/lib/cache/salt/update-dns.sh | ||
- source: salt://certs/files/update-dns.sh.jinja | ||
- makedirs: True | ||
- mode: "0700" | ||
- template: jinja | ||
|
||
cleanup-dns.sh: | ||
file.managed: | ||
- name: /var/lib/cache/salt/cleanup-dns.sh | ||
- source: salt://certs/files/cleanup-dns.sh.jinja | ||
- makedirs: True | ||
- mode: "0700" | ||
- template: jinja | ||
|
||
# Salt's acme module doesn't support any DNS plugin besides Cloudflare, not even manual. Thus use cmd.run. | ||
# TODO add 'unless' condition which checks whether cert needs renewal. | ||
# Expiration date is not enough, should check revocation status as well. As of 2023-06 Cerbot has no command exposed for this. | ||
muenchen.freifunk.net-wildcard-cert: | ||
cmd.run: | ||
- name: > | ||
certbot certonly -n --agree-tos -m [email protected] | ||
--manual --manual-auth-hook /var/lib/cache/salt/update-dns.sh --manual-cleanup-hook /var/lib/cache/salt/cleanup-dns.sh | ||
--preferred-challenges dns --expand | ||
-d "muenchen.freifunk.net" -d "*.muenchen.freifunk.net" | ||
-d "xn--mnchen-3ya.freifunk.net" -d "*.xn--mnchen-3ya.freifunk.net" | ||
-d "wertingen.freifunk.net" -d "*.wertingen.freifunk.net" | ||
-d "donau-ries.freifunk.net" -d "*.donau-ries.freifunk.net" | ||
{#- -d "augsburg.freifunk.net" -d "*.augsburg.freifunk.net" #} | ||
- require: | ||
- cmd: certbot | ||
- pip: acme-client | ||
- file: update-dns.sh | ||
{% endif %} | ||
|
||
|
||
/etc/letsencrypt/renewal-hooks/deploy/01-reload-nginx.sh: | ||
file.managed: | ||
- contents: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
$ORIGIN . | ||
$TTL 3600 ; 1 week | ||
{{ domain }} IN SOA anycast01.ffmuc.net. hostmaster.ffmuc.net. ( | ||
2023071001 ; serial | ||
300 ; refresh (5 minutes) | ||
100 ; retry (1 minute 40 seconds) | ||
6000 ; expire (1 hour 40 minutes) | ||
600 ; minimum (10 minutes) | ||
) | ||
IN NS anycast01.ffmuc.net. | ||
IN NS anycast02.ffmuc.net. | ||
|
||
IN AAAA 2001:678:ed0:f000:: | ||
IN AAAA 2001:678:e68:f000:: | ||
|
||
IN A 5.1.66.255 | ||
IN A 185.150.99.255 | ||
|
||
$ORIGIN {{ domain }}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.