yusing / go-proxy

Easy to use reverse proxy with docker integration
MIT License
99 stars 4 forks source link

Fail to add DuckDns provider to autocert #14

Closed earvingad closed 5 months ago

earvingad commented 5 months ago

Hello,

Modified autocert.go by adding duckdns provider as follow:

import (
    ....
    "github.com/go-acme/lego/v4/providers/dns/duckdns"
)
----snip----
var providersGenMap = map[string]ProviderGenerator{
    "cloudflare": providerGenerator(cloudflare.NewDefaultConfig, cloudflare.NewDNSProviderConfig),
        "clouddns": providerGenerator(clouddns.NewDefaultConfig, clouddns.NewDNSProviderConfig),
    "duckdns": providerGenerator(duckdns.NewDefaultConfig, duckdns.NewDNSProviderConfig),
}

Run make build and it compiles successfully.

Config:

autocert: # (optional, if you need autocert feature)
  email: "user@domain.com" # (required) email for acme certificate
  domains: # (required)
    - "*.server.duckdns.org" # domain for acme certificate, use wild card to allow all subdomains
  provider: duckdns # (required) dns challenge provider (string)
  options: # provider specific options
    DUCKDNS_TOKEN: "<----token--->"

Error after running bin/go-proxy

FATA[04-04 19:57:43] invalid config
  -   validation error
  - I[#/autocert] S[#/properties/autocert/anyOf] anyOf failed
  I[#/autocert/provider] S[#/properties/autocert/anyOf/0/properties/provider/const] value must be "cloudflare"  component=config
yusing commented 5 months ago

Hi, please remove line 27, 41-52 from schema/config.schema.json then try again.

This is an error message from schema validator.

yusing commented 5 months ago

For duckdns, it should be token: instead of DUCKDNS_TOKEN, according to this file.

I will update the README for this, and may support DUCKDNS_TOKEN like environment variable style options

earvingad commented 5 months ago

Hi, please remove line 27, 41-52 from schema/config.schema.json then try again.

This is an error message from schema validator.

yes, after deleting the lines it is working now!!

For duckdns, it should be token: instead of DUCKDNS_TOKEN, according to this file.

I will update the README for this, and may support DUCKDNS_TOKEN like environment variable style options

You were right, it got the tls certificate in just a moment! this is veeeery simple to set up! Thanks a lot!

I dont think there is the need to support DUCKDNS_TOKEN just token is understandable. Same case for clouddns_client_id just as the docs say clien_idis enough it was my confusion.

Config for duckdns:

autocert: # (optional, if you need autocert feature)
  email: "user@domain.com" # (required) email for acme certificate
  domains: # (required)
    - "*.<-domain name->.duckdns.org" # domain for acme certificate, use wild card to allow all subdomain
  provider: duckdns # (required) dns challenge provider (string)
  options: # provider specific options
    token: "<--Token-->"
2024/04/05 00:08:49 [INFO] acme: Registering account for user@domain.com
2024/04/05 00:08:50 [INFO] [*.server.duckdns.org] acme: Obtaining bundled SAN certificate
2024/04/05 00:08:52 [INFO] [*.server.duckdns.org] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz-v3/334657148027
2024/04/05 00:08:52 [INFO] [*.server.duckdns.org] acme: use dns-01 solver
2024/04/05 00:08:52 [INFO] [*.server.duckdns.org] acme: Preparing to solve DNS-01
2024/04/05 00:08:52 [INFO] [*.server.duckdns.org] acme: Trying to solve DNS-01
2024/04/05 00:08:52 [INFO] [*.server.duckdns.org] acme: Checking DNS record propagation. [nameservers=127.0.0.53:53]
2024/04/05 00:08:54 [INFO] Wait for propagation [timeout: 1m0s, interval: 2s]
2024/04/05 00:09:03 [INFO] [*.server.duckdns.org] The server validated our request
2024/04/05 00:09:03 [INFO] [*.server.duckdns.org] acme: Cleaning DNS-01 challenge
2024/04/05 00:09:03 [INFO] [*.server.duckdns.org] acme: Validations succeeded; requesting certificates
2024/04/05 00:09:07 [INFO] [*.server.duckdns.org] Server responded with a certificate.
INFO[04-05 00:09:07] certificate "*.server.duckdns.org": expire on 2024-07-03 23:09:03 +0000 UTC  component=autocert
INFO[04-05 00:09:07] starting http proxy server on :80
INFO[04-05 00:09:07] starting https proxy server on :443
INFO[04-05 00:09:07] starting http panel server on :8080
INFO[04-05 00:09:07] starting https panel server on :8443
INFO[04-05 00:09:07] loaded 1 proxy configurations                 name=server kind=file component=provider
INFO[04-05 00:09:07] next renewal in 71h59m59.99999848s            component=autocert
yusing commented 5 months ago

INFO[04-05 00:09:07] next renewal in 71h59m59.99999848s component=autocert

Thanks for testing it out, there is a bug that the cert will renew every 3 days, but not every N-3 days. I will fix it soon.

earvingad commented 5 months ago

Yes I was about to ask you if it could be changed. Usually it should renew every two months requesting a 3 months certificate. That's the thumb rule I saw in other reverse proxies (swag or npm).