Commit Graph

1468 Commits

Author SHA1 Message Date
Ville Vesilehto
6720959b8b lint(revive): fix unused-parameter violations (#7980) 2026-03-29 17:02:20 -07:00
Ville Vesilehto
6af8fd46fe lint(revive): fix unnecessary-stmt violations (#7978) 2026-03-29 17:02:03 -07:00
Ville Vesilehto
867cd8fd6b lint(revive): fix indent-error-flow violations (#7977) 2026-03-29 17:01:22 -07:00
Ville Vesilehto
7fd983b02c lint(revive): fix context-as-argument violations (#7976) 2026-03-29 17:01:03 -07:00
Ville Vesilehto
61330515de test(forward): restore defaultTimeout (#7981) 2026-03-29 17:00:30 -07:00
Ville Vesilehto
54b06d9a3b lint(revive): fix early-return violations (#7974) 2026-03-29 16:59:22 -07:00
Minghang Chen
34acf8353f proxyproto: add UDP session tracking for Spectrum PPv2 (#7967) 2026-03-28 15:06:36 -07:00
Ingmar Van Glabbeek
12d9457e71 plugin/file: expand SVCB/HTTPS record support (#7950)
* plugin/file: expand SVCB/HTTPS record support

Add proper SVCB (type 64) and HTTPS (type 65) handling:

- Additional section processing: include A/AAAA glue for in-bailiwick
  SVCB/HTTPS targets, matching existing SRV/MX behavior
- Target name normalization: lowercase SVCB/HTTPS Target on zone insert,
  consistent with CNAME/MX handling
- Metrics: add TypeSVCB to monitored query types (TypeHTTPS was already
  present)
- Test helpers: add SVCB()/HTTPS() constructors and Section comparison
  cases
- Tests: basic queries with glue, AliasMode, wildcards, NoData, NXDOMAIN,
  target normalization, and DNS-AID private-use key (65400-65408)
  round-trip

Signed-off-by: Ingmar <ivanglabbeek@infoblox.com>

* plugin/file: simplify HTTPS target access via field promotion

dns.HTTPS embeds dns.SVCB, so .Target is directly accessible
without the redundant .SVCB. qualifier. Fixes gosimple S1027.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ingmar <ivanglabbeek@infoblox.com>

---------

Signed-off-by: Ingmar <ivanglabbeek@infoblox.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 11:46:41 +02:00
Ilya Kulakov
a8caf4c375 plugin/tls: Add the keylog option to configure TLSConfig.KeyLogWriter (#7537)
* tls: Add the keylog option to configure TLSConfig.KeyLogWriter

Signed-off-by: Ilya Kulakov <kulakov.ilya@gmail.com>

* tls: Close keylog file on instance shutdown.

Signed-off-by: Ilya Kulakov <kulakov.ilya@gmail.com>

---------

Signed-off-by: Ilya Kulakov <kulakov.ilya@gmail.com>
2026-03-27 21:10:13 +02:00
Seena Fallah
471d62926d plugin/tsig: add require_opcode directive for opcode-based TSIG (#7828)
Extend the tsig plugin to require TSIG signatures based on DNS opcodes,
similar to the existing qtype-based requirement.

The new require_opcode directive accepts opcode names (QUERY, IQUERY,
STATUS, NOTIFY, UPDATE) or the special values "all" and "none".

This is useful for requiring TSIG on dynamic update (UPDATE) or zone
transfer notification (NOTIFY) requests while allowing unsigned queries.

Example:
```
  tsig {
    secret key. NoTCJU+DMqFWywaPyxSijrDEA/eC3nK0xi3AMEZuPVk=
    require_opcode UPDATE NOTIFY
  }
```

Signed-off-by: Seena Fallah <seenafallah@gmail.com>
2026-03-27 21:05:49 +02:00
Ville Vesilehto
49b18b8af6 test(dnssec): fix err in TestZoneSigningDouble (#7969) 2026-03-26 20:33:55 -07:00
Yong Tang
a025712827 plugin/transfter: Fix longestMatch to select the most specific zone correctly. (#7949)
* plugin/transfter: Fix longestMatch to select the most specific zone correctly.

This PR Fix longestMatch to select the most specific zone correctly.The previous implementation used lexicographic string comparison, which could choose the wrong zone; this change selects the longest matching zone instead.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Tie breaker

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Fix

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

---------

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2026-03-24 20:35:20 +02:00
rpb-ant
31e16025ef plugin/cache: prefetch without holding a client connection (#7944) 2026-03-24 08:47:11 -07:00
Syed Azeez
f582a01dc9 fix(kubernetes): record cluster_ip services in dns_programming_duration metric (#7951)
Signed-off-by: Azeez Syed <syedazeez337@gmail.com>
2026-03-24 05:29:28 -07:00
Yong Tang
f67994442a core: Reject oversized GET dns query parameter of DoH (#7926)
* core: Reject oversized GET dns query parameter of DoH

The DoH POST path limits request size using http.MaxBytesReader(..., 65536), but the GET path passes the dns query value directly to base64ToMsg() with no equivalent bound.

This PR adds length check.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Fix

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

---------

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2026-03-18 09:38:44 +02:00
Ville Vesilehto
ece6a68b04 docs(cache): clarify TTL directive (#7941) 2026-03-17 11:55:11 -07:00
Ville Vesilehto
5a63eb61a3 fix(file): protect Zone.Expired with mutex (#7940) 2026-03-16 14:08:03 -07:00
Yong Tang
c0d676e026 Fix case-sensitive zone handling in the transfer plugin for AXFR/IXFR. (#7899)
This PR fixes Fix case-sensitive zone handling in the transfer plugin for AXFR/IXFR, raised in 7898

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2026-03-15 14:27:03 -07:00
Ville Vesilehto
6819d2ca6c refactor(test): replace deprecated pbutil dep (#7924)
Replace github.com/matttproud/golang_protobuf_extensions/pbutil
with google.golang.org/protobuf/encoding/protodelim for reading
varint size-delimited protobuf messages in the metrics scraper.

The new protodelim package is already available via the existing
google.golang.org/protobuf dependency, so this removes pbutil as
a direct dependency entirely.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2026-03-15 21:35:59 +02:00
Peppi-Lotta
7ff001dca7 Add optional TLS support to /metrics endpoint (#7255)
* Use exporter-toolkit to enable optional TLS encryption on /metrics endpoint

Signed-off-by: peppi-lotta <peppi-lotta.saari@est.tech>

* Implement startup listener to signal server readiness

Signed-off-by: peppi-lotta <peppi-lotta.saari@est.tech>

---------

Signed-off-by: peppi-lotta <peppi-lotta.saari@est.tech>
2026-03-12 13:49:00 -07:00
cangming
500707c43a plugin/forward: add max_age option to enforce an absolute connection lifetime (#7903)
* plugin/pkg/proxy: add max_age for per-connection lifetime cap

Introduce a max_age setting on Transport that closes connections based
on creation time, independent of idle-timeout (expire).

Background: PR #7790 changed the connection pool from LIFO to FIFO for
source-port diversity. Under FIFO, every connection is cycled through
the pool and its used timestamp is refreshed continuously. When request
rate is high enough that pool_size / request_rate < expire, no
connection ever becomes idle and expire never fires. This prevents
CoreDNS from opening new connections to upstreams that scale out (e.g.
new Kubernetes pods behind a ClusterIP service with conntrack pinning).

max_age addresses this by enforcing an absolute upper bound on
connection lifetime regardless of activity:
- persistConn gains a created field set at dial time.
- Transport gains maxAge (default 0 = unlimited, preserving existing
  behaviour).
- Dial(): rejects cached connections whose creation age exceeds max_age.
- cleanup(): when maxAge > 0, uses a linear scan over both idle-timeout
  and max-age predicates; when maxAge == 0, preserves the original
  binary-search path on used time (sorted by FIFO insertion order).
- Both hot paths pre-compute the deadline outside any inner loop to
  avoid repeated time.Now() calls.

Tests added:
- TestMaxAgeExpireByCreation: connection with old created but fresh used
  must be rejected even though idle-timeout would pass.
- TestMaxAgeFIFORotation: three FIFO-rotated connections (old created,
  fresh used) must all be rejected, confirming that continuous rotation
  cannot prevent max-age expiry.

Signed-off-by: cangming <cangming@cangming.app>

* plugin/forward: add max_age option

Expose Transport.SetMaxAge through the forward plugin so operators can
set an absolute upper bound on connection lifetime via the Corefile.

Usage:
  forward . 1.2.3.4 {
      max_age 30s
  }

Default is 0 (unlimited), which preserves existing behaviour.
A positive value causes connections older than max_age to be closed and
re-dialled on the next request, ensuring CoreDNS reconnects to newly
scaled-out upstream pods even under sustained load where the idle
timeout (expire) would never fire.

If max_age is set, it must not be less than expire; the parser rejects
this combination at startup with a clear error message.

Signed-off-by: cangming <cangming@cangming.app>

---------

Signed-off-by: cangming <cangming@cangming.app>
2026-03-09 11:50:03 -07:00
liucongran
2daf48e42d feat(secondary): Send NOTIFY messages after zone transfer (#7901)
* feat(secondary): Send NOTIFY messages after zone transfer

- Modified TransferIn() method to accept a transfer.Transfer parameter
- Added NOTIFY message sending after successful zone transfer in secondary plugin
- Updated Update() method to pass the transfer handler through the zone update cycle
- Added comprehensive tests for the secondary notify functionality

Closes #5669

Signed-off-by: liucongran <liucongran327@gmail.com>

* fix(secondary): Fix TransferIn method call in test

Update test to pass nil parameter to TransferIn method after signature change

Signed-off-by: liucongran <liucongran327@gmail.com>

* refactor(secondary): Clean up imports and add helper methods

- Reorder imports for consistency
- Add hasSOA() and getSOA() helper methods to Zone
- Remove unnecessary blank lines in tests

Signed-off-by: liucongran <liucongran327@gmail.com>

* fix(test): Fix variable declaration in secondary test

Change corefile variable assignment to use short declaration syntax (:=)
to fix compilation error.

Signed-off-by: liucongran <liucongran327@gmail.com>

* refactor(secondary): Use getSOA helper method in shouldTransfer

Replace direct SOA access with getSOA() helper method for consistency.

Signed-off-by: liucongran <liucongran327@gmail.com>

---------

Signed-off-by: liucongran <liucongran327@gmail.com>
Co-authored-by: liucongran <liucongran@cestc.cn>
2026-03-07 21:15:44 -08:00
Ville Vesilehto
90a9739478 chore(lint): bump golangci-lint to v2.11.1 (#7905)
- Added nolint to plugin/auto/walk.go to avoid a symlink/TOCTOU
  warning, as it needs to follow symlink.
- Replaced a few flagged integer conversions with safe equivalents in
  cache hashing, reuseport socket setup, and TLS arg handling
- Preallocated response rule slices in plugin/rewrite/name.go
- Replaced WriteString(fmt.Sprintf/Sprintln(...)) with direct
  fmt.Fprint* calls
- Removed stale nolint directives from code and tests that are no
  longer needed

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2026-03-06 11:50:24 -08:00
Yong Tang
51a11b3664 plugin/reload: Allow disabling jitter with 0s (#7896)
This PR fixes #7894 by allowing reload 2s 0s as documented.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2026-03-05 18:35:41 -08:00
yangsenzk
5b7da1fbf7 plugin/forward: fix parsing error when handling TLS+IPv6 address (#7848) 2026-02-25 02:21:39 -08:00
YOUNEVSKY
7ae1c40db2 plugin/loop: use crypto/rand for query name generation (#7881) 2026-02-25 02:21:04 -08:00
hide
78524a7921 fix(rewrite): fix cname target rewrite for CNAME chains (#7853)
* fix(rewrite): fix cname target rewrite for CNAME chains

This fix corrects the cname target rewrite to handle CNAME chains:
- Preserves only the CNAME records before matching the rule
- Rewrites only the CNAME target that matches the rule
- Includes all records from the re-resolved upstream response

Signed-off-by: hide <hide@hide.net.eu.org>

* docs(rewrite): document how answer records are handled in CNAME target rewrite

Signed-off-by: hide <hide@hide.net.eu.org>

* fix(rewrite): simplify slice append per staticcheck S1011

Signed-off-by: hide <hide@hide.net.eu.org>

* docs(rewrite): add extra line between code and paragraph

Signed-off-by: hide <hide@hide.net.eu.org>

---------

Signed-off-by: hide <hide@hide.net.eu.org>
Co-authored-by: hide <hide@hide.net.eu.org>
2026-02-21 16:10:35 -05:00
Ville Vesilehto
191a783e46 chore(deps): k8s-io group to client-go v0.35.1 (#7868) 2026-02-17 10:13:22 -08:00
Ville Vesilehto
23774edfa4 fix(kubernetes): panic on empty ListenHosts (#7857) 2026-02-16 07:04:19 -08:00
Ville Vesilehto
6fd38dca06 chore: bump minimum Go version to 1.25 (#7788) 2026-02-16 05:28:30 -08:00
Ville Vesilehto
b1080a2934 chore: bump Go version to 1.26.0 (#7856) 2026-02-16 04:26:18 -08:00
Adphi
e9c0db32dc feat(proxyproto): add proxy protocol support (#7738)
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
2026-02-10 17:14:05 -08:00
vflaux
30c20b52ff refactor(cache): modernize with generics (#7842) 2026-02-03 17:23:53 -08:00
Kelly Kane
b3d79f59e5 Add metadata for response Type and Class to Log. (#7806) 2026-01-26 08:03:03 -08:00
Henrik Gerdes
7f410524d0 docs: clarify kubernetes auth docs (#7831)
Signed-off-by: Henrik Gerdes <hegerdes@outlook.de>
2026-01-21 18:36:11 -08:00
Shiv Tyagi
f1f0955cb9 fix: return SOA and NS records when queried for a record CNAMEd to origin (#7808)
* fix: return SOA and NS records when queried for a record CNAMEd to origin

Signed-off-by: Shiv Tyagi <shivtyagi3015@gmail.com>

* chore(test): add test for covering cname to origin scenario in file plugin

Signed-off-by: Shiv Tyagi <shivtyagi3015@gmail.com>

---------

Signed-off-by: Shiv Tyagi <shivtyagi3015@gmail.com>
2026-01-21 18:35:48 -08:00
Ville Vesilehto
f3983c1111 perf(proxy): use mutex-based connection pool (#7790)
* perf(proxy): use mutex-based connection pool

The proxy package (used for example by the forward plugin) utilized
an actor model where a single connManager goroutine managed
connection pooling via unbuffered channels (dial, yield, ret). This
design serialized all connection acquisition and release operations
through a single goroutine, creating a bottleneck under high
concurrency. This was observable as a performance degradation when
using a single upstream backend compared to multiple backends
(which sharded the bottleneck).

Changes:
- Removed dial, yield, and ret channels from the Transport struct.
- Removed the connManager goroutine's request processing loop.
- Implemented Dial() and Yield() using a sync.Mutex to protect the
  connection slice, allowing for fast concurrent access without
  context switching.
- Downgraded connManager to a simple background cleanup loop that
  only handles connection expiration on a ticker.
- Updated plugin/pkg/proxy/connect.go to use direct method calls
  instead of channel sends.
- Updated tests to reflect the removal of internal channels.

Benchmarks show that this change eliminates the single-backend
bottleneck. Now a single upstream backend performs on par with
multiple backends, and overall throughput is improved.

The implementation aligns with standard Go patterns for connection
pooling (e.g., net/http.Transport).

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

* fix: address PR review for persistent.go

- Named mutex field instead of embedding, to not expose
  Lock() and Unlock()
- Move stop check outside of lock in Yield()
- Close() without a separate goroutine
- Change stop channel to struct

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

* fix: address code review feedback for conn pool

- Switch from LIFO to FIFO connection selection for source port
  diversity, reducing DNS cache poisoning risk (RFC 5452).
- Remove "clear entire cache" optimization as it was LIFO-specific.
  FIFO naturally iterates and skips expired connections.
- Remove all goroutines for closing connections; collect connections
  while holding lock, close synchronously after releasing lock.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

* fix: remove unused error consts

No longer utilised after refactoring the channel based approach.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

* feat(forward): add max_idle_conns option

Add configurable connection pool limit for the forward plugin via
the max_idle_conns Corefile option.

Changes:
- Add SetMaxIdleConns to proxy
- Add maxIdleConns field to Forward struct
- Add max_idle_conns parsing in forward plugin setup
- Apply setting to each proxy during configuration
- Update forward plugin README with new option

By default the value is 0 (unbounded). When set, excess
connections returned to the pool are closed immediately
rather than cached.

Also add a yield related test.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

* chore(proxy): simple Dial by closing conns inline

Remove toClose slice collection to reduce complexity. Instead close
expired connections directly while iterating. Reduces complexity with
negligible lock-time impact.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

* chore: fewer explicit Unlock calls

Cleaner and less chance of forgetting to unlock on new possible
code paths.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>

---------

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2026-01-13 17:49:46 -08:00
Ville Vesilehto
b723bd94d4 fix(plugins): add regex length limit (#7802) 2026-01-05 09:48:48 -08:00
Raisa Kabir
adba778626 Refactor: Update the cache getter function (#7800)
Rename the cache getter function to reflect the true functionality of retrieving with
TTL consideration.

Refs: https://github.com/coredns/coredns/issues/6505

Signed-off-by: Raisa Kabir <raisa.kabir2010@gmail.com>
2026-01-05 18:24:04 +02:00
Syed Azeez
6dca5b26d1 fix(lint): address G114 gosec findings in ready, pprof, and health plugins (#7798)
Replace http.Serve() with http.Server{} configured with timeouts to
address G114 gosec findings (HTTP server without timeouts). This
prevents potential slowloris attacks and resource exhaustion.

Changes:
- Add ReadTimeout, WriteTimeout, IdleTimeout (5s each) to HTTP servers
- Use srv.Shutdown(ctx) for graceful shutdown instead of ln.Close()
- Follow existing pattern from plugin/metrics

Fixes part of #7793

Signed-off-by: Azeez Syed <syedazeez337@gmail.com>
2026-01-01 11:25:37 +02:00
Syed Azeez
7b38eb8625 plugin: fix gosec G115 integer overflow warnings (#7799)
Fix integer overflow conversion warnings (G115) by adding appropriate
suppressions where values are provably bounded.

Fixes: https://github.com/coredns/coredns/issues/7793

Changes:
- Updated 56 G115 annotations to use consistent // #nosec G115 format
- Added 2 //nolint:gosec suppressions for conditional expressions
- Removed G115 exclusion from golangci.yml (now explicitly handled per-line)

Suppressions justify why each conversion is safe (e.g., port numbers
are bounded 1-65535, DNS TTL limits, pool lengths, etc.)

Signed-off-by: Azeez Syed <syedazeez337@gmail.com>
2026-01-01 10:20:29 +02:00
Ville Vesilehto
be934b2b06 perf(metrics): implement plugin chain tracking (#7791)
Remove expensive runtime.Caller calls from metrics Recorder.WriteMsg
by tracking the responding plugin through the plugin chain instead.

- Add PluginTracker interface and pluginWriter wrapper in plugin.go
- Modify NextOrFailure to wrap ResponseWriter with plugin name
- Update metrics Recorder to implement PluginTracker
- Remove authoritativePlugin method using filepath inspection

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-12-29 14:33:12 -08:00
Ville Vesilehto
b21c752d7f chore(lint): enable gosec (#7792)
Enable "gosec" linter.

Exclude:

- All G115 (integer overflow) findings, to be fixed separately.

Add targeted gosec annotations for:

- non-crypto math/rand usage
- md5 used only for file change detection
- G114 ("net/http serve with no timeout settings"), to be fixed
  separately.

Other findings fixed.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-12-29 14:01:27 -08:00
Ville Vesilehto
4f0368f8bf feat(clouddns): API to 0.258.0 with deprecations (#7787) 2025-12-23 11:47:59 -08:00
Ville Vesilehto
d37f7f7754 fix(sign): report parser err before missing SOA (#7775) 2025-12-23 09:50:16 -08:00
Ross Golder
f35e57f301 Fix for misleading SOA parser warnings (#7774)
* Improve SOA error handling/reporting.

Signed-off-by: Ross Golder <ross@golder.org>

* Add tests for malformed SOA records

Signed-off-by: Ross Golder <ross@golder.org>

* Address review comments: assert exact parse errors in SOA tests and fix gofmt

Signed-off-by: Ross Golder <ross@golder.org>

---------

Signed-off-by: Ross Golder <ross@golder.org>
2025-12-21 11:54:59 +02:00
Ville Vesilehto
0d8cbb1a6b Merge commit from fork
Add configurable resource limits to prevent potential DoS vectors
via connection/stream exhaustion on gRPC, HTTPS, and HTTPS/3 servers.

New configuration plugins:
- grpc_server: configure max_streams, max_connections
- https: configure max_connections
- https3: configure max_streams

Changes:
- Use netutil.LimitListener for connection limiting
- Use gRPC MaxConcurrentStreams and message size limits
- Add QUIC MaxIncomingStreams for HTTPS/3 stream limiting
- Set secure defaults: 256 max streams, 200 max connections
- Setting any limit to 0 means unbounded/fallback to previous impl

Defaults are applied automatically when plugins are omitted from
config.

Includes tests and integration tests.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-12-17 19:08:59 -08:00
pasteley
388cbc5187 plugin/kubernetes: rate limits to api server (#7771)
Signed-off-by: pasteley <ceasebeing@gmail.com>
2025-12-15 20:06:16 -08:00
Ville Vesilehto
05efeb0a7e fix(test): prevent race condition in dial test (#7770)
The test "TestDial_TransportStoppedDuringRetWait" replaced
tr.dial and tr.ret with test-controlled channels, then called
tr.Start(). Since connManager reads from t.dial, both the test
and connManager were racing to read from the same channel.
Remove tr.Start() since the test manually simulates connManager
behavior.

Also changed some test log formatting to align with other tests.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-12-15 19:30:56 -08:00
rusttech
1fd4ba2e5f fix: fix slice init length (#6901)
Signed-off-by: rusttech <gopher@before.tech>
2025-12-09 18:17:07 -08:00