Skip to content

Commit 54fa423

Browse files
committed
feat: add support for autogroup:tagged
1 parent a303de7 commit 54fa423

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

internal/domain/acl.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
AutoGroupSelf = "autogroup:self"
1919
AutoGroupMember = "autogroup:member"
2020
AutoGroupMembers = "autogroup:members"
21+
AutoGroupTagged = "autogroup:tagged"
2122
AutoGroupInternet = "autogroup:internet"
2223
)
2324

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

321+
if alias == AutoGroupTagged {
322+
if m.HasTags() {
323+
return m.IPs()
324+
} else {
325+
return []string{}
326+
}
327+
}
328+
320329
if alias == AutoGroupInternet && m.IsExitNode() {
321330
return autogroupInternetRanges()
322331
}

internal/domain/acl_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,49 @@ func TestACLPolicy_BuildFilterRulesWithAutoGroupMember(t *testing.T) {
193193
assert.Equal(t, expectedRules, actualRules)
194194
}
195195

196+
func TestACLPolicy_BuildFilterRulesWithAutoGroupTagged(t *testing.T) {
197+
198+
p1 := createMachine("jane@example.com")
199+
p2 := createMachine("nick@example.com")
200+
p3 := createMachine("joe@example.com", "tag:web")
201+
202+
policy := ACLPolicy{
203+
ACLs: []ACL{
204+
{
205+
Action: "accept",
206+
Src: []string{"autogroup:tagged"},
207+
Dst: []string{"*:22"},
208+
},
209+
},
210+
}
211+
212+
dst := createMachine("john@example.com")
213+
214+
actualRules := policy.BuildFilterRules([]Machine{*p1, *p2, *p3}, dst)
215+
216+
expectedSrcIPs := []string{
217+
p3.IPv4.String(), p3.IPv6.String(),
218+
}
219+
sort.Strings(expectedSrcIPs)
220+
221+
expectedRules := []tailcfg.FilterRule{
222+
{
223+
SrcIPs: expectedSrcIPs,
224+
DstPorts: []tailcfg.NetPortRange{
225+
{
226+
IP: "*",
227+
Ports: tailcfg.PortRange{
228+
First: 22,
229+
Last: 22,
230+
},
231+
},
232+
},
233+
},
234+
}
235+
236+
assert.Equal(t, expectedRules, actualRules)
237+
}
238+
196239
func TestACLPolicy_BuildFilterRulesAutogroupSelf(t *testing.T) {
197240
p1 := createMachine("john@example.com")
198241
p2 := createMachine("jane@example.com")

0 commit comments

Comments
 (0)