Implementing JWT Validation

The right authentication strategy is imperative to protecting your user's data. With Ambassador Edge Stack, you can set up JWT validation in your application in just 5 easy steps!

JWTs are validated using public keys supplied in a JWKS file. For the purposes of this demo, we're supplying a Datawire JWKS file (and giving you a JWT that we've generated ourselves). You can change the JWKS file by modifying the jwt-filter.yaml manifest and changing the jwksURI value.

  1. Ambassador Pro is a commercial version of Ambassador that includes integrated Single Sign-On, powerful rate limiting, custom filters, and more. Ambassador Pro also uses a certified version of Ambassador OSS that undergoes additional testing and validation.

    1. Clone the Ambassador Pro configuration repository

      Ambassador Pro consists of a series of modules that communicate with Ambassador. The core Pro module is typically deployed as a sidecar to Ambassador. This means it is an additional process that runs on the same pod as Ambassador. Ambassador communicates with the Pro sidecar locally. Pro thus scales in parallel with Ambassador. Ambassador Pro also relies on a Redis instance for its rate limit service and several Custom Resource Definitions (CRDs) for configuration.

      For this installation, we'll start with a standard set of Ambassador Pro configuration files.

      git clone
    2. License Key

      Copy to, and add your specific license key to the file. If you don’t have a license key, you can request a free 14-day trial key now.

      Note: Ambassador Pro will not start without a valid license key.

    3. Deploy Ambassador Pro

      If you're on GKE, first, create the following ClusterRoleBinding:

      kubectl create clusterrolebinding my-cluster-admin-binding \
      --clusterrole=cluster-admin \
      --user=$(gcloud info --format="value(config.account)")

      Then, deploy Ambassador Pro:

      make apply-ambassador

      This make command will use kubectl to deploy Ambassador Pro and a basic test configuration to the cluster.

      Verify that Ambassador Pro is running:

      kubectl get pods | grep ambassador
      ambassador-79494c799f-vj2dv            2/2       Running            0         1h
      ambassador-pro-redis-dff565f78-88bl2   1/1       Running            0         1h

      Note: If you are not deploying in a cloud environment that supports the LoadBalancertype, you will need to change the ambassador/ambassador-service.yaml to a different service type (e.g., NodePort).

      By default, Ambassador Pro uses ports 8081 and 8082 for rate-limiting and filtering, respectively. If for whatever reason those assignments are problematic (perhaps you set service_port to one of those), you can set adjust these by setting environment variables:

      • GRPC_PORT: Which port to serve the RateLimitService on; 8081 by default.
      • APRO_AUTH_PORT: Which port to serve the filtering AuthService on; 8082 by default.

      If you have deployed Ambassador with AMBASSADOR_NAMESPACE, AMBASSADOR_SINGLE_NAMESPACE, or AMBASSADOR_ID set, you will also need to set them in the Pro container.

  2. Configure the JWT filter and JWT-authenticated httpbin test service:

    make apply-jwt
  3. Send a valid JWT to the jwt-httpbin URL:

    curl -i -k --header "Authorization: Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ." https://$AMBASSADOR_IP/jwt-httpbin/ip
  4. Send an invalid JWT, and get a 401:

    curl -i -k https://$AMBASSADOR_IP/jwt-httpbin/ip
    HTTP/1.1 401 Unauthorized
    content-length: 58
    content-type: text/plain
    date: Thu, 28 Feb 2019 01:07:10 GMT
    server: envoy
  5. Note that we've configured the jwt-httpbin URL to require JWTs, but the httpbin URL does not:

    curl -v -k https://$AMBASSADOR_IP/httpbin/ip
    "origin": ",,"

    This policy is set in the FilterPolicy object in jwt-filter.yaml.

  6. We're sending a short, unsigned JWT (hence the only validAlgorithms type is none).

    For real-world applications, you'll want to delete the validAlgorithms section and supply signed JWTs.


To quickly enable JWT validation for your application, get started with the Ambassador Edge Stack. For commericial or for unlimited use of this feature, contact sales to learn about Ambassador Edge Stack Enterprise today.