aclpolicy

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValidationFailed = errors.New("policy validation failed")
	ErrTestFailed       = errors.New("policy test assertion failed")
)

Errors

Functions

func Standardize

func Standardize(input []byte) ([]byte, error)

Standardize converts HuJSON (JSON with //, /* */ comments and trailing commas) into strictly standard RFC 8259 JSON using Tailscale's official HuJSON parser.

Types

type ACLRuleSpec

type ACLRuleSpec struct {
	Name     string   `json:"name"`
	Action   string   `json:"action"` // "allow" or "deny"
	Src      []string `json:"src"`    // user:<username>, group:<name>, *
	Dst      []string `json:"dst"`    // device:<rustdesk_id>, device_group:<name>, *
	Role     string   `json:"role,omitempty"`
	Priority int      `json:"priority,omitempty"`
	Enabled  *bool    `json:"enabled,omitempty"`
	Note     string   `json:"note,omitempty"`
}

ACLRuleSpec defines an individual access control rule.

type CompiledPolicy

type CompiledPolicy struct {
	Document *Document
	Roles    []*store.ControlRole
	ACLs     []*store.ConnectionACL
}

CompiledPolicy holds the normalized and resolved database representations ready to be persisted.

type Document

type Document struct {
	Version int                 `json:"version,omitempty"`
	Roles   map[string]RoleSpec `json:"roles,omitempty"`
	ACLs    []ACLRuleSpec       `json:"acls,omitempty"`
	Tests   []TestCase          `json:"tests,omitempty"`
}

Document represents a declarative HuJSON/JSON ACL policy file.

func Parse

func Parse(raw []byte) (*Document, error)

Parse converts a HuJSON/JSON byte slice into a Document, validating basic syntax.

type RoleSpec

type RoleSpec struct {
	Note               string `json:"note,omitempty"`
	AllowKeyboardMouse bool   `json:"allow_keyboard_mouse"`
	AllowClipboard     bool   `json:"allow_clipboard"`
	AllowFileTransfer  bool   `json:"allow_file_transfer"`
	AllowAudio         bool   `json:"allow_audio"`
	AllowTCPTunneling  bool   `json:"allow_tcp_tunneling"`
	AllowTerminal      bool   `json:"allow_terminal"`
	AllowRestart       bool   `json:"allow_restart"`
	IsDefault          bool   `json:"is_default,omitempty"`
}

RoleSpec defines a control role's session permissions in the policy document.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service coordinates access policy compilation, testing, exporting, and atomic application.

func NewService

func NewService(s *store.Store) *Service

NewService creates a new aclpolicy Service.

func (*Service) Apply

func (s *Service) Apply(ctx context.Context, raw []byte) (*ValidationResult, error)

Apply compiles, validates, executes tests, and atomically replaces all roles and ACLs in a transaction.

func (*Service) Export

func (s *Service) Export(ctx context.Context) (string, error)

Export serializes the database's current roles and ACLs into a clean, human-readable HuJSON string with comments. Every selector names its target the way compile resolves it (devices by RustDesk id); a rule whose target cannot be named fails the export rather than being written as "*", which would widen it on re-import.

func (*Service) ValidateAndTest

func (s *Service) ValidateAndTest(ctx context.Context, raw []byte) (*CompiledPolicy, *ValidationResult, error)

ValidateAndTest parses HuJSON, resolves names, checks syntax, and executes the in-document tests.

type TestCase

type TestCase struct {
	Src    string `json:"src"`            // e.g. "user:alice", "alice"
	Dst    string `json:"dst"`            // e.g. "device:12345", "12345"
	Expect string `json:"expect"`         // "allow" or "deny"
	Role   string `json:"role,omitempty"` // expected role name if expect is "allow"
}

TestCase defines an assertion evaluated before applying policy changes.

type TestResult

type TestResult struct {
	Test           TestCase `json:"test"`
	Passed         bool     `json:"passed"`
	ActualDecision string   `json:"actual_decision"`
	ActualRole     string   `json:"actual_role,omitempty"`
	Error          string   `json:"error,omitempty"`
}

TestResult reports the outcome of evaluating a TestCase.

type ValidationResult

type ValidationResult struct {
	Valid       bool         `json:"valid"`
	RolesCount  int          `json:"roles_count"`
	RulesCount  int          `json:"rules_count"`
	TestsCount  int          `json:"tests_count"`
	TestResults []TestResult `json:"test_results"`
	Errors      []string     `json:"errors,omitempty"`
}

ValidationResult summarizes the dry-run compilation and testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL