Skip to content

Commit 9029a4c

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

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
@@ -77,6 +77,9 @@ type ACL struct {
7777
Postures map[string][]string `json:"postures,omitempty" hujson:"Postures,omitempty"`
7878
DefaultSourcePosture []string `json:"defaultSrcPosture,omitempty" hujson:"DefaultSrcPosture,omitempty"`
7979

80+
// AttrConfig maps attribute names to their configuration for custom device attributes.
81+
AttrConfig map[string]ACLAttrConfig `json:"attrConfig,omitempty" hujson:"AttrConfig,omitempty"`
82+
8083
// ETag is the etag corresponding to this version of the ACL
8184
ETag string `json:"-"`
8285
}
@@ -171,6 +174,16 @@ type Grant struct {
171174
Via []string `json:"via,omitempty" hujson:"Via,omitempty"`
172175
}
173176

177+
// ACLAttrConfig represents configuration for a custom device attribute.
178+
type ACLAttrConfig struct {
179+
// Type can be one of "string", "bool", or "number".
180+
Type string `json:"type,omitempty" hujson:"Type,omitempty"`
181+
// AllowSetByNode indicates if nodes can set this attribute via LocalAPI.
182+
AllowSetByNode bool `json:"allowSetByNode,omitempty" hujson:"AllowSetByNode,omitempty"`
183+
// BroadcastToPeers is a list of destinations which should receive this attribute value, e.g. ["tag:admin"].
184+
BroadcastToPeers []string `json:"broadcastToPeers,omitempty" hujson:"BroadcastToPeers,omitempty"`
185+
}
186+
174187
// Get retrieves the [ACL] that is currently set for the tailnet.
175188
func (pr *PolicyFileResource) Get(ctx context.Context) (*ACL, error) {
176189
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
@@ -214,6 +214,22 @@ func TestACL_Unmarshal(t *testing.T) {
214214
"tag:monitoring": {"group:devops"},
215215
"tag:prod": {"group:devops"},
216216
},
217+
AttrConfig: map[string]ACLAttrConfig{
218+
"custom:example": {
219+
Type: "string",
220+
AllowSetByNode: true,
221+
BroadcastToPeers: []string{"*"},
222+
},
223+
"custom:secure": {
224+
Type: "bool",
225+
AllowSetByNode: false,
226+
BroadcastToPeers: []string{"tag:admin"},
227+
},
228+
"custom:priority": {
229+
Type: "number",
230+
AllowSetByNode: true,
231+
},
232+
},
217233
DERPMap: (*ACLDERPMap)(nil),
218234
SSH: []ACLSSH{
219235
{

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)