Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
package nebula
|
|
|
|
|
|
|
|
import (
|
2024-07-31 09:18:56 -06:00
|
|
|
"net/netip"
|
Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
"regexp"
|
|
|
|
"testing"
|
|
|
|
|
2024-07-31 09:18:56 -06:00
|
|
|
"github.com/gaissmai/bart"
|
2021-11-03 19:54:04 -06:00
|
|
|
"github.com/slackhq/nebula/config"
|
2021-11-10 20:47:38 -07:00
|
|
|
"github.com/slackhq/nebula/test"
|
Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-11-03 19:54:04 -06:00
|
|
|
func TestNewAllowListFromConfig(t *testing.T) {
|
2021-11-10 20:47:38 -07:00
|
|
|
l := test.NewLogger()
|
2021-11-03 19:54:04 -06:00
|
|
|
c := config.NewC(l)
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"192.168.0.0": true,
|
|
|
|
}
|
|
|
|
r, err := newAllowListFromConfig(c, "allowlist", nil)
|
2024-07-31 09:18:56 -06:00
|
|
|
assert.EqualError(t, err, "config `allowlist` has invalid CIDR: 192.168.0.0. netip.ParsePrefix(\"192.168.0.0\"): no '/'")
|
2021-11-03 19:54:04 -06:00
|
|
|
assert.Nil(t, r)
|
|
|
|
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"192.168.0.0/16": "abc",
|
|
|
|
}
|
|
|
|
r, err = newAllowListFromConfig(c, "allowlist", nil)
|
|
|
|
assert.EqualError(t, err, "config `allowlist` has invalid value (type string): abc")
|
|
|
|
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"192.168.0.0/16": true,
|
|
|
|
"10.0.0.0/8": false,
|
|
|
|
}
|
|
|
|
r, err = newAllowListFromConfig(c, "allowlist", nil)
|
|
|
|
assert.EqualError(t, err, "config `allowlist` contains both true and false rules, but no default set for 0.0.0.0/0")
|
|
|
|
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"0.0.0.0/0": true,
|
|
|
|
"10.0.0.0/8": false,
|
|
|
|
"10.42.42.0/24": true,
|
|
|
|
"fd00::/8": true,
|
|
|
|
"fd00:fd00::/16": false,
|
|
|
|
}
|
|
|
|
r, err = newAllowListFromConfig(c, "allowlist", nil)
|
|
|
|
assert.EqualError(t, err, "config `allowlist` contains both true and false rules, but no default set for ::/0")
|
|
|
|
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"0.0.0.0/0": true,
|
|
|
|
"10.0.0.0/8": false,
|
|
|
|
"10.42.42.0/24": true,
|
|
|
|
}
|
|
|
|
r, err = newAllowListFromConfig(c, "allowlist", nil)
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.NotNil(t, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"0.0.0.0/0": true,
|
|
|
|
"10.0.0.0/8": false,
|
|
|
|
"10.42.42.0/24": true,
|
|
|
|
"::/0": false,
|
|
|
|
"fd00::/8": true,
|
|
|
|
"fd00:fd00::/16": false,
|
|
|
|
}
|
|
|
|
r, err = newAllowListFromConfig(c, "allowlist", nil)
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.NotNil(t, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test interface names
|
|
|
|
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"interfaces": map[interface{}]interface{}{
|
|
|
|
`docker.*`: "foo",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
lr, err := NewLocalAllowListFromConfig(c, "allowlist")
|
|
|
|
assert.EqualError(t, err, "config `allowlist.interfaces` has invalid value (type string): foo")
|
|
|
|
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"interfaces": map[interface{}]interface{}{
|
|
|
|
`docker.*`: false,
|
|
|
|
`eth.*`: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
lr, err = NewLocalAllowListFromConfig(c, "allowlist")
|
|
|
|
assert.EqualError(t, err, "config `allowlist.interfaces` values must all be the same true/false value")
|
|
|
|
|
|
|
|
c.Settings["allowlist"] = map[interface{}]interface{}{
|
|
|
|
"interfaces": map[interface{}]interface{}{
|
|
|
|
`docker.*`: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
lr, err = NewLocalAllowListFromConfig(c, "allowlist")
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.NotNil(t, lr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
func TestAllowList_Allow(t *testing.T) {
|
2024-07-31 09:18:56 -06:00
|
|
|
assert.Equal(t, true, ((*AllowList)(nil)).Allow(netip.MustParseAddr("1.1.1.1")))
|
|
|
|
|
|
|
|
tree := new(bart.Table[bool])
|
|
|
|
tree.Insert(netip.MustParsePrefix("0.0.0.0/0"), true)
|
|
|
|
tree.Insert(netip.MustParsePrefix("10.0.0.0/8"), false)
|
|
|
|
tree.Insert(netip.MustParsePrefix("10.42.42.42/32"), true)
|
|
|
|
tree.Insert(netip.MustParsePrefix("10.42.0.0/16"), true)
|
|
|
|
tree.Insert(netip.MustParsePrefix("10.42.42.0/24"), true)
|
|
|
|
tree.Insert(netip.MustParsePrefix("10.42.42.0/24"), false)
|
|
|
|
tree.Insert(netip.MustParsePrefix("::1/128"), true)
|
|
|
|
tree.Insert(netip.MustParsePrefix("::2/128"), false)
|
Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
al := &AllowList{cidrTree: tree}
|
|
|
|
|
2024-07-31 09:18:56 -06:00
|
|
|
assert.Equal(t, true, al.Allow(netip.MustParseAddr("1.1.1.1")))
|
|
|
|
assert.Equal(t, false, al.Allow(netip.MustParseAddr("10.0.0.4")))
|
|
|
|
assert.Equal(t, true, al.Allow(netip.MustParseAddr("10.42.42.42")))
|
|
|
|
assert.Equal(t, false, al.Allow(netip.MustParseAddr("10.42.42.41")))
|
|
|
|
assert.Equal(t, true, al.Allow(netip.MustParseAddr("10.42.0.1")))
|
|
|
|
assert.Equal(t, true, al.Allow(netip.MustParseAddr("::1")))
|
|
|
|
assert.Equal(t, false, al.Allow(netip.MustParseAddr("::2")))
|
Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
}
|
|
|
|
|
2021-10-19 08:54:30 -06:00
|
|
|
func TestLocalAllowList_AllowName(t *testing.T) {
|
|
|
|
assert.Equal(t, true, ((*LocalAllowList)(nil)).AllowName("docker0"))
|
Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
|
|
|
|
rules := []AllowListNameRule{
|
|
|
|
{Name: regexp.MustCompile("^docker.*$"), Allow: false},
|
|
|
|
{Name: regexp.MustCompile("^tun.*$"), Allow: false},
|
|
|
|
}
|
2021-10-19 08:54:30 -06:00
|
|
|
al := &LocalAllowList{nameRules: rules}
|
Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
|
|
|
|
assert.Equal(t, false, al.AllowName("docker0"))
|
|
|
|
assert.Equal(t, false, al.AllowName("tun0"))
|
|
|
|
assert.Equal(t, true, al.AllowName("eth0"))
|
|
|
|
|
|
|
|
rules = []AllowListNameRule{
|
|
|
|
{Name: regexp.MustCompile("^eth.*$"), Allow: true},
|
|
|
|
{Name: regexp.MustCompile("^ens.*$"), Allow: true},
|
|
|
|
}
|
2021-10-19 08:54:30 -06:00
|
|
|
al = &LocalAllowList{nameRules: rules}
|
Add lighthouse.{remoteAllowList,localAllowList} (#217)
These settings make it possible to blacklist / whitelist IP addresses
that are used for remote connections.
`lighthouse.remoteAllowList` filters which remote IPs are allow when
fetching from the lighthouse (or, if you are the lighthouse, which IPs
you store and forward to querying hosts). By default, any remote IPs are
allowed. You can provide CIDRs here with `true` to allow and `false` to
deny. The most specific CIDR rule applies to each remote. If all rules
are "allow", the default will be "deny", and vice-versa. If both "allow"
and "deny" rules are present, then you MUST set a rule for "0.0.0.0/0"
as the default.
lighthouse:
remoteAllowList:
# Example to block IPs from this subnet from being used for remote IPs.
"172.16.0.0/12": false
# A more complicated example, allow public IPs but only private IPs from a specific subnet
"0.0.0.0/0": true
"10.0.0.0/8": false
"10.42.42.0/24": true
`lighthouse.localAllowList` has the same logic as above, but it applies
to the local addresses we advertise to the lighthouse. Additionally, you
can specify an `interfaces` map of regular expressions to match against
interface names. The regexp must match the entire name. All interface
rules must be either true or false (and the default rule will be the
inverse). CIDR rules are matched after interface name rules.
Default is all local IP addresses.
lighthouse:
localAllowList:
# Example to blacklist docker interfaces.
interfaces:
'docker.*': false
# Example to only advertise IPs in this subnet to the lighthouse.
"10.0.0.0/8": true
2020-04-08 13:36:43 -06:00
|
|
|
|
|
|
|
assert.Equal(t, false, al.AllowName("docker0"))
|
|
|
|
assert.Equal(t, true, al.AllowName("eth0"))
|
|
|
|
assert.Equal(t, true, al.AllowName("ens5"))
|
|
|
|
}
|