Roles and Permissions
COSMOS Enterprise provides a comprehensive role-based access control (RBAC) system that allows you to manage user permissions across different scopes. This system integrates with Keycloak for authentication and authorization.
Overview
Roles in COSMOS Enterprise control what actions users can perform within the system. Roles are assigned to users per scope, allowing fine-grained control over access to different missions or projects.
Roles involve two systems working together:
- Keycloak assigns roles to users. A user's roles are carried in their JWT token as Keycloak realm roles named
{SCOPE}__{ROLE_NAME}(e.g.DEFAULT__operator). - COSMOS defines what each role is allowed to do. The five built-in roles (admin, operator, viewer, approver, runner) have permission sets built into COSMOS itself, so they only need to exist as realm roles in Keycloak. Custom roles additionally require a role definition in COSMOS (created through the Admin Tool or the REST API) that lists the role's permissions.
This means creating a custom role is a two-part process: define the role and its permissions in COSMOS, and create a matching {SCOPE}__{ROLE_NAME} realm role in Keycloak and assign it to users. Creating a role in COSMOS does not create the Keycloak realm role (or vice versa) — if either half is missing, the role grants no permissions.
Role Naming Convention
Roles are assigned using the format: {SCOPE}__{ROLE_NAME}
SCOPE: The scope name (e.g.,DEFAULT) orALLSCOPESfor global permissionsROLE_NAME: One of the built-in roles or a custom role name
Examples:
DEFAULT__operator- Operator role in the DEFAULT scopeMISSION1__viewer- Viewer role in the MISSION1 scopeALLSCOPES__admin- Admin role across all scopes
Built-in Roles
Individual built-in roles in COSMOS Enterprise are scoped to a minimal set of permissions. Individual users can have multiple roles (e.g., Admin and Operator) if users need administrative access and commanding access. COSMOS Enterprise includes five built-in roles with predefined permission sets:
Admin
The Admin role provides administrative access within a scope. Admins can also manage the files within Bucket Explorer.
Permissions:
system- View system informationsystem_set- Modify system settingstlm- View telemetry datacmd_info- View command informationscript_view- View scriptsscript_approver- Approve scriptsnotebook_view- View notebooksadmin- Administrative functions (manage plugins, targets, interfaces, etc.)
Special Cases:
- When assigned to
ALLSCOPES, gainssuperadminpermission for system-wide administration - Can release command authority taken by other users in their scope
Use Case: Users responsible for system configuration and management.
Operator
The Operator role has full access except for administrative functions and command approval rights.
Permissions:
system- View system informationsystem_set- Modify system settingstlm- View telemetry datatlm_set- Modify telemetry settingscmd_info- View command informationcmd_raw- Send raw commandscmd- Send commandsscript_view- View scriptsscript_edit- Create and edit scriptsscript_run- Run scriptsscript_approver- Approve scriptsnotebook_view- View notebooksnotebook_edit- Create and edit notebooksnotebook_run- Run notebooks
Use Case: Power users who need full operational control but not administrative access.
Viewer
The Viewer role provides read-only access to the system.
Permissions:
system- View system informationtlm- View telemetry datacmd_info- View command informationscript_view- View scriptsnotebook_view- View notebooks
Use Case: Users who need to monitor telemetry and system status without making changes.
Approver
The Approver role is specifically for command approval workflows.
Permissions:
approve_hazardous- Approve hazardous commandsapprove_restricted- Approve restricted commandsapprove_normal- Approve normal commands
Use Case: Users responsible for reviewing and approving commands before execution.
Runner
The Runner role allows users to execute commands and scripts but cannot create or edit them. Runner does not come with approval rights.
Permissions:
system- View system informationsystem_set- Modify system settingstlm- View telemetry datatlm_set- Modify telemetry settingscmd_info- View command informationcmd_raw- Send raw commandscmd- Send commandsscript_view- View scriptsscript_run- Run scriptsnotebook_view- View notebooksnotebook_run- Run notebooks
Use Case: Operators who execute procedures and send commands but don't modify configurations or scripts.
Permission Definitions
System Permissions
- system - View system information and status
- system_set - Modify system settings and configurations
Telemetry Permissions
- tlm - View telemetry data
- tlm_set - Modify telemetry settings (limits, conversions, etc.)
Command Permissions
- cmd_info - View command definitions and parameters
- cmd_raw - Send raw binary commands
- cmd - Send commands to targets
Script Permissions
- script_view - View script contents
- script_edit - Create, edit, and delete scripts and other target files, including saving, generating, and deleting tables in Table Manager
- script_run - Execute scripts
- script_approver - Allow a script's state to be changed to or from
approvedwhen Script Lifecycle is enabled. All lifecycle changes also require script_edit.
Notebook Permissions
- notebook_view - View notebooks
- notebook_edit - Create, edit, and delete notebooks
- notebook_run - Start, save, and complete notebook runs. Script cells also require script_run and command cells require cmd.
Administrative Permissions
- admin - Manage scope-level resources (targets, plugins, interfaces, routers, etc.)
- superadmin - System-wide administration across all scopes, including creating and deleting scopes and the raw Redis and TSDB queries in the Admin tool (requires
ALLSCOPES__admin)
Approval Permissions
- approve_hazardous - Approve hazardous commands
- approve_restricted - Approve restricted commands
- approve_normal - Approve normal commands
Command Authority
When command authority is enabled for a scope, an additional layer of authorization is applied to command-related permissions:
- Users must "take" command authority for a specific target before sending commands
- Only the user who holds command authority can send commands to that target
- Admin users (with
ALLSCOPES__adminor{SCOPE}__admin) can release authority taken by other users - Command authority applies to these permissions when executed manually:
tlm_setcmd_rawcmdscript_runnotebook_run
Custom Roles
In addition to the built-in roles, you can create custom roles with specific permission combinations.
Creating a custom role requires two steps:
- Define the role in COSMOS with its permission set, using the Admin Tool or the REST API.
- Create and assign the role in Keycloak as a realm role named
{SCOPE}__{ROLE_NAME}(e.g.DEFAULT__inst_commander), using the Keycloak admin console (see Viewing / Assigning Roles to Users) or the Keycloak Admin REST API.
Both steps are required. The Keycloak realm role puts the role name in the user's token, and the COSMOS role definition maps that name to permissions. A custom role assigned in Keycloak without a COSMOS definition grants no permissions, and a COSMOS role definition with no Keycloak realm role is never assigned to anyone.
Creating Custom Roles
Custom roles are managed through the Admin Tool or programmatically via the REST API:
- Navigate to the Admin Tool
- Go to the Roles tab
- Click "Add" and enter a role name (single lowercase word recommended)
- Click "Edit" to configure permissions for the role

Custom Role Permissions
Custom roles can have granular permissions that target specific resources:
- target_name - Restrict permission to a specific target
- packet_name - Restrict permission to a specific packet
- interface_name - Restrict permission to a specific interface
- router_name - Restrict permission to a specific router
Example: A custom role could allow cmd permission only for the INST1 target.

Role Management REST API
In addition to the Admin Tool, COSMOS Enterprise provides REST endpoints for role CRUD (create, read, update, delete) operations. These are useful for automation and integration workflows, such as provisioning roles as part of a deployment pipeline.
These endpoints only manage the COSMOS side of a role (its permission definition). They do not create or delete the corresponding Keycloak realm role. For users to actually receive a custom role, you must also create a {SCOPE}__{ROLE_NAME} realm role in Keycloak and assign it to users — see Assigning Roles via the Keycloak Admin REST API below.
All endpoints require an Authorization header containing a Keycloak access token and a scope query parameter. See Testing with Curl for details on obtaining and refreshing tokens.
Endpoints
| Method | Endpoint | Required Permission | Description |
|---|---|---|---|
| GET | /openc3-api/roles | admin | List all role names |
| GET | /openc3-api/roles/:name | system | Get a role's definition (use all to return every role) |
| POST | /openc3-api/roles | superadmin (ALLSCOPES__admin) | Create a role |
| PUT / PATCH | /openc3-api/roles/:name | superadmin (ALLSCOPES__admin) | Update a role (replaces the entire permissions list) |
| DELETE | /openc3-api/roles/:name | superadmin (ALLSCOPES__admin) | Delete a role |
Role Definition Format
The POST and PUT endpoints accept a request body with a json field containing the role definition as a JSON-encoded string:
{
"name": "inst_commander",
"permissions": [
{ "permission": "tlm" },
{ "permission": "cmd", "target_name": "INST" }
]
}
Each entry in permissions requires a permission name (see Permission Definitions) and optionally accepts target_name, packet_name, interface_name, or router_name to restrict the permission to a specific resource. Omitting the resource fields grants the permission for all resources.
Note: Creating a role with an empty permissions list automatically seeds it with the Viewer permissions (system, tlm, cmd_info, script_view, notebook_view).
Examples
First obtain an access token from Keycloak as described in Testing with Curl (the user must have ALLSCOPES__admin for create / update / delete):
ACCESS_TOKEN=$(curl -s -H "Content-Type: application/x-www-form-urlencoded" \
-d 'username=admin&password=admin&client_id=api&grant_type=password' \
-X POST http://localhost:2900/auth/realms/openc3/protocol/openid-connect/token | jq -r .access_token)
List all roles. Only custom roles are stored in COSMOS, so the built-in roles (admin, operator, viewer, approver, runner) are not returned:
curl -H "Authorization: $ACCESS_TOKEN" "http://localhost:2900/openc3-api/roles?scope=DEFAULT"
# => ["inst_commander"]
Create a role:
curl -H "Authorization: $ACCESS_TOKEN" -H "Content-Type: application/json" \
-d '{"json": "{\"name\":\"inst_commander\",\"permissions\":[{\"permission\":\"tlm\"},{\"permission\":\"cmd\",\"target_name\":\"INST\"}]}"}' \
-X POST "http://localhost:2900/openc3-api/roles?scope=DEFAULT"
Get a role's definition:
curl -H "Authorization: $ACCESS_TOKEN" "http://localhost:2900/openc3-api/roles/inst_commander?scope=DEFAULT"
# => {"name":"inst_commander","permissions":[{"permission":"tlm"},{"permission":"cmd","target_name":"INST"}],"updated_at":1768424881396924134}
Update a role (the permissions list is fully replaced, so read the current definition first if you want to add to it):
curl -H "Authorization: $ACCESS_TOKEN" -H "Content-Type: application/json" \
-d '{"json": "{\"name\":\"inst_commander\",\"permissions\":[{\"permission\":\"tlm\"},{\"permission\":\"cmd\",\"target_name\":\"INST\"},{\"permission\":\"script_run\"}]}"}' \
-X PUT "http://localhost:2900/openc3-api/roles/inst_commander?scope=DEFAULT"
Delete a role:
curl -H "Authorization: $ACCESS_TOKEN" \
-X DELETE "http://localhost:2900/openc3-api/roles/inst_commander?scope=DEFAULT"
Responses
- Creating a role that already exists, or updating a role that does not exist, fails with HTTP 500. Use GET first to decide between POST and PUT (see Example Automation Workflow).
- Unlike create (see the note above), updating a role with an empty
permissionslist leaves it with no permissions. - Don't give a custom role the same name as a built-in role (admin, operator, viewer, approver, runner). The built-in permissions are checked first, so the custom definition is ignored.
Assigning Roles via the Keycloak Admin REST API
The COSMOS role defines the permission set, but users receive roles through Keycloak. To complete the automation workflow, create a matching Keycloak realm role named {SCOPE}__{ROLE_NAME} and assign it to users using the Keycloak Admin REST API:
# Get a Keycloak admin token (master realm)
KC_TOKEN=$(curl -s -H "Content-Type: application/x-www-form-urlencoded" \
-d 'username=<keycloak-admin>&password=<password>&client_id=admin-cli&grant_type=password' \
-X POST http://localhost:2900/auth/realms/master/protocol/openid-connect/token | jq -r .access_token)
# Create the realm role in the openc3 realm
curl -H "Authorization: Bearer $KC_TOKEN" -H "Content-Type: application/json" \
-d '{"name": "DEFAULT__inst_commander"}' \
-X POST http://localhost:2900/auth/admin/realms/openc3/roles
# Look up the user and role, then assign the role to the user
USER_ID=$(curl -s -H "Authorization: Bearer $KC_TOKEN" \
"http://localhost:2900/auth/admin/realms/openc3/users?username=operator" | jq -r '.[0].id')
ROLE=$(curl -s -H "Authorization: Bearer $KC_TOKEN" \
http://localhost:2900/auth/admin/realms/openc3/roles/DEFAULT__inst_commander)
curl -H "Authorization: Bearer $KC_TOKEN" -H "Content-Type: application/json" \
-d "[$ROLE]" \
-X POST "http://localhost:2900/auth/admin/realms/openc3/users/$USER_ID/role-mappings/realm"
The Keycloak admin account lives in the master realm, while COSMOS users and roles live in the openc3 realm. The admin account is created from KEYCLOAK_ADMIN and KEYCLOAK_ADMIN_PASSWORD in .env (or .env.local), but only the first time Keycloak initializes its database. Changing them later doesn't change the existing account. Creating a realm role that already exists returns HTTP 409.
To remove a role from a user, send the same role array with -X DELETE to the role-mappings/realm endpoint. To delete the realm role entirely, use DELETE /auth/admin/realms/openc3/roles/DEFAULT__inst_commander.
For full details on the available endpoints, authentication options, and payloads, see the Keycloak Admin REST API documentation and the Keycloak Server Administration Guide.
Example Automation Workflow
The following script provisions a custom role end to end and can be rerun safely, which makes it suitable for a CI/CD pipeline. It creates or updates the COSMOS role definition, creates the Keycloak realm role if it is missing, and assigns it to a list of users. It requires curl and jq, and reads credentials from environment variables so they aren't stored in the script:
COSMOS_USER/COSMOS_PASSWORD- a COSMOS user withALLSCOPES__adminKC_ADMIN/KC_ADMIN_PASSWORD- the Keycloak admin account in themasterrealmCOSMOS_URL- optional, defaults tohttp://localhost:2900
Replace ROLE, PERMISSIONS, and the example USERS with your own values.
#!/bin/bash
set -euo pipefail
COSMOS_URL="${COSMOS_URL:-http://localhost:2900}"
SCOPE="DEFAULT"
ROLE="inst_commander"
USERS="operator operator2"
# Permissions for the COSMOS role definition
PERMISSIONS='[{"permission":"tlm"},{"permission":"cmd_info"},{"permission":"cmd","target_name":"INST"}]'
# 1. COSMOS token for a user with ALLSCOPES__admin (COSMOS_USER / COSMOS_PASSWORD)
ACCESS_TOKEN=$(curl -sf -H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "username=${COSMOS_USER}" --data-urlencode "password=${COSMOS_PASSWORD}" \
-d 'client_id=api&grant_type=password' \
-X POST "${COSMOS_URL}/auth/realms/openc3/protocol/openid-connect/token" | jq -r .access_token)
# 2. Create or update the COSMOS role definition
BODY=$(jq -n --arg name "$ROLE" --argjson perms "$PERMISSIONS" \
'{json: ({name: $name, permissions: $perms} | tojson)}')
EXISTING=$(curl -sf -H "Authorization: ${ACCESS_TOKEN}" \
"${COSMOS_URL}/openc3-api/roles/${ROLE}?scope=${SCOPE}")
if [ "$EXISTING" = "null" ]; then
curl -sf -H "Authorization: ${ACCESS_TOKEN}" -H "Content-Type: application/json" \
-d "$BODY" -X POST "${COSMOS_URL}/openc3-api/roles?scope=${SCOPE}"
echo "Created COSMOS role ${ROLE}"
else
curl -sf -H "Authorization: ${ACCESS_TOKEN}" -H "Content-Type: application/json" \
-d "$BODY" -X PUT "${COSMOS_URL}/openc3-api/roles/${ROLE}?scope=${SCOPE}"
echo "Updated COSMOS role ${ROLE}"
fi
# 3. Keycloak admin token from the master realm (KC_ADMIN / KC_ADMIN_PASSWORD)
KC_TOKEN=$(curl -sf -H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "username=${KC_ADMIN}" --data-urlencode "password=${KC_ADMIN_PASSWORD}" \
-d 'client_id=admin-cli&grant_type=password' \
-X POST "${COSMOS_URL}/auth/realms/master/protocol/openid-connect/token" | jq -r .access_token)
KC_API="${COSMOS_URL}/auth/admin/realms/openc3"
# 4. Create the {SCOPE}__{ROLE} realm role if it doesn't exist (409 means it already does)
KC_ROLE="${SCOPE}__${ROLE}"
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: Bearer ${KC_TOKEN}" \
-H "Content-Type: application/json" -d "{\"name\": \"${KC_ROLE}\"}" -X POST "${KC_API}/roles")
case "$STATUS" in
201) echo "Created Keycloak role ${KC_ROLE}" ;;
409) echo "Keycloak role ${KC_ROLE} already exists" ;;
*) echo "Failed to create Keycloak role: HTTP ${STATUS}" >&2; exit 1 ;;
esac
ROLE_JSON=$(curl -sf -H "Authorization: Bearer ${KC_TOKEN}" "${KC_API}/roles/${KC_ROLE}")
# 5. Assign the realm role to each user (assigning an existing mapping is a no-op)
for USERNAME in $USERS; do
USER_ID=$(curl -sf -H "Authorization: Bearer ${KC_TOKEN}" \
"${KC_API}/users?username=${USERNAME}&exact=true" | jq -r '.[0].id')
if [ "$USER_ID" = "null" ]; then
echo "Keycloak user ${USERNAME} not found" >&2
exit 1
fi
curl -sf -H "Authorization: Bearer ${KC_TOKEN}" -H "Content-Type: application/json" \
-d "[${ROLE_JSON}]" -X POST "${KC_API}/users/${USER_ID}/role-mappings/realm"
echo "Assigned ${KC_ROLE} to ${USERNAME}"
done
Users pick up a newly assigned role the next time their access token is issued, which happens within a few minutes as the browser refreshes it, or immediately after logging out and back in.
To retire a role, reverse the order: remove the Keycloak role mappings (or delete the realm role) first so newly issued tokens no longer carry the role, then delete the COSMOS role definition. Access tokens that were already issued keep the role until they expire (5 minutes by default). Running services cache role definitions and are only notified when a role is created or updated, not deleted, so a deleted definition can keep granting its permissions until the services restart. To revoke the permissions immediately, first update the role with an empty permissions list, then delete it:
curl -H "Authorization: $ACCESS_TOKEN" -H "Content-Type: application/json" \
-d '{"json": "{\"name\":\"inst_commander\",\"permissions\":[]}"}' \
-X PUT "http://localhost:2900/openc3-api/roles/inst_commander?scope=DEFAULT"
curl -H "Authorization: $ACCESS_TOKEN" \
-X DELETE "http://localhost:2900/openc3-api/roles/inst_commander?scope=DEFAULT"
Authorization Flow
When a user attempts an action, COSMOS Enterprise performs the following checks:
- Token Validation - Verify the JWT token from Keycloak
- Role Extraction - Extract roles from the token's
realm_accessclaim - Scope Matching - Match user roles against the requested scope or
ALLSCOPES - Permission Check - Verify the action's required permission is granted by the role
- Resource Matching - For custom roles, check if specific resources match
- Command Authority - If applicable, verify command authority for the target
Default Users
COSMOS Enterprise Keycloak realm includes default test users:
| Username | Password | COSMOS Roles | Grafana Role | |
|---|---|---|---|---|
| admin | admin | ALLSCOPES__admin, ALLSCOPES__operator, ALLSCOPES__approver | grafana_admin | admin@openc3.com |
| operator | operator | ALLSCOPES__operator | grafana_editor | operator@openc3.com |
| approver | approver | ALLSCOPES__approver | approver@openc3.com | |
| viewer | viewer | ALLSCOPES__viewer (via default role) | viewer@openc3.com |
The realm's default role (default-roles-openc3) includes ALLSCOPES__viewer, so every user — including newly created ones — receives viewer access across all scopes by default.
These are default development/testing accounts. In production deployments, you should configure proper authentication and remove or change these default credentials.
Grafana Roles (Enterprise)
COSMOS Enterprise includes a Grafana instance for system monitoring and observability dashboards. Grafana uses separate Keycloak realm roles for access control, independent of COSMOS roles. This is important to understand when creating custom users or integrating with LDAP.
Grafana Role Requirements
Grafana authenticates through Keycloak using OAuth and maps Keycloak realm roles to Grafana permissions:
| Keycloak Realm Role | Grafana Permission | Description |
|---|---|---|
grafana_admin | Admin | Full Grafana admin access (dashboards, data sources, users) |
grafana_editor | Editor | Can create and edit dashboards |
| (none) | Viewer | Read-only access to dashboards |
The role mapping is configured in Grafana's OAuth settings:
role_attribute_path = contains(realm_access.roles[*], 'grafana_admin') && 'Admin' || contains(realm_access.roles[*], 'grafana_editor') && 'Editor' || 'Viewer'
Common Issue: "User sync failed"
When users have COSMOS roles (like ALLSCOPES__operator) but no Grafana roles assigned, they may encounter a "Login failed. User sync failed" error when accessing Grafana. This commonly occurs when:
- Creating custom users without assigning Grafana roles
- Importing users or groups from LDAP without mapping Grafana roles
- Assuming COSMOS roles automatically grant Grafana access
Assigning Grafana Roles
To grant Grafana access to users or LDAP groups:
- Access the Keycloak admin console
- Navigate to Users (or Groups for LDAP-federated groups)
- Select the user or group
- Go to Role Mappings
- Assign
grafana_adminorgrafana_editoras needed
When using LDAP user federation, assign Grafana roles to LDAP groups rather than individual users. Map your LDAP admin group to grafana_admin and your operator group to grafana_editor. See User Group Role from LDAP Federation for enabling group-based role assignment.
Best Practices
- Principle of Least Privilege - Assign users the minimum permissions needed for their role
- Use Scopes - Leverage scopes to separate different missions or projects
- Custom Roles - Create custom roles for specialized needs rather than giving admin access
- Command Authority - Enable command authority for production systems to prevent conflicts
- Regular Audits - Review user roles and permissions periodically
- Production Security - Replace default credentials and integrate with your organization's SSO/IdP
Managing Roles
Viewing / Assigning Roles to Users
Roles are managed in Keycloak:
- Access the Keycloak admin console
- Navigate to Users
- Select a user
- Go to Role Mappings
- Assign roles using the
{SCOPE}__{ROLE_NAME}format

User Group Role from LDAP Federation
If you have instead imported user groups from an LDAP user federation system, you can instead assign roles to user groups rather than individual users, but you must do the following:
- Navigate to "Client Scopes"
- Click on the "roles" scope
- Go to the "Mappers" tab
- Click "Add mapper" then "From predefined mappers"
- Search for "groups" and check the box next to that, then click "Add"
