All Products
Search
Document Center

Key Management Service:KMS Agent overview

Last Updated:Aug 24, 2026

KMS Agent is a client-side HTTP proxy that centralizes secret retrieval for your applications. Instead of integrating the KMS SDK into each application, applications send local HTTP requests to the agent, which handles authentication, caching, and communication with KMS on their behalf.

How it works

The agent caches secret values in memory and refreshes them periodically based on the Time To Live (TTL) you configure. When an application requests a secret:

  1. The agent validates the request using a Server-Side Request Forgery (SSRF) token file.

  2. If a valid cached value exists and has not expired, the agent returns it immediately (cache hit).

  3. If no valid cache entry exists, the agent forwards the request to KMS. KMS verifies the agent's identity, decrypts the secret, and returns it. The agent updates the cache and returns the value to the application (cache miss).

The following diagrams show both flows:

  • Cache hit process

image

  • Cache miss (no cache or expired cache) process

image

Important

Cached secret values are stored unencrypted in memory. Protect them by applying appropriate process access permissions to the agent, enabling memory protection mechanisms, and deploying memory leak detection tools.

Deploy the agent alongside your applications on physical servers, virtual machines such as Elastic Compute Service (ECS), or containers such as Kubernetes pods. For the source code and deployment guides, see alibabacloud-kms-agent.

Architecture

The agent comprises four components: HTTP server, cache, KMS client, and log.

image

Configure all four components in a single configuration file. The file below shows all available options and their defaults:

# All configuration items
[Server]
# Optional, default value is 2025. Agent listens on 127.0.0.1:2025.
HttpPort = 2025
# Optional, default value is ["X-KMS-Token", "X-Vault-Token"].
# Requests to the agent must include an SSRF header; requests without one are rejected.
SSRFHeaders = ["X-KMS-Token"]
# Optional, default value is ["KMS_TOKEN", "KMS_SESSION_TOKEN", "KMS_CONTAINER_AUTHORIZATION_TOKEN"].
# The value can be a literal string or a file path, such as file:///var/run/awssmatoken.
# The agent reads the SSRF token from the specified environment variable and compares it
# against the token in the application's request header. Access is granted only on a match.
SSRFEnvVariables = ["KMS_TOKEN"]
# Optional, default value is "/v1/". URI prefix for path-based requests.
PathPrefix = "/v1/"
# Optional, default value is 800. Maximum number of concurrent requests.
MaxConn = 800
# Optional, default value is 0.
# 0: KMS GetSecretValue response format
# 1: AWS Secrets Manager GetSecretValue response format
# 2: HashiCorp Vault KV structure
ResponseType = 0
# Optional, default value is true.
# When true, the agent returns expired cached values if KMS is temporarily unreachable.
IgnoreTransientErrors = true

[Kms]
# Optional, default value is cn-hangzhou.
Region = "cn-hangzhou"
# Optional, default value is kms.cn-hangzhou.aliyuncs.com.
# Accepts both shared and dedicated gateway endpoints.
Endpoint = "kms.cn-hangzhou.aliyuncs.com"

[Cache]
# Optional, default value is InMemory. Only in-memory caching is currently supported.
CacheType = "InMemory"
# Optional, default value is 1000. When set to 0, caching is disabled and every
# request goes directly to KMS.
CacheSize = 1000
# Optional, default value is 300s.
TtlSeconds = 300
# Optional, default value is false.
# false: evicts the oldest cached secret when the cache is full.
# true: evicts the least recently used secret (LRU) based on access frequency.
EnableLRU = false

[Log]
# Optional, default value is Debug.
LogLevel = "Debug"
# Optional, default value is ./logs/ relative to the application startup directory.
LogPath = "./logs/"
# Optional, default value is 100 (MB). Maximum size per log file.
MaxSize = 100
# Optional, default value is 2. Number of log files to retain.
MaxBackups = 2

HTTP server

The HTTP server handles application requests for secret retrieval. By default, responses use the KMS GetSecretValue format. Set ResponseType to return AWS Secrets Manager or HashiCorp Vault KV formats instead.

Supported request formats:

  • Path-based:

    GET /v1/<secret-name>
  • Query-based:

    GET /secretsmanager/get?secretId=<secret-name>

Example request using curl (reads the SSRF token from file):

curl -s \
  -H "X-KMS-Token: $(cat /var/run/kmstoken)" \
  "http://127.0.0.1:2025/v1/<secret-name>"

Example request using Python:

with open("/var/run/kmstoken") as f:
    token = f.read().strip()

headers = {"X-KMS-Token": token}
response = requests.get("http://127.0.0.1:2025/v1/<secret-name>", headers=headers)
print(response.json())

Replace <secret-name> with the name of the secret to retrieve.

Supported response formats:

The agent is compatible with the AWS Secrets Manager and HashiCorp Vault KV response formats. If your code already integrates Spring Vault, change the access endpoint to the KMS Agent address and complete configuration adaptation through the agent to quickly switch to the Alibaba Cloud platform.

  • Alibaba Cloud KMS (default, ResponseType=0):

    {
       "CreateTime": "2025-01-03T07:59:17Z",
       "RequestId": "cc315250-04c9-4caf-a055-6648f36598b9",
       "SecretData": "{\"k3\":\"v3\"}",
       "SecretDataType": "text",
       "SecretName": "agent-test",
       "SecretType": "Generic",
       "VersionId": "v2",
       "VersionStages": {
          "VersionStage": [
             "ACSCurrent"
          ]
       }
    }
  • AWS Secrets Manager (ResponseType=1):

    {
       "ARN": "",
       "Name": "agent-test",
       "VersionId": "v2",
       "SecretString": "{\"k3\":\"v3\"}",
       "VersionStages": [
          "ACSCurrent"
       ],
       "CreatedDate": "2025-01-03T07:59:17Z"
    }
  • HashiCorp Vault (ResponseType=2):

    {
       "data": {
          "k3": "v3"
       }
    }

Cache

The agent caches secret values in memory, reducing the number of requests sent to KMS. Configure the cache TTL, size, and eviction policy to match your access patterns and secret rotation schedule.

Parameter

Description

Default

CacheType

Cache backend. Only InMemory is supported.

InMemory

CacheSize

Maximum number of secrets to cache. Set to 0 to disable caching.

1000

TtlSeconds

How long a cached value is considered valid, in seconds.

300

EnableLRU

Eviction policy when the cache is full. false evicts by age; true evicts by least recent use.

false

KMS client

The KMS client connects the agent to KMS. Set Region and Endpoint to match your KMS deployment. Both shared and dedicated gateway endpoints are supported.

Note

When using a dedicated gateway endpoint, the agent includes built-in CA certificates for all regions — no additional certificate configuration is required.

Log

The agent uses the Zap logging framework to emit structured JSON logs. Configure the log level, file size limit, and retention count to match your operational requirements.

Security

Authentication and authorization

Agent authenticating to KMS

The agent uses the Alibaba Cloud default credential provider chain, which checks the following sources in order: environment variables, OIDC IdP RAM role, config.json, ECS RAM role, and credential URI — unless a specific initialization method is provided in credentials.NewDefaultCredentialsProvider().

Grant the agent only the permissions it needs to retrieve and decrypt secrets. Follow the principle of least privilege when configuring RAM policies.

Applications authenticating to the agent

The agent generates an SSRF token file (for example, /var/run/kmstoken) on startup. Applications must include this token in their request headers. Requests without a valid token are rejected.

Access to the token file is restricted by default:

  • Linux: Only the agent process and the application's OS user can read the token file.

  • Sidecar container: Token file access is scoped to the pod.

Communication security

  • Agent to KMS: All traffic uses Transport Layer Security (TLS). For stronger isolation, use a dedicated gateway endpoint — traffic stays within your VPC and is not exposed to the public internet.

  • Agent to application: The agent listens only on 127.0.0.1, restricting access to the local machine.

Auditing and logging

All secret retrieval operations are logged in JSON format using the Zap framework. Logs are configurable for file size and retention count, providing an auditable record of agent activity.

Stability

The agent is designed to remain available during network disruptions and transient failures.

Startup self-check: On startup, the agent verifies connectivity to KMS. If verification fails, the agent exits rather than starting in a degraded state.

Automatic retry: The agent uses the Alibaba Cloud SDK (V2) built-in retry logic. For HTTP 429 (throttling) and HTTP 500 (internal server error) responses, it will retry 3 times using an exponential backoff method for interval times.

Stale cache fallback: When IgnoreTransientErrors is enabled (the default), the agent returns the most recent cached value if KMS is temporarily unreachable. This prevents application failures during short-lived network or server issues.

High availability:

  • Linux (systemd): systemd monitors the agent process and restarts it automatically if it crashes.

  • Kubernetes (sidecar container): Deployed as an init container, the agent failing will trigger a container restart, guaranteeing application stability.

KMS Agent vs. Secret Client

KMS Agent acts as a middle layer — applications access secrets through the agent rather than calling KMS directly. Secret Client integrates the KMS SDK into each application. Choose based on your deployment scale and access control requirements.

Aspect

KMS Agent

Secret Client

Recommended for

Enterprises with multiple applications and diverse programming languages that need centralized access control

Single applications or small deployments with simple access control requirements

Deployment

Independent process, decoupled from applications

Library integrated into application code

Integration complexity

Low

High

Access control

Centralized: enforced at a single point for all applications

Decentralized: each application manages its own policies

Language support

Any language (HTTP interface)

Java 8+, Python, and Go

Performance

In-memory cache minimizes latency and KMS throttling in high-frequency scenarios

High-frequency access may trigger KMS throttling

Secret rotation

Cached with a configurable TTL; refreshed automatically from KMS on expiry

Retrieved automatically using a refresh mechanism and retry logic

Maintenance

Low: one configuration for all applications

High: separate configuration per application