Skip to content

Commit 9a05e12

Browse files
committed
policyfile: add AttrConfig support to ACLDetails
Signed-off-by: Raj Singh <[email protected]>
1 parent d51fc60 commit 9a05e12

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

policyfile.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ type ACL struct {
7474
Postures map[string][]string `json:"postures,omitempty" hujson:"Postures,omitempty"`
7575
DefaultSourcePosture []string `json:"defaultSrcPosture,omitempty" hujson:"DefaultSrcPosture,omitempty"`
7676

77+
// AttrConfig maps attribute names to their configuration for custom device attributes.
78+
AttrConfig map[string]ACLAttrConfig `json:"attrConfig,omitempty" hujson:"AttrConfig,omitempty"`
79+
7780
// ETag is the etag corresponding to this version of the ACL
7881
ETag string `json:"-"`
7982
}
@@ -159,6 +162,15 @@ type NodeAttrGrantApp struct {
159162
Domains []string `json:"domains,omitempty" hujson:"Domains,omitempty"`
160163
}
161164

165+
// ACLAttrConfig represents configuration for a custom device attribute.
166+
type ACLAttrConfig struct {
167+
Type string `json:"type,omitempty" hujson:"Type,omitempty"`
168+
// AllowSetByNode indicates if nodes can set this attribute via LocalAPI.
169+
AllowSetByNode bool `json:"allowSetByNode,omitempty" hujson:"AllowSetByNode,omitempty"`
170+
// BroadcastToPeers lists which nodes should receive this attribute value.
171+
BroadcastToPeers []string `json:"broadcastToPeers,omitempty" hujson:"BroadcastToPeers,omitempty"`
172+
}
173+
162174
// Get retrieves the [ACL] that is currently set for the tailnet.
163175
func (pr *PolicyFileResource) Get(ctx context.Context) (*ACL, error) {
164176
req, err := pr.buildRequest(ctx, http.MethodGet, pr.buildTailnetURL("acl"))

policyfile_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ func TestACL_Unmarshal(t *testing.T) {
175175
"tag:monitoring": {"group:devops"},
176176
"tag:prod": {"group:devops"},
177177
},
178+
AttrConfig: map[string]ACLAttrConfig{
179+
"custom:example": {
180+
Type: "string",
181+
AllowSetByNode: true,
182+
BroadcastToPeers: []string{"*"},
183+
},
184+
"custom:secure": {
185+
Type: "bool",
186+
AllowSetByNode: false,
187+
BroadcastToPeers: []string{"tag:admin"},
188+
},
189+
"custom:priority": {
190+
Type: "number",
191+
AllowSetByNode: true,
192+
},
193+
},
178194
DERPMap: (*ACLDERPMap)(nil),
179195
SSH: []ACLSSH{
180196
{

testdata/acl.hujson

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424
// users in group:devops can apply the tag tag:prod
2525
"tag:prod": ["group:devops"],
2626
},
27+
"attrConfig": {
28+
// example string attribute that nodes can set
29+
"custom:example": {
30+
"type": "string",
31+
"allowSetByNode": true,
32+
"broadcastToPeers": ["*"]
33+
},
34+
// secure boolean attribute only settable by admin
35+
"custom:secure": {
36+
"type": "bool",
37+
"allowSetByNode": false,
38+
"broadcastToPeers": ["tag:admin"]
39+
},
40+
// priority number attribute nodes can set themselves
41+
"custom:priority": {
42+
"type": "number",
43+
"allowSetByNode": true,
44+
// no broadcastToPeers means it won't be broadcast
45+
}
46+
},
2747
"tests": [
2848
{
2949

0 commit comments

Comments
 (0)