Auto TLS
Automatic HTTPS certificates through ACME, with CertMagic (Caddy's
certificate engine). PocketBase already gets Let's Encrypt certificates for serve example.com. Auto TLS takes over
that job and adds other certificate authorities, extra domains and wildcard certificates.
Status: stable under pocker, beta on a single app.
Install · Configure · Use · Integrations · Example
Install
Auto TLS is built into pocketone and off by default. Turn it on with --autotls (or auto: true in
pocketone.yaml). It only does something when the app serves HTTPS, that is with serve <domain> or --https; on
plain HTTP it stays idle, and without it PocketBase's own certificates are used as before.
In your own Go build, register it before the app starts:
import (
"github.com/pockethost/pocketone/ext/autotls"
"github.com/pockethost/pocketone/ext/extkit"
)
app := pocketbase.New()
extkit.MustRegister(app, autotls.NewApp(autotls.Config{Auto: true, Email: "[email protected]"}))
app.Start()
Configure
Command-line flags
pocketone serve example.com --autotls --autotlsEmail [email protected]
pocketone serve example.com --autotls --autotlsDomains "*.example.com" --autotlsDNS cloudflare # token in $CF_API_TOKEN
| Flag | Default | What it does |
|---|---|---|
--autotls |
false |
Turn it on. |
--autotlsEmail |
ACME account email, for expiry notices from the CA. | |
--autotlsCA |
letsencrypt |
letsencrypt, letsencrypt-staging, zerossl, or an ACME directory URL. |
--autotlsDomains |
Extra domains, obtained at start (comma separated). Wildcards need --autotlsDNS. |
|
--autotlsDNS |
DNS provider for DNS-01 challenges. Only cloudflare is supported. |
|
--autotlsDNSTokenEnv |
CF_API_TOKEN |
Environment variable holding the DNS provider's API token. |
pocketone.yaml
The autotls section sets the defaults for those flags. Flags win over the file.
autotls:
auto: true
email: [email protected]
ca: letsencrypt
domains: ["*.example.com"] # wildcards need dns
dns:
provider: cloudflare
api_token: $CF_API_TOKEN # read from the .env beside pocketone.yaml
storage is only in the file: where certificates are kept (default pb_data/.autotls). The DNS token can be given
as api_token (write $VAR to read it from the .env beside the file) or through api_token_env, the name of an
environment variable. api_token is only used when --autotlsDNS names the same provider as the file.
The Cloudflare token needs permission to edit the zone's DNS.
There are no dashboard settings.
pocketone.yaml reference
autotls:
Automatic HTTPS certificates (ACME): auto, email, CA, domains, DNS-01, certificate storage. The --autotls* flags win.
| Key | Type | Default | Description |
|---|---|---|---|
auto |
bool | Get certificates through ACME (CertMagic). Flag: --autotls. | |
email |
string | ACME account email, for expiry notices from the CA. Flag: --autotlsEmail. | |
ca |
string | letsencrypt (default), letsencrypt-staging, zerossl, or an ACME directory URL. Flag: --autotlsCA. | |
storage |
string | Where certificates are kept. Default pb_data/.autotls. | |
domains |
list of string | Extra domains to get at start; wildcards (*.example.com) need dns. Flag: --autotlsDomains. | |
dns.provider |
string | DNS provider for DNS-01 challenges (needed for wildcards): cloudflare. Flag: --autotlsDNS. | |
dns.api_token |
string | The provider's API token. Write $VAR to read it from the .env beside the file. | |
dns.api_token_env |
string | Or: the environment variable holding the token. Default CF_API_TOKEN. Flag: --autotlsDNSTokenEnv. |
Use
Once on, there's nothing to click. Start the app as usual with serve <domain> (or --https):
- Which hostnames get a certificate. The domains given to
serveand theirwww.variants, issued on the first request for each, plus--autotlsDomains, obtained at start. Any other hostname is refused at the TLS handshake, so a randomHostcan't trigger issuance. - How they're proved. TLS-ALPN-01 on the HTTPS port, or DNS-01 when a DNS provider is set (needed for wildcards). HTTP-01 isn't used on a single app, because port 80 is PocketBase's redirect server.
- Renewal is automatic.
- Where they're stored.
pb_data/.autotlsby default, separate from PocketBase's own.autocert_cache.
Settings are checked at start, before anything touches the network. A wildcard domain without a DNS provider, a Cloudflare provider without a token, or an unknown provider stops the app with an error such as:
tls.domains: wildcard "*.example.com" needs a DNS provider (tls.dns); per-hostname certificates work without one
With debug logging, the start shows autotls: CertMagic serves HTTPS certificates with the CA and extra domains.
Use --autotlsCA letsencrypt-staging while testing, so failed attempts don't count against Let's Encrypt's rate limits.
Integrations
Pocker
Under pocker, the stock pocketone binary (with provider: pocker) runs autotls.New(), a
server extension that gets certificates for every instance the host serves. It's configured by the same autotls
section:
autotls:
auto: true
email: [email protected]
storage: ./pb_root/.pocker-certs # default: .pocker-certs in the pocker root
domains: ["*.example.com", "example.com"]
dns: { provider: cloudflare, api_token_env: CF_API_TOKEN } # only needed for wildcards
- Without
dns, every hostname the instance source maps gets its own certificate on its first TLS handshake, with any DNS host and no API token. Hostnames no instance serves never trigger issuance. - Challenges include HTTP-01 on the pocker server's port 80, as well as TLS-ALPN-01 and DNS-01.
- Certificate files (
server.tls.cert/key) stay a core pocker feature. Setting both files andautois an error. - Certificates belong to the pocker server, not to instances; the single-app extension (
NewApp) is a separate type so it never runs per instance.
Building on Auto TLS
-
autotls.New()implements pocker'sConfigurerandTLSProvider. A host that builds its ownpocker.Serveradds it toExtensions:srv := &pocker.Server{Config: cfg, Extensions: []pocker.Extension{autotls.New()}} -
AutoTLS.Configcan be set in Go before the server starts; theautotlssection is read only whenAutois false there. -
autotls.SupportedDNSProviderslists thedns.providervalues it understands.
Example
Auto TLS is built into pocketone: examples/pocketone/main.go registers it with the other default extensions.
How it works
- Go module
github.com/pockethost/pocketone/ext/autotls. - On a single app, an
OnServehook swaps the TLS config of PocketBase's HTTPS server for CertMagic's. PocketBase's own host policy (theservedomains andwww.) decides which on-demand hostnames are allowed. The certificate manager stops when the app terminates. - TLS 1.2 is the minimum;
h2andhttp/1.1are offered, andacme-tls/1stays on for TLS-ALPN challenges. - A wildcard in
domainscovers one level (*.example.comcoversa.example.com, nota.b.example.com).
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.