Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Issue 20 #23

Merged
merged 7 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gcloud/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.aws/*
.gcloud/*
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ This script is setup such that if it determines that on-boot-script is enabled,

AWS Route53 DNS challenge can use configuration and authentication values easily through shared credentials and configuration files [as described here](https://go-acme.github.io/lego/dns/route53/). This script will check for and include these files during the initial certificate generation and subsequent renewals. Ensure that `route53` is set for `DNS_PROVIDER` in `udm-le.env`, create a new directory called `.aws` in `/mnt/data/udm-le` and add `credentials` and `config` files as required for your authentication. See the [AWS CLI Documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) for more information. Currently only the `default` profile is supported.

### GCP Cloud DNS

GCP Cloud DNS can be configured by establishing a service account with the role [`roles/dns.admin`](https://cloud.google.com/iam/docs/understanding-roles#dns-roles) and exporting a [service account key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) for that service account. Ensure that `gcloud` is set for `DNS_PROVIDER` in `udm-le.env`, and `GCE_SERVICE_ACCOUNT_FILE` references the path to the service account key (e.g. `./root/.gcloud/my_service_account.json`) . Create a new directory called `.gcloud` in `/mnt/data/udm-le` and add the service account file.

### Cloudflare

In your Cloudflare account settings, create an API token with the following permissions:
Expand Down
9 changes: 8 additions & 1 deletion udm-le.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CERT_EMAIL='your@email.com'

# The FQDN of your UDMP (comma separated fqdns are supported)
CERT_HOSTS='whatever.hostname.com,*.whatever.hostname.com'
CERT_HOSTS='whatever.hostname.com,*.whatever.anotherhostname.com'

# Enable updating Captive Portal certificate as well as device certificate
ENABLE_CAPTIVE='no'
Expand All @@ -16,6 +16,13 @@ ENABLE_CAPTIVE='no'
CLOUDFLARE_DNS_API_TOKEN=YOUR_CLOUDFLARE_API_TOKEN
DNS_PROVIDER='cloudflare'

# GCP CloudDNS settings, see the README.md for information about other providers.
# Note: The default path for the service account file is /root/.gcloud
#GCE_SERVICE_ACCOUNT_FILE=/root/.gcloud/sa.json
#DNS_PROVIDER='gcloud'
#GCE_PROPAGATION_TIMEOUT=3600


#
# Change stuff below at your own risk
#
Expand Down
18 changes: 15 additions & 3 deletions udm-le.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ LEGO_ARGS="--dns ${DNS_PROVIDER} --email ${CERT_EMAIL} --key-type rsa2048"
NEW_CERT=""

deploy_cert() {
if [ "$(find -L "${UDM_LE_PATH}"/lego -type f -name "${CERT_NAME}".crt -mmin -5)" ]; then
#Re-write CERT_NAME if it is a wildcard cert. Replace * with _
LEGO_CERT_NAME=${CERT_NAME/\*/_}
if [ "$(find -L "${UDM_LE_PATH}"/lego -type f -name "${LEGO_CERT_NAME}".crt -mmin -5)" ]; then
echo 'New certificate was generated, time to deploy it'
# Controller certificate
cp -f ${UDM_LE_PATH}/lego/certificates/${CERT_NAME}.crt ${UBIOS_CERT_PATH}/unifi-core.crt
cp -f ${UDM_LE_PATH}/lego/certificates/${CERT_NAME}.key ${UBIOS_CERT_PATH}/unifi-core.key
cp -f ${UDM_LE_PATH}/lego/certificates/${LEGO_CERT_NAME}.crt ${UBIOS_CERT_PATH}/unifi-core.crt
cp -f ${UDM_LE_PATH}/lego/certificates/${LEGO_CERT_NAME}.key ${UBIOS_CERT_PATH}/unifi-core.key
chmod 644 ${UBIOS_CERT_PATH}/unifi-core.*
NEW_CERT="yes"
else
Expand Down Expand Up @@ -48,6 +50,12 @@ if [ -d "${UDM_LE_PATH}/.aws" ]; then
DOCKER_VOLUMES="${DOCKER_VOLUMES} -v ${UDM_LE_PATH}/.aws:/root/.aws/"
fi

# Check for optional .gcloud directory, and add it to the mounts if it exists
if [ -d "${UDM_LE_PATH}/.gcloud" ]; then
DOCKER_VOLUMES="${DOCKER_VOLUMES} -v ${UDM_LE_PATH}/.gcloud:/root/.gcloud/"
fi


# Setup persistent on_boot.d trigger
ON_BOOT_DIR='/mnt/data/on_boot.d'
ON_BOOT_FILE='99-udm-le.sh'
Expand Down Expand Up @@ -88,4 +96,8 @@ bootrenew)
echo 'Attempting certificate renewal'
${PODMAN_CMD} ${LEGO_ARGS} renew --days 60 && deploy_cert && add_captive && unifi-os restart
;;
testdeploy)
echo 'Attempting to deploy certificate'
deploy_cert
;;
esac