4.0 KiB
Telemt Control API
Purpose
This document specifies the control-plane HTTP API used for:
- runtime statistics access,
- user management,
- safe configuration mutations.
The data-plane (MTProto proxy traffic) is out of scope.
Design Principles
-
Keep data-plane isolated. The API must not affect MTProto hot paths.
-
Keep configuration authoritative.
config.tomlis the single source of truth for managed entities. -
Make writes safe. All config mutations are validated and persisted atomically.
-
Be explicit about concurrency. Mutating endpoints support optimistic concurrency through revision matching.
-
Prefer fail-fast contract errors. Input validation errors are returned with machine-readable error codes.
Runtime and Configuration
Control API runtime is configured under [server.api].
Parameters:
enabled: boollisten: "IP:PORT"whitelist: [CIDR, ...]auth_header: string(exact match againstAuthorizationheader; empty disables header auth)request_body_limit_bytes: usizeread_only: bool
Backward compatibility:
server.admin_apiis accepted as an alias whileserver.apiis canonical.
Operational note:
- Changes in
server.apirequire process restart to take effect.
Protocol Contract
- Transport: HTTP/1.1
- Payload format: JSON (
application/json; charset=utf-8) - API prefix:
/v1
Success Envelope
{
"ok": true,
"data": {},
"revision": "sha256-of-config"
}
Error Envelope
{
"ok": false,
"error": {
"code": "machine_code",
"message": "human-readable text"
},
"request_id": 1
}
Revision / Concurrency Contract
- Mutating operations MAY include
If-Match: <revision>. - If provided and stale, API returns
409 revision_conflict. - Revision is a SHA-256 hash of current config file content.
Endpoints
Read endpoints
GET /v1/healthGET /v1/stats/summaryGET /v1/stats/usersGET /v1/usersGET /v1/users/{username}
Mutating endpoints
POST /v1/usersPATCH /v1/users/{username}POST /v1/users/{username}/rotate-secretDELETE /v1/users/{username}
Entity Contract: User
Managed user fields:
usernamesecret(32 hex chars)user_ad_tag(32 hex chars, optional)max_tcp_conns(optional)expiration_rfc3339(optional)data_quota_bytes(optional)max_unique_ips(optional)
Derived runtime fields (read-only in API responses):
current_connectionsactive_unique_ipstotal_octets
Validation Rules
usernamemust match[A-Za-z0-9_.-], length1..64.secretmust be exactly 32 hexadecimal characters.user_ad_tagmust be exactly 32 hexadecimal characters.- Request body size must not exceed
request_body_limit_bytes.
Security Model
-
Network perimeter. Access is limited by CIDR whitelist.
-
Optional application header auth. If
auth_headeris configured,Authorizationmust match exactly. -
Read-only mode. If
read_only = true, mutating endpoints are rejected with403.
Mutation Approach
- Acquire mutation lock.
- Load config from disk.
- Validate optional
If-Matchrevision. - Apply in-memory mutation.
- Run config validation.
- Persist via atomic write (
tmp + fsync + rename). - Return updated revision.
Runtime apply path:
- Existing config watcher picks up persisted changes and applies them through the standard hot-reload path.
Known Limitations
-
Built-in TLS/mTLS is not provided by this API server. Use loopback bind plus reverse proxy for external exposure.
-
No pagination/filtering for user list in current version.
-
PATCHupdates present fields only. Field deletion semantics are not implemented as explicit nullable operations. -
Config comments and manual formatting are not preserved after mutation. Config is serialized from structured state.
-
API configuration itself (
server.api) is not hot-applied. Restart is required. -
Atomic file replacement can conflict with external editors/tools writing the same config concurrently. Use revision checks to reduce race impact.