Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"permissions": {
"allow": [
"Bash(git pull:*)"
"Bash(git pull:*)",
"Bash(git rebase *)",
"Bash(git branch *)",
"Bash(git checkout *)",
"Bash(git cherry-pick *)",
"Bash(git rm *)",
"Bash(git add *)",
"Bash(go build *)",
"Bash(go test *)",
"Bash(npx vitest *)"
]
}
}
8 changes: 8 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ on:
description: Existing release tag to publish
required: true
type: string
# Called by "Build and release" after it publishes a release, because a
# release created with GITHUB_TOKEN does not trigger other workflows.
workflow_call:
inputs:
tag:
description: Existing release tag to publish
required: true
type: string

permissions:
contents: read
Expand Down
36 changes: 35 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
REQUESTED_REVISION: ${{ inputs.revision }}
REQUESTED_TAG: ${{ inputs.tag }}
EVENT_TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
# A push to the default branch that changes GATESENTRY_VERSION in
# main.go releases that version; no release branch or manual tag.
AUTO_RELEASE: ${{ github.event_name == 'push' && github.ref_type == 'branch' }}
run: |
revision=$(git rev-parse HEAD)
if [[ -n "$REQUESTED_REVISION" ]]; then
Expand All @@ -49,7 +52,17 @@ jobs:
tag="$EVENT_TAG"
fi
publish=false
if [[ -n "$tag" ]]; then
if [[ -z "$tag" && "$AUTO_RELEASE" == "true" ]]; then
version=$(sed -n 's/^var GATESENTRY_VERSION = "\(.*\)"$/\1/p' main.go)
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "unexpected GATESENTRY_VERSION '$version'" >&2; exit 1; }
if git show-ref --verify --quiet "refs/tags/v$version"; then
echo "v$version is already released; building without publishing"
else
echo "GATESENTRY_VERSION is $version and v$version is not tagged; releasing it"
tag="v$version"
publish=true
fi
elif [[ -n "$tag" ]]; then
git check-ref-format "refs/tags/$tag"
git show-ref --verify --quiet "refs/tags/$tag"
test "$(git rev-parse "refs/tags/$tag^{commit}")" = "$revision"
Expand Down Expand Up @@ -112,6 +125,18 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.build.outputs.revision }}
sparse-checkout: CHANGELOG.md
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Extract release notes from CHANGELOG
env:
TAG: ${{ needs.build.outputs.tag }}
run: |
awk -v h="## $TAG" 'index($0, h) == 1 {p=1; next} p && /^## v/ {exit} p' CHANGELOG.md > release-notes.md
test -s release-notes.md || echo "GateSentry $TAG" > release-notes.md
- uses: actions/download-artifact@v5
with:
name: gatesentry-${{ needs.build.outputs.revision }}
Expand All @@ -123,6 +148,15 @@ jobs:
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.build.outputs.tag }}
target_commitish: ${{ needs.build.outputs.revision }}
body_path: release-notes.md
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
needs: [build, publish]
uses: ./.github/workflows/build-docker.yml
with:
tag: ${{ needs.build.outputs.tag }}
secrets: inherit
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ __pycache__/
*.pyc
*.pyo
.pytest_cache/
.codex/
.factory/
.mcp.json
code-factory-audit.html
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
# CHANGELOG

## v2.0.0 (24 September 2026)

**Breaking:** the policy document format changes from version 1 to version 2. Existing policies upgrade automatically on first read and keep enforcing what they enforced before; the next policy write persists the new format. The v1 API fields (`action`, `domains`, `categories` on a group, and `mitm_action` on a rule) are replaced by the fields below.

### Policy model

- **One policy per request:** every request resolves to the signed-in proxy user's policy, then the device's assigned policy, then an undeletable Default policy — so unassigned, unknown, and NATed clients always have a policy instead of falling through to nothing
- **Blocked and allowed lists:** a policy has `blocked_categories`, `blocked_domains`, and `allowed_domains` (which win over the blocked lists and the gateway-wide categories)
- **Targeted rules:** each rule names its own target (all traffic, specific domains, or specific categories) and can carry a schedule, a user scope, URL patterns, and response-type conditions — so "block TikTok but allow YouTube" or "no internet at bedtime" is one policy instead of two
- **First-match evaluation:** rules run top to bottom before the lists; the first active rule whose target covers the request decides
- **Safe search:** DNS-enforced safe search for Google (all country domains), Bing, DuckDuckGo, and YouTube restricted mode, using the providers' documented restricted-mode endpoints; fails closed on lookup error
- **Short block TTL:** DNS block answers use a 60-second TTL so schedules and pauses take effect within a minute
- **Proxy user over device:** a signed-in proxy user's policy wins over the device's, because the login is the more specific identity; the device stays recorded for logs and drilldown
- **User conflict detection:** a proxy user listed on two policies is rejected at save time
- **Default policy protection:** the default policy cannot be deleted or given proxy users

### DNS

- Safe search rewrites search engine and YouTube host names to their restricted-mode endpoints via CNAME + upstream resolution
- Gateway-wide categories are now evaluated inside the policy evaluator, so a policy's allowed domains can exempt a category hit on DNS the same way they do on the proxy

### Proxy

- Typed `PolicyDecision` replaces the reflection-based `interface{}` contract between the policy service and the proxy
- URL patterns are tested before the request leaves the gateway, not after fetching the response
- URL patterns skip CONNECT tunnels (which carry only host:port) and are tested per-request inside the decrypted connection instead
- A policy allow skips the gateway-wide URL blocklist and content-type rules
- The block page names the deciding policy and rule
- Transparent HTTP connections are handled by the full proxy handler (with block pages) instead of being silently dropped
- Transparent proxy connections feed the device inventory so per-device policies work on routed deployments where DNS bypasses GateSentry

### Templates

- Starters are useful out of the box: Young child and Teen block categories, force safe search, and add a bedtime rule; Guest blocks adult content and malware; Focused work blocks social media during working hours
- Schedule presets add a rule (block all traffic during the window) instead of setting a removed group-level schedule field

### UI

- Policies page rebuilt: each policy card shows its blocked categories, domains, rules as sentences, assigned devices with add/remove, and safe search status
- Device assignment lives on the policy card with an "Add a device" picker; removing a device tag moves it to the default policy
- "Test a site" panel: pick a device, type a domain or URL, choose DNS or proxy path, and see the verdict, the deciding rule, the evaluator trace, and safe-search status — uses the live evaluator and changes nothing
- Policy editor: blocked categories, blocked domains, always-allowed domains, safe search toggle, proxy users, and ordered rules with their own target (all traffic / categories / domains), schedule, user scope, and collapsible URL/response-type conditions with a proxy-only warning
- Domain input accepts pasted URLs and strips them to the domain
- Device detail shows the effective policy (including the default) instead of reporting no policy when unassigned
- `/policies` registered as a server-side SPA route (fixes 404 on reload)

### Upgrade notes

- The policy document upgrades from v1 to v2 on first read; the old `action`/`domains`/`categories` fields become `blocked_domains`/`blocked_categories`/`allowed_domains` and rules get explicit targets
- A v1 group with a schedule becomes a v2 group with a scheduled rule
- The per-rule TLS inspection setting (`mitm_action`) is removed; URL and response-type conditions turn inspection on by themselves
- API consumers using `action`, `domains`, or `categories` on a policy group must switch to the new fields

## v1.27.0 (20 September 2026)

- Policy rules now belong to a policy group: a group owns its categories, domains, and rules, and one evaluator decides for both DNS and the proxy. A rule is no longer a separate record that has to be matched to a group by hand
Expand Down
3 changes: 1 addition & 2 deletions application/dns/server/decision_provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func TestDNSDecisionProvenanceBlock(t *testing.T) {
})
devices := deviceStore.GetAllDevices()
if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{
ID: "kids", Name: "Kids", Action: gatesentryPolicy.ActionBlock,
Domains: []string{"*.games.example"},
ID: "kids", Name: "Kids", BlockedDomains: []string{"*.games.example"},
}}); err != nil {
t.Fatal(err)
}
Expand Down
116 changes: 96 additions & 20 deletions application/dns/server/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func TestDNSPolicyGroupBlocksForAssignedDevice(t *testing.T) {
t.Fatalf("devices = %d", len(devices))
}
if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{
ID: "kids", Name: "Kids", Action: gatesentryPolicy.ActionBlock,
Domains: []string{"*.games.example"},
ID: "kids", Name: "Kids", BlockedDomains: []string{"*.games.example"},
}}); err != nil {
t.Fatal(err)
}
Expand All @@ -77,7 +76,7 @@ func TestDNSPolicyAllowExemptsGlobalBlocklist(t *testing.T) {
deviceStore.UpsertDevice(&discovery.Device{Hostnames: []string{"adult-pc"}, IPv4: "192.0.2.20"})
devices := deviceStore.GetAllDevices()
if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{
ID: "adults", Action: gatesentryPolicy.ActionAllow, Domains: []string{"ads.example"},
ID: "adults", AllowedDomains: []string{"ads.example"},
}}); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -105,7 +104,7 @@ func TestDNSPolicyUnknownClientKeepsGlobalBehavior(t *testing.T) {
defer cleanup()

if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{
ID: "kids", Action: gatesentryPolicy.ActionBlock, Domains: []string{"games.example"},
ID: "kids", BlockedDomains: []string{"games.example"},
}}); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -134,7 +133,7 @@ func TestDNSPolicyAmbiguousIPDoesNotBorrowGroupPolicy(t *testing.T) {
t.Fatalf("devices = %d", len(devices))
}
if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{
ID: "kids", Action: gatesentryPolicy.ActionBlock, Domains: []string{"games.example"},
ID: "kids", BlockedDomains: []string{"games.example"},
}}); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -172,7 +171,7 @@ func TestDNSPolicyStaleDeviceStillResolvedForLiveQuery(t *testing.T) {
stale.LastSeen = time.Now().Add(-2 * time.Hour)
deviceStore.UpsertDevice(&stale)
if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{
ID: "kids", Action: gatesentryPolicy.ActionBlock, Domains: []string{"games.example"},
ID: "kids", BlockedDomains: []string{"games.example"},
}}); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -215,11 +214,11 @@ func TestMigrateLegacyDevicePolicyRunsOnlyOnce(t *testing.T) {
t.Fatal(err)
}
snap := svc.Snapshot()
if len(snap.Groups) != 1 {
t.Fatalf("groups after first migration = %d, want 1", len(snap.Groups))
if len(snap.Groups) != 2 {
t.Fatalf("groups after first migration = %d, want the migrated one and the default policy", len(snap.Groups))
}
// Simulate an API edit after migration.
if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{ID: "edited", Action: gatesentryPolicy.ActionBlock, Domains: []string{"x.example"}}}); err != nil {
if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{ID: "edited", BlockedDomains: []string{"x.example"}}}); err != nil {
t.Fatal(err)
}
// Re-running migration must not clobber the edit.
Expand Down Expand Up @@ -267,27 +266,26 @@ func TestMigrateLegacyRulesBecomesUnassignedGroups(t *testing.T) {
}

snapshot := svc.Snapshot()
if len(snapshot.Groups) != 1 {
t.Fatalf("groups after rule migration = %d, want 1", len(snapshot.Groups))
if len(snapshot.Groups) != 2 {
t.Fatalf("groups after rule migration = %d, want the imported one and the default policy", len(snapshot.Groups))
}
var imported gatesentryPolicy.PolicyGroup
for _, group := range snapshot.Groups {
imported = group
if group.ID != gatesentryPolicy.DefaultGroupID {
imported = group
}
}
if len(snapshot.Assignments) != 0 {
t.Fatalf("imported rules were assigned: %+v", snapshot.Assignments)
}
if imported.Name != "No games" || len(imported.Domains) != 1 || imported.Domains[0] != "games.example" {
if imported.Name != "No games" {
t.Fatalf("imported group = %+v", imported)
}
if imported.Action != gatesentryPolicy.ActionBlock {
t.Fatalf("imported group action = %q, want block", imported.Action)
}
if len(imported.Rules) != 1 {
t.Fatalf("imported rules = %d, want 1", len(imported.Rules))
}
rule := imported.Rules[0]
if rule.Action != gatesentryPolicy.ActionBlock || rule.MITMAction != gatesentryPolicy.MITMActionEnable {
if rule.Action != gatesentryPolicy.ActionBlock || len(rule.Target.Domains) != 1 || rule.Target.Domains[0] != "games.example" {
t.Fatalf("imported rule = %+v", rule)
}
if len(rule.URLRegexes) != 1 || rule.URLRegexes[0] != "/play" {
Expand All @@ -306,8 +304,8 @@ func TestMigrateLegacyRulesBecomesUnassignedGroups(t *testing.T) {
if err := svc.Reload(); err != nil {
t.Fatal(err)
}
if count := len(svc.Snapshot().Groups); count != 1 {
t.Fatalf("groups after repeated migration = %d, want 1", count)
if count := len(svc.Snapshot().Groups); count != 2 {
t.Fatalf("groups after repeated migration = %d, want the imported one and the default policy", count)
}
}

Expand Down Expand Up @@ -373,7 +371,7 @@ func TestDNSPolicyGroupAllowExemptsGatewayCategory(t *testing.T) {
t.Fatal(err)
}
if err := svc.SaveGroups([]gatesentryPolicy.PolicyGroup{{
ID: "adults", Action: gatesentryPolicy.ActionAllow, Categories: []string{"social"},
ID: "adults", Name: "Adults", AllowedDomains: []string{"facebook.com"},
}}); err != nil {
t.Fatal(err)
}
Expand All @@ -394,3 +392,81 @@ func TestDNSPolicyGroupAllowExemptsGatewayCategory(t *testing.T) {
t.Fatal("group allow must exempt a gateway-wide category")
}
}

// startFakeUpstream serves A answers for the safe-search endpoints so the
// rewrite can be tested without the network.
func startFakeUpstream(t *testing.T) {
t.Helper()
mux := dns.NewServeMux()
mux.HandleFunc(".", func(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.SetReply(r)
if r.Question[0].Name == "restrict.youtube.com." {
rr, _ := dns.NewRR("restrict.youtube.com. 300 IN A 216.239.38.120")
m.Answer = append(m.Answer, rr)
}
w.WriteMsg(m)
})
server := &dns.Server{Addr: "127.0.0.1:0", Net: "udp", Handler: mux}
ready := make(chan struct{})
server.NotifyStartedFunc = func() { close(ready) }
go server.ListenAndServe()
<-ready
previous := externalResolver
externalResolver = server.PacketConn.LocalAddr().String()
t.Cleanup(func() {
externalResolver = previous
server.Shutdown()
})
}

func TestDNSDefaultPolicyBlocksUnassignedClients(t *testing.T) {
svc, cleanup := setupTestPolicyServer(t)
defer cleanup()
if err := svc.UpdateGroup(gatesentryPolicy.DefaultGroupID, gatesentryPolicy.PolicyGroup{
Name: "Default", BlockedDomains: []string{"tiktok.com"},
}); err != nil {
t.Fatal(err)
}
if err := svc.Reload(); err != nil {
t.Fatal(err)
}
req := new(dns.Msg)
req.SetQuestion("www.tiktok.com.", dns.TypeA)
w := newMockResponseWriter("198.51.100.44")
handleDNSRequest(w, req)
if w.msg == nil || w.msg.Rcode != dns.RcodeNameError {
t.Fatalf("expected the default policy to block an unknown client, got %+v", w.msg)
}
if ttl := w.msg.Answer[0].Header().Ttl; ttl > 60 {
t.Fatalf("block answer TTL = %d, want a short TTL so schedules apply promptly", ttl)
}
}

func TestDNSSafeSearchRewritesYouTube(t *testing.T) {
svc, cleanup := setupTestPolicyServer(t)
defer cleanup()
startFakeUpstream(t)
if err := svc.UpdateGroup(gatesentryPolicy.DefaultGroupID, gatesentryPolicy.PolicyGroup{
Name: "Default", SafeSearch: true,
}); err != nil {
t.Fatal(err)
}
if err := svc.Reload(); err != nil {
t.Fatal(err)
}
req := new(dns.Msg)
req.SetQuestion("www.youtube.com.", dns.TypeA)
w := newMockResponseWriter("198.51.100.44")
handleDNSRequest(w, req)
if w.msg == nil || len(w.msg.Answer) < 2 {
t.Fatalf("answer = %+v, want a CNAME and the target's address", w.msg)
}
cname, ok := w.msg.Answer[0].(*dns.CNAME)
if !ok || cname.Target != "restrict.youtube.com." {
t.Fatalf("first answer = %v, want a CNAME to restrict.youtube.com", w.msg.Answer[0])
}
if a, ok := w.msg.Answer[1].(*dns.A); !ok || a.A.String() != "216.239.38.120" {
t.Fatalf("second answer = %v, want the restricted endpoint's address", w.msg.Answer[1])
}
}
Loading
Loading