API Gateway Security for Microservices: What It Covers

How an API gateway secures microservices: TLS, token checks, rate limits, schema validation, OWASP API Top 10 mapping, and what services must still do.

Aug 18, 2025 - 11:24
Nov 10, 2026 - 12:03
 0  64
API Gateway Security for Microservices: What It Covers

An API gateway secures a microservice architecture by acting as the single checkpoint that external traffic must pass. It terminates TLS, validates tokens, applies coarse authorization, rate limits clients, filters malformed requests and logs every call. It cannot see object-level permissions inside a service, so services must still authorize each request themselves.

This guide is about the security job of a gateway: which threats it stops, which ones it only reduces, and which ones it cannot touch. If you are choosing a product, read our comparisons of managed cloud API gateways and self-hosted API gateways for cloud-native apps. Here we stay with the controls themselves and map them to the OWASP API Security Top 10.

Key takeaways

  • The gateway is the right place for checks that are the same for every request: TLS, token validation, rate limits, size limits, schema checks and audit logging.
  • It is the wrong place for business rules such as "can user 42 read invoice 9001". That check belongs in the service that owns the data.
  • Of the ten OWASP API Security 2023 risks, a gateway helps a lot with authentication, resource consumption and inventory, and helps little with object-level authorization.
  • East-west traffic between services needs its own controls, usually mutual TLS from a service mesh or workload identity.
  • A gateway is itself a high-value target. Treat its configuration as code, review it, and alert on changes.

Why microservices need a checkpoint at all

A monolith has one front door. Split it into thirty services and you can end up with thirty front doors, each written by a different team, each with its own idea of how to check a token. Some will forget rate limiting. One will log full request bodies, including passwords. Another will accept an expired JWT because a library default was left on.

The gateway pattern fixes this by putting one shared component in front of the services. Clients talk only to the gateway, and the services sit on a private network that the internet cannot reach. Every cross-cutting security rule gets written once, reviewed once and applied the same way to every route.

That consistency is the main security benefit. Fewer exposed endpoints means a smaller attack surface, and one policy file is far easier to audit than thirty codebases.

The security controls a gateway enforces

TLS termination and certificate management

The gateway holds the public certificate and terminates HTTPS. You set the minimum TLS version and cipher list in one place, rotate certificates in one place, and turn on HSTS for browser clients. Behind the gateway, traffic should be encrypted again, either by re-encrypting to the upstream or by a mesh that provides mutual TLS. Terminating TLS at the edge and sending plain HTTP across a shared network gives an attacker who lands inside the cluster an easy read of every request.

Authentication: who is calling

Most gateways can validate OAuth 2.0 access tokens and OpenID Connect ID tokens. For a JWT, the gateway checks the signature against the issuer's published keys, then checks the expiry, the issuer and the audience claims. Requests with a missing or bad token are rejected before any service code runs. API keys are still common for machine clients, and a gateway can check them too, but treat a key as an identifier for metering more than as strong proof of identity.

For partner integrations, mutual TLS at the gateway lets you require a client certificate, which ties each call to a specific organisation's private key.

Coarse authorization: what kind of call is allowed

The gateway can decide "only tokens with the orders:write scope may call POST /orders" or "the /admin routes accept only tokens from the internal identity provider". This is function-level authorization, and the gateway is good at it because it sees the route, the method and the token claims together.

It cannot decide whether this particular user owns order 9001. The gateway does not have the order table. That object-level check must happen in the service.

Rate limiting, quotas and size limits

Per-client rate limits slow down credential stuffing, scraping and accidental retry storms. Quotas cap how much a partner can use per day. Request body size limits and timeouts stop a single client from tying up workers with huge uploads or slow connections. These map directly to the OWASP risk called Unrestricted Resource Consumption.

Input validation and request filtering

If you publish an OpenAPI description, many gateways can validate requests against it: reject unknown fields, wrong types or missing required parameters. Some teams add a web application firewall rule set at the same layer. Schema validation is underrated. It blocks mass-assignment attempts where a client sends "role": "admin" in a profile update, because the schema never allowed a role field.

Header hygiene

The gateway should strip headers that clients must never set, such as internal identity headers your services trust, and add the ones you want, such as a verified user ID taken from the token. If a client can send X-User-Id: 1 straight through to a service that trusts it, every other control is moot.

Logging, tracing and anomaly signals

Because every external request passes through it, the gateway produces the most complete access log you have. Log the route, status, latency, client ID and token subject. Do not log tokens, passwords or full bodies. Forward a trace ID so the request can be followed across services. Spikes in 401 or 429 responses from one client are a cheap and early signal of abuse.

Mapping gateway controls to the OWASP API Security Top 10 (2023)

The OWASP API Security Top 10 2023 is the most widely used list of API-specific risks. The table shows how much a gateway can realistically do about each one.

OWASP riskGateway contributionWhat else you need
API1 Broken Object Level AuthorizationLow. It cannot see who owns a record.Ownership checks in every service handler
API2 Broken AuthenticationHigh. Central token and key validation.A well-configured identity provider
API3 Broken Object Property Level AuthorizationMedium. Schema validation blocks unexpected fields.Response filtering in the service
API4 Unrestricted Resource ConsumptionHigh. Rate limits, quotas, size limits, timeouts.Pagination limits in the service
API5 Broken Function Level AuthorizationHigh. Scope and role checks per route.Consistent role design
API6 Unrestricted Access to Sensitive Business FlowsMedium. Per-client limits, bot signals.Business logic limits, fraud checks
API7 Server Side Request ForgeryLow to medium. Can block URL parameters by schema.Egress controls and URL allow-lists in the service
API8 Security MisconfigurationMedium. One place for headers, CORS, TLS.Config review and scanning
API9 Improper Inventory ManagementHigh. Only routes defined at the gateway are reachable.Retiring old versions on purpose
API10 Unsafe Consumption of APIsLow. This is about your outbound calls.Validation of third-party responses

The pattern is clear. A gateway covers the generic risks very well and the business-specific ones poorly. Any architecture review that says "the gateway handles security" without naming who handles object-level authorization has a gap.

Where the gateway stops: north-south versus east-west

Traffic from clients into the system is called north-south. Traffic between services is east-west. A gateway handles north-south. Once a request is inside, services call each other directly, and the gateway never sees those calls.

If one service is compromised, an attacker can call any other service on the internal network unless something stops them. That is the job of a service mesh or of workload identity. A mesh such as Istio or Linkerd gives each workload a certificate and encrypts service-to-service calls with mutual TLS, and lets you write policies such as "only the checkout service may call the payment service". Our guide on where service meshes add the most value covers that layer. Combining both is the practical form of zero trust described in why zero trust matters in DevSecOps.

ConcernAPI gatewayService meshThe service itself
Public TLS certificateYesNoNo
End-user token validationYesPossible, less commonRe-check claims it relies on
Service-to-service encryptionNoYes (mTLS)No
Which service may call whichNoYesNo
Client rate limitsYesLimitedNo
Record ownership checksNoNoYes

Gateways in Kubernetes: Ingress and Gateway API

In Kubernetes the gateway often runs as an ingress controller or as an implementation of the Gateway API. Gateway API splits responsibility by role: the platform team owns the GatewayClass and Gateway (listeners, certificates, which namespaces may attach routes), and application teams own HTTPRoute objects for their paths. That split is itself a security control, because an app team cannot change the TLS settings or attach a route to a listener it was not granted.

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: public-gw
  namespace: edge
spec:
  gatewayClassName: example-class
  listeners:
  - name: https
    protocol: HTTPS
    port: 443
    hostname: "api.example.com"
    tls:
      certificateRefs:
      - name: api-example-com-tls
    allowedRoutes:
      namespaces:
        from: Selector
        selector:
          matchLabels:
            exposure: public

Here only namespaces labelled exposure: public can attach routes to the public listener. Token validation, rate limiting and request filtering are not part of the core Gateway API resources; each implementation adds them through its own policy resources or plugins, so check your product's documentation.

Securing the gateway itself

Concentrating controls in one place also concentrates risk. A misconfigured gateway can expose every service at once. Treat it like any other critical system:

  • Keep gateway configuration in Git and deploy it through a pipeline with review, the same way you handle application code. A GitOps flow, covered in our GitOps guide, works well here.
  • Lock down the admin API. Bind it to a private interface, require authentication, and never expose it on the same listener as client traffic.
  • Run at least two replicas across zones so a single failure does not take down every API.
  • Patch the gateway and its plugins on a schedule. Subscribe to the vendor's security advisories.
  • Alert on configuration changes, certificate expiry and sudden drops in rejected requests (which can mean a rule was removed).
  • Test it. Add API security tests to CI so a route that suddenly accepts unauthenticated calls fails the build. Our guide on running OWASP ZAP in a CI/CD pipeline shows one way.

A layered request path, step by step

  1. The client opens a TLS connection to the gateway. Weak protocol versions are refused.
  2. The gateway checks the client's rate limit and the request size.
  3. It validates the bearer token: signature, expiry, issuer, audience.
  4. It checks that the token's scopes allow this method on this route.
  5. It validates the body against the published schema and strips untrusted headers.
  6. It forwards the request over an encrypted connection, adding the verified subject and a trace ID.
  7. The mesh sidecar or workload identity confirms the gateway is allowed to call this service.
  8. The service checks that the subject is allowed to act on this specific record, then responds.
  9. The gateway logs the result without sensitive fields.

Remove any one layer and a specific class of attack becomes easier. Remove step 8 and you have the most common API breach pattern on the OWASP list.

Common mistakes

  • Leaving services reachable directly, bypassing the gateway. Use network policies so only the gateway (and approved services) can reach them.
  • Trusting identity headers that clients can set.
  • Putting business rules in gateway plugins until nobody understands the routing file.
  • Logging tokens or personal data in access logs.
  • Keeping old API versions live at the gateway long after clients moved, which is exactly the inventory problem OWASP describes.
  • Using the same rate limit for login and for read-only catalogue calls.

Learning the skills

Gateway security sits where networking, identity and CI/CD meet. If you want structured practice with these controls, the DevSecOps training covers API security testing and policy in pipelines, with classroom batches in Kharadi, Pune and live online sessions across India. The Kubernetes side is covered in the CKA course.

FAQ

Is an API gateway enough to secure microservices?

No. It handles shared edge controls such as TLS, token validation and rate limits. Services still need object-level authorization, and service-to-service traffic needs its own protection such as mutual TLS.

What is the difference between an API gateway and a service mesh for security?

A gateway protects traffic entering the system from clients. A mesh protects traffic between services inside the system, usually with mutual TLS and service-to-service access policies. Most production setups use both.

Should the gateway or the service validate JWTs?

Validate at the gateway to reject bad tokens early. Services should still check the claims they rely on, or trust a verified identity header that the gateway sets and clients cannot forge.

Can an API gateway stop broken object level authorization?

Not on its own. The gateway does not know which records belong to which user. That check must run in the service that owns the data.

How does rate limiting at the gateway improve security?

It slows credential stuffing, scraping and denial-of-service attempts, and limits the damage of runaway clients. Set tighter limits on sensitive routes such as login and password reset.

Is a web application firewall the same as an API gateway?

No. A WAF inspects traffic for attack patterns. A gateway routes, authenticates and governs API calls. Some products bundle both, and they work well together.

Where should the gateway run in Kubernetes?

Usually as an ingress controller or Gateway API implementation in a dedicated namespace, with network policies so services accept traffic only from the gateway and approved callers.

References

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.