permits

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package permits implements JumpServer asset authorization (AssetPermission).

An asset that exists is not yet reachable: JumpServer only exposes an asset to a user through an AssetPermission record, which binds a set of users (or user groups) to a set of assets (or nodes) together with the allowed accounts, protocols and actions. Creating an asset therefore takes two steps — the asset, then the permission — and `jms ls` only shows assets that the second step has granted.

Endpoint facts, verified against the JumpServer source (apps/perms/urls/asset_permission.py registers the AssetPermissionViewSet on the BulkRouter under "asset-permissions") and against the running instance on 2026-11-04:

POST   /api/v1/perms/asset-permissions/        create a permission
GET    /api/v1/perms/asset-permissions/        list permissions
DELETE /api/v1/perms/asset-permissions/<id>/   revoke

The read-only user view (/api/v1/perms/users/<user>/assets/) answers "what may this user reach" and implements no write method at all, so it cannot be used to grant anything.

Dependency direction: permits depends on api.

Index

Constants

View Source
const AccountAll = "@ALL"

AccountAll grants every account that the asset holds. JumpServer also accepts "@SPEC", "@USER", "@ANON", "@INPUT" and explicit account names.

View Source
const PathPermissions = "/api/v1/perms/asset-permissions/"

PathPermissions is the AssetPermission collection.

View Source
const ProtocolAll = "all"

ProtocolAll grants every protocol the asset offers.

Variables

This section is empty.

Functions

func CurrentUser

func CurrentUser(ctx context.Context, c *api.Client) (string, string, error)

CurrentUser returns the id of the authenticated user.

It reads /api/v1/users/profile/, which the login already established; the id is what a permission's users array needs.

func DefaultActions

func DefaultActions() []string

DefaultActions is what a permission grants when GrantSpec.Actions is empty: connect, which covers opening a session in any protocol.

func RelationNames added in v0.2.4

func RelationNames(relations []Relation) []string

RelationNames returns the display names of the given relations.

func Revoke

func Revoke(ctx context.Context, c *api.Client, id string) error

Revoke deletes a permission by id.

Types

type Action

type Action struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

Action is one entry of the `actions` field.

The API returns it as an object ({"label":..,"value":"connect"}) in a read but accepts a bare string in a write, so both shapes have to be understood.

func (Action) MarshalJSON

func (a Action) MarshalJSON() ([]byte, error)

MarshalJSON writes the bare value, which is what a write request wants.

func (*Action) UnmarshalJSON

func (a *Action) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts either a bare string or the labelled object the server returns.

type GrantSpec

type GrantSpec struct {
	// Name is the permission's display name; it must be unique.
	Name string
	// UserIDs are the users the grant applies to.
	UserIDs []string
	// GroupIDs are the user groups the grant applies to. At least one
	// UserID or GroupID is required: a rule with neither grants nothing.
	GroupIDs []string
	// AssetIDs are the assets being granted.
	AssetIDs []string
	// Accounts selects which accounts are usable; empty means AccountAll.
	Accounts []string
	// Protocols selects which protocols are usable; empty means ProtocolAll.
	Protocols []string
	// Actions are the allowed operations; empty means a plain connect.
	Actions []string
	// Comment is the free-text note.
	Comment string
}

GrantSpec describes one permission to create.

type Permission

type Permission struct {
	ID         string     `json:"id"`
	Name       string     `json:"name"`
	Users      []Relation `json:"users"`
	UserGroups []Relation `json:"user_groups"`
	Assets     []Relation `json:"assets"`
	Nodes      []Relation `json:"nodes"`

	UsersAmount      *int `json:"users_amount"`
	UserGroupsAmount *int `json:"user_groups_amount"`
	AssetsAmount     *int `json:"assets_amount"`
	NodesAmount      *int `json:"nodes_amount"`

	Accounts  []string `json:"accounts"`
	Protocols []string `json:"protocols"`
	Actions   []Action `json:"actions"`
	IsActive  bool     `json:"is_active"`
	Comment   string   `json:"comment"`
	DateStart string   `json:"date_start"`
}

Permission is one authorization rule.

The list endpoint carries the relation *counts* and leaves the relation arrays null; the detail endpoint expands both. The amount fields are pointers so "the server did not report a count" stays distinguishable from "the count is zero" — only the first case needs a detail read.

func FindByAsset

func FindByAsset(ctx context.Context, c *api.Client, assetID string) ([]Permission, error)

FindByAsset returns the permissions that grant the given asset.

The list endpoint reports only the relation *counts* (assets_amount, users_amount), not the related objects: users and assets come back as null. The relations are expanded only by the detail endpoint, so each candidate has to be read individually before its assets can be inspected.

func Get

func Get(ctx context.Context, c *api.Client, id string) (Permission, error)

Get returns one permission with its relations expanded.

func Grant

func Grant(ctx context.Context, c *api.Client, spec GrantSpec) (Permission, error)

Grant creates an AssetPermission.

This is the step that makes an asset appear in `jms ls`. Creating an asset without granting it leaves it visible only to the administrator view (`jms asset list`).

func List

func List(ctx context.Context, c *api.Client) ([]Permission, error)

List returns every permission rule.

func (Permission) NeedsDetail added in v0.2.4

func (p Permission) NeedsDetail() bool

NeedsDetail reports whether this row is a list summary whose relations still have to be read from the detail endpoint.

A relation is missing when its array is empty but the server reports a nonzero count for it. When the server reports no count at all (older builds, fixtures) the relations are unknown rather than empty, so the detail is read as well; that keeps the node-only and group-only rules visible instead of rendering them as blank.

type Relation added in v0.2.4

type Relation struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Relation is one expanded relation of a permission: a user, a user group, an asset or a node. All four share the same (id, name) shape.

Jump to

Keyboard shortcuts

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