@@ -2,6 +2,7 @@ package main
22
33import (
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