Authentication, RBAC & Security
Comprehensive security features for production deployments. MynaDB provides built-in authentication, role-based access control, TLS encryption, and audit logging to protect your time series data at every layer.
MynaDB security follows a layered approach: authenticate users, authorize actions via RBAC, encrypt data in transit with TLS, and record all operations with audit logging. Each layer can be enabled independently to match your deployment requirements.
Basic Authentication
MynaDB supports basic username/password authentication for all API endpoints. When authentication is enabled, every request must include valid credentials.
Configuration
Enable authentication in config.toml:
[auth]
# Enable authentication (default: false)
enabled = true
# Admin user credentials
username = "admin"
password = "your-secure-password"
Using Authentication with curl
Pass credentials using the -u flag:
# Write data with authentication
curl -u admin:your-secure-password \
-X POST http://localhost:7000/write/mydb \
-d 'cpu,host=server01 usage=45.2'
# Query data with authentication
curl -u admin:your-secure-password \
"http://localhost:7000/query/mydb?sql=SELECT+*+FROM+cpu+LIMIT+10"
# Health check (no authentication required)
curl http://localhost:7000/health
When authentication is disabled, all endpoints are open to unauthenticated access.
Always enable authentication in production environments. The /health
endpoint remains unauthenticated even when auth is enabled, to support load balancer
health checks.
Role-Based Access Control (RBAC)
RBAC extends basic authentication with fine-grained permissions. Users are assigned roles that control what operations they can perform and on which databases.
Roles
MynaDB defines three built-in roles with increasing levels of access:
| Role | Description | Typical Use |
|---|---|---|
admin |
Full access to all operations and databases | Database administrators, DevOps engineers |
writer |
Read and write access to assigned databases | Application services, data pipelines, collectors |
reader |
Read-only access to assigned databases | Dashboard users, analysts, monitoring tools |
Permissions Matrix
Each role grants specific permissions per database:
| Permission | reader | writer | admin |
|---|---|---|---|
Read data (SELECT, /query) |
✓ | ✓ | ✓ |
Write data (/write) |
✗ | ✓ | ✓ |
| List tables and schemas | ✓ | ✓ | ✓ |
| Trigger compaction | ✗ | ✗ | ✓ |
| Manage retention | ✗ | ✗ | ✓ |
| Delete partitions | ✗ | ✗ | ✓ |
| Manage users and roles | ✗ | ✗ | ✓ |
| Flush cache | ✗ | ✗ | ✓ |
| View system stats | ✗ | ✗ | ✓ |
User Management API
Manage users and their roles through the REST API. All user management endpoints require admin role.
Create a User
# Create a new user with the writer role
curl -u admin:your-secure-password \
-X POST http://localhost:7000/auth/users \
-H "Content-Type: application/json" \
-d '{
"username": "app_writer",
"password": "writer-password-123",
"role": "writer",
"databases": ["mydb", "metrics"]
}'
# Response
{
"status": "ok",
"message": "User app_writer created with role writer"
}
List Users
# List all users
curl -u admin:your-secure-password \
http://localhost:7000/auth/users
# Response
{
"users": [
{
"username": "admin",
"role": "admin",
"databases": ["*"]
},
{
"username": "app_writer",
"role": "writer",
"databases": ["mydb", "metrics"]
},
{
"username": "dashboard",
"role": "reader",
"databases": ["mydb"]
}
]
}
Update User Role
# Promote a user to admin
curl -u admin:your-secure-password \
-X PUT http://localhost:7000/auth/users/app_writer/role \
-H "Content-Type: application/json" \
-d '{
"role": "admin",
"databases": ["*"]
}'
# Response
{
"status": "ok",
"message": "User app_writer role updated to admin"
}
Delete a User
# Delete a user
curl -u admin:your-secure-password \
-X DELETE http://localhost:7000/auth/users/dashboard
# Response
{
"status": "ok",
"message": "User dashboard deleted"
}
TLS/SSL Configuration
Encrypt all client-server communication using TLS. MynaDB supports both standard TLS and mutual TLS (mTLS) for environments that require client certificate verification.
Configuration
[tls]
# Enable TLS encryption (default: false)
enabled = true
# Path to the server certificate (PEM format)
cert_file = "/etc/mynadb/certs/server.crt"
# Path to the server private key (PEM format)
key_file = "/etc/mynadb/certs/server.key"
# Path to the Certificate Authority bundle (PEM format)
# Required for mutual TLS (mTLS) client verification
ca_file = "/etc/mynadb/certs/ca.crt"
# Enable mutual TLS - clients must present a valid certificate
# signed by the CA specified in ca_file (default: false)
mutual_auth = false
Connecting with TLS
# Connect using TLS with CA certificate verification
curl --cacert /etc/mynadb/certs/ca.crt \
-u admin:your-secure-password \
"https://localhost:7000/query/mydb?sql=SELECT+*+FROM+cpu+LIMIT+5"
# Connect with mutual TLS (mTLS) - client certificate required
curl --cacert /etc/mynadb/certs/ca.crt \
--cert /etc/mynadb/certs/client.crt \
--key /etc/mynadb/certs/client.key \
-u admin:your-secure-password \
"https://localhost:7000/query/mydb?sql=SELECT+*+FROM+cpu+LIMIT+5"
# Write data over TLS
curl --cacert /etc/mynadb/certs/ca.crt \
-u admin:your-secure-password \
-X POST https://localhost:7000/write/mydb \
-d 'cpu,host=server01 usage=45.2'
TLS Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
bool | false |
Enable TLS encryption |
cert_file |
string | - | Path to server certificate (PEM) |
key_file |
string | - | Path to server private key (PEM) |
ca_file |
string | - | Path to CA certificate bundle (PEM) |
mutual_auth |
bool | false |
Require client certificates (mTLS) |
For development and testing, you can generate self-signed certificates with OpenSSL:
openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.crt -days 365 -nodes -subj "/CN=localhost"
For production, use certificates issued by a trusted Certificate Authority or an internal PKI such as HashiCorp Vault, cert-manager, or AWS ACM.
Audit Logging
Audit logging records all authenticated operations for compliance, forensics, and security monitoring. Each entry captures the user, action, target resource, timestamp, and outcome.
Configuration
[audit]
# Enable audit logging (default: false)
enabled = true
# Path to the audit log file
log_file = "/var/log/mynadb/audit.log"
# Log rotation policy: "daily", "size", or "never"
rotation = "daily"
# Maximum number of rotated log files to retain
max_files = 90
Audit Log Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
bool | false |
Enable audit logging |
log_file |
string | /var/log/mynadb/audit.log |
Path to the audit log file |
rotation |
string | daily |
Rotation policy (daily, size, never) |
max_files |
u32 | 90 |
Number of rotated files to keep |
Sample Audit Log Entry
Each audit log entry is written as a single JSON line:
{
"timestamp": "2026-02-13T10:32:15.847Z",
"user": "app_writer",
"role": "writer",
"action": "WRITE",
"resource": "/write/mydb",
"method": "POST",
"source_ip": "10.0.1.42",
"status": 200,
"duration_ms": 12,
"details": {
"database": "mydb",
"points": 1500,
"bytes": 48210
}
}
{
"timestamp": "2026-02-13T10:32:18.103Z",
"user": "dashboard",
"role": "reader",
"action": "QUERY",
"resource": "/query/mydb",
"method": "GET",
"source_ip": "10.0.2.15",
"status": 200,
"duration_ms": 45,
"details": {
"database": "mydb",
"sql": "SELECT time, usage FROM cpu WHERE host = 'server01' ORDER BY time DESC LIMIT 100",
"rows_returned": 100
}
}
{
"timestamp": "2026-02-13T10:35:02.991Z",
"user": "unknown",
"role": null,
"action": "AUTH_FAILURE",
"resource": "/write/mydb",
"method": "POST",
"source_ip": "192.168.1.99",
"status": 401,
"duration_ms": 1,
"details": {
"reason": "Invalid credentials"
}
}
Audit logs use structured JSON format (one entry per line), making them easy to ingest into log aggregation tools such as Elasticsearch, Loki, or Splunk. You can also query audit logs directly with standard tools:
# Find all failed authentication attempts
jq 'select(.action == "AUTH_FAILURE")' /var/log/mynadb/audit.log
# Count operations per user
jq -r '.user' /var/log/mynadb/audit.log | sort | uniq -c | sort -rn
API Authentication
When authentication is enabled, clients must provide credentials with every request. MynaDB supports two methods for passing authentication credentials.
Method 1: Basic Auth Header
Send credentials via the standard HTTP Authorization header with
Base64-encoded username:password:
# Using curl -u (automatically sets Authorization header)
curl -u admin:your-secure-password \
"http://localhost:7000/query/mydb?sql=SELECT+1"
# Equivalent explicit header
curl -H "Authorization: Basic YWRtaW46eW91ci1zZWN1cmUtcGFzc3dvcmQ=" \
"http://localhost:7000/query/mydb?sql=SELECT+1"
Method 2: Token Query Parameter
For environments where setting headers is difficult (such as browser-based tools or simple monitoring scripts), pass a token as a query parameter:
# Pass token as a query parameter
curl "http://localhost:7000/query/mydb?sql=SELECT+1&token=your-api-token"
# Write data with token parameter
curl -X POST "http://localhost:7000/write/mydb?token=your-api-token" \
-d 'cpu,host=server01 usage=72.5'
Query parameter tokens may appear in server access logs and browser history.
Prefer the Authorization header method for production use. If you
must use token parameters, ensure TLS is enabled to prevent tokens from being
transmitted in plain text.
Protocol-Specific Authentication
| Protocol | Authentication Method |
|---|---|
| HTTP REST API | Basic Auth header or token query parameter |
| Arrow Flight (gRPC) | gRPC metadata header authorization: Basic ... |
| MySQL Wire Protocol | Native MySQL authentication handshake |
| OpenTelemetry (OTLP) | gRPC metadata header or HTTP Basic Auth |
Security Best Practices
- Always enable authentication in production. Running without authentication exposes all data and administrative operations to anyone with network access.
- Enable TLS for all connections. Without TLS, credentials and data are transmitted in plain text and can be intercepted on the network.
- Use mutual TLS (mTLS) in zero-trust environments. Require client certificates to verify both sides of the connection.
- Follow the principle of least privilege. Assign users the most restrictive role that allows them to do their job. Use
readerfor dashboards,writerfor ingestion, andadminonly for operators. - Scope database access per user. Grant access only to the databases each user needs rather than using wildcard (
*) access. - Rotate credentials regularly. Update passwords on a scheduled basis and immediately revoke access for departing team members.
- Enable audit logging. Maintain a complete record of all operations for security monitoring, incident investigation, and compliance.
- Monitor authentication failures. Set up alerts on repeated
AUTH_FAILUREevents in the audit log to detect brute-force attempts. - Restrict network access. Use firewalls and network policies to limit which hosts can reach MynaDB ports (7000, 7001, 7002).
- Secure the configuration file. The
config.tomlfile contains passwords and should be readable only by the MynaDB service user (chmod 600). - Use environment variables for secrets. Instead of storing passwords directly in config files, use environment variable references:
password = "${MYNADB_ADMIN_PASSWORD}". - Keep audit logs on separate storage. Store audit logs on a different volume or ship them to a remote system so they cannot be tampered with if the data node is compromised.
Example: Production Security Configuration
# Production security configuration
[auth]
enabled = true
username = "admin"
password = "${MYNADB_ADMIN_PASSWORD}"
[tls]
enabled = true
cert_file = "/etc/mynadb/certs/server.crt"
key_file = "/etc/mynadb/certs/server.key"
ca_file = "/etc/mynadb/certs/ca.crt"
mutual_auth = true
[audit]
enabled = true
log_file = "/var/log/mynadb/audit.log"
rotation = "daily"
max_files = 90
[logging]
level = "info"
log_dir = "/var/log/mynadb"
Configuration - Full configuration reference
High Availability - HA setup with TLS between nodes
Enterprise Cluster - Cluster security with etcd TLS
API Reference - Complete API endpoint documentation