Skip to content

feat(#409): view-only API key model — role/permission for uteke-serve - #423

Merged
ajianaz merged 2 commits into
developfrom
feat/409-view-only-apikey
Jun 21, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/409-view-only-apikey

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Implements #409.

Summary

Add dual-role API token support to uteke-server.

Changes

  • Admin token (--auth-token): full access to all endpoints
  • Read-only token (--read-only-token): GET-only access (403 on POST/DELETE)
  • Both use SHA-256 hashing with constant-time comparison
  • Env vars: UTEKE_AUTH_TOKEN, UTEKE_READ_ONLY_TOKEN

Usage

uteke-serve --auth-token admin-secret --read-only-token viewer-key

# Read-only client:
curl -H "Authorization: Bearer viewer-key" http://localhost:8767/stats

# Write attempt fails:
curl -X POST -H "Authorization: Bearer viewer-key" ... # 403 Forbidden

Enforced restrictions

Read-only tokens can access: GET /health, /stats, /namespaces, /graph, /memory.
POST/DELETE operations return 403.

Milestone: v0.3.0 — Graph RAG

ajianaz added 2 commits June 21, 2026 20:12
Add dual-role API token support to uteke-server:

- Admin token (--auth-token): full access to all endpoints
- Read-only token (--read-only-token): GET-only access

Read-only tokens can access recall, search, list, stats, graph, and
health endpoints. POST/DELETE operations return 403 Forbidden.

Both tokens use SHA-256 hashing with constant-time comparison.

Env vars: UTEKE_AUTH_TOKEN (admin), UTEKE_READ_ONLY_TOKEN (read-only)

Usage:
  uteke-serve --auth-token admin-secret --read-only-token viewer-key

  # Read-only client:
  curl -H "Authorization: Bearer viewer-key" http://localhost:8767/stats

  # Write attempt fails:
  curl -X POST -H "Authorization: Bearer viewer-key" ... → 403
@github-actions

github-actions Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (3)

  • crates/uteke-server/src/main.rs:481 — The new restriction only checks if method != Method::Get for ApiRole::ReadOnly, but the help text and enum comment describe read-only access as limited to specific GET endpoints like recall, search, list, stats, and graph. As written, any GET route other than /health is permitted for a read-only token, including future GET endpoints that may expose sensitive or administrative data. This is a functional authorization gap caused by the specific code added in route.
  • crates/uteke-server/src/main.rs:1295 — Authentication is considered enabled when either ctx.auth_token_hash or ctx.read_only_token_hash is set, and check_auth returns Authenticated(ApiRole::ReadOnly) when only the read-only token matches. This means configuring just --read-only-token or UTEKE_READ_ONLY_TOKEN exposes the server with no way to perform authenticated write/admin operations, while still allowing unauthenticated clients to probe for a valid low-privilege credential. Given the existing semantics where auth_token is the primary protection, accepting a standalone read-only token is a risky configuration behavior introduced by the new if ctx.auth_token_hash.is_none() && ctx.read_only_token_hash.is_none() logic and subsequent read-only hash check.
  • crates/uteke-server/src/main.rs:1121 — Static security scanner detected: Hardcoded password or secret in variable in crates/uteke-server/src/main.rs:1121

Review powered by cora-cli · BYOK · MIT

Comment thread crates/uteke-server/src/main.rs Fixed
let mut cli_host: Option<String> = None;
let mut cli_port: Option<u16> = None;
let mut cli_auth_token: Option<String> = None;
let mut cli_read_only_token: Option<String> = None;
Comment thread crates/uteke-server/src/main.rs Fixed
Comment thread crates/uteke-server/src/main.rs Fixed
AuthResult::Disabled
};

// Enforce read-only restriction (#409): ReadOnly tokens can only use GET.
// need hashing per-request (avoids double-hash on every auth check).
let auth_token_hash = auth_token.as_deref().map(|t| Sha256::digest(t).into());

// Read-only token (#409): CLI arg or env var.
@ajianaz
ajianaz merged commit 9da9ab5 into develop Jun 21, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the feat/409-view-only-apikey branch June 21, 2026 13:19
ajianaz added a commit that referenced this pull request Aug 13, 2026
…#423)

* feat(#409): view-only API key model — role/permission for uteke-serve

Add dual-role API token support to uteke-server:

- Admin token (--auth-token): full access to all endpoints
- Read-only token (--read-only-token): GET-only access

Read-only tokens can access recall, search, list, stats, graph, and
health endpoints. POST/DELETE operations return 403 Forbidden.

Both tokens use SHA-256 hashing with constant-time comparison.

Env vars: UTEKE_AUTH_TOKEN (admin), UTEKE_READ_ONLY_TOKEN (read-only)

Usage:
  uteke-serve --auth-token admin-secret --read-only-token viewer-key

  # Read-only client:
  curl -H "Authorization: Bearer viewer-key" http://localhost:8767/stats

  # Write attempt fails:
  curl -X POST -H "Authorization: Bearer viewer-key" ... → 403

* style: fmt
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.

2 participants