Administrator configuration options

If you have cluster administrator permissions for your Knative installation, you can modify ConfigMaps to change the global default configuration options for Brokers on the cluster.

Knative Eventing provides a config-br-defaults ConfigMap that contains the configuration settings that govern default Broker creation.

The default config-br-defaults ConfigMap is as follows:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-br-defaults
  5. namespace: knative-eventing
  6. labels:
  7. eventing.knative.dev/release: devel
  8. data:
  9. # Configures the default for any Broker that does not specify a spec.config or Broker class.
  10. default-br-config: |
  11. clusterDefault:
  12. brokerClass: MTChannelBasedBroker
  13. apiVersion: v1
  14. kind: ConfigMap
  15. name: config-br-default-channel
  16. namespace: knative-eventing

Channel implementation options

The following example shows a Broker object where the spec.config configuration is specified in a config-br-default-channel ConfigMap:

  1. apiVersion: eventing.knative.dev/v1
  2. kind: Broker
  3. metadata:
  4. annotations:
  5. eventing.knative.dev/broker.class: MTChannelBasedBroker
  6. name: default
  7. spec:
  8. # Configuration specific to this broker.
  9. config:
  10. apiVersion: v1
  11. kind: ConfigMap
  12. name: config-br-default-channel
  13. namespace: knative-eventing

A Broker object that does not have a spec.config specified uses the config-br-default-channel ConfigMap dy default because this is specified in the config-br-defaults ConfigMap.

However, if you have installed a different Channel implementation, for example, Kafka, and would like this to be used as the default Channel implementation for any Broker that is created, you can change the config-br-defaults ConfigMap to look as follows:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-br-defaults
  5. namespace: knative-eventing
  6. labels:
  7. eventing.knative.dev/release: devel
  8. data:
  9. # Configures the default for any Broker that does not specify a spec.config or Broker class.
  10. default-br-config: |
  11. clusterDefault:
  12. brokerClass: MTChannelBasedBroker
  13. apiVersion: v1
  14. kind: ConfigMap
  15. name: kafka-channel
  16. namespace: knative-eventing

Now every Broker created in the cluster that does not have a spec.config will be configured to use the kafka-channel ConfigMap.

For more information about creating a kafka-channel ConfigMap to use with your Broker, see the Kafka Channel ConfigMap documentation.

Changing the default Channel implementation for a namespace

You can modify the default Broker creation behavior for one or more namespaces.

For example, if you wanted to use the kafka-channel ConfigMap for all other Brokers created, but wanted to use config-br-default-channel ConfigMap for namespace-1 and namespace-2, you would use the following ConfigMap settings:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-br-defaults
  5. namespace: knative-eventing
  6. labels:
  7. eventing.knative.dev/release: devel
  8. data:
  9. # Configures the default for any Broker that does not specify a spec.config or Broker class.
  10. default-br-config: |
  11. clusterDefault:
  12. brokerClass: MTChannelBasedBroker
  13. apiVersion: v1
  14. kind: ConfigMap
  15. name: config-kafka-channel
  16. namespace: knative-eventing
  17. namespaceDefaults:
  18. namespace-1:
  19. apiVersion: v1
  20. kind: ConfigMap
  21. name: config-br-default-channel
  22. namespace: knative-eventing
  23. namespace-2:
  24. apiVersion: v1
  25. kind: ConfigMap
  26. name: config-br-default-channel
  27. namespace: knative-eventing

Configuring delivery spec defaults

You can configure default event delivery parameters for Brokers that are applied in cases where an event fails to be delivered:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-br-defaults
  5. namespace: knative-eventing
  6. labels:
  7. eventing.knative.dev/release: devel
  8. data:
  9. # Configures the default for any Broker that does not specify a spec.config or Broker class.
  10. default-br-config: |
  11. clusterDefault:
  12. brokerClass: MTChannelBasedBroker
  13. apiVersion: v1
  14. kind: ConfigMap
  15. name: config-kafka-channel
  16. namespace: knative-eventing
  17. delivery:
  18. retry: 10
  19. backoffDelay: PT0.2S
  20. backoffPolicy: exponential
  21. namespaceDefaults:
  22. namespace-1:
  23. apiVersion: v1
  24. kind: ConfigMap
  25. name: config-br-default-channel
  26. namespace: knative-eventing
  27. delivery:
  28. deadLetterSink:
  29. ref:
  30. kind: Service
  31. namespace: example-namespace
  32. name: example-service
  33. apiVersion: v1
  34. uri: example-uri
  35. retry: 10
  36. backoffPolicy: exponential
  37. backoffDelay: "PT0.2S"

Dead letter sink

You can configure the deadLetterSink delivery parameter so that if an event fails to be delivered it is sent to the specified event sink.

Retries

You can set a minimum number of times that the delivery must be retried before the event is sent to the dead letter sink, by configuring the retry delivery parameter with an integer value.

Back off delay

You can set the backoffDelay delivery parameter to specify the time delay before an event delivery retry is attempted after a failure. The duration of the backoffDelay parameter is specified using the ISO 8601 format.

Back off policy

The backoffPolicy delivery parameter can be used to specify the retry back off policy. The policy can be specified as either linear or exponential. When using the linear back off policy, the back off delay is the time interval specified between retries. When using the exponential backoff policy, the back off delay is equal to backoffDelay*2^<numberOfRetries>.

Broker class options

When a Broker is created without a specified BrokerClass annotation, the default MTChannelBasedBroker Broker class is used, as specified in the config-br-defaults ConfigMap.

The following example creates a Broker called default in the default namespace, and uses MTChannelBasedBroker as the implementation:

  1. Create a YAML file for your Broker using the following example:

    1. apiVersion: eventing.knative.dev/v1
    2. kind: Broker
    3. metadata:
    4. name: default
    5. namespace: default
  2. Apply the YAML file by running the command:

    1. kubectl apply -f <filename>.yaml

    Where <filename> is the name of the file you created in the previous step.

Configuring the Broker class

To configure a Broker class, you can modify the eventing.knative.dev/broker.class annotation and spec.config for the Broker object. MTChannelBasedBroker is the Broker class default.

  1. Modify the eventing.knative.dev/broker.class annotation. Replace MTChannelBasedBroker with the class type you want to use:

    1. apiVersion: eventing.knative.dev/v1
    2. kind: Broker
    3. metadata:
    4. annotations:
    5. eventing.knative.dev/broker.class: MTChannelBasedBroker
    6. name: default
    7. namespace: default
  2. Configure the spec.config with the details of the ConfigMap that defines the backing Channel for the Broker class:

    1. apiVersion: eventing.knative.dev/v1
    2. kind: Broker
    3. metadata:
    4. annotations:
    5. eventing.knative.dev/broker.class: MTChannelBasedBroker
    6. name: default
    7. namespace: default
    8. spec:
    9. config:
    10. apiVersion: v1
    11. kind: ConfigMap
    12. name: config-br-default-channel
    13. namespace: knative-eventing

Configuring the default BrokerClass for the cluster

You can configure the clusterDefault Broker class so that any Broker created in the cluster that does not have a BrokerClass annotation uses this default class.

Example

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-br-defaults
  5. namespace: knative-eventing
  6. labels:
  7. eventing.knative.dev/release: devel
  8. data:
  9. # Configures the default for any Broker that does not specify a spec.config or Broker class.
  10. default-br-config: |
  11. clusterDefault:
  12. brokerClass: MTChannelBasedBroker

Configuring the default BrokerClass for namespaces

You can modify the default Broker class for one or more namespaces.

For example, if you want to use a KafkaBroker class for all other Brokers created on the cluster, but you want to use the MTChannelBasedBroker class for Brokers created in namespace-1 and namespace-2, you would use the following ConfigMap settings:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-br-defaults
  5. namespace: knative-eventing
  6. labels:
  7. eventing.knative.dev/release: devel
  8. data:
  9. # Configures the default for any Broker that does not specify a spec.config or Broker class.
  10. default-br-config: |
  11. clusterDefault:
  12. brokerClass: KafkaBroker
  13. namespaceDefaults:
  14. namespace1:
  15. brokerClass: MTChannelBasedBroker
  16. namespace2:
  17. brokerClass: MTChannelBasedBroker

Integrating Istio with Knative Brokers

Protect a Knative Broker by using JSON Web Token (JWT) and Istio

Prerequisites

  • You have installed Knative Eventing.
  • You have installed Istio.

Procedure

  1. Label the knative-eventing namespace, so that Istio can handle JWT-based user authentication, by running the command:

    1. kubectl label namespace knative-eventing istio-injection=enabled
  2. Restart the broker ingress pod, so that the istio-proxy container can be injected as a sidecar, by running the command:

    1. kubectl delete pod <broker-ingress-pod-name> -n knative-eventing

    Where <broker-ingress-pod-name> is the name of your broker ingress pod.

    The pod now has two containers:

    1. knative-eventing <broker-ingress-pod-name> 2/2 Running 1 175m
  3. Create a broker, then use get the URL of your broker by running the command:

    1. kubectl get broker <broker-name>

    Example output:

    1. NAMESPACE NAME URL AGE READY REASON
    2. default my-broker http://broker-ingress.knative-eventing.svc.cluster.local/default/my-broker 6s True
  4. Start a curl pod:

    1. kubectl -n default run curl --image=radial/busyboxplus:curl -i --tty
  5. Send a CloudEvent with an HTTP POST against the broker URL:

    1. curl -X POST -v \
    2. -H "content-type: application/json" \
    3. -H "ce-specversion: 1.0" \
    4. -H "ce-source: my/curl/command" \
    5. -H "ce-type: my.demo.event" \
    6. -H "ce-id: 0815" \
    7. -d '{"value":"Hello Knative"}' \
    8. <broker-URL>

    Where <broker-URL> is the URL of your broker. For example:

    1. curl -X POST -v \
    2. -H "content-type: application/json" \
    3. -H "ce-specversion: 1.0" \
    4. -H "ce-source: my/curl/command" \
    5. -H "ce-type: my.demo.event" \
    6. -H "ce-id: 0815" \
    7. -d '{"value":"Hello Knative"}' \
    8. http://broker-ingress.knative-eventing.svc.cluster.local/default/my-broker
  6. You will receive a 202 HTTP response code, that the broker did accept the request:

    1. ...
    2. * Mark bundle as not supporting multiuse
    3. < HTTP/1.1 202 Accepted
    4. < allow: POST, OPTIONS
    5. < date: Tue, 15 Mar 2022 13:37:57 GMT
    6. < content-length: 0
    7. < x-envoy-upstream-service-time: 79
    8. < server: istio-envoy
    9. < x-envoy-decorator-operation: broker-ingress.knative-eventing.svc.cluster.local:80/*
  7. Apply a AuthorizationPolicy object in the knative-eventing namespace to describe that the path to the Broker is restricted to a given user:

    1. apiVersion: security.istio.io/v1beta1
    2. kind: AuthorizationPolicy
    3. metadata:
    4. name: require-jwt
    5. namespace: knative-eventing
    6. spec:
    7. action: ALLOW
    8. rules:
    9. - from:
    10. - source:
    11. requestPrincipals: ["testing@secure.istio.io/testing@secure.istio.io"]
    12. to:
    13. - operation:
    14. methods: ["POST"]
    15. paths: ["/default/my-broker"]
  8. Create a RequestAuthentication object for the user requestPrincipal in the istio-system namespace:

    1. apiVersion: security.istio.io/v1beta1
    2. kind: RequestAuthentication
    3. metadata:
    4. name: "jwt-example"
    5. namespace: istio-system
    6. spec:
    7. jwtRules:
    8. - issuer: "testing@secure.istio.io"
    9. jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.13/security/tools/jwt/samples/jwks.json"
  9. Now retrying the curl command results in a 403 - Forbidden response code from the server:

    1. ...
    2. * Mark bundle as not supporting multiuse
    3. < HTTP/1.1 403 Forbidden
    4. < content-length: 19
    5. < content-type: text/plain
    6. < date: Tue, 15 Mar 2022 13:47:53 GMT
    7. < server: istio-envoy
    8. < connection: close
    9. < x-envoy-decorator-operation: broker-ingress.knative-eventing.svc.cluster.local:80/*
  10. To access the Broker, add the Bearer JSON Web Token as part of the request:

    1. TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.13/security/tools/jwt/samples/demo.jwt -s)
    2. curl -X POST -v \
    3. -H "content-type: application/json" \
    4. -H "Authorization: Bearer ${TOKEN}" \
    5. -H "ce-specversion: 1.0" \
    6. -H "ce-source: my/curl/command" \
    7. -H "ce-type: my.demo.event" \
    8. -H "ce-id: 0815" \
    9. -d '{"value":"Hello Knative"}' \
    10. <broker-URL>

    The server now responds with a 202 response code, indicating that it has accepted the HTTP request:

    1. * Mark bundle as not supporting multiuse
    2. < HTTP/1.1 202 Accepted
    3. < allow: POST, OPTIONS
    4. < date: Tue, 15 Mar 2022 14:05:09 GMT
    5. < content-length: 0
    6. < x-envoy-upstream-service-time: 40
    7. < server: istio-envoy
    8. < x-envoy-decorator-operation: broker-ingress.knative-eventing.svc.cluster.local:80/*