feat(coderd): add retention policy configuration (#21021)

Add `RetentionConfig` with server flags for configuring data retention:

- `--audit-logs-retention`: retention for audit log entries
- `--connection-logs-retention`: retention for connection logs
- `--api-keys-retention`: retention for expired API keys (default 7d)

Updates #20743
This commit is contained in:
Mathias Fredriksson
2025-12-02 16:04:06 +02:00
committed by GitHub
parent 74d0c39cb3
commit 56e7858570
11 changed files with 314 additions and 0 deletions
+5
View File
@@ -463,6 +463,11 @@ curl -X GET http://coder-server:8080/api/v2/deployment/config \
"disable_all": true
},
"redirect_to_access_url": true,
"retention": {
"api_keys": 0,
"audit_logs": 0,
"connection_logs": 0
},
"scim_api_key": "string",
"session_lifetime": {
"default_duration": 0,
+29
View File
@@ -3147,6 +3147,11 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o
"disable_all": true
},
"redirect_to_access_url": true,
"retention": {
"api_keys": 0,
"audit_logs": 0,
"connection_logs": 0
},
"scim_api_key": "string",
"session_lifetime": {
"default_duration": 0,
@@ -3663,6 +3668,11 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o
"disable_all": true
},
"redirect_to_access_url": true,
"retention": {
"api_keys": 0,
"audit_logs": 0,
"connection_logs": 0
},
"scim_api_key": "string",
"session_lifetime": {
"default_duration": 0,
@@ -3808,6 +3818,7 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o
| `proxy_trusted_origins` | array of string | false | | |
| `rate_limit` | [codersdk.RateLimitConfig](#codersdkratelimitconfig) | false | | |
| `redirect_to_access_url` | boolean | false | | |
| `retention` | [codersdk.RetentionConfig](#codersdkretentionconfig) | false | | |
| `scim_api_key` | string | false | | |
| `session_lifetime` | [codersdk.SessionLifetime](#codersdksessionlifetime) | false | | |
| `ssh_keygen_algorithm` | string | false | | |
@@ -7506,6 +7517,24 @@ Only certain features set these fields: - FeatureManagedAgentLimit|
| `message` | string | false | | Message is an actionable message that depicts actions the request took. These messages should be fully formed sentences with proper punctuation. Examples: - "A user has been created." - "Failed to create a user." |
| `validations` | array of [codersdk.ValidationError](#codersdkvalidationerror) | false | | Validations are form field-specific friendly error messages. They will be shown on a form field in the UI. These can also be used to add additional context if there is a set of errors in the primary 'Message'. |
## codersdk.RetentionConfig
```json
{
"api_keys": 0,
"audit_logs": 0,
"connection_logs": 0
}
```
### Properties
| Name | Type | Required | Restrictions | Description |
|-------------------|---------|----------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `api_keys` | integer | false | | Api keys controls how long expired API keys are retained before being deleted. Keys are only deleted if they have been expired for at least this duration. Defaults to 7 days to preserve existing behavior. |
| `audit_logs` | integer | false | | Audit logs controls how long audit log entries are retained. Set to 0 to disable (keep indefinitely). |
| `connection_logs` | integer | false | | Connection logs controls how long connection log entries are retained. Set to 0 to disable (keep indefinitely). |
## codersdk.Role
```json
+33
View File
@@ -1770,3 +1770,36 @@ Whether to inject Coder's MCP tools into intercepted AI Bridge requests (require
| Default | <code>60d</code> |
Length of time to retain data such as interceptions and all related records (token, prompt, tool use).
### --audit-logs-retention
| | |
|-------------|------------------------------------------|
| Type | <code>duration</code> |
| Environment | <code>$CODER_AUDIT_LOGS_RETENTION</code> |
| YAML | <code>retention.audit_logs</code> |
| Default | <code>0</code> |
How long audit log entries are retained. Set to 0 to disable (keep indefinitely). We advise keeping audit logs for at least a year, and in accordance with your compliance requirements.
### --connection-logs-retention
| | |
|-------------|-----------------------------------------------|
| Type | <code>duration</code> |
| Environment | <code>$CODER_CONNECTION_LOGS_RETENTION</code> |
| YAML | <code>retention.connection_logs</code> |
| Default | <code>0</code> |
How long connection log entries are retained. Set to 0 to disable (keep indefinitely).
### --api-keys-retention
| | |
|-------------|----------------------------------------|
| Type | <code>duration</code> |
| Environment | <code>$CODER_API_KEYS_RETENTION</code> |
| YAML | <code>retention.api_keys</code> |
| Default | <code>7d</code> |
How long expired API keys are retained before being deleted. Keeping expired keys allows the backend to return a more helpful error when a user tries to use an expired key. Set to 0 to disable automatic deletion of expired keys.