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 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)
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.
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
// 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 []struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"users"`
UserGroups []struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"user_groups"`
Assets []struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"assets"`
Nodes []struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"nodes"`
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.
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.