Skip to content

Commit

Permalink
feat: add support for autogroup:tagged
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Jan 2, 2024
1 parent a303de7 commit 54fa423
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/domain/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
AutoGroupSelf = "autogroup:self"
AutoGroupMember = "autogroup:member"
AutoGroupMembers = "autogroup:members"
AutoGroupTagged = "autogroup:tagged"
AutoGroupInternet = "autogroup:internet"
)

Expand Down Expand Up @@ -317,6 +318,14 @@ func (a ACLPolicy) expandMachineAlias(m *Machine, alias string, src bool, u *Use
}
}

if alias == AutoGroupTagged {
if m.HasTags() {
return m.IPs()
} else {
return []string{}
}
}

if alias == AutoGroupInternet && m.IsExitNode() {
return autogroupInternetRanges()
}
Expand Down
43 changes: 43 additions & 0 deletions internal/domain/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,49 @@ func TestACLPolicy_BuildFilterRulesWithAutoGroupMember(t *testing.T) {
assert.Equal(t, expectedRules, actualRules)
}

func TestACLPolicy_BuildFilterRulesWithAutoGroupTagged(t *testing.T) {

p1 := createMachine("[email protected]")
p2 := createMachine("[email protected]")
p3 := createMachine("[email protected]", "tag:web")

policy := ACLPolicy{
ACLs: []ACL{
{
Action: "accept",
Src: []string{"autogroup:tagged"},
Dst: []string{"*:22"},
},
},
}

dst := createMachine("[email protected]")

actualRules := policy.BuildFilterRules([]Machine{*p1, *p2, *p3}, dst)

expectedSrcIPs := []string{
p3.IPv4.String(), p3.IPv6.String(),
}
sort.Strings(expectedSrcIPs)

expectedRules := []tailcfg.FilterRule{
{
SrcIPs: expectedSrcIPs,
DstPorts: []tailcfg.NetPortRange{
{
IP: "*",
Ports: tailcfg.PortRange{
First: 22,
Last: 22,
},
},
},
},
}

assert.Equal(t, expectedRules, actualRules)
}

func TestACLPolicy_BuildFilterRulesAutogroupSelf(t *testing.T) {
p1 := createMachine("[email protected]")
p2 := createMachine("[email protected]")
Expand Down

0 comments on commit 54fa423

Please sign in to comment.