You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "oscerd (via GitHub)" <gi...@apache.org> on 2026/09/21 08:00:00 UTC
[PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
oscerd opened a new pull request, #26664:
URL: https://github.com/apache/camel/pull/26664
## What
Adds `CamelOpaDecisionFailedOpen`, set only when an exchange proceeded because `failOpen` is enabled and the policy could not be evaluated.
## Why
`CamelOpaDecisionAllow` is `true` in two very different situations: a policy allowed the exchange, and no policy ran at all but `failOpen` told the component to continue. On its own the header cannot separate them, so neither a route nor an audit trail can answer "which exchanges went through unauthorized?".
The only existing signal was a WARN in the application log:
```java
LOG.warn("Policy {} could not be evaluated, allowing the exchange to proceed because failOpen is enabled...");
```
"This route is currently allowing traffic nothing authorized" is precisely the condition an operator wants to alert on, and an application log is the weakest channel available for it — easy to lose in volume, invisible to metrics.
## How
The marker is set on the fail-open path and nowhere else, so its **presence** is the signal:
```java
.choice()
.when(header(OpaConstants.DECISION_FAILED_OPEN).isEqualTo(true))
.to("log:unauthorized?level=WARN")
.end()
```
It is cleared before every evaluation along with the other decision headers. That is not incidental: without it a sender could preload `CamelOpaDecisionFailedOpen=false` and disguise an unauthorized exchange as one a policy allowed, which would make the header worse than useless given it exists to be an audit trail. This is the same attacker-settable-header problem CAMEL-24754 fixed for the verdict itself, and it applies identically to any future marker.
## Testing
Four cases in `OpaProducerTest`:
- the marker appears when `failOpen` carried the exchange
- it is **absent** on an allow a policy actually made — the separation is the whole point
- a sender cannot claim `false` on the fail-open path
- a claimed marker is cleared on an ordinary decision
Removing the `clearDecisionHeaders` line turns the last one red. 86 tests in the module, full reactor green.
## Scope
`main` only, additive. `failOpen` remains `false` by default and marked `insecure:dev`.
This is Option 1 of the three in the issue. Option 2 (the health check reporting DEGRADED while a route is failing open) is deliberately not included — it needs the evaluator to publish state to the check, which is a different change and worth its own review.
_Claude Code on behalf of @oscerd_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd merged PR #26664:
URL: https://github.com/apache/camel/pull/26664
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #26664:
URL: https://github.com/apache/camel/pull/26664#discussion_r4061652116
##########
components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java:
##########
@@ -233,6 +237,9 @@ private static void clearDecisionHeaders(Exchange exchange) {
message.removeHeader(OpaConstants.DECISION_ALLOW);
message.removeHeader(OpaConstants.DECISION);
message.removeHeader(OpaConstants.POLICY_PATH);
+ // as attacker-settable as the verdict itself: left in place, a sender could preload it false and make a
+ // fail-open read as a decision a policy actually made
+ message.removeHeader(OpaConstants.DECISION_FAILED_OPEN);
Review Comment:
⚠️ **Missing companion guard in `isDecisionHeader()`**
`DECISION_FAILED_OPEN` is now a decision header — its presence is the audit signal this PR is adding, and a Rego policy that reads it from the `input.headers` document would silently see a stale sender-injected value on a second evaluation in a pipeline (where the header hasn't been cleared yet between exchanges). `clearDecisionHeaders()` removing it here is the runtime protection, but `isDecisionHeader()` is the code-level contract:
```java
private static boolean isDecisionHeader(String name) {
return OpaConstants.DECISION_ALLOW.equalsIgnoreCase(name)
|| OpaConstants.DECISION.equalsIgnoreCase(name)
|| OpaConstants.POLICY_PATH.equalsIgnoreCase(name)
|| OpaConstants.DECISION_FAILED_OPEN.equalsIgnoreCase(name);
}
```
The comment in `buildInput()` (line 150) says "never feed our own decision headers back in" — `DECISION_FAILED_OPEN` is one of them and should be listed here too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd commented on code in PR #26664:
URL: https://github.com/apache/camel/pull/26664#discussion_r4061629565
##########
components/camel-opa/src/main/docs/opa-component.adoc:
##########
@@ -326,6 +326,25 @@ decision point available".
Setting `failOpen=true` reverses this and lets the exchange proceed when the policy cannot be evaluated. It exists
for development and for non-critical policies, and should not be enabled in production.
+An exchange that proceeds that way carries `CamelOpaDecisionFailedOpen=true`. `CamelOpaDecisionAllow` is `true`
+in both cases, and on its own it cannot tell "a policy allowed this" from "no policy ran and we were told to
+proceed" — which is exactly the distinction an audit trail needs. The marker is set only on the fail-open path,
+so a route can branch on it and an operator can alert on its presence:
+
+[source,java]
+------------------------------------------------------------
+from("platform-http:/orders")
+ .to("opa:authz/orders/allow?failOpen=true")
+ .choice()
+ .when(header(OpaConstants.DECISION_FAILED_OPEN).isEqualTo(true))
+ .to("log:unauthorized?level=WARN")
+ .end()
+ .to("direct:orders")
+------------------------------------------------------------
+
+Like the other decision headers it is cleared before every evaluation, so a message cannot arrive claiming
Review Comment:
Good point — the evaluator is shared, so a policy failing open sets the marker identically, and the only reason a route author using `.policy(...)` would know that is if they went looking in the producer's section.
Cross-referenced from the `healthCheckEnabled` note where `failOpen` already comes up, with an anchor added to the section it points at so the link resolves:
> A policy running `failOpen` marks the exchanges it let through with `CamelOpaDecisionFailedOpen`, exactly as the producer does; the evaluator is shared, so everything in <<failure-handling>> about that header applies to `.policy(...)` too.
Pushed with the regenerated catalog copy of the adoc — a docs-only edit still needs the full reactor, since the component page is copied verbatim into `camel-catalog`.
_Claude Code on behalf of @oscerd_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd commented on code in PR #26664:
URL: https://github.com/apache/camel/pull/26664#discussion_r4062254835
##########
components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java:
##########
@@ -233,6 +237,9 @@ private static void clearDecisionHeaders(Exchange exchange) {
message.removeHeader(OpaConstants.DECISION_ALLOW);
message.removeHeader(OpaConstants.DECISION);
message.removeHeader(OpaConstants.POLICY_PATH);
+ // as attacker-settable as the verdict itself: left in place, a sender could preload it false and make a
+ // fail-open read as a decision a policy actually made
+ message.removeHeader(OpaConstants.DECISION_FAILED_OPEN);
}
Review Comment:
Fixed. You're right that the current path is safe and right that the contract isn't.
`clearDecisionHeaders()` at line 84 runs before `buildInput()` at 87, so today the header is already gone when the filter is consulted — which means `isDecisionHeader()` returning false for it changes nothing *now*. But the filter is what documents the rule, and anyone reordering those two calls, or setting the marker from somewhere other than `evaluate()`, reintroduces the leak with nothing to catch it. Added:
```java
|| OpaConstants.DECISION_FAILED_OPEN.equalsIgnoreCase(name);
```
Same reasoning as CAMEL-24732, which withheld credential headers from the wildcard: OPA's decision logging ships the whole input document off the box, so anything that can reach `input.headers` deserves a deliberate answer rather than an incidental one.
_Claude Code on behalf of @oscerd_
##########
components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java:
##########
@@ -233,6 +237,9 @@ private static void clearDecisionHeaders(Exchange exchange) {
message.removeHeader(OpaConstants.DECISION_ALLOW);
message.removeHeader(OpaConstants.DECISION);
message.removeHeader(OpaConstants.POLICY_PATH);
+ // as attacker-settable as the verdict itself: left in place, a sender could preload it false and make a
+ // fail-open read as a decision a policy actually made
+ message.removeHeader(OpaConstants.DECISION_FAILED_OPEN);
Review Comment:
Same fix as the adjacent thread — `DECISION_FAILED_OPEN` is in `isDecisionHeader()` now.
On the pipeline scenario you describe: within a single `evaluate()` the clear always precedes `buildInput`, so a stale sender-injected value cannot reach the input document even before this change. Where it would have mattered is a second evaluator in the same route reading it, or any future path that builds input without clearing first. Closing the contract rather than relying on call order is the right call either way.
_Claude Code on behalf of @oscerd_
##########
components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaProducerTest.java:
##########
@@ -157,6 +157,52 @@ void deniesWhenTheVerdictIsNotABoolean() throws Exception {
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isEqualTo(false);
}
+ @Test
+ void marksAnExchangeThatOnlyProceededBecauseOfFailOpen() throws Exception {
+ when(client.evaluate(eq(PATH), anyMap(), eq(Object.class))).thenThrow(new OPAException("connection refused"));
+
+ Exchange out = template.request(ENDPOINT + "&failOpen=true", e -> {
+ });
+
+ assertThat(out.getException()).isNull();
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isEqualTo(true);
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isEqualTo(true);
+ }
+
+ @Test
+ void doesNotMarkADecisionAPolicyActuallyMade() throws Exception {
+ // the point of the marker is that it separates the two, so an allow from a real policy must not carry it
+ givenDecision(Boolean.TRUE);
+
+ Exchange out = template.request(ENDPOINT + "&failOpen=true", e -> {
+ });
+
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isEqualTo(true);
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
+ }
+
+ @Test
+ void doesNotLetAnInboundMessageClaimItDidNotFailOpen() throws Exception {
+ // as settable by a sender as the verdict was: left in place, "FailedOpen=false" would disguise an
+ // unauthorized exchange as one a policy allowed - which is the audit trail this header exists to give
+ when(client.evaluate(eq(PATH), anyMap(), eq(Object.class))).thenThrow(new OPAException("connection refused"));
+
+ Exchange out = template.request(ENDPOINT + "&failOpen=true",
+ e -> e.getMessage().setHeader(OpaConstants.DECISION_FAILED_OPEN, false));
+
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isEqualTo(true);
+ }
+
+ @Test
+ void clearsAClaimedFailOpenMarkerOnAnOrdinaryDecision() throws Exception {
+ givenDecision(Boolean.TRUE);
+
+ Exchange out = template.request(ENDPOINT,
+ e -> e.getMessage().setHeader(OpaConstants.DECISION_FAILED_OPEN, true));
+
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
+ }
+
@Test
void failsClosedWhenThePolicyCannotBeEvaluated() throws Exception {
Review Comment:
Added — that was a real gap between what the tests check and what the PR claims.
```java
// the marker is for the deliberate failOpen path only, not for any exception the evaluator happens to hit
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
```
"Set only on the fail-open path" was carried by three tests asserting its presence and none asserting its absence on the closed path, so the separation the header exists to provide was an assumption. 86 tests in the module.
_Claude Code on behalf of @oscerd_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26664:
URL: https://github.com/apache/camel/pull/26664#issuecomment-5757586498
<!-- ci-tested-modules -->
:test_tube: **CI tested the following changed modules:**
- `catalog/camel-catalog`
- `components/camel-opa`
- `dsl/camel-endpointdsl`
---
<details><summary>:microscope: Scalpel shadow comparison — Scalpel: 9 of 692 tested, 25 compile-only — current: 9 all tested</summary>
[Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **36 affected modules** (current approach: 9).
**Skip-tests mode would test 9 modules** (3 direct + 8 downstream), **skip tests for 25** (generated code, meta-modules)
<details><summary>:warning: Modules only in Scalpel (27)</summary>
- `apache-camel`
- `camel-allcomponents`
- `camel-catalog`
- `camel-catalog-console`
- `camel-catalog-maven`
- `camel-catalog-suggest`
- `camel-componentdsl`
- `camel-endpointdsl`
- `camel-endpointdsl-support`
- `camel-itest`
- `camel-jbang-core`
- `camel-jbang-it`
- `camel-jbang-main`
- `camel-jbang-plugin-edit`
- `camel-jbang-plugin-generate`
- `camel-jbang-plugin-kubernetes`
- `camel-jbang-plugin-test`
- `camel-kamelet-main`
- `camel-launcher`
- `camel-report-maven-plugin`
- `camel-route-parser`
- `camel-yaml-dsl`
- `camel-yaml-dsl-deserializers`
- `camel-yaml-dsl-maven-plugin`
- `coverage`
- `docs`
- `dummy-component`
</details>
<details><summary>Modules Scalpel would test (9)</summary>
- `camel-catalog` ← catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/opa.json, catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
- `camel-endpointdsl` ← dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpaEndpointBuilderFactory.java
- `camel-jbang-mcp` ← downstream of org.apache.camel:camel-catalog
- `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
- `camel-jbang-plugin-route-parser` ← downstream of org.apache.camel:camel-route-parser
- `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-catalog
- `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-yaml-dsl-validator
- `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
- `camel-opa` ← components/camel-opa/src/generated/resources/META-INF/org/apache/camel/component/opa/opa.json, components/camel-opa/src/main/docs/opa-component.adoc, components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaConstants.java, components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java, components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaProducerTest.java
- `camel-yaml-dsl-validator` ← downstream of org.apache.camel:camel-catalog
- `camel-yaml-dsl-validator-maven-plugin` ← downstream of org.apache.camel:camel-yaml-dsl-validator
</details>
<details><summary>Modules with tests skipped (25)</summary>
- `apache-camel`
- `camel-allcomponents`
- `camel-catalog-console`
- `camel-catalog-maven`
- `camel-catalog-suggest`
- `camel-componentdsl`
- `camel-endpointdsl-support`
- `camel-itest`
- `camel-jbang-core`
- `camel-jbang-it`
- `camel-jbang-main`
- `camel-jbang-plugin-edit`
- `camel-jbang-plugin-generate`
- `camel-jbang-plugin-kubernetes`
- `camel-jbang-plugin-test`
- `camel-kamelet-main`
- `camel-launcher`
- `camel-report-maven-plugin`
- `camel-route-parser`
- `camel-yaml-dsl`
- `camel-yaml-dsl-deserializers`
- `camel-yaml-dsl-maven-plugin`
- `coverage`
- `docs`
- `dummy-component`
</details>
> :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
</details>
<details><summary>All tested modules (36 modules, 4m 50s total)</summary>
**Total reactor time:** 4m 50s
| Module | Duration | Status |
| --- | --- | --- |
| Camel :: YAML DSL | 55.1s | SUCCESS |
| Camel :: Launcher | 38.2s | SUCCESS |
| Camel :: JBang :: MCP | 29.8s | SUCCESS |
| Camel :: JBang :: Plugin :: TUI | 24.9s | SUCCESS |
| Camel :: OPA | 23.6s | SUCCESS |
| Camel :: Catalog :: Camel Catalog | 17.2s | SUCCESS |
| Camel :: Component DSL | 16.2s | SUCCESS |
| Camel :: JBang :: Plugin :: Kubernetes | 10.4s | SUCCESS |
| Camel :: Docs | 9.4s | SUCCESS |
| Camel :: Kamelet Main | 7.6s | SUCCESS |
| Camel :: YAML DSL :: Validator | 7.5s | SUCCESS |
| Camel :: JBang :: Plugin :: Testing | 6.2s | SUCCESS |
| Camel :: Catalog :: Camel Route Parser | 6.0s | SUCCESS |
| Camel :: Catalog :: Camel Report Maven Plugin | 5.2s | SUCCESS |
| Camel :: All Components Sync point | 4.0s | SUCCESS |
| Camel :: JBang :: Plugin :: Validate | 4.0s | SUCCESS |
| Camel :: YAML DSL :: Deserializers | 4.0s | SUCCESS |
| Camel :: Catalog :: Maven | 2.4s | SUCCESS |
| Camel :: YAML DSL :: Maven Plugins | 2.4s | SUCCESS |
| Camel :: YAML DSL :: Validator Maven Plugin | 2.1s | SUCCESS |
| Camel :: Catalog :: Suggest (deprecated) | 2.1s | SUCCESS |
| Camel :: Assembly | 1.8s | SUCCESS |
| Camel :: JBang :: Plugin :: Edit | 1.7s | SUCCESS |
| Camel :: Coverage | 1.6s | SUCCESS |
| Camel :: JBang :: Integration tests | 1.0s | SUCCESS |
| Camel :: Catalog :: Console | 0.8s | SUCCESS |
| Camel :: Catalog :: Dummy Component | 0.8s | SUCCESS |
| Camel :: JBang :: Plugin :: Generate | 0.8s | SUCCESS |
| Camel :: JBang :: Plugin :: MCP | 0.7s | SUCCESS |
| Camel :: Endpoint DSL :: Support | 0.7s | SUCCESS |
| Camel :: Launcher :: Container | 0.6s | SUCCESS |
| Camel :: JBang :: Main | 0.6s | SUCCESS |
| Camel :: JBang :: Plugin :: Route Parser | 0.4s | SUCCESS |
| Camel :: Endpoint DSL | n/a | |
| Camel :: Integration Tests | n/a | |
| Camel :: JBang :: Core | n/a | |
**Top 20 slowest modules:**
- `Camel :: YAML DSL` (55.1s)
- `Camel :: Launcher` (38.2s)
- `Camel :: JBang :: MCP` (29.8s)
- `Camel :: JBang :: Plugin :: TUI` (24.9s)
- `Camel :: OPA` (23.6s)
- `Camel :: Catalog :: Camel Catalog` (17.2s)
- `Camel :: Component DSL` (16.2s)
- `Camel :: JBang :: Plugin :: Kubernetes` (10.4s)
- `Camel :: Docs` (9.4s)
- `Camel :: Kamelet Main` (7.6s)
- `Camel :: YAML DSL :: Validator` (7.5s)
- `Camel :: JBang :: Plugin :: Testing` (6.2s)
- `Camel :: Catalog :: Camel Route Parser` (6.0s)
- `Camel :: Catalog :: Camel Report Maven Plugin` (5.2s)
- `Camel :: All Components Sync point` (4.0s)
- `Camel :: JBang :: Plugin :: Validate` (4.0s)
- `Camel :: YAML DSL :: Deserializers` (4.0s)
- `Camel :: Catalog :: Maven` (2.4s)
- `Camel :: YAML DSL :: Maven Plugins` (2.4s)
- `Camel :: YAML DSL :: Validator Maven Plugin` (2.1s)
</details>
---
:gear: [View full build and test results](https://github.com/apache/camel/actions/runs/35575621523)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26664:
URL: https://github.com/apache/camel/pull/26664#issuecomment-5757280800
:star2: Thank you for your contribution to the Apache Camel project! :star2:
:robot: CI automation will test this PR automatically.
:camel: Apache Camel Committers, please review the following items:
* First-time contributors **require MANUAL approval** for the GitHub Actions to run
* You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
* You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
* Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
:warning: Be careful when sharing logs. Review their contents before sharing them publicly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #26664:
URL: https://github.com/apache/camel/pull/26664#discussion_r4061649980
##########
components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaProducerTest.java:
##########
@@ -157,6 +157,52 @@ void deniesWhenTheVerdictIsNotABoolean() throws Exception {
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isEqualTo(false);
}
+ @Test
+ void marksAnExchangeThatOnlyProceededBecauseOfFailOpen() throws Exception {
+ when(client.evaluate(eq(PATH), anyMap(), eq(Object.class))).thenThrow(new OPAException("connection refused"));
+
+ Exchange out = template.request(ENDPOINT + "&failOpen=true", e -> {
+ });
+
+ assertThat(out.getException()).isNull();
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isEqualTo(true);
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isEqualTo(true);
+ }
+
+ @Test
+ void doesNotMarkADecisionAPolicyActuallyMade() throws Exception {
+ // the point of the marker is that it separates the two, so an allow from a real policy must not carry it
+ givenDecision(Boolean.TRUE);
+
+ Exchange out = template.request(ENDPOINT + "&failOpen=true", e -> {
+ });
+
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isEqualTo(true);
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
+ }
+
+ @Test
+ void doesNotLetAnInboundMessageClaimItDidNotFailOpen() throws Exception {
+ // as settable by a sender as the verdict was: left in place, "FailedOpen=false" would disguise an
+ // unauthorized exchange as one a policy allowed - which is the audit trail this header exists to give
+ when(client.evaluate(eq(PATH), anyMap(), eq(Object.class))).thenThrow(new OPAException("connection refused"));
+
+ Exchange out = template.request(ENDPOINT + "&failOpen=true",
+ e -> e.getMessage().setHeader(OpaConstants.DECISION_FAILED_OPEN, false));
+
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isEqualTo(true);
+ }
+
+ @Test
+ void clearsAClaimedFailOpenMarkerOnAnOrdinaryDecision() throws Exception {
+ givenDecision(Boolean.TRUE);
+
+ Exchange out = template.request(ENDPOINT,
+ e -> e.getMessage().setHeader(OpaConstants.DECISION_FAILED_OPEN, true));
+
+ assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
+ }
+
@Test
void failsClosedWhenThePolicyCannotBeEvaluated() throws Exception {
Review Comment:
💡 **Suggestion: add explicit negative assertion on fail-closed path**
The four new tests cover the fail-open marker comprehensively. The existing `failsClosedWhenThePolicyCannotBeEvaluated` test already verifies that an exception is thrown when `failOpen=false`, but it does not assert that `DECISION_FAILED_OPEN` is absent. Adding that assertion turns a silent assumption into an explicit contract: the marker only fires on the intentional `failOpen` path, not as a side-effect of any exception in the evaluator.
Suggested addition to the existing test (not a new test — just one more `assertThat`):
```java
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
```
##########
components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java:
##########
@@ -233,6 +237,9 @@ private static void clearDecisionHeaders(Exchange exchange) {
message.removeHeader(OpaConstants.DECISION_ALLOW);
message.removeHeader(OpaConstants.DECISION);
message.removeHeader(OpaConstants.POLICY_PATH);
+ // as attacker-settable as the verdict itself: left in place, a sender could preload it false and make a
+ // fail-open read as a decision a policy actually made
+ message.removeHeader(OpaConstants.DECISION_FAILED_OPEN);
}
Review Comment:
⚠️ **`isDecisionHeader()` is not updated — incomplete defensive filter**
`clearDecisionHeaders()` now correctly removes `DECISION_FAILED_OPEN` (this line), but `isDecisionHeader()` — the method that prevents decision headers from being fed back into OPA as input — was not updated to include it.
The current code path makes this safe: `clearDecisionHeaders()` runs at line 84, before `buildInput()` at line 87, so by the time `isDecisionHeader()` is consulted the header is already gone. But the method's contract is "never let any of our own decision headers into the OPA input document" — and it now silently fails to cover `DECISION_FAILED_OPEN`. If the call ordering ever shifts (an early-return path, a subclass that calls `buildInput()` before `clearDecisionHeaders()`, a test that calls `buildInput()` directly), the gap becomes exploitable: a sender that pre-sets `CamelOpaDecisionFailedOpen` could have it included in the OPA input, which defeats the purpose of the header being a component-only output.
The fix is one line:
```suggestion
message.removeHeader(OpaConstants.DECISION_FAILED_OPEN);
}
private static boolean isDecisionHeader(String name) {
return OpaConstants.DECISION_ALLOW.equalsIgnoreCase(name)
|| OpaConstants.DECISION.equalsIgnoreCase(name)
|| OpaConstants.POLICY_PATH.equalsIgnoreCase(name)
|| OpaConstants.DECISION_FAILED_OPEN.equalsIgnoreCase(name);
```
(The suggestion includes the closing `}` of `clearDecisionHeaders` and the first lines of `isDecisionHeader` — adjust the diff range as needed if the suggestion block spans them.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd commented on PR #26664:
URL: https://github.com/apache/camel/pull/26664#issuecomment-5763889885
Added in `715e2d05`. You're right that the doc made a claim the tests didn't back.
`OpaSecurityPolicyTest` now has a second policy with `failOpen=true` on its own route:
```java
@Test
void marksAnExchangeTheFailOpenPolicyLetThrough() throws Exception {
when(client.evaluate(eq(PATH), anyMap(), eq(Object.class))).thenThrow(new OPAException("connection refused"));
MockEndpoint result = getMockEndpoint("mock:failOpen");
result.expectedMessageCount(1);
Exchange out = template.request("direct:failOpen", e -> e.getMessage().setBody("an order"));
assertThat(out.getException()).isNull();
result.assertIsSatisfied();
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isEqualTo(true);
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isEqualTo(true);
}
```
Two deviations from your sketch, both deliberate:
1. I added `expectedMessageCount(1)` on the mock. "No exception" and "the route actually ran" are
different properties, and the whole point of `failOpen` is the second one.
2. I also added the mirror assertion to `deniesWhenThePolicyCannotBeEvaluated`, that the marker is
**absent** on the fail-closed denial. Without it the suite proves the marker can appear but never
that it stays off, which is the half that matters for an auditor filtering on it.
On "the test passes trivially because the evaluator is shared" — I checked rather than assumed, since
a test that cannot fail is worse than no test. Both assertions are load-bearing:
- commenting out `setHeader(DECISION_FAILED_OPEN, true)` inside the `failOpen` branch:
`marksAnExchangeTheFailOpenPolicyLetThrough` fails, `expected: true but was: null`;
- hoisting that same line above `if (failOpen)`: `deniesWhenThePolicyCannotBeEvaluated` fails,
`expected: null but was: true`.
So the shared evaluator makes the test *cheap*, not vacuous — it still fails on exactly the divergence
the adoc paragraph would otherwise be lying about.
Full `camel-opa` suite: 87 tests, 0 failures.
_Claude Code on behalf of @oscerd_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-24738: camel-opa - make a failOpen decision distinguishable from a real one [camel]
Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #26664:
URL: https://github.com/apache/camel/pull/26664#discussion_r4060485739
##########
components/camel-opa/src/main/docs/opa-component.adoc:
##########
@@ -326,6 +326,25 @@ decision point available".
Setting `failOpen=true` reverses this and lets the exchange proceed when the policy cannot be evaluated. It exists
for development and for non-critical policies, and should not be enabled in production.
+An exchange that proceeds that way carries `CamelOpaDecisionFailedOpen=true`. `CamelOpaDecisionAllow` is `true`
+in both cases, and on its own it cannot tell "a policy allowed this" from "no policy ran and we were told to
+proceed" — which is exactly the distinction an audit trail needs. The marker is set only on the fail-open path,
+so a route can branch on it and an operator can alert on its presence:
+
+[source,java]
+------------------------------------------------------------
+from("platform-http:/orders")
+ .to("opa:authz/orders/allow?failOpen=true")
+ .choice()
+ .when(header(OpaConstants.DECISION_FAILED_OPEN).isEqualTo(true))
+ .to("log:unauthorized?level=WARN")
+ .end()
+ .to("direct:orders")
+------------------------------------------------------------
+
+Like the other decision headers it is cleared before every evaluation, so a message cannot arrive claiming
Review Comment:
Non-blocking: the evaluator is shared with `OpaSecurityPolicy`, so this marker is also set when a *policy* fails open, but the paragraph only lives in the producer's `failOpen` section. A short cross-reference in the policy section (where `healthCheckEnabled=false ... one running failOpen` is mentioned) would tell route authors using `.policy(...)` that the same `CamelOpaDecisionFailedOpen` header applies there too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org