Skip to content

Commit

Permalink
Merge joohoi#283 and joohoi#291 to our fork
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Schneider <ms@wck.biz>
Co-authored-by: Johannes Doll <jodoll@users.noreply.github.com>
Signed-off-by: İlteriş Yağıztegin Eroğlu <me@linuxgemini.space>
  • Loading branch information
3 people committed Feb 9, 2022
1 parent a33c09a commit 9ad3bf3
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 20 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Docker Publish

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
schedule:
- cron: '25 1 * * *'
push:
branches: [ master ]
# Publish tags starting with 'v' as releases.
tags: [ 'v*' ]
pull_request:
branches: [ master ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@main
with:
cosign-release: 'v1.5.1'


# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v1

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=,suffix=,format=short
type=schedule,pattern=nightly
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ ip = "0.0.0.0"
disable_registration = false
# listen port, eg. 443 for default HTTPS
port = "443"
# possible values: "letsencrypt", "letsencryptstaging", "cert", "none"
# possible values: "letsencrypt", "letsencryptstaging", "cert", "custom", "none"
tls = "letsencryptstaging"
# only used if tls = "custom"
tls_custom_url = "https://acme-v02.example.com/directory"
# only used if tls = "cert"
tls_cert_privkey = "/etc/tls/example.org/privkey.pem"
tls_cert_fullchain = "/etc/tls/example.org/fullchain.pem"
Expand Down
4 changes: 3 additions & 1 deletion config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ ip = "0.0.0.0"
disable_registration = false
# listen port, eg. 443 for default HTTPS
port = "443"
# possible values: "letsencrypt", "letsencryptstaging", "cert", "none"
# possible values: "letsencrypt", "letsencryptstaging", "cert", "custom", "none"
tls = "letsencryptstaging"
# only used if tls = "custom"
tls_custom_url = "https://acme-v02.example.com/directory"
# only used if tls = "cert"
tls_cert_privkey = "/etc/tls/example.org/privkey.pem"
tls_cert_fullchain = "/etc/tls/example.org/fullchain.pem"
Expand Down
24 changes: 6 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ func startHTTPAPI(errChan chan error, config DNSConfig, dnsservers []*DNSServer)
// Set up certmagic for getting certificate for acme-dns api
certmagic.DefaultACME.DNS01Solver = &provider
certmagic.DefaultACME.Agreed = true
if Config.API.TLS == "letsencrypt" {
switch Config.API.TLS {
case "letsencrypt":
certmagic.DefaultACME.CA = certmagic.LetsEncryptProductionCA
} else {
case "custom":
certmagic.DefaultACME.CA = Config.API.TLSCustomURL
default:
certmagic.DefaultACME.CA = certmagic.LetsEncryptStagingCA
}
certmagic.DefaultACME.Email = Config.API.NotificationEmail
Expand All @@ -160,29 +163,14 @@ func startHTTPAPI(errChan chan error, config DNSConfig, dnsservers []*DNSServer)
magic := certmagic.New(magicCache, *magicConf)
var err error
switch Config.API.TLS {
case "letsencryptstaging":
case "letsencrypt", "letsencryptstaging", "custom":
err = magic.ManageAsync(context.Background(), []string{Config.General.Domain})
if err != nil {
errChan <- err
return
}
cfg.GetCertificate = magic.GetCertificate

srv := &http.Server{
Addr: host,
Handler: c.Handler(api),
TLSConfig: cfg,
ErrorLog: stdlog.New(logwriter, "", 0),
}
log.WithFields(log.Fields{"host": host, "domain": Config.General.Domain}).Info("Listening HTTPS")
err = srv.ListenAndServeTLS("", "")
case "letsencrypt":
err = magic.ManageAsync(context.Background(), []string{Config.General.Domain})
if err != nil {
errChan <- err
return
}
cfg.GetCertificate = magic.GetCertificate
srv := &http.Server{
Addr: host,
Handler: c.Handler(api),
Expand Down
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type httpapi struct {
AutocertPort string `toml:"autocert_port"`
Port string `toml:"port"`
TLS string
TLSCustomURL string `toml:"tls_custom_url"`
TLSCertPrivkey string `toml:"tls_cert_privkey"`
TLSCertFullchain string `toml:"tls_cert_fullchain"`
ACMECacheDir string `toml:"acme_cache_dir"`
Expand Down

0 comments on commit 9ad3bf3

Please sign in to comment.