-
-
Notifications
You must be signed in to change notification settings - Fork 573
Implement FCrDNS and other DNS features #1308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7f29fe7
Implement FCrDNS and other DNS features
btomaev 1b8634c
Redesign DNS cache and methods
btomaev c22747d
Redesign DNS cache
btomaev 3afa0e9
Fix DNS cache
btomaev ef6d58b
Rename regexSafe arg
btomaev a872e66
Alter verifyFCrDNS(addr) behaviour
btomaev b1cc3e7
Remove unused dnsCache field from Server struct
btomaev bea3696
Upd expressions docs
btomaev 872e675
Update docs/docs/CHANGELOG.md
Xe 9d56738
Merge branch 'main' of https://github.com/TecharoHQ/anubis into featu…
btomaev 0e4b5a2
Merge branch 'feature/dns' of https://github.com/btomaev/anubis into …
btomaev 8ccb5b8
refactor(dns): simplify FCrDNS logging
btomaev 418234f
docs: clarify verifyFCrDNS behavior
btomaev 186f535
fix(dns): Improve FCrDNS error handling and tests
btomaev bdf84bd
docs: Update FCrDNS documentation and spelling
btomaev 31305be
chore: update spelling
Xe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| - name: telegrambot | ||
| action: ALLOW | ||
| expression: | ||
| all: | ||
| - userAgent.matches("TelegramBot") | ||
| - verifyFCrDNS(remoteAddress, "ptr\\.telegram\\.org$") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| - name: vkbot | ||
| action: ALLOW | ||
| expression: | ||
| all: | ||
| - userAgent.matches("vkShare[^+]+\\+http\\://vk\\.com/dev/Share") | ||
| - verifyFCrDNS(remoteAddress, "^snipster\\d+\\.go\\.mail\\.ru$") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| - name: yandexbot | ||
| action: ALLOW | ||
| expression: | ||
| all: | ||
| - userAgent.matches("\\+http\\://yandex\\.com/bots") | ||
| - verifyFCrDNS(remoteAddress, "^.*\\.yandex\\.(ru|com|net)$") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - import: (data)/clients/telegram-preview.yaml | ||
| - import: (data)/clients/vk-preview.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
| - Add support to simple Valkey/Redis cluster mode | ||
| - Open Graph passthrough now reuses the configured target Host/SNI/TLS settings, so metadata fetches succeed when the upstream certificate differs from the public domain. ([1283](https://github.com/TecharoHQ/anubis/pull/1283)) | ||
| - Stabilize the CVE-2025-24369 regression test by always submitting an invalid proof instead of relying on random POW failures. | ||
| - Add Polish locale ([#1292](https://github.com/TecharoHQ/anubis/pull/1309)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ### Logging customization | ||
|
|
||
|
|
@@ -44,6 +43,30 @@ logging: | |
| ``` | ||
|
|
||
| Additionally, information about [how Anubis uses each logging level](./admin/policies.mdx#log-levels) has been added to the documentation. | ||
|
Xe marked this conversation as resolved.
|
||
| ### DNS Features | ||
|
|
||
| - CEL expressions for: | ||
| - FCrDNS checks | ||
| - Forward DNS queries | ||
| - Reverse DNS queries | ||
| - `arpaReverseIP` to transform IPv4/6 addresses into ARPA reverse IP notation. | ||
| - `regexSafe` to escape regex special characters (useful for including `remoteAddress` or headers in regular expressions). | ||
| - DNS cache and other optimizations to minimize unnecessary DNS queries. | ||
|
|
||
| The DNS cache TTL can be changed in the bots config like this: | ||
| ```yaml | ||
| dns_ttl: | ||
| forward: 600 | ||
| reverse: 600 | ||
| ``` | ||
| The default value for both forward and reverse queries is 300 seconds. | ||
|
|
||
| The `verifyFCrDNS` CEL function has two overloads: | ||
| - `(addr)` | ||
| Simply verifies that the remote side has PTR records pointing to the target address. | ||
| - `(addr, ptrPattern)` | ||
| Verifies that the remote side refers to a specific domain and that this domain points to the target IP. | ||
|
|
||
|
|
||
| ## v1.23.1: Lyse Hext - Echo 1 | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package dns | ||
|
|
||
| import ( | ||
| "log/slog" | ||
| "time" | ||
|
|
||
| "github.com/TecharoHQ/anubis/lib/store" | ||
|
|
||
| _ "github.com/TecharoHQ/anubis/lib/store/all" | ||
| ) | ||
|
|
||
| type DnsCache struct { | ||
| forward store.JSON[[]string] | ||
| reverse store.JSON[[]string] | ||
| forwardTTL time.Duration | ||
| reverseTTL time.Duration | ||
| } | ||
|
|
||
| func NewDNSCache(forwardTTL int, reverseTTL int, backend store.Interface) *DnsCache { | ||
| return &DnsCache{ | ||
| forward: store.JSON[[]string]{ | ||
| Underlying: backend, | ||
| Prefix: "forwardDNS", | ||
| }, | ||
| reverse: store.JSON[[]string]{ | ||
| Underlying: backend, | ||
| Prefix: "reverseDNS", | ||
| }, | ||
| forwardTTL: time.Duration(forwardTTL) * time.Second, | ||
| reverseTTL: time.Duration(reverseTTL) * time.Second, | ||
| } | ||
| } | ||
|
|
||
| func (d *Dns) getCachedForward(host string) ([]string, bool) { | ||
| if d.cache == nil { | ||
| return nil, false | ||
| } | ||
| if cached, err := d.cache.forward.Get(d.ctx, host); err == nil { | ||
| slog.Debug("DNS: forward cache hit", "name", host, "ips", cached) | ||
| return cached, true | ||
| } | ||
| slog.Debug("DNS: forward cache miss", "name", host) | ||
| return nil, false | ||
| } | ||
|
|
||
| func (d *Dns) getCachedReverse(addr string) ([]string, bool) { | ||
| if d.cache == nil { | ||
| return nil, false | ||
| } | ||
| if cached, err := d.cache.reverse.Get(d.ctx, addr); err == nil { | ||
| slog.Debug("DNS: reverse cache hit", "addr", addr, "names", cached) | ||
| return cached, true | ||
| } | ||
| slog.Debug("DNS: reverse cache miss", "addr", addr) | ||
| return nil, false | ||
| } | ||
|
|
||
| func (d *Dns) forwardCachePut(host string, entries []string) { | ||
| if d.cache == nil { | ||
| return | ||
| } | ||
| d.cache.forward.Set(d.ctx, host, entries, d.cache.forwardTTL) | ||
| } | ||
|
|
||
| func (d *Dns) reverseCachePut(addr string, entries []string) { | ||
| if d.cache == nil { | ||
| return | ||
| } | ||
| d.cache.reverse.Set(d.ctx, addr, entries, d.cache.reverseTTL) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this. So much.