Skip to content

Commit

Permalink
Add etcd basic auth support for coredns provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ch4nn0n committed Feb 13, 2024
1 parent f71a822 commit c076bed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/tutorials/coredns.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ helm install --name my-coredns --values values.yaml stable/coredns
### Install external ExternalDNS
ETCD_URLS is configured to etcd client service address.

If the etcd client being used has basic auth enabled, for example when using the [bitnami/etcd](https://artifacthub.io/packages/helm/bitnami/etcd) chart, the `ETCD_USERNAME` and `ETCD_PASSWORD` environment variables can be used to provide the credentials.

#### Manifest (for clusters without RBAC enabled)

```yaml
Expand Down
10 changes: 9 additions & 1 deletion provider/coredns/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,14 @@ func getETCDConfig() (*etcdcv3.Config, error) {
}
etcdURLs := strings.Split(etcdURLsStr, ",")
firstURL := strings.ToLower(etcdURLs[0])
etcdUsername := os.Getenv("ETCD_USERNAME")
etcdPassword := os.Getenv("ETCD_PASSWORD")
if strings.HasPrefix(firstURL, "http://") {
return &etcdcv3.Config{Endpoints: etcdURLs}, nil
return &etcdcv3.Config{
Endpoints: etcdURLs,
Username: etcdUsername,
Password: etcdPassword,
}, nil
} else if strings.HasPrefix(firstURL, "https://") {
caFile := os.Getenv("ETCD_CA_FILE")
certFile := os.Getenv("ETCD_CERT_FILE")
Expand All @@ -221,6 +227,8 @@ func getETCDConfig() (*etcdcv3.Config, error) {
return &etcdcv3.Config{
Endpoints: etcdURLs,
TLS: tlsConfig,
Username: etcdUsername,
Password: etcdPassword,
}, nil
} else {
return nil, errors.New("etcd URLs must start with either http:// or https://")
Expand Down

0 comments on commit c076bed

Please sign in to comment.