Enabling requests to Knative services when additional authorization policies are enabled

Knative Serving system pods, such as the activator and autoscaler components, require access to your deployed Knative services. If you have configured additional security features, such as Istio’s authorization policy, you must enable access to your Knative service for these system pods.

Before you begin

You must meet the following prerequisites to use Istio AuthorizationPolicy:

Enabling Istio AuthorizationPolicy

For example, the following authorization policy denies all requests to workloads in namespace serving-tests.

  1. $ cat <<EOF | kubectl apply -f -
  2. apiVersion: security.istio.io/v1beta1
  3. kind: AuthorizationPolicy
  4. metadata:
  5. name: deny-all
  6. namespace: serving-tests
  7. spec:
  8. {}
  9. EOF

In addition to allowing your application path, you’ll need to configure Istio AuthorizationPolicy to allow health checking and metrics collection to your applications from system pods. You can allow access from system pods by paths.

Allowing access from system pods by paths

Knative system pods access your application using the following paths:

  • /metrics
  • /healthz

The /metrics path allows the autoscaler pod to collect metrics. The /healthz path allows system pods to probe the service.

You can add the /metrics and /healthz paths to the AuthorizationPolicy as shown in the example:

  1. $ cat <<EOF | kubectl apply -f -
  2. apiVersion: security.istio.io/v1beta1
  3. kind: AuthorizationPolicy
  4. metadata:
  5. name: allowlist-by-paths
  6. namespace: serving-tests
  7. spec:
  8. action: ALLOW
  9. rules:
  10. - to:
  11. - operation:
  12. paths:
  13. - /metrics # The path to collect metrics by system pod.
  14. - /healthz # The path to probe by system pod.
  15. EOF