AI API SSRF to Kubernetes Credential Exposure: An Internal Attack Chain

    An authorized penetration test traced a path from an exposed AI inference API to internal services and Kubernetes Secrets. This article reconstructs the chain, covering model metadata disclosure, debug endpoint leaks, SSRF, and excessive service account permissions, then maps each stage to practical defenses.

    1. Background: AI Infrastructure and Its Security Blind Spots

    As large language models become more widely adopted, organizations are incorporating inference services into their internal infrastructure. A common deployment runs an inference framework in containers, exposes an OpenAI-style HTTP API, and uses an API gateway for routing and authentication. Employees access the model through internal tools for tasks such as knowledge retrieval and support ticket processing.

    The architecture is straightforward from a functional perspective, but it creates a recurring security blind spot: AI APIs are often treated as simple “send a prompt, receive a response” endpoints with a limited attack surface.

    An authorized penetration test demonstrated otherwise. Starting from a single externally accessible AI API, testers assembled a path to Kubernetes credentials in less than two hours. This article reconstructs the sanitized attack chain and its validation in a local simulation environment.

    2. Attack Chain Overview

    The chain consisted of three progressively deeper stages:

    1. AI API entry point
    2. ├── Information disclosure: asset discovery
    3. │ ├── Model listing endpoint → names, quantization formats, file sizes
    4. │ └── Debug endpoint → environment variables
    5. │ ├── Internal API addresses
    6. │ ├── Kubernetes API server address
    7. │ ├── MongoDB connection string
    8. │ └── Redis connection string
    9. ├── SSRF exploitation: internal network access
    10. │ ├── Access internal management interfaces
    11. │ ├── Probe internal ports
    12. │ └── Reach the Kubernetes API server
    13. └── Credential exposure: access expansion
    14. ├── Read Kubernetes Secrets
    15. └── Base64-decode API keys and database credentials

    3. Stage One: Asset Discovery and Information Disclosure

    3.1 Exposed Model Listing Endpoint

    Inference frameworks commonly provide a model discovery endpoint such as /v1/models. Its purpose is to let clients identify available models. When exposed without authentication, however, it can disclose useful deployment details:

    • Model names: These may suggest business use cases, such as customer support, code generation, or summarization.
    • Quantization formats and file sizes: Where included in the response, these can provide clues about hardware requirements and deployment scale.
    • Response headers and error messages: These may reveal the inference framework and version, helping an attacker identify potentially relevant known vulnerabilities.

    3.2 Environment Variables Leaked Through a Debug Endpoint

    The more serious disclosure came from a debugging interface. Some deployments enable debug endpoints for troubleshooting. In this case, the exposed endpoint allowed access to process environment variables.

    Environment variables are commonly used to inject configuration into containers. Their disclosure can therefore reveal both internal topology and sensitive connection details:

    1. INTERNAL_API_URL=http://internal-api.svc.cluster.local:8080
    2. KUBERNETES_SERVICE_HOST=10.0.0.1
    3. MONGO_CONN_STR=mongodb://user:***@mongo-svc:27017
    4. REDIS_URL=redis://redis-svc:6379

    Without direct access to the internal network, the tester had obtained the Kubernetes API server address, downstream service locations, and middleware connection strings.

    This information did not itself provide internal connectivity, but it supplied targets for the next stage.

    4. Stage Two: SSRF Turns Disclosure into Internal Access

    4.1 How the SSRF Vulnerability Arose

    Some inference frameworks support loading model files from a URL supplied in a request. If the application does not properly validate the URL scheme and destination, an attacker can provide an arbitrary HTTP or HTTPS address and cause the server to request it.

    This is server-side request forgery, or SSRF.

    The request originates from the inference service’s network environment rather than the attacker’s machine. As a result, it may reach services that are inaccessible from the public internet, subject to the network restrictions applied to the workload.

    An externally accessible AI endpoint can therefore become a bridge into internal infrastructure.

    4.2 Internal Reconnaissance and Service Access

    The disclosed addresses made the SSRF vulnerability more useful in several ways.

    Probing internal ports. Differences in timeouts, error messages, and response sizes can help distinguish reachable services from closed or filtered ports. These differences can support broader internal network probing.

    Accessing internal management interfaces. Internal API addresses exposed through environment variables can become direct SSRF targets, potentially revealing management functionality or additional information.

    Reaching the Kubernetes API server. This was the most consequential step in the chain. The Kubernetes API server exposes an HTTPS interface that is typically reachable from workloads inside the cluster, depending on network controls.

    Network reachability alone, however, does not grant access to Kubernetes resources. Reading Secrets also requires an authenticated identity with the necessary permissions. The credential-access stage therefore depended on the ability to use a pod-mounted service account token and on that account having excessive RBAC permissions. SSRF by itself does not automatically attach the token.

    4.3 Credential Exposure Through Kubernetes Secrets

    With an available service account token and permission to list Secrets in the target namespace, the relevant request took this form:

    1. GET /api/v1/namespaces/ai-prod/secrets
    2. Authorization: Bearer <pod-mounted service account token>

    The Secret data returned through the API was Base64-encoded. Decoding the relevant fields exposed plaintext values associated with:

    • ai-api-key: the AI service API key.
    • db-credentials: database credentials.

    Base64 is an encoding, not an encryption mechanism.

    The chain had now progressed from an externally reachable AI interface to database credentials and sensitive cluster-held secrets. The impact resulted from several weaknesses working together: information disclosure, unrestricted server-side requests, usable credentials, and excessive permissions.

    5. Defenses Mapped to the Attack Chain

    5.1 Reduce the Exposed API Surface

    • Disable unnecessary model listing, health-check, and debug endpoints in production, or protect them with appropriate authentication.
    • Configure granular API gateway routing so that only endpoints required by the application are exposed.

    Auxiliary endpoints deserve the same security review as the main inference API. A route that appears operationally harmless may disclose information that makes another vulnerability easier to exploit.

    5.2 Address SSRF at Both the Application and Network Layers

    • Apply strict scheme allowlists and destination validation to model-loading features and other URL-fetching functionality.
    • Prevent requests to unauthorized internal destinations, including Kubernetes Service networks and link-local metadata addresses such as 169.254 ranges.
    • Restrict inference pod egress to the minimum required destinations using NetworkPolicy.

    The objective is to prevent attacker-controlled requests and limit their reach if application-level validation fails. Where the inference service does not need Kubernetes API access, network controls should prevent it from reaching that API.

    5.3 Harden Kubernetes Permissions and Secret Handling

    • Apply least-privilege RBAC to service accounts. Do not grant the default ServiceAccount permission to read Secrets.
    • Enable encryption at rest for sensitive Secrets rather than treating Base64 encoding as protection.
    • Enable Kubernetes API server audit logging and alert on unexpected Secret-listing requests.

    Encryption at rest protects stored data, but it does not prevent an authorized API identity from retrieving Secret values. Least-privilege access controls remain essential.

    5.4 Eliminate Environment-Variable Disclosure Paths

    • Avoid placing sensitive configuration in plaintext environment variables where practical; use a secret-management approach with mounted secrets instead.
    • Disable debug endpoints in production, or restrict access to designated operations networks through network controls.

    Changing how secrets are delivered does not remove the need to secure diagnostic interfaces. Debug endpoints must not expose sensitive process or runtime information.

    6. Conclusion

    An AI inference service is not merely a chat interface. It is a networked application running inside infrastructure with internal dependencies and assigned permissions.

    Every auxiliary endpoint and URL-handling feature can become the starting point of an attack chain. When AI services run on Kubernetes, weak isolation and excessive service account permissions can turn a single application vulnerability into broader credential exposure.

    The central lesson is to apply established security principles consistently: minimize exposed functionality, enforce least privilege, and use defense in depth. Each control interrupts a different part of the chain; together, they prevent a seemingly narrow API flaw from becoming an infrastructure-wide incident.