Skip to main content

KV Service

The KV Service is a secure key-value storage platform for managing secrets, environment variables, and configuration data across your applications.

Overview

The KV Service enables you to:

  • Store and retrieve key-value pairs with hierarchical keys
  • Encrypt sensitive data with AES-256-GCM encryption
  • Set TTL (time-to-live) for automatic expiration
  • Track version history for secret rotation
  • Perform bulk operations efficiently
  • Audit all access to sensitive data

Architecture

┌─────────────────────────────────────────────────────────────┐
│ KV Service │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Namespaces │───▶│ Entries │───▶│ Versions │ │
│ │ (Logical │ │ (Key-Value │ │ (History) │ │
│ │ Grouping) │ │ Pairs) │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │ │
│ │ ▼ │
│ │ ┌─────────────┐ │
│ │ │ Encryption │ ◄── AES-256-GCM │
│ │ │ Service │ │
│ │ └─────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ Audit │ ◄── All operations logged │
│ │ Logging │ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘

┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│PostgreSQL│ │ RabbitMQ │ │ API │
│ Database │ │ Events │ │(Perms) │
└──────────┘ └──────────┘ └──────────┘

Core Concepts

Namespaces

Namespaces provide logical grouping for key-value entries. Each namespace has:

PropertyDescription
NameUnique identifier within an application
DescriptionWhat the namespace is used for
Application IDParent application reference
Is Secret NamespaceIf true, all values are encrypted
Default TTLDefault expiration time for entries

Entries

An entry is a key-value pair stored within a namespace:

PropertyDescription
Key PathHierarchical key (e.g., config/database/host)
ValueThe stored data (encrypted if secret namespace)
Value TypeSTRING, JSON, NUMBER, BOOLEAN, or BINARY
VersionOptimistic locking version
Expires AtOptional TTL expiration timestamp
MetadataAdditional JSON metadata

Value Types

TypeDescriptionExample
STRINGPlain text value"localhost"
JSONJSON object or array{"port": 5432}
NUMBERNumeric value3306
BOOLEANTrue/false valuetrue
BINARYBase64 encoded data"SGVsbG8gV29ybGQ="

Version History

For secret namespaces, all value changes are tracked:

  • Previous values are preserved
  • Each version records who made the change
  • Supports rollback to any previous version
  • Tracks reason for change (update, rotation, rollback)

API Endpoints

Namespace Management

MethodEndpointDescription
GET/api/v1/kv/namespacesList all namespaces
GET/api/v1/kv/namespaces/{id}Get a specific namespace
POST/api/v1/kv/namespacesCreate a new namespace
PUT/api/v1/kv/namespaces/{id}Update a namespace
DELETE/api/v1/kv/namespaces/{id}Delete a namespace

Entry Operations

MethodEndpointDescription
GET/api/v1/kv/{nsId}/entriesList entries (with optional prefix)
GET/api/v1/kv/{nsId}/entries/{key}Get a specific entry
PUT/api/v1/kv/{nsId}/entries/{key}Set/update an entry
DELETE/api/v1/kv/{nsId}/entries/{key}Delete an entry

Bulk Operations

MethodEndpointDescription
POST/api/v1/kv/{nsId}/bulk/getGet multiple entries
POST/api/v1/kv/{nsId}/bulk/setSet multiple entries
POST/api/v1/kv/{nsId}/bulk/deleteDelete multiple entries

Secret Operations

MethodEndpointDescription
POST/api/v1/kv/{nsId}/entries/{key}/rotateRotate a secret value
GET/api/v1/kv/{nsId}/entries/{key}/versionsGet version history
POST/api/v1/kv/{nsId}/entries/{key}/rollbackRollback to previous version

How It Works

Creating a Namespace

POST /api/v1/kv/namespaces
{
"name": "production-secrets",
"description": "Production environment secrets",
"applicationId": "app-123",
"isSecretNamespace": true,
"defaultTtlSeconds": null
}

Secret namespaces automatically encrypt all stored values.

Storing a Value

PUT /api/v1/kv/{namespaceId}/entries/database/connection-string
{
"value": "postgresql://user:pass@host:5432/db",
"valueType": "STRING",
"ttlSeconds": 3600
}

For secret namespaces, the value is automatically encrypted before storage.

Retrieving a Value

GET /api/v1/kv/{namespaceId}/entries/database/connection-string

Response:

{
"id": "uuid",
"keyPath": "database/connection-string",
"value": "postgresql://user:pass@host:5432/db",
"valueType": "STRING",
"version": 1,
"expiresAt": "2024-01-15T10:00:00Z"
}

For secret namespaces, values are automatically decrypted on retrieval.

Rotating a Secret

POST /api/v1/kv/{namespaceId}/entries/api-key/rotate
{
"value": "new-api-key-value"
}

The rotation process:

  1. Saves current value to version history
  2. Encrypts and stores new value
  3. Increments version number
  4. Logs audit entry

Using Hierarchical Keys

Keys support hierarchical paths using / as separator:

config/database/host       → "localhost"
config/database/port → 5432
config/database/credentials → {"user": "admin", "pass": "secret"}
config/api/timeout → 30000

List entries with prefix:

GET /api/v1/kv/{nsId}/entries?prefix=config/database

Integration Points

The KV Service integrates with:

ServicePurpose
PostgreSQLStores namespaces, entries, versions, and audit logs
FunctionsProvides environment variables and secrets
WorkflowsStores workflow configuration and credentials
RabbitMQPublishes events for entry changes
API ServiceValidates permissions
GatewayRoutes external requests

Security

Encryption

  • Secret namespaces use AES-256-GCM encryption
  • Unique IV generated per encryption operation
  • Master key configured via environment variable
  • Values never logged in plaintext

Audit Logging

All operations are logged to the audit table:

FieldDescription
Namespace IDWhich namespace was accessed
Entry IDWhich entry (if applicable)
Key PathThe key that was accessed
ActionREAD, WRITE, DELETE, ROTATE, ROLLBACK
User IDWho performed the action
SuccessWhether operation succeeded
TimestampWhen it occurred

Permission Integration

The KV Service uses the shared permission library:

PermissionDescription
kv-namespace:readView namespace and list entries
kv-namespace:writeCreate/update namespace
kv-namespace:deleteDelete namespace
kv-entry:readRead entry values
kv-entry:writeCreate/update entries
kv-entry:deleteDelete entries
kv-secret:rotateRotate secrets and rollback

Best Practices

Key Naming

  • Use hierarchical paths for organization
  • Keep keys descriptive but concise
  • Use consistent naming conventions
  • Example: {category}/{subcategory}/{name}

Secret Management

  • Always use secret namespaces for sensitive data
  • Rotate secrets regularly
  • Never log or expose decrypted values
  • Use version history for audit trails

TTL Usage

  • Set TTL for temporary values
  • Use default TTL at namespace level for consistency
  • Consider security implications of long-lived secrets

Performance

  • Use bulk operations for multiple keys
  • Leverage prefix queries for related entries
  • Consider caching for frequently accessed values

API Documentation

Interactive API documentation is available at:

/api/v1/kv/swagger-ui

Next Steps