HDNS is a DNS to DNS over TLS (DoT) proxy that can handle both TCP and UDP DNS queries. It can be implemented either as a standalone service or within a Kubernetes infrastructure using the sidecar approach. Upstream DoT servers and their SPKI can be configured using the HDNS config file (stored as a ConfigMap in Kubernetes) . Additionally, HDNS can block domains specified in the config file or through Custom Resource Definitions (CRDs) in a Kubernetes environment.
echo | openssl s_client -connect 8.8.4.4:853 2>/dev/null | openssl x509 -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
Generate an hdns.cfg file based on the provided template and place it in the directory /etc/hdns/hdns.cfg.
{
"service_host" : "127.0.0.1",
"service_port" : "53",
"service_proto": "all",// can be tcp, udp or all
"sidecar_injection": "true",
"dns_host" : "9.9.9.9",
"dns_port" : "853",
"dns_spki" : "/SlsviBkb05Y/8XiKF9+CZsgCtrqPQk5bh47o0R3/Cg=",
"block_domains" : ["google.com"] // you can block unwanted domains
}
Any changes to the hdns configuration file (e.g., DNS SPKI) are detected at runtime.
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o hdns .
./hdns
cd hdns-service
docker build . -t hdns:v0.0.1
cd admission-webhook
docker build . -t admission-webhook:v0.0.1
cd helm-charts
helm package webhook
helm install hdns hdns-webhook-0.0.1.tgz -n hdns --create-namespace
The hdns configuration file is stored in the 'hdns-cm' ConfigMap
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: hdns
labels:
DNSProxy: "true"
spec:
containers:
- name: alpine
image: busybox:latest
command: ["sleep", "3600"]
restartPolicy: Never
The mutating webhook adds an hdns sidecar to each pod containing the label 'DNSProxy'.
+===============+ +=================+ +==================+
| Pod1 | | Pod2 | | Pod3 |
| Microservice1 | | Microservice2 | | Microservice3 |
|---------------| |-----------------| |------------------|
| | | | | |
| hdns sidecar | | hdns sidecar | | hdns sidecar |
+===============+ +=================+ +==================+
|| || ||
|| || ||
|| || ||
|| || ||
|| +====================+ ||
|| | Pod4 | ||
||===========| Mutating Webhook |============
| (sidecar injection)|
+====================+
block unwanted domains using CRD
install 1 -
cd hdns-operator
docker build . -t hdns-operator:v0.0.1
2 - install helm chart
cd helm-charts
helm package operator
helm install hdns hdns-operator-0.0.1.tgz -n hdns --create
apiVersion: hdns.io/v1alpha1
kind: DNSBlock
metadata:
name: test
namespace: hdns
spec:
domains:
- google.com
- youtube.com
- facebook.com