Skip to content

Commit 8c5b238

Browse files
committed
Add sinkhole IP address
1 parent 9624f9e commit 8c5b238

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

dnsproxy.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type Answer struct {
3939
Data string `json:"data"`
4040
}
4141

42+
const StepSecuritySinkHoleIPAddress = "54.185.253.63"
43+
4244
func (proxy *DNSProxy) getResponse(requestMsg *dns.Msg) (*dns.Msg, error) {
4345

4446
responseMsg := new(dns.Msg)
@@ -98,7 +100,12 @@ func (proxy *DNSProxy) getIPByDomain(domain string) (string, error) {
98100
if !proxy.isAllowedDomain(domain) {
99101
go WriteLog(fmt.Sprintf("domain not allowed: %s", domain))
100102
go WriteAnnotation(fmt.Sprintf("DNS resolution for domain %s was blocked", domain))
101-
return "", fmt.Errorf("domain not allowed %s", domain)
103+
104+
// return an ip address, so calling process calls the ip address
105+
// the call will be blocked by the firewall
106+
proxy.Cache.Set(domain, StepSecuritySinkHoleIPAddress)
107+
108+
return StepSecuritySinkHoleIPAddress, nil
102109
}
103110
}
104111

dnsproxy_test.go

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

33
import (
4+
"fmt"
45
"net/http"
56
"reflect"
67
"testing"
@@ -21,6 +22,7 @@ func TestDNSProxy_getResponse(t *testing.T) {
2122
Cache := InitCache(60 * 1000000000)
2223
rrDnsGoogle, _ := dns.NewRR("dns.google. IN A 8.8.8.8")
2324
rrDnsTest, _ := dns.NewRR("test.com. IN A 67.225.146.248")
25+
rrDnsNotAllowed, _ := dns.NewRR(fmt.Sprintf("notallowed.com. IN A %s", StepSecuritySinkHoleIPAddress))
2426
rrDnsAllowed, _ := dns.NewRR("allowed.com. IN A 67.225.146.248")
2527

2628
apiclient := &ApiClient{Client: &http.Client{}, APIURL: agentApiBaseUrl}
@@ -61,8 +63,8 @@ func TestDNSProxy_getResponse(t *testing.T) {
6163
{name: "type A notallowed.com",
6264
fields: fields{Cache: &Cache, EgressPolicy: EgressPolicyBlock, AllowedEndpoints: []Endpoint{{domainName: "allowed.com"}}},
6365
args: args{requestMsg: &dns.Msg{Question: []dns.Question{{Name: "notallowed.com.", Qtype: dns.TypeA}}}},
64-
want: &dns.Msg{},
65-
wantErr: true,
66+
want: &dns.Msg{Answer: []dns.RR{rrDnsNotAllowed}},
67+
wantErr: false,
6668
},
6769
{name: "type A test.com egress policy cached",
6870
fields: fields{Cache: &Cache, EgressPolicy: EgressPolicyBlock, AllowedEndpoints: []Endpoint{{domainName: "test.com"}}},

0 commit comments

Comments
 (0)