Skip to content

Commit 7edc21b

Browse files
h0x0ervarunsh-coder
authored andcommitted
restrict calls to dns_servers from agent-uid
1 parent 689409c commit 7edc21b

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ coverage.txt
1919
.vscode/
2020

2121
vendor
22-
private-src
22+
private-src
23+
24+
dist
25+
local

firewall.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/coreos/go-iptables/iptables"
78
"github.com/pkg/errors"
@@ -77,6 +78,24 @@ func addBlockRules(firewall *Firewall, endpoints []ipAddressEndpoint, chain, net
7778
}
7879
}
7980

81+
// Agent uses HTTPs to resolve domain names
82+
// Only apply UID filtering for OUTPUT chain
83+
if chain == outputChain {
84+
agentUID := fmt.Sprintf("%d", os.Getuid())
85+
for _, dnsServer := range dnsServers {
86+
err = ipt.Append(filterTable, chain, direction, netInterface,
87+
"-m", "owner", "--uid-owner", agentUID,
88+
protocol, tcp,
89+
destination, dnsServer,
90+
destinationPort, "443",
91+
target, accept)
92+
93+
if err != nil {
94+
return errors.Wrapf(err, "failed to add rule for DNS server %s", dnsServer)
95+
}
96+
}
97+
}
98+
8099
for _, endpoint := range endpoints {
81100
err = ipt.Append(filterTable, chain, direction, netInterface, protocol, tcp,
82101
destination, endpoint.ipAddress,
@@ -87,16 +106,6 @@ func addBlockRules(firewall *Firewall, endpoints []ipAddressEndpoint, chain, net
87106
}
88107
}
89108

90-
// Agent uses HTTPs to resolve domain names
91-
for _, dnsServer := range dnsServers {
92-
err = ipt.Append(filterTable, chain, direction, netInterface, protocol, tcp,
93-
destination, dnsServer, target, accept)
94-
95-
if err != nil {
96-
return errors.Wrapf(err, "failed to add rule for DNS server %s", dnsServer)
97-
}
98-
}
99-
100109
// Allow AzureIPAddress
101110
err = ipt.Append(filterTable, chain, direction, netInterface, protocol, tcp,
102111
destination, AzureIPAddress, target, accept)

0 commit comments

Comments
 (0)