Skip to content

api: fine-grained permission control for service account creation#837

Open
alvarofraguas wants to merge 1 commit into
jmpsec:mainfrom
alvarofraguas:pr/fine-grained-permissions
Open

api: fine-grained permission control for service account creation#837
alvarofraguas wants to merge 1 commit into
jmpsec:mainfrom
alvarofraguas:pr/fine-grained-permissions

Conversation

@alvarofraguas
Copy link
Copy Markdown
Collaborator

Summary

  • Adds optional user_access, query_access, carve_access, and admin_access fields to the user creation API endpoint
  • When provided, these override the legacy behavior where all permission levels were derived from the binary admin flag
  • Enables creating service accounts with specific permission combinations (e.g. read + query for monitoring, read + carve for forensics)

Backward compatibility

Fields use pointer types (*bool) so nil (not provided) is distinguishable from false (explicitly denied). When none of the new fields are provided, the handler falls back to the existing behavior: user_access=true, everything else = admin value.

Existing API clients and the CLI continue working unchanged.

API usage

POST /api/v1/users/my-monitoring-bot/add
{
  "username": "my-monitoring-bot",
  "password": "secure_password",
  "email": "monitoring@example.com",
  "service": true,
  "admin": false,
  "environments": ["env-uuid"],
  "user_access": true,
  "query_access": true,
  "carve_access": false,
  "admin_access": false
}

Security

The endpoint is already gated behind global admin permission (AdminLevel check). Only admins can create users or assign permissions. This change adds granularity to what admins can already do — it does not expand the attack surface.

Closes #774

Test plan

  • go build ./... clean
  • go test ./cmd/api/... ./pkg/users/... passes
  • Legacy behavior preserved: omitting new fields produces same permissions as before
  • Fine-grained: admin=false + query_access=true creates user with read + query only

Add optional user_access, query_access, carve_access, and admin_access
fields to ApiUserRequest. When provided, these override the legacy
behavior where all permission levels were derived from the admin flag.

Pointer types (*bool) distinguish "not provided" (nil → legacy
fallback) from "explicitly false", preserving backward compatibility
for existing API clients and the CLI.

Closes jmpsec#774
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fine-grained permission control for service accounts

1 participant