Camel Spring Boot

OPA

Evaluate an Open Policy Agent (OPA) policy decision for each message and set the allow or deny verdict in headers.

What’s inside

Please refer to the above links for usage and configuration details.

Maven coordinates

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-opa-starter</artifactId>
</dependency>

Spring Boot Auto-Configuration

The starter supports 27 options, which are listed below.

Name Description Default Type

camel.component.opa.allow-key

Where to read the allow or deny verdict when the policy decision is a JSON object rather than a boolean: the name of a top-level key, or a dotted path such as result.allow for a verdict nested in the object. A decision that is a boolean is the verdict itself. Only a JSON boolean counts as a verdict: when the key is missing or holds another value, the message is denied (CamelOpaDecisionAllow=false) and a warning is logged once.

allow

String

camel.component.opa.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.opa.batch

Whether to evaluate the elements of a List body in one call: one input document per element, with the element as input.body and the same headers and properties for all. The verdicts are set in the CamelOpaBatchDecision header, a List of Boolean in the order of the body, and the details in CamelOpaBatchOutcomes; CamelOpaDecisionAllow is not set. An element whose evaluation failed is denied, unless failOpen is set and its decision point was unavailable. Uses the OPA batch API (/v1/batch/data), and one request per element when the server answers 404 to it. A body that is not a List fails the exchange. Only for rest mode: with evaluationMode=wasm the endpoint fails to start.

false

Boolean

camel.component.opa.bearer-token

The bearer token for an OPA server that has API authentication enabled. It is sent in the Authorization header, after Bearer, with each policy decision request and with the readiness check. Only used in rest mode, and not used when opaClient is set.

String

camel.component.opa.borrow-timeout

How long, in milliseconds, an evaluation in wasm mode waits for a free WebAssembly policy instance (see poolSize). When none is free in time, the evaluation fails with OpaPolicyEvaluationException, or the message proceeds when failOpen is set. The option is a long type.

30000

Long

camel.component.opa.configuration

The component configuration. The option is a org.apache.camel.component.opa.OpaConfiguration type.

OpaConfiguration

camel.component.opa.connection-timeout

How long, in milliseconds, to wait for the connection to the OPA server to be established, in rest mode. When it runs out, the evaluation fails with OpaPolicyEvaluationException, or the message proceeds when failOpen is set. Not used when opaClient is set. The option is a long type.

10000

Long

camel.component.opa.enabled

Whether to enable auto configuration of the opa component. This is enabled by default.

Boolean

camel.component.opa.entrypoint

The entrypoint of the WebAssembly module to evaluate in wasm mode, as named with opa build -e when the bundle was built, such as authz/orders/allow. Defaults to the policy path, which is the name opa build gives it.

String

camel.component.opa.evaluation-mode

How the policy is evaluated. rest sends each decision request to an OPA server over its REST Data API. wasm evaluates the policy compiled to WebAssembly (policyBundle) in-process, with no server: serverUrl, bearerToken, opaClient, connectionTimeout, requestTimeout, sslContextParameters and healthCheckBundles are not used, failOpen only applies to borrowTimeout, and batch is not supported (the endpoint fails to start).

rest

String

camel.component.opa.fail-open

Whether to let the message proceed when the policy decision point is unavailable: in rest mode the OPA server cannot be reached, connectionTimeout or requestTimeout runs out, or the server (or a gateway in front of it) answers 429, 502, 503 or 504; in wasm mode no policy instance is free within borrowTimeout. The message then proceeds with CamelOpaDecisionAllow=true and CamelOpaDecisionFailedOpen=true. It never applies when the decision point answered, nor to an input document that cannot be built: an undefined decision, a rejected request (400, or another 4xx such as for a wrong bearer token) and an error evaluating the policy (500) always fail the evaluation with OpaPolicyEvaluationException. Disabled by default, so an unavailable decision point fails the evaluation too. Do not enable this in production.

false

Boolean

camel.component.opa.health-check-bundles

Whether the readiness check of the OPA server also requires that OPA has activated its configured bundles: it probes /health?bundles=true instead of /health. It does not enable the health check, change the policy evaluation or ensure a particular policy revision. Not used in wasm mode or when opaClient is set.

false

Boolean

camel.component.opa.health-check-consumer-enabled

Used for enabling or disabling all consumer based health checks from this component

true

Boolean

camel.component.opa.health-check-producer-enabled

Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

Boolean

camel.component.opa.include-body

Whether to send the message body to OPA in input.body of the input document. A string, number, boolean, Map or List is sent as it is, any other body as its string form. A stream body is read for this, so enable stream caching to keep it readable for the rest of the route. In batch mode each element of the List body is always sent as input.body, whatever this option. Not used when inputExpression is set.

false

Boolean

camel.component.opa.include-headers

Comma-separated list of the message header names (case-insensitive) to send to OPA in input.headers of the input document. The default * sends every header except Authorization, Proxy-Authorization, Cookie and Set-Cookie, which carry a caller credential and are sent only when named in the list. The CamelOpa decision headers are never sent. A value that is not a string, number, boolean, Map or List is sent as its string form. Not used when inputExpression is set.

*

String

camel.component.opa.include-properties

Comma-separated list of the exchange property names (case-insensitive) to send to OPA in input.properties of the input document, or * for all custom exchange properties; the internal properties of Camel are never sent. Not set by default, so no properties are sent. Use it to give the policy the identity that an earlier authentication step stored as an exchange property, such as CamelKeycloakTokenSubject, rather than a header that the caller can set. Not used when inputExpression is set.

String

camel.component.opa.input-expression

An expression that builds the complete OPA input document, in place of the default one (headers, properties, body, exchangeId and routeId), so includeHeaders, includeProperties and includeBody are not used. The result must convert to a JSON object: a Map, a JSON object node or a POJO. Any other result (null, a scalar, an array or a stream) fails the evaluation with OpaPolicyEvaluationException, also when failOpen is set. In batch mode the expression is evaluated once per element, on a copy of the exchange with the element as the body. The option is a org.apache.camel.Expression type.

Expression

camel.component.opa.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.opa.opa-client

An OPAClient of the OPA Java SDK to send the policy decision requests with, in place of the client the endpoint creates. When set, serverUrl, bearerToken, connectionTimeout, requestTimeout and sslContextParameters are not used, and no readiness check is registered. When a single OPAClient is in the registry, it is used automatically. Not used in wasm mode. The option is a com.styra.opa.OPAClient type.

OPAClient

camel.component.opa.policy-bundle

The policy compiled to WebAssembly, for wasm mode: the location of the bundle.tar.gz that opa build -t wasm produces, or of a bare .wasm module, with a file:, classpath: (the default when there is no prefix), http: or https: prefix. Required when evaluationMode=wasm. A bundle also carries its data.json, which the policy reads as data; a bare module has no data.

String

camel.component.opa.policy-reload-interval

How often, in milliseconds, to read the policyBundle again in wasm mode, to pick up a changed policy or data. When the content changed, the new policy is loaded and replaces the active one; when it fails to load, the active policy stays. 0 disables the reload. The option is a long type.

0

Long

camel.component.opa.pool-size

How many WebAssembly policy instances to pool in wasm mode. An instance is not thread-safe, so each evaluation borrows one: this limits how many messages are evaluated at the same time. Must be at least 1.

8

Integer

camel.component.opa.request-timeout

How long, in milliseconds, to wait for the complete response of the OPA server to a decision request, in rest mode. When it runs out, the evaluation fails with OpaPolicyEvaluationException, or the message proceeds when failOpen is set. Not used when opaClient is set. The option is a long type.

30000

Long

camel.component.opa.server-url

The base URL of the OPA server, without the /v1/data suffix. Each policy decision is requested with a POST to this URL followed by /v1/data/ and the policy path, and the readiness check probes /health on it. Only used in rest mode, and not used when opaClient is set.

http://localhost:8181

String

camel.component.opa.ssl-context-parameters

TLS configuration for the HTTPS connection to the OPA server in rest mode, for example to trust a server certificate from a private CA, or to present a client certificate to a server that requires mutual TLS. Also used by the readiness check. When not set, the global SSL context parameters are used if useGlobalSslContextParameters is enabled, otherwise the JVM default. Not used when opaClient is set. The option is a org.apache.camel.support.jsse.SSLContextParameters type.

SSLContextParameters

camel.component.opa.use-global-ssl-context-parameters

Whether to use the global SSL context parameters of the CamelContext for the connection to the OPA server, for an endpoint that has no sslContextParameters. Only used in rest mode.

false

Boolean