Skip to content

Commit d444089

Browse files
Merge pull request #142 from step-security/int
Address issues running on devspaces
2 parents 0ff42ee + 928bd53 commit d444089

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

dnsproxy.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io/ioutil"
77
"math"
8+
"strings"
89
"sync"
910

1011
"github.com/miekg/dns"
@@ -154,6 +155,11 @@ func (proxy *DNSProxy) getIPByDomain(domain string) (string, error) {
154155
}
155156

156157
if proxy.EgressPolicy == EgressPolicyBlock {
158+
if strings.HasSuffix(domain, ".internal.") || strings.HasSuffix(domain, ".internal.cloudapp.net.") {
159+
go WriteLog(fmt.Sprintf("unable to resolve internal domains: %s", domain))
160+
return "", fmt.Errorf("cannot resolve internal domains")
161+
}
162+
157163
if !proxy.isAllowedDomain(domain) {
158164
go WriteLog(fmt.Sprintf("domain not allowed: %s", domain))
159165
go WriteAnnotation(fmt.Sprintf("DNS resolution for domain %s was blocked", domain))
@@ -170,6 +176,7 @@ func (proxy *DNSProxy) getIPByDomain(domain string) (string, error) {
170176

171177
answer, err := proxy.ResolveDomain(domain)
172178
if err != nil {
179+
go WriteLog(fmt.Sprintf("unable to resolve domain: %s", domain))
173180
return "", fmt.Errorf("error in response from dns.google %v", err)
174181
}
175182

eventhandler.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type EventHandler struct {
3131
procMutex sync.RWMutex
3232
}
3333

34-
var classAPrivateSubnet, classBPrivateSubnet, classCPrivateSubnet, loopBackSubnet *net.IPNet
34+
var classAPrivateSubnet, classBPrivateSubnet, classCPrivateSubnet, loopBackSubnet, ipv6LinkLocalSubnet, ipv6LocalSubnet *net.IPNet
3535

3636
func (eventHandler *EventHandler) handleFileEvent(event *Event) {
3737
eventHandler.fileMutex.Lock()
@@ -239,6 +239,11 @@ func (eventHandler *EventHandler) GetToolChain(ppid, exe string) *Tool {
239239
}
240240

241241
func isPrivateIPAddress(ipAddress string) bool {
242+
243+
if ipAddress == AllZeros {
244+
return true
245+
}
246+
242247
if classAPrivateSubnet == nil {
243248
_, classAPrivateSubnet, _ = net.ParseCIDR(classAPrivateAddressRange)
244249
}
@@ -251,6 +256,12 @@ func isPrivateIPAddress(ipAddress string) bool {
251256
if loopBackSubnet == nil {
252257
_, loopBackSubnet, _ = net.ParseCIDR(loopBackAddressRange)
253258
}
259+
if ipv6LinkLocalSubnet == nil {
260+
_, ipv6LinkLocalSubnet, _ = net.ParseCIDR(ipv6LinkLocalAddressRange)
261+
}
262+
if ipv6LocalSubnet == nil {
263+
_, ipv6LocalSubnet, _ = net.ParseCIDR(ipv6LocalAddressRange)
264+
}
254265

255266
ip := net.ParseIP(ipAddress)
256267

@@ -270,5 +281,18 @@ func isPrivateIPAddress(ipAddress string) bool {
270281
return true
271282
}
272283

284+
if ipv6LinkLocalSubnet.Contains(ip) {
285+
return true
286+
}
287+
288+
if ipv6LocalSubnet.Contains(ip) {
289+
return true
290+
}
291+
292+
// https://gist.github.com/nanmu42/9c8139e15542b3c4a1709cb9e9ac61eb
293+
if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
294+
return true
295+
}
296+
273297
return false
274298
}

firewall.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ const (
2727
classAPrivateAddressRange = "10.0.0.0/8"
2828
classBPrivateAddressRange = "172.16.0.0/12"
2929
classCPrivateAddressRange = "192.168.0.0/16"
30+
ipv6LinkLocalAddressRange = "fe80::/10"
31+
ipv6LocalAddressRange = "fc00::/7"
3032
loopBackAddressRange = "127.0.0.0/8"
3133
AzureIPAddress = "168.63.129.16"
3234
MetadataIPAddress = "169.254.169.254"
35+
AllZeros = "0.0.0.0"
3336
)
3437

3538
type ipAddressEndpoint struct {

0 commit comments

Comments
 (0)