This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.12.2. Using JSON Web Token authentication with Service Mesh and OpenShift Serverless
You can enable JSON Web Token (JWT) authentication for Knative services by creating a policy in your serverless application namespace that only allows requests with valid JWTs.
Prerequisites
- Install OpenShift Serverless.
- Install Red Hat OpenShift Service Mesh.
- Configure Service Mesh with OpenShift Serverless, including enabling sidecar injection for your Knative services.
Adding sidecar injection to pods in system namespaces such as knative-serving
and knative-serving-ingress
is not supported.
Procedure
Copy the following
Policy
resource into a YAML file:重要The paths
/metrics
and/healthz
must be included inexcludedPaths
because they are accessed from system pods in theknative-serving
namespace.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the
Policy
resource YAML file:oc apply -f <filename>
$ oc apply -f <filename>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
If you try to use a
curl
request to get the Knative service URL, it is denied.curl http://hello-example-default.apps.mycluster.example.com/
$ curl http://hello-example-default.apps.mycluster.example.com/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Origin authentication failed.
Origin authentication failed.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the request with a valid JWT.
Get the valid JWT token by entering the following command:
TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/demo.jwt -s) && echo "$TOKEN" | cut -d '.' -f2 - | base64 --decode -
$ TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/demo.jwt -s) && echo "$TOKEN" | cut -d '.' -f2 - | base64 --decode -
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Access the service by using the valid token in the
curl
request header:curl http://hello-example-default.apps.mycluster.example.com/ -H "Authorization: Bearer $TOKEN"
$ curl http://hello-example-default.apps.mycluster.example.com/ -H "Authorization: Bearer $TOKEN"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The request is now allowed.
Example output
Hello OpenShift!
Hello OpenShift!
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.2.1. Additional resources 复制链接链接已复制到粘贴板!
- See Red Hat OpenShift Service Mesh architecture.
-
For more information about verifying Knative services and using
curl
requests, see Verifying your serverless application deployment.