cert-manager webhook & CoreDNS plugin for solving DNS01 challenge on self-hosted authoritative DNS server.

Release Charts Build and publish webhook images Build and publish CoreDNS image

cert-manager webhook & CoreDNS plugin

This repo exists for a niche case scenario in which we are running cert-manager on one or multiple Kubernetes clusters to issue/manage certificates but also running our own authoritative DNS using CoreDNS and need to get DNS01 challenges solved from it.

Contents:

  1. Overview of the repository
  2. Certificates & mTLS
  3. CoreDNS Plugin
  4. cert-manager's webhook
  5. Limitations
  6. Contributing
  7. Resources

Overview

architecture - monorepo - not typical go structure

go modules

ci - releases/packages

Certificates

Authentication/encryption between webhook and CoreDNS is achieved via mTLS.

For this purpose we need to 3 things:

  1. Certificate Authority (CA) key pair PEM encoded

  2. Server certificate PEM encoded (signed by CA) and key

  3. Client certificate PEM encoded (signed by CA) and key

There are many ways to achieve this. For this guide we are using Minica to keep the whole process as pure Go as possible.

Note: the rest of the certificate section exist as demonstration, for production use you probably want a much more secure key strategy (rolling keys etc).

Minica

The simplest way acquiring Minica is:

go install github.com/jsha/[email protected]

But you can also directly download a binary from project's latest releases.

Now generate server and client cert/key pairs:

minica -domains server,localhost
minica -domains client

Note: replace localhost with your actual FQDN (ie. example.org) when not developing locally.

The above commands should generate 6 files. A key pair on top level named minica.pem & minica-key.pem, and the equivalent client & server key pairs.

files

Transfer cert files to DNS machines

We need to copy to all our DNS servers a. the CA certificate and b. server's cert/key pair.

scp minica.pem yourusername@yourserver:/home/yourusername/CAcerts/
scp -r server yourusername@yourserver:/home/yourusername/server

Create Kubernetes secrets

We also need to create 2 Kubernetes tls secrets, one with the CA key pair and a second with client's key pair.

kubectl create secret tls dns01-ca --cert=minica.pem --key=minica-key.pem
kubectl create secret tls dns01-client --cert=client/cert.pem --key=client/key.pem

Note: create the above secrets in the same namespace cert-manager lives in.

CoreDNS

plugin

Corefile example configuration:

.:1053 {
        reload
        selfhosted 4771 /path/to/ca/folder /path/to/server/cert.pem /path/to/server/key.pem
        records {
            @   60  IN SOA ns.example-acme-webook.example.org ns.example-acme-webook.example.org. 20 5 5 5 5
            @   60  IN NS ns.example-acme-webook.example.org.
            @   60  IN A  127.0.0.1
        }
}

Security note: a second gRPC server will start at the port number given + 1. So make sure the port is available and behind firewall as it is meant for internal communication only. In the future I plan to add authentication for internal communications but until then you have to secure this port manually from the outside world.

Docker

docker run -it --rm --volume "$(pwd):/conf" -p 1053:53 -p 4771:4771 delete:latest -conf /conf/corefile

Build

You may opt to build CoreDNS. For complete instructions read the official documentation first.

To add the plugin you have to:

cd path/to/coredns/plugin
ln -s path/to/this/repo/selfhosted .
cd ..
nano plugin.cfg # add selfhosted:selfhosted
selfhosted:github.com/bh90210/selfhosted/selfhosted
go get github.com/bh90210/selfhosted
go generate
go build

webhook

intro

Repo

helm repo add selfhosted-webhook https://bh90210.github.io/selfhosted
helm repo update
# Replace the groupName value with your desired domain
helm install --namespace cert-manager selfhosted-webhook selfhosted-webhook/selfhosted-webhook --set groupName=acme.example.org
helm uninstall --namespace cert-manager selfhosted-webhook
helm repo remove selfhosted-webhook

Manual

helm install --namespace cert-manager selfhosted-webhook deploy/selfhosted-webhook

configuration

Limitations

Due to the fact that each time you make use of the selfhosted plugin in Corefile’s blocks a new gRPC server is spawned my solution will not scale well for all scenarios. If you use multiple blocks to organise/separate zones it will add unnecessary overhead. I tend to use a few blocks (3-4) and group together many zones on each block. While this works very good for me, given my hardware, use-case and design choices, it might be a no-go solution for you. If you have an idea to fix this limitation consider opening a ticket to discuss about it.

Contributing

All contributions small or big are welcome. Just open an issue to discuss or directly open a PR against master branch.

Resources

https://codeburst.io/mutual-tls-authentication-mtls-de-mystified-11fa2a52e9cf

https://dev.to/techschoolguru/how-to-secure-grpc-connection-with-ssl-tls-in-go-4ph

https://coredns.io/2016/12/19/writing-plugins-for-coredns

https://coredns.io/manual/setups

https://cert-manager.io/docs/configuration/acme/dns01/#webhook

Similar Resources

DNS server with per-client targeted responses

GeoDNS servers This is the DNS server powering the NTP Pool system and other similar services. Questions or suggestions? For bug reports or feature re

Dec 15, 2022

Are you forwarding DNS traffic to another server for some reason, but want to make sure only queries for certain names are passed? Say no more.

DNSFWD Redirect DNS traffic to an upstream. Get Latest: wget https://github.com/C-Sto/dnsfwd/releases/latest/download/dnsfwd_linux (replace linux with

Dec 16, 2022

Free and open source, powerful network-wide ads & trackers blocking DNS server

Free and open source, powerful network-wide ads & trackers blocking DNS server

Privacy protection center for you and your devices Free and open source, powerful network-wide ads & trackers blocking DNS server. AdGuard.com | Wiki

Nov 20, 2021

DNS Server

运行: nohup ./server serve -c ../conf/confile 2&1 & 使用: 修改dns-client的dns服务器地址为dns-server的ip即可 部署目录结构描述: . ├── bin │   ├── nohup.out │   └── server //二进

Dec 2, 2021

A minimalist-configuration reverse DNS name server

autoreverse autoreverse is a specialized authoritative DNS server whose goal is to make it as easy as possible to auto-answer reverse queries without

Feb 14, 2022

DNS server with Redis-cache

GoNS DNS server for home usage. Can resolve by global DNS (external dns) and internal by searching in private_domains list. Also, GoNS can use redis-c

Dec 28, 2021

DNS library in Go

Alternative (more granular) approach to a DNS library Less is more. Complete and usable DNS library. All Resource Records are supported, including the

Dec 26, 2022

DNS over HTTPS [mirror]

dnss dnss is a daemon for using DNS over HTTPS. It can act as a proxy, receiving DNS requests and resolving them using DNS-over-HTTPs (DoH). This can

Dec 26, 2022

Multicast DNS library for Go

Introduction This package allows Go processes to publish multicast DNS style records onto their local network segment. For more information about mDNS

Oct 23, 2022
Cert-manager ACME DNS webhook provider for DnsMadeEasy.

cert-manager-webhook-dnsmadeasy Cert-manager ACME DNS01 challenge wehook provider for DNS Made Easy. Installing To install with helm, run: $ helm repo

Apr 28, 2022
GRONG is a DNS (Domain Name System) authoritative name server.It is more a research project than a production-ready program.

GRONG (Gross and ROugh Nameserver written in Go) is a DNS (Domain Name System) authoritative name server. It is intended as a research project and is

Oct 17, 2020
CoreDNS plugin implementing K8s multi-cluster services DNS spec.

corends-multicluster Name multicluster - implementation of Multicluster DNS Description This plugin implements the Kubernetes DNS-Based Multicluster S

Dec 3, 2022
CoreDNS is a DNS server that chains plugins
CoreDNS is a DNS server that chains plugins

CoreDNS is a DNS server/forwarder, written in Go, that chains plugins. Each plugin performs a (DNS) function. CoreDNS is a Cloud Native Computing Foun

Jan 3, 2023
DNS server using miekg/dns offering dynamic subdomains, time-over-dns, and standard zone file support.

dns-go DNS server using miekg/dns offering dynamic subdomains, time-over-dns, and standard zone file support. dynamic subdomains web.myapp.192.168.1.1

Dec 14, 2021
ACME Webhook for next layer DNS

ACME Webhook for next layer DNS This project provides a cert-manager ACME Webhook for next layer DNS and is based on the Example Webhook. Requirements

Nov 17, 2021
A smol DNS server (<100 loc) that's configured with a static JSON file. Useful for split-dns.

A smol DNS server (<100 loc) that's configured with a static JSON file. Useful for split-dns.

Jul 27, 2022
DNSTake — A fast tool to check missing hosted DNS zones that can lead to subdomain takeover
DNSTake — A fast tool to check missing hosted DNS zones that can lead to subdomain takeover

DNSTake — A fast tool to check missing hosted DNS zones that can lead to subdomain takeover

Dec 28, 2022
A DNS client in Go that supports Google DNS over HTTPS

dingo A DNS client (stub resolver) implemented in Go for the Google DNS-over-HTTPS. It effectively encrypts all your DNS traffic. It also supports Ope

Nov 9, 2022
dnscrypt-proxy 2 - A flexible DNS proxy, with support for encrypted DNS protocols.
dnscrypt-proxy 2 - A flexible DNS proxy, with support for encrypted DNS protocols.

Overview A flexible DNS proxy, with support for modern encrypted DNS protocols such as DNSCrypt v2, DNS-over-HTTPS and Anonymized DNSCrypt. dnscrypt-p

Jan 3, 2023