Skip to content

Commit 1a98fde

Browse files
committed
policyfile: add AttrConfig support to ACLDetails
fixes: #30 Signed-off-by: Raj Singh [email protected]
1 parent d692cd6 commit 1a98fde

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

policyfile.go

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

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

166+
// ACLAttrConfig represents configuration for a custom device attribute.
167+
type ACLAttrConfig struct {
168+
// Type can be one of "string", "bool", or "number".
169+
Type string `json:"type,omitempty" hujson:"Type,omitempty"`
170+
// AllowSetByNode indicates if nodes can set this attribute via LocalAPI.
171+
AllowSetByNode bool `json:"allowSetByNode,omitempty" hujson:"AllowSetByNode,omitempty"`
172+
// BroadcastToPeers is a list of destinations which should receive this attribute value, e.g. ["tag:admin"].
173+
BroadcastToPeers []string `json:"broadcastToPeers,omitempty" hujson:"BroadcastToPeers,omitempty"`
174+
}
175+
163176
// Get retrieves the [ACL] that is currently set for the tailnet.
164177
func (pr *PolicyFileResource) Get(ctx context.Context) (*ACL, error) {
165178
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)