Skip to content

feat: add API token authentication for REST API access#3

Open
cnewkirk wants to merge 1 commit into
release-35.xfrom
api-tokens-clean-tmp
Open

feat: add API token authentication for REST API access#3
cnewkirk wants to merge 1 commit into
release-35.xfrom
api-tokens-clean-tmp

Conversation

@cnewkirk

Copy link
Copy Markdown
Owner

Summary

  • Database-backed API token authentication as an alternative to basic auth for REST API access
  • Tokens are SHA-256 hashed at rest, plaintext shown only once at creation
  • Configurable expiry with admin-enforced maximum lifetime
  • Three access points: REST API (/api/v2/apiTokens), Web UI (self-service + admin), and Karaf shell
  • Token auth inherits the user's full role set, matching existing basic auth behavior

Key Components

  • features/api-tokens/ — API, impl, and Karaf shell modules
  • features/springframework-security/ApiTokenAuthenticationFilter (bearer token auth)
  • opennms-webapp-rest/ApiTokenRestService (JAX-RS REST endpoint)
  • opennms-webapp/ — Self-service and admin JSP pages
  • core/schema/ — Liquibase changeset for api_tokens table

Security

  • SHA-256 hashed storage, one-time plaintext display
  • Per-user ReentrantLock prevents TOCTOU race on maxTokensPerUser
  • XSS prevention in JSPs (OWASP sanitization)
  • Error messages don't leak config values
  • Bearer header only (no query parameter support)

Verification

  • 17 unit tests (8 service + 9 filter) — all passing
  • Full compile and assembly: PASS
  • E2E: 21/21 tests passing against container overlay

Test plan

  • Basic auth still works
  • Token CRUD: create (201), list (200), revoke (204), revoke-all (204)
  • Bearer auth: valid → 200, invalid/revoked → 401, malformed → 401, no auth → 401
  • lastUsedAt tracking, hash leak prevention, token format validation
  • Bad/negative expiry rejected (400), non-existent token (404)
  • Admin cross-user operations, revoke isolation

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant