rbac

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceServers         = "servers"
	ResourceServerConfig    = "server_config"
	ResourceMods            = "mods"
	ResourceModpacks        = "modpacks"
	ResourceModules         = "modules"
	ResourceModuleTemplates = "module_templates"
	ResourceFiles           = "files"
	ResourceTasks           = "tasks"
	ResourceProxy           = "proxy"
	ResourceUsers           = "users"
	ResourceRoles           = "roles"
	ResourceSettings        = "settings"
	ResourceSupport         = "support"
	ResourceUploads         = "uploads"
	ResourceNodes           = "nodes"
	ResourceActivity        = "activity"
	ResourceSubusers        = "subusers"
	ResourceBackups         = "backups"
)

Resource constants

View Source
const (
	ActionRead    = "read"
	ActionCreate  = "create"
	ActionUpdate  = "update"
	ActionDelete  = "delete"
	ActionStart   = "start"
	ActionStop    = "stop"
	ActionRestart = "restart"
	ActionCommand = "command"

	// ActionManageDockerPrivileged gates host-breakout-capable Docker
	// container overrides: full --privileged mode, added Linux
	// capabilities (CapAdd), and confinement-weakening SecurityOpt values
	// (e.g. apparmor:unconfined, seccomp:unconfined, label:disable).
	//
	// Unlike the other actions above, this is not tied 1:1 to an RPC
	// procedure - ServerService/CreateServer and UpdateServer are ordinary
	// ResourceServers create/update operations for most requests, but when
	// the request payload's DockerOverrides contains one of the dangerous
	// fields above, the handler performs an *additional* enforcer check for
	// (ResourceServers, ActionManageDockerPrivileged) before honoring it.
	// Because it is derived from payload content rather than from
	// ProcedurePermissions, it intentionally does not appear in
	// ResourceActionsFromProcedures' output; only the built-in admin role
	// (which matches "*" actions) has it until an operator explicitly
	// grants it to another role.
	ActionManageDockerPrivileged = "manage_docker_privileged"
)

Action constants

Variables

AllActions in display order.

AllResources in display order.

View Source
var AuthenticatedOnlyProcedures = map[string]bool{

	"/carbonpanel.v1.AuthService/GetCurrentUser": true,
	"/carbonpanel.v1.AuthService/Logout":         true,
	"/carbonpanel.v1.AuthService/ChangePassword": true,
	"/carbonpanel.v1.AuthService/CreateAPIToken": true,
	"/carbonpanel.v1.AuthService/ListAPITokens":  true,
	"/carbonpanel.v1.AuthService/DeleteAPIToken": true,

	"/carbonpanel.v1.MinecraftService/GetMinecraftVersions": true,
	"/carbonpanel.v1.MinecraftService/GetModLoaders":        true,
	"/carbonpanel.v1.MinecraftService/GetDockerImages":      true,
}

AuthenticatedOnlyProcedures lists RPC procedures that require authentication but no specific resource permission.

View Source
var ProcedurePermissions = map[string]ProcedurePermission{}/* 153 elements not displayed */

ProcedurePermissions maps each RPC procedure path to the resource and action required to invoke it, plus an optional ObjectIDField for per-object scoping.

View Source
var PublicProcedures = map[string]bool{
	"/carbonpanel.v1.AuthService/GetAuthStatus":   true,
	"/carbonpanel.v1.AuthService/Login":           true,
	"/carbonpanel.v1.AuthService/Register":        true,
	"/carbonpanel.v1.AuthService/GetOIDCLoginURL": true,
	"/carbonpanel.v1.AuthService/ValidateInvite":  true,
	"/carbonpanel.v1.AuthService/UseRecoveryKey":  true,
}

PublicProcedures lists RPC procedures that require no authentication.

ResourceScopeSource maps each scopeable resource to the resource that provides its scope objects. For example, files are scoped by server_id, so ResourceFiles → ResourceServers. Resources absent from this map (users, roles, settings, support, uploads) have no per-object scoping.

Functions

func DefaultRolePolicies

func DefaultRolePolicies() map[string][][]string

DefaultRolePolicies returns the built-in role policy sets (role, resource, action, object). It is exported so tests can assert that a procedure's required permission is not accidentally granted to a low-privilege role.

Types

type Enforcer

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

Enforcer wraps a Casbin enforcer with convenience methods for RBAC.

func NewEnforcer

func NewEnforcer(db *gorm.DB) (*Enforcer, error)

NewEnforcer creates a new Casbin RBAC enforcer backed by the given GORM database.

func (*Enforcer) Enforce

func (e *Enforcer) Enforce(roles []string, resource, action, objectID string) (bool, error)

Enforce checks if any of the given roles allows the specified action on a resource with the given object ID. Returns true on the first matching role.

func (*Enforcer) GetPermissionMatrix

func (e *Enforcer) GetPermissionMatrix() map[string][]Permission

GetPermissionMatrix returns a map of role names to their permission slices, covering all roles that have any policy defined.

func (*Enforcer) GetPermissionsForRole

func (e *Enforcer) GetPermissionsForRole(role string) []Permission

GetPermissionsForRole returns all permissions currently assigned to the role.

func (*Enforcer) SeedDefaultPolicies

func (e *Enforcer) SeedDefaultPolicies(anonymousEnabled bool) error

Ensures default roles have their base permissions

func (*Enforcer) SetPermissionsForRole

func (e *Enforcer) SetPermissionsForRole(role string, perms []Permission) error

SetPermissionsForRole replaces all permissions for a role atomically. The admin role cannot be modified.

type Permission

type Permission struct {
	Resource string
	Action   string
	ObjectID string
}

Permission represents a single resource/action/object permission tuple.

type ProcedurePermission

type ProcedurePermission struct {
	Resource      string
	Action        string
	ObjectIDField string // Protobuf field name to extract for per-object RBAC (empty = "*")
}

ProcedurePermission maps an RPC procedure to a resource and action.

type ResourceActionEntry

type ResourceActionEntry struct {
	Resource string
	Actions  []string
}

ResourceActionEntry pairs a resource with its valid actions.

func ResourceActionsFromProcedures

func ResourceActionsFromProcedures() []ResourceActionEntry

ResourceActionsFromProcedures derives which actions are valid for each resource by inspecting the ProcedurePermissions mapping. Maintains stable resource ordering via AllResources and stable action ordering via AllActions.

Jump to

Keyboard shortcuts

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