DNS: run separate CoreDNS instance for each PCloud env.
Previously shared CoreDNS instance was used to handle all domains. This has multiple downsides, most important which is security. For example DNS-Sec keys of all domains were persisted on the same shared volume. Also key itself was generated by PCloud env-manager as part of bootstrapping new env. Which is counter to the main aspirations of PCloud, that environment internal private data must not leak outside of the environment.
With new approach implemented in this change, environment starts up it’s own CoreDNS and DNS record manager servers. Manager generates dns-sec keys internally and only exposes public information to the outside world. PCloud infrastructure runes another instance of CoreDNS which acts as a proxy service forwarding requests to individual environments based an requested domain.
This simplifies DNS based TLS challenge solvers, as private certificate issuer of each env will point directly to the DNS record manager of the same environment.
Change-Id: Ifb0f36d2a133e3b53da22030cc7d6b9099136b3d
diff --git a/core/dns-challenge-solver/main.go b/core/dns-challenge-solver/main.go
index 9055735..8daa353 100644
--- a/core/dns-challenge-solver/main.go
+++ b/core/dns-challenge-solver/main.go
@@ -2,7 +2,6 @@
import (
"bytes"
- "context"
"encoding/json"
"fmt"
"io"
@@ -11,7 +10,6 @@
"strings"
extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
@@ -111,11 +109,6 @@
// be used by your provider here, you should reference a Kubernetes Secret
// resource and fetch these credentials using a Kubernetes clientset.
type pcloudDNSProviderConfig struct {
- APIConfigMapName string `json:"apiConfigMapName,omitempty"`
- APIConfigMapNamespace string `json:"apiConfigMapNamespace,omitempty"`
-}
-
-type apiConfig struct {
CreateAddress string `json:"createTXTAddr,omitempty"`
DeleteAddress string `json:"deleteTXTAddr,omitempty"`
}
@@ -141,13 +134,8 @@
if err != nil {
return err
}
- apiCfg, err := loadAPIConfig(c.client, cfg)
- if err != nil {
- fmt.Printf("Failed to load API config: %s\n", err.Error())
- return err
- }
- fmt.Printf("API config: %+v\n", apiCfg)
- zm := &zoneControllerManager{apiCfg.CreateAddress, apiCfg.DeleteAddress}
+ fmt.Printf("API config: %+v\n", cfg)
+ zm := &zoneControllerManager{cfg.CreateAddress, cfg.DeleteAddress}
domain, entry := getDomainAndEntry(ch)
fmt.Printf("%s %s\n", domain, entry)
err = zm.CreateTextRecord(domain, entry, ch.Key)
@@ -169,13 +157,8 @@
if err != nil {
return err
}
- apiCfg, err := loadAPIConfig(c.client, cfg)
- if err != nil {
- fmt.Printf("Failed to load API config: %s\n", err.Error())
- return err
- }
- fmt.Printf("API config: %+v\n", apiCfg)
- zm := &zoneControllerManager{apiCfg.CreateAddress, apiCfg.DeleteAddress}
+ fmt.Printf("API config: %+v\n", cfg)
+ zm := &zoneControllerManager{cfg.CreateAddress, cfg.DeleteAddress}
domain, entry := getDomainAndEntry(ch)
err = zm.DeleteTextRecord(domain, entry, ch.Key)
if err != nil {
@@ -220,22 +203,6 @@
return cfg, nil
}
-func loadAPIConfig(client *kubernetes.Clientset, cfg pcloudDNSProviderConfig) (apiConfig, error) {
- config, err := client.CoreV1().ConfigMaps(cfg.APIConfigMapNamespace).Get(context.Background(), cfg.APIConfigMapName, metav1.GetOptions{})
- if err != nil {
- return apiConfig{}, fmt.Errorf("unable to get api config map `%s` `%s`; %v", cfg.APIConfigMapName, cfg.APIConfigMapNamespace, err)
- }
- create, ok := config.Data["createTXTAddr"]
- if !ok {
- return apiConfig{}, fmt.Errorf("create address missing")
- }
- delete, ok := config.Data["deleteTXTAddr"]
- if !ok {
- return apiConfig{}, fmt.Errorf("delete address missing")
- }
- return apiConfig{create, delete}, nil
-}
-
func getDomainAndEntry(ch *v1alpha1.ChallengeRequest) (string, string) {
// Both ch.ResolvedZone and ch.ResolvedFQDN end with a dot: '.'
resolvedFQDN := strings.TrimSuffix(ch.ResolvedFQDN, ".")