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
- func CurrentUser(ctx context.Context, c *api.Client) (string, string, error)
- func DefaultActions() []string
- func RelationNames(relations []Relation) []string
- func Revoke(ctx context.Context, c *api.Client, id string) error
- type Action
- type GrantSpec
- type Permission
- func FindByAsset(ctx context.Context, c *api.Client, assetID string) ([]Permission, error)
- func Get(ctx context.Context, c *api.Client, id string) (Permission, error)
- func Grant(ctx context.Context, c *api.Client, spec GrantSpec) (Permission, error)
- func List(ctx context.Context, c *api.Client) ([]Permission, error)
- type Relation
Constants ¶
const AccountAll = "@ALL"
AccountAll grants every account that the asset holds. JumpServer also accepts "@SPEC", "@USER", "@ANON", "@INPUT" and explicit account names.
const PathPermissions = "/api/v1/perms/asset-permissions/"
PathPermissions is the AssetPermission collection.
const ProtocolAll = "all"
ProtocolAll grants every protocol the asset offers.
Variables ¶
This section is empty.
Functions ¶
func CurrentUser ¶
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
RelationNames returns the display names of the given relations.
Types ¶
type Action ¶
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 ¶
MarshalJSON writes the bare value, which is what a write request wants.
func (*Action) UnmarshalJSON ¶
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 ¶
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 Grant ¶
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 (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.