Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MB-39080 Allow http for local IP addresses
Change-Id: Id2be708f1da3e448b703d0e4ebc70f9dcf066ad8
Reviewed-on: http://review.couchbase.org/c/eventing/+/132844
Tested-by: Sriram Melkote <siri@couchbase.com>
Reviewed-by: Jeelan Basha Poola <jeelan.poola@couchbase.com>
(cherry picked from commit 6cdc9a7)
Reviewed-on: http://review.couchbase.org/c/eventing/+/132848
Well-Formed: Build Bot <build@couchbase.com>
Reviewed-by: Sriram Melkote <siri@couchbase.com>
  • Loading branch information
Sriram Melkote committed Jul 20, 2020
1 parent 1d47652 commit 96a4b6c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cmd/cbevent/main.go
Expand Up @@ -216,7 +216,7 @@ func resolve(nsaddr, user, pass string, insecure bool) (*url.URL, error) {
sort.Slice(ips, func(i, j int) bool { return ips[i].To4() != nil && ips[j].To4() == nil }) // prefer v4

for _, ip := range ips {
if !ip.IsLoopback() && !insecure {
if !IsLocal(&ip) && !insecure {
msg := fmt.Errorf("Host specified is not localhost, refusing to send creds over plain http. Use -insecure to override")
return nil, msg
}
Expand Down Expand Up @@ -244,3 +244,33 @@ func resolve(nsaddr, user, pass string, insecure bool) (*url.URL, error) {
}
return nil, fmt.Errorf("Cannot access specified Console URL")
}

func IsLocal(ip *net.IP) bool {
if ip.IsLoopback() {
return true
}
ifaces, err := net.Interfaces()
if err != nil {
return false
}
for _, iface := range ifaces {
addrs, err := iface.Addrs()
if err != nil {
return false
}
for _, addr := range addrs {
switch ifip := addr.(type) {
case *net.IPAddr:
if ip.Equal(ifip.IP) {
return true
}
case *net.IPNet:
if ip.Equal(ifip.IP) {
return true
}
}
}
}

return false
}

0 comments on commit 96a4b6c

Please sign in to comment.