You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add E2E tests and documentation for ephemeral API key cleanup (#639)
<!--- Provide a general summary of your changes in the Title above -->
## Description
Add TestEphemeralKeyCleanup E2E test class covering:
- CronJob existence and configuration validation (schedule, security)
- NetworkPolicy existence and restriction validation
- Ephemeral key creation and search visibility (includeEphemeral filter)
- Cleanup trigger via oc exec preserves active ephemeral keys
Update documentation:
- token-management.md: ephemeral keys section, cleanup mechanics, grace
period, security model, troubleshooting commands
- maas-api-overview.md: internal endpoints table listing cleanup,
validate, and subscription select routes
<!--- Describe your changes in detail -->
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
## Merge criteria:
<!--- This PR will be merged by any repository approver when it meets
all the points in the checklist -->
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [ ] The commits are squashed in a cohesive manner and have meaningful
messages.
- [ ] Testing instructions have been added in the PR body (for PRs
involving changes that are not immediately obvious).
- [ ] The developer has manually tested the changes and verified that
the changes work
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Documentation**
* Added comprehensive documentation for ephemeral API keys with built-in
automatic cleanup capabilities
* Documented new subscription endpoints and internal cluster-only API
endpoints with security and operational details
* Included configuration guidance, operational behavior documentation,
and troubleshooting instructions for key management
* **Tests**
* Added end-to-end tests validating ephemeral key creation, search,
filtering, and automatic cleanup behavior
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
Copy file name to clipboardExpand all lines: docs/content/configuration-and-management/token-management.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -206,6 +206,66 @@ Revocation updates the key status to `revoked` in the database. The next validat
206
206
!!! warning "Important"
207
207
**For Platform Administrators**: Admins can revoke any user's keys via `DELETE /v1/api-keys/:id` (if they own or have admin access) or `POST /v1/api-keys/bulk-revoke` with the target username. This is an effective way to immediately cut off access for a specific user in response to a security event.
208
208
209
+
### Ephemeral Keys
210
+
211
+
Ephemeral keys are short-lived credentials designed for temporary programmatic access (e.g., playground sessions). They differ from regular keys:
| Maximum expiration | Configured maximum | 1 hour |
217
+
| Name required | Yes | No (auto-generated if omitted) |
218
+
| Visible in default search | Yes | No (`includeEphemeral: true` required) |
219
+
220
+
Create an ephemeral key:
221
+
222
+
```bash
223
+
curl -sSk -X POST "${MAAS_API_URL}/maas-api/v1/api-keys" \
224
+
-H "Authorization: Bearer $(oc whoami -t)" \
225
+
-H "Content-Type: application/json" \
226
+
-d '{"ephemeral": true, "expiresIn": "30m"}'
227
+
```
228
+
229
+
### Ephemeral Key Cleanup
230
+
231
+
Expired ephemeral keys are automatically deleted from the database by a **CronJob** (`maas-api-key-cleanup`) that runs every 15 minutes. This prevents unbounded accumulation of expired short-lived credentials.
232
+
233
+
**How it works:**
234
+
235
+
1. The CronJob sends `POST /internal/v1/api-keys/cleanup` to the maas-api Service
236
+
2. The endpoint deletes ephemeral keys that expired **more than 30 minutes ago** (grace period)
237
+
3. Regular (non-ephemeral) keys are **never** deleted by cleanup — they remain until manually revoked
238
+
239
+
**Grace period:** A 30-minute grace period after expiration ensures that recently-expired keys are not deleted while in-flight requests may still reference them. Only keys expired for longer than 30 minutes are removed.
240
+
241
+
**Security:** The cleanup endpoint is cluster-internal only:
242
+
243
+
- It is registered under `/internal/v1/` and is **not exposed** on the external Service or Route
244
+
- A `NetworkPolicy` (`maas-api-cleanup-restrict`) restricts cleanup pods to communicate only with `maas-api:8080` and DNS
245
+
- No authentication is required on the endpoint itself — access control is enforced at the network layer
246
+
247
+
!!! tip "Troubleshooting cleanup"
248
+
**Check CronJob status:**
249
+
```bash
250
+
oc get cronjob maas-api-key-cleanup -n <namespace>
251
+
oc get jobs -n <namespace> -l app=maas-api-cleanup --sort-by=.metadata.creationTimestamp
252
+
```
253
+
254
+
**View cleanup logs:**
255
+
```bash
256
+
# Latest CronJob run
257
+
oc logs job/$(oc get jobs -n <namespace> -l app=maas-api-cleanup \
Copy file name to clipboardExpand all lines: docs/content/reference/maas-api-overview.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,23 @@ All endpoints except `/health` require authentication via the `Authorization: Be
44
44
| DELETE |`/v1/api-keys/{id}`| Revoke a specific API key. |
45
45
| POST |`/v1/api-keys/bulk-revoke`| Revoke all active API keys for a user. Admins can revoke any user's keys. |
46
46
47
+
### Subscriptions
48
+
49
+
| Method | Path | Description |
50
+
|--------|------|-------------|
51
+
| GET |`/v1/subscriptions`| List subscriptions accessible to the authenticated user. |
52
+
| GET |`/v1/model/{model-id}/subscriptions`| List subscriptions that provide access to a specific model. |
53
+
54
+
### Internal Endpoints (Cluster-Only)
55
+
56
+
These endpoints are registered under `/internal/v1/` and are **not exposed** on the external Service or Route. They are called by internal components (Authorino, CronJob) and protected by NetworkPolicy.
57
+
58
+
| Method | Path | Called By | Description |
59
+
|--------|------|-----------|-------------|
60
+
| POST |`/internal/v1/api-keys/validate`| Authorino | Validate an API key (hash lookup, status/expiry check). Returns user identity and subscription for the gateway. |
61
+
| POST |`/internal/v1/api-keys/cleanup`| CronJob `maas-api-key-cleanup`| Delete expired ephemeral keys (30-minute grace period). Returns `{"deletedCount": N, "message": "..."}`. |
62
+
| POST |`/internal/v1/subscriptions/select`| Authorino | Select the appropriate subscription for a request based on user groups and optional explicit selection. |
0 commit comments