Skip to main content

Generate

Generate a new token.

osapi controller token generate [flags]

Examples​

osapi controller token generate --subject user123 --roles=read
osapi controller token generate --subject svc@example.com --roles=read \
-p status:read -p health:read
osapi controller token generate --subject team-web --roles=operator \
-t group:web -t web-01

Result​

The command prints:

$ osapi controller token generate --subject user123 --roles=read
Token:
  Token:    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMTIzIiwicm9sZXMiOlsicmVhZCJdfQ.Xq3a8Zt0n2Jv5k7XqW1yR4sB6cD9eF0gH2iJ3kL5mN8
  Key ID:   2026-11
  Subject:  user123
  Roles:    read

With --json, the command prints:

{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMTIzIiwicm9sZXMiOlsicmVhZCJdfQ.Xq3a8Zt0n2Jv5k7XqW1yR4sB6cD9eF0gH2iJ3kL5mN8",
"kid": "2026-11",
"subject": "user123",
"roles": ["read"]
}

Flags​

FlagDescriptionDefault
-p, --permissionsDirect permissions, which override the roles; osapi controller role get --name admin lists each one
-r, --rolesRoles for the token: built-in, or a custom role of the config (required)
-u, --subjectSubject for the token (e.g., user ID or unique identifier) (required)
-t, --targetsHosts the token may act on: hostnames and labels, such as group:web; without it, each host

Global flags​

FlagDescriptionDefault
-d, --debugEnable or disable debug mode
-j, --jsonEnable JSON output
-f, --osapi-filePath to config file; without one at the default path, osapi runs on the defaults/etc/osapi/osapi.yaml

Output tells how the result is printed, and what --json gives.