Skip to content

provision: allow third-party apps to access caddytls.TLS.dns filed - #7930

Open
PurplestViper wants to merge 1 commit into
caddyserver:masterfrom
PurplestViper:globaldns
Open

provision: allow third-party apps to access caddytls.TLS.dns filed#7930
PurplestViper wants to merge 1 commit into
caddyserver:masterfrom
PurplestViper:globaldns

Conversation

@PurplestViper

@PurplestViper PurplestViper commented Aug 8, 2026

Copy link
Copy Markdown

No AI was used.

The global dns option can be used publicly, but caddytls.TLS.dns should be exported for use by third-party app; otherwise, reflection must be used.
For example, mholt/caddy-dynamicdns#106
https://github.com/mholt/caddy-dynamicdns/pull/106/changes#diff-3d56da1a5c865a0689b48c66b4b24ff2441ea4c442c2bc9dd074814034f78fc8R136-R152

tlsAppModule, err := a.ctx.App("tls")
if err != nil {
	return fmt.Errorf("failed to get TLS app module: %v", err)
}
tlsApp, ok := tlsAppModule.(*caddytls.TLS)
if !ok {
	return fmt.Errorf("TLS app is not of type *caddytls.TLS")
}
dnsField := reflect.ValueOf(tlsApp).Elem().FieldByName("dns")
if !dnsField.IsValid() {
	return fmt.Errorf("incompatible Caddy version: private field 'dns' not found in caddytls.TLS")
}
dnsInterface := reflect.NewAt(dnsField.Type(), unsafe.Pointer(dnsField.UnsafeAddr())).Elem().Interface()
if dnsInterface == nil {
	return fmt.Errorf("a DNS provider is required")
}
a.Providers[0].dnsProvider = dnsInterface.(libdns.RecordSetter)

@CLAassistant

CLAassistant commented Aug 8, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@PurplestViper PurplestViper changed the title Allow third-party apps to access TLS DNS data provision: allow third-party apps to access caddytls.TLS.dns filed Aug 8, 2026
@mohammed90

Copy link
Copy Markdown
Member

Exporting an any field for random access by 3rd party feels like code-smell. Are we sure this is absolutely the only way?

@PurplestViper

Copy link
Copy Markdown
Author

There is no data in DNSRaw, data exists only in the dns field. However, even if DNSRaw did contain data, calling LoadModule() again would not be a good approach.
The specific types here originate from the providers in libdns. I have reviewed all the providers, with the exception of websupport, dode, and nanelo—which implement only the RecordAppender and RecordDeleter interfaces—all of the nearly one hundred providers implement at least the RecordGetter, RecordAppender, RecordSetter, and RecordDeleter interfaces. Perhaps, when exporting the dns field, we could change its type to RecordAppender or RecordDeleter or all?

@PurplestViper

PurplestViper commented Aug 8, 2026

Copy link
Copy Markdown
Author

Based on the existing code,
ACME DNS-01 requires the provider to implement at least the RecordAppender and RecordDeleter interfaces,
https://github.com/caddyserver/certmagic/blob/d93662a04b9232e986ce76d657b016e58a8e69b3/solvers.go#L583-L592

// DNSProvider defines the set of operations required for
// ACME challenges or other sorts of domain verification.
// A DNS provider must be able to append and delete records
// in order to solve ACME challenges. Find one you can use
// at https://github.com/libdns. If your provider isn't
// implemented yet, feel free to contribute!
type DNSProvider interface {
	libdns.RecordAppender
	libdns.RecordDeleter
}

Encrypted ClientHello (ECH) requires the provider to implement at least the RecordGetter and RecordSetter interfaces.

// ECHDNSProvider can service DNS entries for ECH purposes.
type ECHDNSProvider interface {
libdns.RecordGetter
libdns.RecordSetter
}

Given the widespread adoption of the DNS-01 challenge and the implementation status of the libdns library, the minimum requirement here should be the implementation of the RecordAppender and RecordDeleter interfaces, setting the dns field type to any is unreasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants