mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-30 02:43:05 +00:00
fix(acl): fix issue with groups in excludeCorretlyTaggedNodes
This commit fix issue #563
This commit is contained in:
parent
f9c4d577e2
commit
babf9470c2
2 changed files with 64 additions and 7 deletions
5
acls.go
5
acls.go
|
@ -367,7 +367,7 @@ func expandAlias(
|
||||||
|
|
||||||
// if alias is a namespace
|
// if alias is a namespace
|
||||||
nodes := filterMachinesByNamespace(machines, alias)
|
nodes := filterMachinesByNamespace(machines, alias)
|
||||||
nodes = excludeCorrectlyTaggedNodes(aclPolicy, nodes, alias)
|
nodes = excludeCorrectlyTaggedNodes(aclPolicy, nodes, alias, stripEmailDomain)
|
||||||
|
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
ips = append(ips, n.IPAddresses.ToStringSlice()...)
|
ips = append(ips, n.IPAddresses.ToStringSlice()...)
|
||||||
|
@ -405,10 +405,13 @@ func excludeCorrectlyTaggedNodes(
|
||||||
aclPolicy ACLPolicy,
|
aclPolicy ACLPolicy,
|
||||||
nodes []Machine,
|
nodes []Machine,
|
||||||
namespace string,
|
namespace string,
|
||||||
|
stripEmailDomain bool,
|
||||||
) []Machine {
|
) []Machine {
|
||||||
out := []Machine{}
|
out := []Machine{}
|
||||||
tags := []string{}
|
tags := []string{}
|
||||||
for tag, ns := range aclPolicy.TagOwners {
|
for tag, ns := range aclPolicy.TagOwners {
|
||||||
|
owners, _ := expandTagOwners(aclPolicy, namespace, stripEmailDomain)
|
||||||
|
ns = append(owners, namespace)
|
||||||
if contains(ns, namespace) {
|
if contains(ns, namespace) {
|
||||||
tags = append(tags, tag)
|
tags = append(tags, tag)
|
||||||
}
|
}
|
||||||
|
|
54
acls_test.go
54
acls_test.go
|
@ -1204,6 +1204,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
|
||||||
aclPolicy ACLPolicy
|
aclPolicy ACLPolicy
|
||||||
nodes []Machine
|
nodes []Machine
|
||||||
namespace string
|
namespace string
|
||||||
|
stripEmailDomain bool
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -1248,6 +1249,56 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
namespace: "joe",
|
namespace: "joe",
|
||||||
|
stripEmailDomain: true,
|
||||||
|
},
|
||||||
|
want: []Machine{
|
||||||
|
{
|
||||||
|
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.4")},
|
||||||
|
Namespace: Namespace{Name: "joe"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "exclude nodes with valid tags, and owner is in a group",
|
||||||
|
args: args{
|
||||||
|
aclPolicy: ACLPolicy{
|
||||||
|
Groups: Groups{
|
||||||
|
"group:accountant": []string{"joe", "bar"},
|
||||||
|
},
|
||||||
|
TagOwners: TagOwners{"tag:accountant-webserver": []string{"group:accountant"}},
|
||||||
|
},
|
||||||
|
nodes: []Machine{
|
||||||
|
{
|
||||||
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.1"),
|
||||||
|
},
|
||||||
|
Namespace: Namespace{Name: "joe"},
|
||||||
|
HostInfo: HostInfo{
|
||||||
|
OS: "centos",
|
||||||
|
Hostname: "foo",
|
||||||
|
RequestTags: []string{"tag:accountant-webserver"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.2"),
|
||||||
|
},
|
||||||
|
Namespace: Namespace{Name: "joe"},
|
||||||
|
HostInfo: HostInfo{
|
||||||
|
OS: "centos",
|
||||||
|
Hostname: "foo",
|
||||||
|
RequestTags: []string{"tag:accountant-webserver"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.4"),
|
||||||
|
},
|
||||||
|
Namespace: Namespace{Name: "joe"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
namespace: "joe",
|
||||||
|
stripEmailDomain: true,
|
||||||
},
|
},
|
||||||
want: []Machine{
|
want: []Machine{
|
||||||
{
|
{
|
||||||
|
@ -1289,6 +1340,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
namespace: "joe",
|
namespace: "joe",
|
||||||
|
stripEmailDomain: true,
|
||||||
},
|
},
|
||||||
want: []Machine{
|
want: []Machine{
|
||||||
{
|
{
|
||||||
|
@ -1334,6 +1386,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
namespace: "joe",
|
namespace: "joe",
|
||||||
|
stripEmailDomain: true,
|
||||||
},
|
},
|
||||||
want: []Machine{
|
want: []Machine{
|
||||||
{
|
{
|
||||||
|
@ -1373,6 +1426,7 @@ func Test_excludeCorrectlyTaggedNodes(t *testing.T) {
|
||||||
test.args.aclPolicy,
|
test.args.aclPolicy,
|
||||||
test.args.nodes,
|
test.args.nodes,
|
||||||
test.args.namespace,
|
test.args.namespace,
|
||||||
|
test.args.stripEmailDomain,
|
||||||
)
|
)
|
||||||
if !reflect.DeepEqual(got, test.want) {
|
if !reflect.DeepEqual(got, test.want) {
|
||||||
t.Errorf("excludeCorrectlyTaggedNodes() = %v, want %v", got, test.want)
|
t.Errorf("excludeCorrectlyTaggedNodes() = %v, want %v", got, test.want)
|
||||||
|
|
Loading…
Reference in a new issue