Skip to content

policyfile: add AttrConfig support to ACLDetails #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions policyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ type ACL struct {
Postures map[string][]string `json:"postures,omitempty" hujson:"Postures,omitempty"`
DefaultSourcePosture []string `json:"defaultSrcPosture,omitempty" hujson:"DefaultSrcPosture,omitempty"`

// AttrConfig maps attribute names to their configuration for custom device attributes.
AttrConfig map[string]ACLAttrConfig `json:"attrConfig,omitempty" hujson:"AttrConfig,omitempty"`

// ETag is the etag corresponding to this version of the ACL
ETag string `json:"-"`
}
Expand Down Expand Up @@ -159,6 +162,16 @@ type NodeAttrGrantApp struct {
Domains []string `json:"domains,omitempty" hujson:"Domains,omitempty"`
}

// ACLAttrConfig represents configuration for a custom device attribute.
type ACLAttrConfig struct {
// Type can be one of "string", "bool", or "number".
Type string `json:"type,omitempty" hujson:"Type,omitempty"`
// AllowSetByNode indicates if nodes can set this attribute via LocalAPI.
AllowSetByNode bool `json:"allowSetByNode,omitempty" hujson:"AllowSetByNode,omitempty"`
// BroadcastToPeers is a list of destinations which should receive this attribute value, e.g. ["tag:admin"].
BroadcastToPeers []string `json:"broadcastToPeers,omitempty" hujson:"BroadcastToPeers,omitempty"`
}

// Get retrieves the [ACL] that is currently set for the tailnet.
func (pr *PolicyFileResource) Get(ctx context.Context) (*ACL, error) {
req, err := pr.buildRequest(ctx, http.MethodGet, pr.buildTailnetURL("acl"))
Expand Down
16 changes: 16 additions & 0 deletions policyfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ func TestACL_Unmarshal(t *testing.T) {
"tag:monitoring": {"group:devops"},
"tag:prod": {"group:devops"},
},
AttrConfig: map[string]ACLAttrConfig{
"custom:example": {
Type: "string",
AllowSetByNode: true,
BroadcastToPeers: []string{"*"},
},
"custom:secure": {
Type: "bool",
AllowSetByNode: false,
BroadcastToPeers: []string{"tag:admin"},
},
"custom:priority": {
Type: "number",
AllowSetByNode: true,
},
},
DERPMap: (*ACLDERPMap)(nil),
SSH: []ACLSSH{
{
Expand Down
20 changes: 20 additions & 0 deletions testdata/acl.hujson
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@
// users in group:devops can apply the tag tag:prod
"tag:prod": ["group:devops"],
},
"attrConfig": {
// example string attribute that nodes can set
"custom:example": {
"type": "string",
"allowSetByNode": true,
"broadcastToPeers": ["*"]
},
// secure boolean attribute only settable by admin
"custom:secure": {
"type": "bool",
"allowSetByNode": false,
"broadcastToPeers": ["tag:admin"]
},
// priority number attribute nodes can set themselves
"custom:priority": {
"type": "number",
"allowSetByNode": true,
// no broadcastToPeers means it won't be broadcast
}
},
"tests": [
{
"src": "[email protected]",
Expand Down