This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 24917d5cff16 CAMEL-26833: Add SPIFFE identity readiness checks (#29821)
24917d5cff16 is described below
commit 24917d5cff166c89f4166741cf7b94c51043da5b
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Nov 17 14:09:08 2026 +0100
CAMEL-26833: Add SPIFFE identity readiness checks (#29821)
- CAMEL-26833: Expose SPIFFE identity readiness and expiry
- CAMEL-26833: The readiness check reports the state of the watch, not a
connection it cannot see, and names its check after the endpoint
- CAMEL-26833: The health-check cleanup runs inside the stop's try, and two
doc sentences read better
- CAMEL-26833: The readiness check watches the identity the producer
serves, and the stop closes the observer client whatever the repository does
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-authored-by: Codex <[email protected]>
---
.../apache/camel/catalog/components/spiffe.json | 20 +-
.../camel/catalog/docs/spiffe-component.adoc | 38 ++++
components/camel-spiffe/pom.xml | 5 +
.../spiffe/SpiffeComponentConfigurer.java | 18 ++
.../component/spiffe/SpiffeEndpointConfigurer.java | 6 +
.../component/spiffe/SpiffeEndpointUriFactory.java | 3 +-
.../org/apache/camel/component/spiffe/spiffe.json | 20 +-
.../src/main/docs/spiffe-component.adoc | 38 ++++
.../camel/component/spiffe/SpiffeComponent.java | 4 +-
.../component/spiffe/SpiffeConfiguration.java | 16 ++
.../camel/component/spiffe/SpiffeEndpoint.java | 22 +-
.../camel/component/spiffe/SpiffeProducer.java | 64 ++++++
.../spiffe/SpiffeProducerHealthCheck.java | 185 ++++++++++++++++
.../spiffe/SpiffeHealthCheckRegistrationTest.java | 192 +++++++++++++++++
.../spiffe/SpiffeProducerHealthCheckTest.java | 240 +++++++++++++++++++++
.../dsl/SpiffeComponentBuilderFactory.java | 62 ++++++
.../endpoint/dsl/SpiffeEndpointBuilderFactory.java | 38 ++++
17 files changed, 944 insertions(+), 27 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spiffe.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spiffe.json
index b2dd3b8004a6..830c1e9c20de 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spiffe.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/spiffe.json
@@ -31,10 +31,13 @@
"preserveBody": { "index": 4, "kind": "property", "displayName": "Preserve
Body", "group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether validateJwtSvid leaves the application
body untouched and publishes the verified identit [...]
"autowiredEnabled": { "index": 5, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"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 t [...]
"workloadApiClient": { "index": 6, "kind": "property", "displayName":
"Workload Api Client", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType": "io.spiffe.workloadapi.WorkloadApiClient",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "An existing WorkloadApiClient to use. When
set, the component does not [...]
- "allowOperationHeader": { "index": 7, "kind": "property", "displayName":
"Allow Operation Header", "group": "security", "label": "security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "security": "insecure:dev",
"defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether the CamelSpiffeOperation header may
[...]
- "localSpiffeId": { "index": 8, "kind": "property", "displayName": "Local
Spiffe Id", "group": "security", "label": "producer,security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The exact local SPIFFE ID to use when the
Workload API supplies several identities: fetchX5 [...]
- "spiffeSocketPath": { "index": 9, "kind": "property", "displayName":
"Spiffe Socket Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The address of the SPIFFE Workload API
endpoint (for example unix:\/\/\/tmp\/agent.sock or tcp [...]
- "x509Response": { "index": 10, "kind": "property", "displayName": "X509
Response", "group": "security", "label": "producer,security", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.spiffe.SpiffeX509Response", "enum": [ "svid",
"chain", "id" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "chain", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": [...]
+ "healthCheckConsumerEnabled": { "index": 7, "kind": "property",
"displayName": "Health Check Consumer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all consumer based health checks
from this component" },
+ "healthCheckExpiryThreshold": { "index": 8, "kind": "property",
"displayName": "Health Check Expiry Threshold", "group": "health", "label":
"health", "required": false, "type": "duration", "javaType": "long",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
"60000", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Minimum remaining X.509-SVID validity, in
milliseconds, for th [...]
+ "healthCheckProducerEnabled": { "index": 9, "kind": "property",
"displayName": "Health Check Producer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "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 [...]
+ "allowOperationHeader": { "index": 10, "kind": "property", "displayName":
"Allow Operation Header", "group": "security", "label": "security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "security": "insecure:dev",
"defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether the CamelSpiffeOperation header ma
[...]
+ "localSpiffeId": { "index": 11, "kind": "property", "displayName": "Local
Spiffe Id", "group": "security", "label": "producer,security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The exact local SPIFFE ID to use when the
Workload API supplies several identities: fetchX [...]
+ "spiffeSocketPath": { "index": 12, "kind": "property", "displayName":
"Spiffe Socket Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The address of the SPIFFE Workload API
endpoint (for example unix:\/\/\/tmp\/agent.sock or tc [...]
+ "x509Response": { "index": 13, "kind": "property", "displayName": "X509
Response", "group": "security", "label": "producer,security", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.spiffe.SpiffeX509Response", "enum": [ "svid",
"chain", "id" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "chain", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": [...]
},
"headers": {
"CamelSpiffeOperation": { "index": 0, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"org.apache.camel.component.spiffe.SpiffeOperation or String", "deprecated":
false, "autowired": false, "secret": false, "description": "Overrides the
operation to be used by the producer. Ignored unless the endpoint sets
allowOperationHeader=true, because the operation decides whether the endpoint
validates a token or mints one.", "const [...]
@@ -54,9 +57,10 @@
"preserveBody": { "index": 3, "kind": "parameter", "displayName":
"Preserve Body", "group": "producer", "label": "", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether validateJwtSvid leaves the application
body untouched and publishes the verified identi [...]
"lazyStartProducer": { "index": 4, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "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 produc [...]
"workloadApiClient": { "index": 5, "kind": "parameter", "displayName":
"Workload Api Client", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType": "io.spiffe.workloadapi.WorkloadApiClient",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "An existing WorkloadApiClient to use. When
set, the component does no [...]
- "allowOperationHeader": { "index": 6, "kind": "parameter", "displayName":
"Allow Operation Header", "group": "security", "label": "security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "security": "insecure:dev",
"defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether the CamelSpiffeOperation header ma
[...]
- "localSpiffeId": { "index": 7, "kind": "parameter", "displayName": "Local
Spiffe Id", "group": "security", "label": "producer,security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The exact local SPIFFE ID to use when the
Workload API supplies several identities: fetchX [...]
- "spiffeSocketPath": { "index": 8, "kind": "parameter", "displayName":
"Spiffe Socket Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The address of the SPIFFE Workload API
endpoint (for example unix:\/\/\/tmp\/agent.sock or tc [...]
- "x509Response": { "index": 9, "kind": "parameter", "displayName": "X509
Response", "group": "security", "label": "producer,security", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.spiffe.SpiffeX509Response", "enum": [ "svid",
"chain", "id" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "chain", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": [...]
+ "healthCheckExpiryThreshold": { "index": 6, "kind": "parameter",
"displayName": "Health Check Expiry Threshold", "group": "health", "label":
"health", "required": false, "type": "duration", "javaType": "long",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
"60000", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Minimum remaining X.509-SVID validity, in
milliseconds, for t [...]
+ "allowOperationHeader": { "index": 7, "kind": "parameter", "displayName":
"Allow Operation Header", "group": "security", "label": "security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "security": "insecure:dev",
"defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether the CamelSpiffeOperation header ma
[...]
+ "localSpiffeId": { "index": 8, "kind": "parameter", "displayName": "Local
Spiffe Id", "group": "security", "label": "producer,security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The exact local SPIFFE ID to use when the
Workload API supplies several identities: fetchX [...]
+ "spiffeSocketPath": { "index": 9, "kind": "parameter", "displayName":
"Spiffe Socket Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The address of the SPIFFE Workload API
endpoint (for example unix:\/\/\/tmp\/agent.sock or tc [...]
+ "x509Response": { "index": 10, "kind": "parameter", "displayName": "X509
Response", "group": "security", "label": "producer,security", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.spiffe.SpiffeX509Response", "enum": [ "svid",
"chain", "id" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "chain", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spiffe-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spiffe-component.adoc
index 40df966c744c..e15b62e8b0b6 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spiffe-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spiffe-component.adoc
@@ -630,3 +630,41 @@ include::spring-boot:partial$starter.adoc[]
cannot assert an identity by setting a header - and it requires mutual TLS,
failing closed when the peer presented
no verified certificate. The verified id it publishes is the
`CamelSpiffePeerId` exchange *property*, never a header,
so it likewise cannot be injected by an inbound message.
+
+== Producer readiness and identity observations
+
+Enable producer health checks with `camel.health.producersEnabled=true` before
starting the route. The component
+also supports `healthCheckProducerEnabled` to disable its checks. The producer
registers a check on start and removes
+it on stop. For each enabled check, a dedicated SDK-managed Workload API
client maintains one streaming observer;
+stopping the producer closes that client and cancels its observer, even when
the endpoint remains cached. Health
+calls read an immutable metadata snapshot and never fetch credentials, contact
the API, or start another observer.
+Producer checks remain disabled globally by default, and no observer client is
opened while they are disabled.
+If producer checks are enabled dynamically after route startup, restart the
route to start its observer.
+
+The observation depends on the endpoint's configured operation:
+
+* `fetchX509Svid` observes the X.509 identity the producer serves: the one
named by `localSpiffeId` when that option is
+ set, otherwise the default SVID. Readiness requires an available, unexpired
SVID outside
+ `healthCheckExpiryThreshold` (default 60000 milliseconds, a duration such as
`5m` is accepted). Set the threshold to
+ zero to require only that it has not expired. Health details include the
observed expiry, remaining validity, and whether the identity is approaching
expiry.
+* `fetchJwtSvid` and `validateJwtSvid` observe JWT trust bundles. Readiness
requires a non-empty bundle update. Bundles
+ have no expiry timestamp, so the check makes no expiry claim and does not
mint or validate a token. In particular,
+ it does not prove that a particular audience can be issued or that an
incoming token will validate.
+
+Both report the most recent update timestamp and the state of the watch
(`not-started`, `starting`, `watching`, `failed`
+or `stopped`). These are SDK callback observations, not an independently
measured connection heartbeat; `lastUpdate` is
+the local observation time, not the SPIRE credential's issuance time. The
check measures whether the identity the
+Workload API last delivered is valid and not about to expire, not whether the
agent is reachable right now. The SDK
+reconnects to an unreachable agent on its own, with unlimited retries and
without telling the watch, so an agent outage
+shows up only as an SVID that is no longer refreshed and comes within
`healthCheckExpiryThreshold` of its expiry.
+`watch=failed` appears only after an error the SDK does not retry; the SDK
then delivers no more updates, readiness
+stays DOWN with the last observation's validity details (`materialValid` keeps
saying whether that material is still
+valid), and the route has to be restarted to watch again. Producer operations
still contact the Workload API; the watch
+is not a credential cache for those operations. The rotating SSL context has
its own source lifecycle and is not measured
+by these producer checks.
+
+No token, private key, certificate contents or exception text is retained or
published by the check. A configured
+`workloadApiClient` is not actively probed: it can address a different API
from `spiffeSocketPath`, and the SDK offers
+no independent unsubscribe handle for a borrowed client. Supply your own
health check for that injected client. If
+`allowOperationHeader=true` is explicitly enabled, changing an individual
message's operation does not retarget the
+readiness observer, which always reflects the endpoint's configured operation.
diff --git a/components/camel-spiffe/pom.xml b/components/camel-spiffe/pom.xml
index 2d204d4d7d2f..e3625314bae7 100644
--- a/components/camel-spiffe/pom.xml
+++ b/components/camel-spiffe/pom.xml
@@ -45,6 +45,11 @@
<artifactId>camel-support</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-health</artifactId>
+ </dependency>
+
<dependency>
<groupId>io.spiffe</groupId>
<artifactId>java-spiffe-core</artifactId>
diff --git
a/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeComponentConfigurer.java
b/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeComponentConfigurer.java
index 8b3d79f36ab1..8920502f6563 100644
---
a/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeComponentConfigurer.java
+++
b/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeComponentConfigurer.java
@@ -37,6 +37,12 @@ public class SpiffeComponentConfigurer extends
PropertyConfigurerSupport impleme
case "autowiredenabled":
case "autowiredEnabled":
target.setAutowiredEnabled(property(camelContext, boolean.class, value));
return true;
case "configuration": target.setConfiguration(property(camelContext,
org.apache.camel.component.spiffe.SpiffeConfiguration.class, value)); return
true;
+ case "healthcheckconsumerenabled":
+ case "healthCheckConsumerEnabled":
target.setHealthCheckConsumerEnabled(property(camelContext, boolean.class,
value)); return true;
+ case "healthcheckexpirythreshold":
+ case "healthCheckExpiryThreshold":
getOrCreateConfiguration(target).setHealthCheckExpiryThreshold(property(camelContext,
java.time.Duration.class, value).toMillis()); return true;
+ case "healthcheckproducerenabled":
+ case "healthCheckProducerEnabled":
target.setHealthCheckProducerEnabled(property(camelContext, boolean.class,
value)); return true;
case "lazystartproducer":
case "lazyStartProducer":
target.setLazyStartProducer(property(camelContext, boolean.class, value));
return true;
case "localspiffeid":
@@ -68,6 +74,12 @@ public class SpiffeComponentConfigurer extends
PropertyConfigurerSupport impleme
case "autowiredenabled":
case "autowiredEnabled": return boolean.class;
case "configuration": return
org.apache.camel.component.spiffe.SpiffeConfiguration.class;
+ case "healthcheckconsumerenabled":
+ case "healthCheckConsumerEnabled": return boolean.class;
+ case "healthcheckexpirythreshold":
+ case "healthCheckExpiryThreshold": return long.class;
+ case "healthcheckproducerenabled":
+ case "healthCheckProducerEnabled": return boolean.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
case "localspiffeid":
@@ -95,6 +107,12 @@ public class SpiffeComponentConfigurer extends
PropertyConfigurerSupport impleme
case "autowiredenabled":
case "autowiredEnabled": return target.isAutowiredEnabled();
case "configuration": return target.getConfiguration();
+ case "healthcheckconsumerenabled":
+ case "healthCheckConsumerEnabled": return
target.isHealthCheckConsumerEnabled();
+ case "healthcheckexpirythreshold":
+ case "healthCheckExpiryThreshold": return
getOrCreateConfiguration(target).getHealthCheckExpiryThreshold();
+ case "healthcheckproducerenabled":
+ case "healthCheckProducerEnabled": return
target.isHealthCheckProducerEnabled();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "localspiffeid":
diff --git
a/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeEndpointConfigurer.java
b/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeEndpointConfigurer.java
index 10c9d653393d..c9c8f5d720a6 100644
---
a/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeEndpointConfigurer.java
+++
b/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeEndpointConfigurer.java
@@ -27,6 +27,8 @@ public class SpiffeEndpointConfigurer extends
PropertyConfigurerSupport implemen
case "allowoperationheader":
case "allowOperationHeader":
target.getConfiguration().setAllowOperationHeader(property(camelContext,
boolean.class, value)); return true;
case "audience":
target.getConfiguration().setAudience(property(camelContext,
java.lang.String.class, value)); return true;
+ case "healthcheckexpirythreshold":
+ case "healthCheckExpiryThreshold":
target.getConfiguration().setHealthCheckExpiryThreshold(property(camelContext,
java.time.Duration.class, value).toMillis()); return true;
case "lazystartproducer":
case "lazyStartProducer":
target.setLazyStartProducer(property(camelContext, boolean.class, value));
return true;
case "localspiffeid":
@@ -55,6 +57,8 @@ public class SpiffeEndpointConfigurer extends
PropertyConfigurerSupport implemen
case "allowoperationheader":
case "allowOperationHeader": return boolean.class;
case "audience": return java.lang.String.class;
+ case "healthcheckexpirythreshold":
+ case "healthCheckExpiryThreshold": return long.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
case "localspiffeid":
@@ -79,6 +83,8 @@ public class SpiffeEndpointConfigurer extends
PropertyConfigurerSupport implemen
case "allowoperationheader":
case "allowOperationHeader": return
target.getConfiguration().isAllowOperationHeader();
case "audience": return target.getConfiguration().getAudience();
+ case "healthcheckexpirythreshold":
+ case "healthCheckExpiryThreshold": return
target.getConfiguration().getHealthCheckExpiryThreshold();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "localspiffeid":
diff --git
a/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeEndpointUriFactory.java
b/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeEndpointUriFactory.java
index 48689c10e14c..f7f3e7c0b2bb 100644
---
a/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeEndpointUriFactory.java
+++
b/components/camel-spiffe/src/generated/java/org/apache/camel/component/spiffe/SpiffeEndpointUriFactory.java
@@ -24,9 +24,10 @@ public class SpiffeEndpointUriFactory extends
org.apache.camel.support.component
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(10);
+ Set<String> props = new HashSet<>(11);
props.add("allowOperationHeader");
props.add("audience");
+ props.add("healthCheckExpiryThreshold");
props.add("label");
props.add("lazyStartProducer");
props.add("localSpiffeId");
diff --git
a/components/camel-spiffe/src/generated/resources/META-INF/org/apache/camel/component/spiffe/spiffe.json
b/components/camel-spiffe/src/generated/resources/META-INF/org/apache/camel/component/spiffe/spiffe.json
index b2dd3b8004a6..830c1e9c20de 100644
---
a/components/camel-spiffe/src/generated/resources/META-INF/org/apache/camel/component/spiffe/spiffe.json
+++
b/components/camel-spiffe/src/generated/resources/META-INF/org/apache/camel/component/spiffe/spiffe.json
@@ -31,10 +31,13 @@
"preserveBody": { "index": 4, "kind": "property", "displayName": "Preserve
Body", "group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether validateJwtSvid leaves the application
body untouched and publishes the verified identit [...]
"autowiredEnabled": { "index": 5, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"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 t [...]
"workloadApiClient": { "index": 6, "kind": "property", "displayName":
"Workload Api Client", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType": "io.spiffe.workloadapi.WorkloadApiClient",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "An existing WorkloadApiClient to use. When
set, the component does not [...]
- "allowOperationHeader": { "index": 7, "kind": "property", "displayName":
"Allow Operation Header", "group": "security", "label": "security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "security": "insecure:dev",
"defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether the CamelSpiffeOperation header may
[...]
- "localSpiffeId": { "index": 8, "kind": "property", "displayName": "Local
Spiffe Id", "group": "security", "label": "producer,security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The exact local SPIFFE ID to use when the
Workload API supplies several identities: fetchX5 [...]
- "spiffeSocketPath": { "index": 9, "kind": "property", "displayName":
"Spiffe Socket Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The address of the SPIFFE Workload API
endpoint (for example unix:\/\/\/tmp\/agent.sock or tcp [...]
- "x509Response": { "index": 10, "kind": "property", "displayName": "X509
Response", "group": "security", "label": "producer,security", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.spiffe.SpiffeX509Response", "enum": [ "svid",
"chain", "id" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "chain", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": [...]
+ "healthCheckConsumerEnabled": { "index": 7, "kind": "property",
"displayName": "Health Check Consumer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all consumer based health checks
from this component" },
+ "healthCheckExpiryThreshold": { "index": 8, "kind": "property",
"displayName": "Health Check Expiry Threshold", "group": "health", "label":
"health", "required": false, "type": "duration", "javaType": "long",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
"60000", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Minimum remaining X.509-SVID validity, in
milliseconds, for th [...]
+ "healthCheckProducerEnabled": { "index": 9, "kind": "property",
"displayName": "Health Check Producer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "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 [...]
+ "allowOperationHeader": { "index": 10, "kind": "property", "displayName":
"Allow Operation Header", "group": "security", "label": "security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "security": "insecure:dev",
"defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether the CamelSpiffeOperation header ma
[...]
+ "localSpiffeId": { "index": 11, "kind": "property", "displayName": "Local
Spiffe Id", "group": "security", "label": "producer,security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The exact local SPIFFE ID to use when the
Workload API supplies several identities: fetchX [...]
+ "spiffeSocketPath": { "index": 12, "kind": "property", "displayName":
"Spiffe Socket Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The address of the SPIFFE Workload API
endpoint (for example unix:\/\/\/tmp\/agent.sock or tc [...]
+ "x509Response": { "index": 13, "kind": "property", "displayName": "X509
Response", "group": "security", "label": "producer,security", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.spiffe.SpiffeX509Response", "enum": [ "svid",
"chain", "id" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "chain", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": [...]
},
"headers": {
"CamelSpiffeOperation": { "index": 0, "kind": "header", "displayName": "",
"group": "producer", "label": "producer", "required": false, "javaType":
"org.apache.camel.component.spiffe.SpiffeOperation or String", "deprecated":
false, "autowired": false, "secret": false, "description": "Overrides the
operation to be used by the producer. Ignored unless the endpoint sets
allowOperationHeader=true, because the operation decides whether the endpoint
validates a token or mints one.", "const [...]
@@ -54,9 +57,10 @@
"preserveBody": { "index": 3, "kind": "parameter", "displayName":
"Preserve Body", "group": "producer", "label": "", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether validateJwtSvid leaves the application
body untouched and publishes the verified identi [...]
"lazyStartProducer": { "index": 4, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "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 produc [...]
"workloadApiClient": { "index": 5, "kind": "parameter", "displayName":
"Workload Api Client", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType": "io.spiffe.workloadapi.WorkloadApiClient",
"deprecated": false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "An existing WorkloadApiClient to use. When
set, the component does no [...]
- "allowOperationHeader": { "index": 6, "kind": "parameter", "displayName":
"Allow Operation Header", "group": "security", "label": "security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "security": "insecure:dev",
"defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether the CamelSpiffeOperation header ma
[...]
- "localSpiffeId": { "index": 7, "kind": "parameter", "displayName": "Local
Spiffe Id", "group": "security", "label": "producer,security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The exact local SPIFFE ID to use when the
Workload API supplies several identities: fetchX [...]
- "spiffeSocketPath": { "index": 8, "kind": "parameter", "displayName":
"Spiffe Socket Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The address of the SPIFFE Workload API
endpoint (for example unix:\/\/\/tmp\/agent.sock or tc [...]
- "x509Response": { "index": 9, "kind": "parameter", "displayName": "X509
Response", "group": "security", "label": "producer,security", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.spiffe.SpiffeX509Response", "enum": [ "svid",
"chain", "id" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "chain", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": [...]
+ "healthCheckExpiryThreshold": { "index": 6, "kind": "parameter",
"displayName": "Health Check Expiry Threshold", "group": "health", "label":
"health", "required": false, "type": "duration", "javaType": "long",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
"60000", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Minimum remaining X.509-SVID validity, in
milliseconds, for t [...]
+ "allowOperationHeader": { "index": 7, "kind": "parameter", "displayName":
"Allow Operation Header", "group": "security", "label": "security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "security": "insecure:dev",
"defaultValue": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "Whether the CamelSpiffeOperation header ma
[...]
+ "localSpiffeId": { "index": 8, "kind": "parameter", "displayName": "Local
Spiffe Id", "group": "security", "label": "producer,security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The exact local SPIFFE ID to use when the
Workload API supplies several identities: fetchX [...]
+ "spiffeSocketPath": { "index": 9, "kind": "parameter", "displayName":
"Spiffe Socket Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": "The address of the SPIFFE Workload API
endpoint (for example unix:\/\/\/tmp\/agent.sock or tc [...]
+ "x509Response": { "index": 10, "kind": "parameter", "displayName": "X509
Response", "group": "security", "label": "producer,security", "required":
false, "type": "enum", "javaType":
"org.apache.camel.component.spiffe.SpiffeX509Response", "enum": [ "svid",
"chain", "id" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "chain", "configurationClass":
"org.apache.camel.component.spiffe.SpiffeConfiguration", "configurationField":
"configuration", "description": [...]
}
}
diff --git a/components/camel-spiffe/src/main/docs/spiffe-component.adoc
b/components/camel-spiffe/src/main/docs/spiffe-component.adoc
index 40df966c744c..e15b62e8b0b6 100644
--- a/components/camel-spiffe/src/main/docs/spiffe-component.adoc
+++ b/components/camel-spiffe/src/main/docs/spiffe-component.adoc
@@ -630,3 +630,41 @@ include::spring-boot:partial$starter.adoc[]
cannot assert an identity by setting a header - and it requires mutual TLS,
failing closed when the peer presented
no verified certificate. The verified id it publishes is the
`CamelSpiffePeerId` exchange *property*, never a header,
so it likewise cannot be injected by an inbound message.
+
+== Producer readiness and identity observations
+
+Enable producer health checks with `camel.health.producersEnabled=true` before
starting the route. The component
+also supports `healthCheckProducerEnabled` to disable its checks. The producer
registers a check on start and removes
+it on stop. For each enabled check, a dedicated SDK-managed Workload API
client maintains one streaming observer;
+stopping the producer closes that client and cancels its observer, even when
the endpoint remains cached. Health
+calls read an immutable metadata snapshot and never fetch credentials, contact
the API, or start another observer.
+Producer checks remain disabled globally by default, and no observer client is
opened while they are disabled.
+If producer checks are enabled dynamically after route startup, restart the
route to start its observer.
+
+The observation depends on the endpoint's configured operation:
+
+* `fetchX509Svid` observes the X.509 identity the producer serves: the one
named by `localSpiffeId` when that option is
+ set, otherwise the default SVID. Readiness requires an available, unexpired
SVID outside
+ `healthCheckExpiryThreshold` (default 60000 milliseconds, a duration such as
`5m` is accepted). Set the threshold to
+ zero to require only that it has not expired. Health details include the
observed expiry, remaining validity, and whether the identity is approaching
expiry.
+* `fetchJwtSvid` and `validateJwtSvid` observe JWT trust bundles. Readiness
requires a non-empty bundle update. Bundles
+ have no expiry timestamp, so the check makes no expiry claim and does not
mint or validate a token. In particular,
+ it does not prove that a particular audience can be issued or that an
incoming token will validate.
+
+Both report the most recent update timestamp and the state of the watch
(`not-started`, `starting`, `watching`, `failed`
+or `stopped`). These are SDK callback observations, not an independently
measured connection heartbeat; `lastUpdate` is
+the local observation time, not the SPIRE credential's issuance time. The
check measures whether the identity the
+Workload API last delivered is valid and not about to expire, not whether the
agent is reachable right now. The SDK
+reconnects to an unreachable agent on its own, with unlimited retries and
without telling the watch, so an agent outage
+shows up only as an SVID that is no longer refreshed and comes within
`healthCheckExpiryThreshold` of its expiry.
+`watch=failed` appears only after an error the SDK does not retry; the SDK
then delivers no more updates, readiness
+stays DOWN with the last observation's validity details (`materialValid` keeps
saying whether that material is still
+valid), and the route has to be restarted to watch again. Producer operations
still contact the Workload API; the watch
+is not a credential cache for those operations. The rotating SSL context has
its own source lifecycle and is not measured
+by these producer checks.
+
+No token, private key, certificate contents or exception text is retained or
published by the check. A configured
+`workloadApiClient` is not actively probed: it can address a different API
from `spiffeSocketPath`, and the SDK offers
+no independent unsubscribe handle for a borrowed client. Supply your own
health check for that injected client. If
+`allowOperationHeader=true` is explicitly enabled, changing an individual
message's operation does not retarget the
+readiness observer, which always reflects the endpoint's configured operation.
diff --git
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeComponent.java
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeComponent.java
index 6cbc40fd416f..c22e35828394 100644
---
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeComponent.java
+++
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeComponent.java
@@ -22,13 +22,13 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.annotations.Component;
-import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.HealthCheckComponent;
/**
* SPIFFE Workload Identity component.
*/
@Component("spiffe")
-public class SpiffeComponent extends DefaultComponent {
+public class SpiffeComponent extends HealthCheckComponent {
@Metadata
private SpiffeConfiguration configuration = new SpiffeConfiguration();
diff --git
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeConfiguration.java
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeConfiguration.java
index 00d7df3ea2e6..270484d2202d 100644
---
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeConfiguration.java
+++
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeConfiguration.java
@@ -46,6 +46,9 @@ public class SpiffeConfiguration implements Cloneable {
@UriParam(label = "security", defaultValue = "false", security =
"insecure:dev")
private boolean allowOperationHeader;
+ @UriParam(label = "health", defaultValue = "60000", javaType =
"java.time.Duration")
+ private long healthCheckExpiryThreshold = 60000;
+
@UriParam(label = "advanced",
description = "An existing WorkloadApiClient to use. When set,
the component does not"
+ " create or close its own client and
spiffeSocketPath is ignored.")
@@ -148,6 +151,19 @@ public class SpiffeConfiguration implements Cloneable {
this.allowOperationHeader = allowOperationHeader;
}
+ public long getHealthCheckExpiryThreshold() {
+ return healthCheckExpiryThreshold;
+ }
+
+ /**
+ * Minimum remaining X.509-SVID validity, in milliseconds, for the
producer readiness check to report UP. A
+ * certificate at or below this threshold reports DOWN before expiry. Zero
requires only an unexpired identity. Does
+ * not apply to JWT-bundle readiness because bundles have no expiry
timestamp.
+ */
+ public void setHealthCheckExpiryThreshold(long healthCheckExpiryThreshold)
{
+ this.healthCheckExpiryThreshold = healthCheckExpiryThreshold;
+ }
+
/**
* An already-configured {@link WorkloadApiClient} to use instead of
letting the endpoint create one.
*/
diff --git
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeEndpoint.java
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeEndpoint.java
index 953203fd112b..cca57d46251c 100644
---
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeEndpoint.java
+++
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeEndpoint.java
@@ -83,19 +83,25 @@ public class SpiffeEndpoint extends DefaultEndpoint {
if (configuration.getWorkloadApiClient() != null) {
workloadApiClient = configuration.getWorkloadApiClient();
ownClient = false;
- } else if
(ObjectHelper.isNotEmpty(configuration.getSpiffeSocketPath())) {
- workloadApiClient = DefaultWorkloadApiClient.newClient(
- DefaultWorkloadApiClient.ClientOptions.builder()
-
.spiffeSocketPath(configuration.getSpiffeSocketPath())
- .build());
- ownClient = true;
} else {
- // uses the SPIFFE_ENDPOINT_SOCKET environment variable
- workloadApiClient = DefaultWorkloadApiClient.newClient();
+ workloadApiClient =
createWorkloadApiClient(configuration.getSpiffeSocketPath());
ownClient = true;
}
}
+ static WorkloadApiClient createWorkloadApiClient(String socketPath) throws
Exception {
+ if (ObjectHelper.isNotEmpty(socketPath)) {
+ return DefaultWorkloadApiClient.newClient(
+
DefaultWorkloadApiClient.ClientOptions.builder().spiffeSocketPath(socketPath).build());
+ }
+ return DefaultWorkloadApiClient.newClient();
+ }
+
+ @Override
+ public SpiffeComponent getComponent() {
+ return (SpiffeComponent) super.getComponent();
+ }
+
@Override
protected void doStop() throws Exception {
if (ownClient && workloadApiClient != null) {
diff --git
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducer.java
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducer.java
index 3e4e9c63acfd..3372f52b9ca6 100644
---
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducer.java
+++
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducer.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.spiffe;
import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicInteger;
import io.spiffe.spiffeid.SpiffeId;
import io.spiffe.svid.jwtsvid.JwtSvid;
@@ -25,12 +26,20 @@ import io.spiffe.workloadapi.WorkloadApiClient;
import io.spiffe.workloadapi.X509Context;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.WritableHealthCheckRepository;
import org.apache.camel.support.DefaultProducer;
import org.apache.camel.util.ObjectHelper;
public class SpiffeProducer extends DefaultProducer {
private final SpiffeId localSpiffeId;
+ /** Several producers of one endpoint register one check each; the id
names the endpoint and numbers them. */
+ private static final AtomicInteger HEALTH_CHECK_IDS = new AtomicInteger();
+ private WritableHealthCheckRepository healthCheckRepository;
+ private SpiffeProducerHealthCheck producerHealthCheck;
+ private WorkloadApiClient healthClient;
+
public SpiffeProducer(final SpiffeEndpoint endpoint) {
super(endpoint);
localSpiffeId =
SpiffeX509SvidSelector.parse(endpoint.getConfiguration().getLocalSpiffeId());
@@ -41,6 +50,61 @@ public class SpiffeProducer extends DefaultProducer {
return (SpiffeEndpoint) super.getEndpoint();
}
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ SpiffeConfiguration configuration = getEndpoint().getConfiguration();
+ if (configuration.getWorkloadApiClient() != null) {
+ // A supplied client need not use the configured/default socket,
and has no watcher unsubscribe API.
+ return;
+ }
+ healthCheckRepository = HealthCheckHelper.getHealthCheckRepository(
+ getEndpoint().getCamelContext(), "producers",
WritableHealthCheckRepository.class);
+ if (healthCheckRepository != null) {
+ producerHealthCheck = new SpiffeProducerHealthCheck(
+ getEndpoint().getId() + "-" +
HEALTH_CHECK_IDS.incrementAndGet(), configuration.getOperation(),
+ configuration.getHealthCheckExpiryThreshold(),
localSpiffeId);
+
producerHealthCheck.setEnabled(getEndpoint().getComponent().isHealthCheckProducerEnabled());
+ healthCheckRepository.addHealthCheck(producerHealthCheck);
+ if (healthCheckRepository.isEnabled() &&
producerHealthCheck.isEnabled()) {
+ try {
+ // A separate SDK-managed client makes the subscription
cancellable on producer stop, even
+ // when the endpoint remains cached or has other
producers. No client is created by health calls.
+ healthClient =
SpiffeEndpoint.createWorkloadApiClient(configuration.getSpiffeSocketPath());
+ producerHealthCheck.observe(healthClient);
+ } catch (Exception e) {
+ producerHealthCheck.unavailable();
+ if (healthClient != null) {
+ healthClient.close();
+ healthClient = null;
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ try {
+ try {
+ if (producerHealthCheck != null) {
+ producerHealthCheck.close();
+
healthCheckRepository.removeHealthCheck(producerHealthCheck);
+ producerHealthCheck = null;
+ }
+ } finally {
+ // a repository that throws must not keep the observer client
open
+ WorkloadApiClient client = healthClient;
+ healthClient = null;
+ if (client != null) {
+ client.close();
+ }
+ }
+ } finally {
+ super.doStop();
+ }
+ }
+
@Override
public void process(Exchange exchange) throws Exception {
final WorkloadApiClient client = getEndpoint().getWorkloadApiClient();
diff --git
a/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducerHealthCheck.java
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducerHealthCheck.java
new file mode 100644
index 000000000000..51ccdf23fef9
--- /dev/null
+++
b/components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducerHealthCheck.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.spiffe;
+
+import java.time.Clock;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import io.spiffe.bundle.jwtbundle.JwtBundleSet;
+import io.spiffe.spiffeid.SpiffeId;
+import io.spiffe.svid.x509svid.X509Svid;
+import io.spiffe.workloadapi.Watcher;
+import io.spiffe.workloadapi.WorkloadApiClient;
+import io.spiffe.workloadapi.X509Context;
+import org.apache.camel.health.HealthCheckResultBuilder;
+import org.apache.camel.impl.health.AbstractHealthCheck;
+
+/** Readiness from SDK watch callbacks. Health calls only inspect immutable
metadata and never contact the API. */
+public final class SpiffeProducerHealthCheck extends AbstractHealthCheck
implements AutoCloseable {
+ private final boolean x509;
+ /** The local identity the producer serves when {@code localSpiffeId} is
set; null watches the default SVID. */
+ private final SpiffeId localSpiffeId;
+ private final long expiryThreshold;
+ private final Clock clock;
+ private final AtomicReference<Observation> observation
+ = new AtomicReference<>(new Observation("not-started", false,
null, null, null));
+ // the watch states: not-started, starting, watching (the SDK delivers
updates), failed (the SDK gave the watch up
+ // after a non-retryable error and delivers nothing more until the route
restarts) and stopped. An unreachable agent
+ // is not a state: the SDK reconnects on its own without telling the
watcher, so it shows up only as an identity
+ // that is no longer refreshed and comes close to its expiry
+
+ public SpiffeProducerHealthCheck(String id, SpiffeOperation operation,
long expiryThreshold) {
+ this(id, operation, expiryThreshold, null, Clock.systemUTC());
+ }
+
+ public SpiffeProducerHealthCheck(String id, SpiffeOperation operation,
long expiryThreshold, SpiffeId localSpiffeId) {
+ this(id, operation, expiryThreshold, localSpiffeId, Clock.systemUTC());
+ }
+
+ SpiffeProducerHealthCheck(String id, SpiffeOperation operation, long
expiryThreshold, Clock clock) {
+ this(id, operation, expiryThreshold, null, clock);
+ }
+
+ SpiffeProducerHealthCheck(String id, SpiffeOperation operation, long
expiryThreshold, SpiffeId localSpiffeId,
+ Clock clock) {
+ super("camel", "producer:spiffe-" + id);
+ this.localSpiffeId = localSpiffeId;
+ if (expiryThreshold < 0) {
+ throw new IllegalArgumentException("healthCheckExpiryThreshold
must not be negative");
+ }
+ this.x509 = operation == SpiffeOperation.fetchX509Svid;
+ this.expiryThreshold = expiryThreshold;
+ this.clock = clock;
+ }
+
+ void observe(WorkloadApiClient client) {
+ observation.set(new Observation("starting", false, null, null, null));
+ if (x509) {
+ client.watchX509Context(new Watcher<>() {
+ @Override
+ public void onUpdate(X509Context update) {
+ Instant validFrom = null;
+ Instant expiry = null;
+ try {
+ if (update != null) {
+ // the identity the producer serves: the
configured local one, or the SDK's default
+ X509Svid svid = localSpiffeId == null
+ ? update.getDefaultSvid()
+ :
SpiffeX509SvidSelector.select(update.getX509Svids(), localSpiffeId);
+ if (svid != null && svid.getLeaf() != null &&
svid.getLeaf().getNotAfter() != null) {
+ expiry =
svid.getLeaf().getNotAfter().toInstant();
+ if (svid.getLeaf().getNotBefore() != null) {
+ validFrom =
svid.getLeaf().getNotBefore().toInstant();
+ }
+ }
+ }
+ } catch (RuntimeException e) {
+ // An empty/malformed update is unavailable material,
not a reason to throw on an SDK thread.
+ validFrom = null;
+ expiry = null;
+ }
+ record(expiry != null, validFrom, expiry);
+ }
+
+ @Override
+ public void onError(Throwable error) {
+ unavailable();
+ }
+ });
+ } else {
+ client.watchJwtBundles(new Watcher<>() {
+ @Override
+ public void onUpdate(JwtBundleSet update) {
+ record(update != null && update.getBundles() != null &&
!update.getBundles().isEmpty(), null, null);
+ }
+
+ @Override
+ public void onError(Throwable error) {
+ unavailable();
+ }
+ });
+ }
+ }
+
+ private void record(boolean material, Instant validFrom, Instant expiry) {
+ Instant now = clock.instant();
+ observation.updateAndGet(previous -> previous.watch().equals("stopped")
+ ? previous
+ : new Observation("watching", material, validFrom, expiry,
now));
+ }
+
+ void unavailable() {
+ // Exception text can contain request details. Retain no exception,
credential, certificate or key material.
+ observation.updateAndGet(previous -> previous.watch().equals("stopped")
+ ? previous
+ : new Observation(
+ "failed", previous.material(), previous.validFrom(),
previous.expiry(), previous.lastUpdate()));
+ }
+
+ @Override
+ protected void doCall(HealthCheckResultBuilder builder, Map<String,
Object> options) {
+ Observation current = observation.get();
+ Instant now = clock.instant();
+ builder.detail("spiffe.observation", x509 ? "x509-identity" :
"jwt-bundles");
+ builder.detail("spiffe.watch", current.watch());
+ if (localSpiffeId != null) {
+ builder.detail("spiffe.localSpiffeId", localSpiffeId.toString());
+ }
+ builder.detail("spiffe.materialAvailable", current.material());
+ if (current.lastUpdate() != null) {
+ builder.detail("spiffe.lastUpdate",
current.lastUpdate().toString());
+ }
+ boolean materialValid = current.material();
+ boolean expiring = false;
+ if (current.expiry() != null) {
+ long remaining = Duration.between(now,
current.expiry()).toMillis();
+ materialValid = remaining > 0 && (current.validFrom() == null ||
!now.isBefore(current.validFrom()));
+ expiring = remaining <= expiryThreshold;
+ builder.detail("spiffe.expiry", current.expiry().toString());
+ builder.detail("spiffe.remainingValidityMillis", remaining);
+ builder.detail("spiffe.expiring", expiring);
+ }
+ if (x509) {
+ builder.detail("spiffe.materialValid", materialValid);
+ }
+ if (!current.watch().equals("watching")) {
+ builder.down();
+ builder.message(current.watch().equals("failed")
+ ? "The SPIFFE Workload API watch failed and delivers no
more updates until the route restarts"
+ : "The SPIFFE Workload API watch is " + current.watch());
+ } else if (!materialValid) {
+ builder.down();
+ builder.message("No usable SPIFFE " + (x509 ? "X.509 identity" :
"JWT bundles") + " observed");
+ } else if (expiring) {
+ builder.down();
+ builder.message("SPIFFE X.509 identity is within the configured
expiry threshold");
+ } else {
+ builder.up();
+ }
+ }
+
+ @Override
+ public void close() {
+ observation.set(new Observation("stopped", false, null, null, null));
+ }
+
+ private record Observation(String watch, boolean material, Instant
validFrom, Instant expiry, Instant lastUpdate) {
+ }
+}
diff --git
a/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeHealthCheckRegistrationTest.java
b/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeHealthCheckRegistrationTest.java
new file mode 100644
index 000000000000..7e1143a696f1
--- /dev/null
+++
b/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeHealthCheckRegistrationTest.java
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.spiffe;
+
+import io.spiffe.workloadapi.DefaultWorkloadApiClient;
+import io.spiffe.workloadapi.WorkloadApiClient;
+import org.apache.camel.CamelContext;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.WritableHealthCheckRepository;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+class SpiffeHealthCheckRegistrationTest {
+ @Test
+ void producersSharingAnEndpointOwnIndependentObservers() throws Exception {
+ try (CamelContext context = new DefaultCamelContext();
+ MockedStatic<DefaultWorkloadApiClient> factory =
mockStatic(DefaultWorkloadApiClient.class)) {
+ WorkloadApiClient endpointClient = mock(WorkloadApiClient.class);
+ WorkloadApiClient firstObserver = mock(WorkloadApiClient.class);
+ WorkloadApiClient secondObserver = mock(WorkloadApiClient.class);
+
factory.when(DefaultWorkloadApiClient::newClient).thenReturn(endpointClient,
firstObserver, secondObserver);
+ WritableHealthCheckRepository repository = repository(context);
+ repository.setEnabled(true);
+ SpiffeEndpoint endpoint = endpoint(context, new
SpiffeConfiguration());
+ endpoint.start();
+ SpiffeProducer first = new SpiffeProducer(endpoint);
+ SpiffeProducer second = new SpiffeProducer(endpoint);
+ try {
+ first.start();
+ second.start();
+ assertThat(repository.stream().map(check ->
check.getId()).toList()).hasSize(2).doesNotHaveDuplicates();
+ first.stop();
+ assertThat(repository.stream().toList()).hasSize(1);
+ verify(firstObserver).close();
+ verify(secondObserver, never()).close();
+ second.stop();
+ assertThat(repository.stream().toList()).isEmpty();
+ verify(secondObserver).close();
+ } finally {
+ first.stop();
+ second.stop();
+ endpoint.stop();
+ }
+ }
+ }
+
+ @Test
+ void observerStartupFailureIsDownAndClosesItsClient() throws Exception {
+ try (CamelContext context = new DefaultCamelContext();
+ MockedStatic<DefaultWorkloadApiClient> factory =
mockStatic(DefaultWorkloadApiClient.class)) {
+ WorkloadApiClient endpointClient = mock(WorkloadApiClient.class);
+ WorkloadApiClient observer = mock(WorkloadApiClient.class);
+ doThrow(new IllegalStateException("private failure
details")).when(observer).watchX509Context(any());
+
factory.when(DefaultWorkloadApiClient::newClient).thenReturn(endpointClient,
observer);
+ WritableHealthCheckRepository repository = repository(context);
+ repository.setEnabled(true);
+ SpiffeEndpoint endpoint = endpoint(context, new
SpiffeConfiguration());
+ endpoint.start();
+ SpiffeProducer producer = new SpiffeProducer(endpoint);
+ try {
+ producer.start();
+
assertThat(repository.stream().findFirst().orElseThrow().call().getDetails())
+ .containsEntry("spiffe.watch", "failed");
+ verify(observer).close();
+ } finally {
+ producer.stop();
+ endpoint.stop();
+ }
+ verify(observer).close();
+ }
+ }
+
+ @Test
+ void startsOneObserverPerProducerLifecycleAndRemovesItOnStop() throws
Exception {
+ try (CamelContext context = new DefaultCamelContext();
+ MockedStatic<DefaultWorkloadApiClient> factory =
mockStatic(DefaultWorkloadApiClient.class)) {
+ WorkloadApiClient endpointClient = mock(WorkloadApiClient.class);
+ WorkloadApiClient firstObserver = mock(WorkloadApiClient.class);
+ WorkloadApiClient secondObserver = mock(WorkloadApiClient.class);
+
factory.when(DefaultWorkloadApiClient::newClient).thenReturn(endpointClient,
firstObserver, secondObserver);
+ WritableHealthCheckRepository repository = repository(context);
+ repository.setEnabled(true);
+ SpiffeEndpoint endpoint = endpoint(context, new
SpiffeConfiguration());
+ endpoint.start();
+ SpiffeProducer producer = new SpiffeProducer(endpoint);
+ try {
+ producer.start();
+ assertThat(repository.stream().toList()).hasSize(1);
+ verify(firstObserver).watchX509Context(any());
+ producer.stop();
+ assertThat(repository.stream().toList()).isEmpty();
+ verify(firstObserver).close();
+ verify(endpointClient, never()).close();
+
+ producer.start();
+ assertThat(repository.stream().toList()).hasSize(1);
+ verify(secondObserver).watchX509Context(any());
+ producer.stop();
+ assertThat(repository.stream().toList()).isEmpty();
+ verify(firstObserver).close();
+ verify(secondObserver).close();
+ } finally {
+ producer.stop();
+ endpoint.stop();
+ }
+ verify(endpointClient).close();
+ }
+ }
+
+ @Test
+ void disabledProducerHealthDoesNotOpenAnObserverClient() throws Exception {
+ try (CamelContext context = new DefaultCamelContext();
+ MockedStatic<DefaultWorkloadApiClient> factory =
mockStatic(DefaultWorkloadApiClient.class)) {
+ WorkloadApiClient endpointClient = mock(WorkloadApiClient.class);
+
factory.when(DefaultWorkloadApiClient::newClient).thenReturn(endpointClient);
+ WritableHealthCheckRepository repository = repository(context);
+ SpiffeEndpoint endpoint = endpoint(context, new
SpiffeConfiguration());
+ endpoint.start();
+ SpiffeProducer producer = new SpiffeProducer(endpoint);
+ try {
+ producer.start();
+ factory.verify(DefaultWorkloadApiClient::newClient, times(1));
+ repository.setEnabled(true);
+ assertThat(repository.stream().toList()).hasSize(1);
+
assertThat(repository.stream().findFirst().orElseThrow().call().getDetails())
+ .containsEntry("spiffe.watch", "not-started");
+ } finally {
+ producer.stop();
+ endpoint.stop();
+ }
+ }
+ }
+
+ @Test
+ void injectedClientsAreNeitherProbedNorClosed() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ WorkloadApiClient client = mock(WorkloadApiClient.class);
+ SpiffeConfiguration configuration = new SpiffeConfiguration();
+ configuration.setWorkloadApiClient(client);
+ WritableHealthCheckRepository repository = repository(context);
+ repository.setEnabled(true);
+ SpiffeEndpoint endpoint = endpoint(context, configuration);
+ endpoint.start();
+ SpiffeProducer producer = new SpiffeProducer(endpoint);
+ try {
+ producer.start();
+ assertThat(repository.stream().toList()).isEmpty();
+ verify(client, never()).watchX509Context(any());
+ verify(client, never()).watchJwtBundles(any());
+ } finally {
+ producer.stop();
+ endpoint.stop();
+ }
+ verify(client, never()).close();
+ }
+ }
+
+ private static WritableHealthCheckRepository repository(CamelContext
context) {
+ WritableHealthCheckRepository repository =
HealthCheckHelper.getHealthCheckRepository(
+ context, "producers", WritableHealthCheckRepository.class);
+ assertThat(repository).isNotNull();
+ return repository;
+ }
+
+ private static SpiffeEndpoint endpoint(CamelContext context,
SpiffeConfiguration configuration) {
+ return new SpiffeEndpoint("spiffe:health", new
SpiffeComponent(context), configuration);
+ }
+}
diff --git
a/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeProducerHealthCheckTest.java
b/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeProducerHealthCheckTest.java
new file mode 100644
index 000000000000..b3349a5f39ea
--- /dev/null
+++
b/components/camel-spiffe/src/test/java/org/apache/camel/component/spiffe/SpiffeProducerHealthCheckTest.java
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.spiffe;
+
+import java.security.cert.X509Certificate;
+import java.time.Clock;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import io.spiffe.bundle.jwtbundle.JwtBundle;
+import io.spiffe.bundle.jwtbundle.JwtBundleSet;
+import io.spiffe.spiffeid.SpiffeId;
+import io.spiffe.spiffeid.TrustDomain;
+import io.spiffe.svid.x509svid.X509Svid;
+import io.spiffe.workloadapi.Watcher;
+import io.spiffe.workloadapi.WorkloadApiClient;
+import io.spiffe.workloadapi.X509Context;
+import org.apache.camel.health.HealthCheck;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class SpiffeProducerHealthCheckTest {
+ private static final Instant NOW = Instant.parse("2026-01-01T00:00:00Z");
+
+ @Test
+ void
reportsUnavailableBeforeMaterialThenTracksValidityWithoutFurtherApiCalls()
throws Exception {
+ MutableClock clock = new MutableClock();
+ SpiffeProducerHealthCheck check = check(SpiffeOperation.fetchX509Svid,
clock);
+ WorkloadApiClient client = mock(WorkloadApiClient.class);
+ check.observe(client);
+ Watcher<X509Context> watcher = x509Watcher(client);
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.DOWN);
+
+ watcher.onUpdate(x509(NOW.plusSeconds(120)));
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.UP);
+
assertThat(check.call().getDetails()).containsEntry("spiffe.remainingValidityMillis",
120000L)
+ .containsEntry("spiffe.lastUpdate", NOW.toString());
+ clock.now = NOW.plusSeconds(70);
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.DOWN);
+ assertThat(check.call().getDetails()).containsEntry("spiffe.expiring",
true)
+ .containsEntry("spiffe.materialValid", true);
+ clock.now = NOW.plusSeconds(121);
+
assertThat(check.call().getDetails()).containsEntry("spiffe.materialValid",
false);
+ verify(client, never()).fetchX509Context();
+ }
+
+ @Test
+ void
failedWatchStaysDownAndRetainsMaterialMetadataWithoutPublishingFailureDetails()
throws Exception {
+ MutableClock clock = new MutableClock();
+ SpiffeProducerHealthCheck check = check(SpiffeOperation.fetchX509Svid,
clock);
+ WorkloadApiClient client = mock(WorkloadApiClient.class);
+ check.observe(client);
+ Watcher<X509Context> watcher = x509Watcher(client);
+ watcher.onUpdate(x509(NOW.plusSeconds(120)));
+ // the SDK calls onError only for an error it does not retry, and then
cancels the watch for good
+ watcher.onError(new
IllegalStateException("credential-must-not-appear"));
+
+ HealthCheck.Result failed = check.call();
+ assertThat(failed.getState()).isEqualTo(HealthCheck.State.DOWN);
+ assertThat(failed.getDetails()).containsEntry("spiffe.watch", "failed")
+ .containsEntry("spiffe.materialValid", true)
+ .containsEntry("spiffe.lastUpdate", NOW.toString());
+ assertThat(failed.getError()).isEmpty();
+ assertThat(failed.getMessage().orElse("")).contains("until the route
restarts")
+ .doesNotContain("credential-must-not-appear");
+
assertThat(failed.getDetails().toString()).doesNotContain("credential-must-not-appear");
+
+ // no update follows a failed watch; time passing only makes the
retained material expire
+ clock.now = NOW.plusSeconds(121);
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.DOWN);
+ assertThat(check.call().getDetails()).containsEntry("spiffe.watch",
"failed")
+ .containsEntry("spiffe.materialValid", false);
+ }
+
+ @Test
+ void missingIdentityAndLateCallbacksAfterCloseNeverReportReady() throws
Exception {
+ SpiffeProducerHealthCheck check = check(SpiffeOperation.fetchX509Svid,
new MutableClock());
+ WorkloadApiClient client = mock(WorkloadApiClient.class);
+ check.observe(client);
+ Watcher<X509Context> watcher = x509Watcher(client);
+ watcher.onUpdate(null);
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.DOWN);
+ check.close();
+ watcher.onUpdate(x509(NOW.plusSeconds(120)));
+ watcher.onError(new IllegalStateException("late error"));
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.DOWN);
+ assertThat(check.call().getDetails()).containsEntry("spiffe.watch",
"stopped")
+ .doesNotContainKeys("spiffe.expiry", "spiffe.lastUpdate");
+ }
+
+ @Test
+ void jwtOperationsObserveBundlesWithoutClaimingIdentityExpiry() {
+ for (SpiffeOperation operation : List.of(SpiffeOperation.fetchJwtSvid,
SpiffeOperation.validateJwtSvid)) {
+ SpiffeProducerHealthCheck check = check(operation, new
MutableClock());
+ WorkloadApiClient client = mock(WorkloadApiClient.class);
+ check.observe(client);
+ ArgumentCaptor<Watcher<JwtBundleSet>> captor =
ArgumentCaptor.captor();
+ verify(client).watchJwtBundles(captor.capture());
+ captor.getValue().onUpdate(JwtBundleSet.emptySet());
+
assertThat(check.call().getState()).isEqualTo(HealthCheck.State.DOWN);
+ JwtBundleSet bundles = mock(JwtBundleSet.class);
+ JwtBundle bundle = mock(JwtBundle.class);
+
when(bundles.getBundles()).thenReturn(Map.of(TrustDomain.parse("example.org"),
bundle));
+ captor.getValue().onUpdate(bundles);
+
assertThat(check.call().getState()).isEqualTo(HealthCheck.State.UP);
+
assertThat(check.call().getDetails()).containsEntry("spiffe.observation",
"jwt-bundles")
+ .doesNotContainKeys("spiffe.expiry",
"spiffe.remainingValidityMillis", "spiffe.materialValid");
+ }
+ }
+
+ @Test
+ void futureDatedIdentityIsUnavailableUntilItsValidityStarts() throws
Exception {
+ MutableClock clock = new MutableClock();
+ SpiffeProducerHealthCheck check = check(SpiffeOperation.fetchX509Svid,
clock);
+ WorkloadApiClient client = mock(WorkloadApiClient.class);
+ check.observe(client);
+ X509Context context = x509(NOW.plusSeconds(300));
+
when(context.getDefaultSvid().getLeaf().getNotBefore()).thenReturn(Date.from(NOW.plusSeconds(30)));
+ x509Watcher(client).onUpdate(context);
+
assertThat(check.call().getDetails()).containsEntry("spiffe.materialAvailable",
true)
+ .containsEntry("spiffe.materialValid", false);
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.DOWN);
+ clock.now = NOW.plusSeconds(30);
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.UP);
+ }
+
+ @Test
+ void rejectsANegativeExpiryThreshold() {
+ assertThatThrownBy(() -> new SpiffeProducerHealthCheck("test",
SpiffeOperation.fetchX509Svid, -1))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("healthCheckExpiryThreshold");
+ }
+
+ @Test
+ void watchesTheConfiguredLocalIdentityInsteadOfTheDefault() throws
Exception {
+ SpiffeId billing = SpiffeId.parse("spiffe://example.org/billing");
+ SpiffeProducerHealthCheck check = new SpiffeProducerHealthCheck(
+ "test", SpiffeOperation.fetchX509Svid, 60000,
+ billing, new MutableClock());
+ check.setEnabled(true);
+ WorkloadApiClient client = mock(WorkloadApiClient.class);
+ check.observe(client);
+ Watcher<X509Context> watcher = x509Watcher(client);
+
+ // the default identity expires soon, the configured one is fine: the
check follows the configured one
+ X509Svid defaultSvid =
svid(SpiffeId.parse("spiffe://example.org/workload"), NOW.plusSeconds(10));
+ X509Svid billingSvid = svid(billing, NOW.plusSeconds(600));
+ watcher.onUpdate(x509(defaultSvid, List.of(defaultSvid, billingSvid)));
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.UP);
+
assertThat(check.call().getDetails()).containsEntry("spiffe.localSpiffeId",
billing.toString())
+ .containsEntry("spiffe.remainingValidityMillis", 600000L);
+
+ // an update that no longer carries the configured identity is
unusable material, not a fallback
+ watcher.onUpdate(x509(defaultSvid, List.of(defaultSvid)));
+ assertThat(check.call().getState()).isEqualTo(HealthCheck.State.DOWN);
+
assertThat(check.call().getDetails()).containsEntry("spiffe.materialAvailable",
false);
+ }
+
+ private static X509Svid svid(SpiffeId id, Instant expiry) {
+ X509Svid svid = mock(X509Svid.class);
+ X509Certificate leaf = mock(X509Certificate.class);
+ when(leaf.getNotAfter()).thenReturn(Date.from(expiry));
+ when(svid.getLeaf()).thenReturn(leaf);
+ when(svid.getSpiffeId()).thenReturn(id);
+ return svid;
+ }
+
+ private static X509Context x509(X509Svid defaultSvid, List<X509Svid> all) {
+ X509Context context = mock(X509Context.class);
+ when(context.getDefaultSvid()).thenReturn(defaultSvid);
+ when(context.getX509Svids()).thenReturn(all);
+ return context;
+ }
+
+ private static SpiffeProducerHealthCheck check(SpiffeOperation operation,
Clock clock) {
+ SpiffeProducerHealthCheck check = new
SpiffeProducerHealthCheck("test", operation, 60000, clock);
+ check.setEnabled(true);
+ return check;
+ }
+
+ private static Watcher<X509Context> x509Watcher(WorkloadApiClient client) {
+ ArgumentCaptor<Watcher<X509Context>> captor = ArgumentCaptor.captor();
+ verify(client).watchX509Context(captor.capture());
+ return captor.getValue();
+ }
+
+ private static X509Context x509(Instant expiry) throws Exception {
+ X509Svid svid = mock(X509Svid.class);
+ X509Certificate leaf = mock(X509Certificate.class);
+ when(leaf.getNotAfter()).thenReturn(Date.from(expiry));
+ when(svid.getLeaf()).thenReturn(leaf);
+ X509Context context = mock(X509Context.class);
+ when(context.getDefaultSvid()).thenReturn(svid);
+ return context;
+ }
+
+ private static final class MutableClock extends Clock {
+ private Instant now = NOW;
+
+ @Override
+ public ZoneId getZone() {
+ return ZoneOffset.UTC;
+ }
+
+ @Override
+ public Clock withZone(ZoneId zone) {
+ return this;
+ }
+
+ @Override
+ public Instant instant() {
+ return now;
+ }
+ }
+}
diff --git
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SpiffeComponentBuilderFactory.java
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SpiffeComponentBuilderFactory.java
index fb31aa2e8f81..db290a07c692 100644
---
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SpiffeComponentBuilderFactory.java
+++
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SpiffeComponentBuilderFactory.java
@@ -193,6 +193,65 @@ public interface SpiffeComponentBuilderFactory {
}
+ /**
+ * Used for enabling or disabling all consumer based health checks from
+ * this component.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: true
+ * Group: health
+ *
+ * @param healthCheckConsumerEnabled the value to set
+ * @return the dsl builder
+ */
+ default SpiffeComponentBuilder healthCheckConsumerEnabled(boolean
healthCheckConsumerEnabled) {
+ doSetProperty("healthCheckConsumerEnabled",
healthCheckConsumerEnabled);
+ return this;
+ }
+
+
+ /**
+ * Minimum remaining X.509-SVID validity, in milliseconds, for the
+ * producer readiness check to report UP. A certificate at or below
this
+ * threshold reports DOWN before expiry. Zero requires only an
unexpired
+ * identity. Does not apply to JWT-bundle readiness because bundles
have
+ * no expiry timestamp.
+ *
+ * The option is a: <code>long</code> type.
+ *
+ * Default: 60000
+ * Group: health
+ *
+ * @param healthCheckExpiryThreshold the value to set
+ * @return the dsl builder
+ */
+ default SpiffeComponentBuilder healthCheckExpiryThreshold(long
healthCheckExpiryThreshold) {
+ doSetProperty("healthCheckExpiryThreshold",
healthCheckExpiryThreshold);
+ return this;
+ }
+
+
+ /**
+ * 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.
+ *
+ * The option is a: <code>boolean</code> type.
+ *
+ * Default: true
+ * Group: health
+ *
+ * @param healthCheckProducerEnabled the value to set
+ * @return the dsl builder
+ */
+ default SpiffeComponentBuilder healthCheckProducerEnabled(boolean
healthCheckProducerEnabled) {
+ doSetProperty("healthCheckProducerEnabled",
healthCheckProducerEnabled);
+ return this;
+ }
+
+
/**
* Whether the CamelSpiffeOperation header may override the configured
* operation. Disabled by default: the operation decides whether this
@@ -303,6 +362,9 @@ public interface SpiffeComponentBuilderFactory {
case "preserveBody": getOrCreateConfiguration((SpiffeComponent)
component).setPreserveBody((boolean) value); return true;
case "autowiredEnabled": ((SpiffeComponent)
component).setAutowiredEnabled((boolean) value); return true;
case "workloadApiClient":
getOrCreateConfiguration((SpiffeComponent)
component).setWorkloadApiClient((io.spiffe.workloadapi.WorkloadApiClient)
value); return true;
+ case "healthCheckConsumerEnabled": ((SpiffeComponent)
component).setHealthCheckConsumerEnabled((boolean) value); return true;
+ case "healthCheckExpiryThreshold":
getOrCreateConfiguration((SpiffeComponent)
component).setHealthCheckExpiryThreshold((long) value); return true;
+ case "healthCheckProducerEnabled": ((SpiffeComponent)
component).setHealthCheckProducerEnabled((boolean) value); return true;
case "allowOperationHeader":
getOrCreateConfiguration((SpiffeComponent)
component).setAllowOperationHeader((boolean) value); return true;
case "localSpiffeId": getOrCreateConfiguration((SpiffeComponent)
component).setLocalSpiffeId((java.lang.String) value); return true;
case "spiffeSocketPath":
getOrCreateConfiguration((SpiffeComponent)
component).setSpiffeSocketPath((java.lang.String) value); return true;
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SpiffeEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SpiffeEndpointBuilderFactory.java
index b0e64e0f6c6a..c99046d904ca 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SpiffeEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SpiffeEndpointBuilderFactory.java
@@ -134,6 +134,44 @@ public interface SpiffeEndpointBuilderFactory {
doSetProperty("preserveBody", preserveBody);
return this;
}
+ /**
+ * Minimum remaining X.509-SVID validity, in milliseconds, for the
+ * producer readiness check to report UP. A certificate at or below
this
+ * threshold reports DOWN before expiry. Zero requires only an
unexpired
+ * identity. Does not apply to JWT-bundle readiness because bundles
have
+ * no expiry timestamp.
+ *
+ * The option is a: <code>long</code> type.
+ *
+ * Default: 60000
+ * Group: health
+ *
+ * @param healthCheckExpiryThreshold the value to set
+ * @return the dsl builder
+ */
+ default SpiffeEndpointBuilder healthCheckExpiryThreshold(long
healthCheckExpiryThreshold) {
+ doSetProperty("healthCheckExpiryThreshold",
healthCheckExpiryThreshold);
+ return this;
+ }
+ /**
+ * Minimum remaining X.509-SVID validity, in milliseconds, for the
+ * producer readiness check to report UP. A certificate at or below
this
+ * threshold reports DOWN before expiry. Zero requires only an
unexpired
+ * identity. Does not apply to JWT-bundle readiness because bundles
have
+ * no expiry timestamp.
+ *
+ * The option will be converted to a <code>long</code> type.
+ *
+ * Default: 60000
+ * Group: health
+ *
+ * @param healthCheckExpiryThreshold the value to set
+ * @return the dsl builder
+ */
+ default SpiffeEndpointBuilder healthCheckExpiryThreshold(String
healthCheckExpiryThreshold) {
+ doSetProperty("healthCheckExpiryThreshold",
healthCheckExpiryThreshold);
+ return this;
+ }
/**
* Whether the CamelSpiffeOperation header may override the configured
* operation. Disabled by default: the operation decides whether this