gcloud: adds an option to allow the use of private zones (#1258)

This commit is contained in:
sebastien-baillet 2020-09-26 13:29:42 +02:00 committed by GitHub
parent ba6eb9729c
commit 77aef9deb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View file

@ -791,6 +791,7 @@ func displayDNSHelp(name string) error {
ew.writeln() ew.writeln()
ew.writeln(`Additional Configuration:`) ew.writeln(`Additional Configuration:`)
ew.writeln(` - "GCE_ALLOW_PRIVATE_ZONE": Allows requested domain to be in private DNS zone, works only with a private ACME server (by default: false)`)
ew.writeln(` - "GCE_POLLING_INTERVAL": Time between DNS propagation check`) ew.writeln(` - "GCE_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "GCE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`) ew.writeln(` - "GCE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "GCE_TTL": The TTL of the TXT record used for the DNS challenge`) ew.writeln(` - "GCE_TTL": The TTL of the TXT record used for the DNS challenge`)

View file

@ -42,6 +42,7 @@ More information [here](/lego/dns/#configuration-and-credentials).
| Environment Variable Name | Description | | Environment Variable Name | Description |
|--------------------------------|-------------| |--------------------------------|-------------|
| `GCE_ALLOW_PRIVATE_ZONE` | Allows requested domain to be in private DNS zone, works only with a private ACME server (by default: false) |
| `GCE_POLLING_INTERVAL` | Time between DNS propagation check | | `GCE_POLLING_INTERVAL` | Time between DNS propagation check |
| `GCE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | | `GCE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `GCE_TTL` | The TTL of the TXT record used for the DNS challenge | | `GCE_TTL` | The TTL of the TXT record used for the DNS challenge |

View file

@ -13,6 +13,7 @@ Example = ''''''
GCE_SERVICE_ACCOUNT_FILE = "Account file path" GCE_SERVICE_ACCOUNT_FILE = "Account file path"
GCE_SERVICE_ACCOUNT = "Account" GCE_SERVICE_ACCOUNT = "Account"
[Configuration.Additional] [Configuration.Additional]
GCE_ALLOW_PRIVATE_ZONE = "Allows requested domain to be in private DNS zone, works only with a private ACME server (by default: false)"
GCE_POLLING_INTERVAL = "Time between DNS propagation check" GCE_POLLING_INTERVAL = "Time between DNS propagation check"
GCE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" GCE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
GCE_TTL = "The TTL of the TXT record used for the DNS challenge" GCE_TTL = "The TTL of the TXT record used for the DNS challenge"

View file

@ -32,6 +32,7 @@ const (
EnvServiceAccount = envNamespace + "SERVICE_ACCOUNT" EnvServiceAccount = envNamespace + "SERVICE_ACCOUNT"
EnvProject = envNamespace + "PROJECT" EnvProject = envNamespace + "PROJECT"
EnvAllowPrivateZone = envNamespace + "ALLOW_PRIVATE_ZONE"
EnvDebug = envNamespace + "DEBUG" EnvDebug = envNamespace + "DEBUG"
EnvTTL = envNamespace + "TTL" EnvTTL = envNamespace + "TTL"
@ -43,6 +44,7 @@ const (
type Config struct { type Config struct {
Debug bool Debug bool
Project string Project string
AllowPrivateZone bool
PropagationTimeout time.Duration PropagationTimeout time.Duration
PollingInterval time.Duration PollingInterval time.Duration
TTL int TTL int
@ -53,6 +55,7 @@ type Config struct {
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
Debug: env.GetOrDefaultBool(EnvDebug, false), Debug: env.GetOrDefaultBool(EnvDebug, false),
AllowPrivateZone: env.GetOrDefaultBool(EnvAllowPrivateZone, false),
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL), TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 180*time.Second), PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 180*time.Second),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*time.Second), PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*time.Second),
@ -326,11 +329,15 @@ func (d *DNSProvider) getHostedZone(domain string) (string, error) {
} }
for _, z := range zones.ManagedZones { for _, z := range zones.ManagedZones {
if z.Visibility == "public" || z.Visibility == "" { if z.Visibility == "public" || z.Visibility == "" || (z.Visibility == "private" && d.config.AllowPrivateZone) {
return z.Name, nil return z.Name, nil
} }
} }
if d.config.AllowPrivateZone {
return "", fmt.Errorf("no public or private zone found for domain %s", authZone)
}
return "", fmt.Errorf("no public zone found for domain %s", authZone) return "", fmt.Errorf("no public zone found for domain %s", authZone)
} }