Repository navigation
fix(plugins): fail closed on client pipelines - #526
Conversation
A client pipeline replaces plugins.pipeline, so with client pipelines enabled by default any caller could drop policy steps that sit only in the default pipeline, even plugins that are not client_selectable. - Disable client_pipelines by default; admins enable them explicitly. - Refuse pipeline and backend choices of unauthenticated callers (no subject), also in the plugin listing. - Warn on startup about steps of plugins.pipeline whose plugins are in neither client_pipelines.prepend nor append. - Correct the docstring and both warning boxes: the frame runs only around client pipelines and presets, so policies belong in both pipeline and prepend. Closes #518 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Count only prepend and unconditional append steps as framed, and compare alternatives (plugins and params) and on_failure, so policy routers in append with if_missing_phase or weaker copies in the frame are reported. - Check authentication for both choices right after reading the tags. - Rewrap and deduplicate the docs; split the tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Skip the warning for steps that every preset has when clients may choose presets only. - Check pipeline authentication in resolve only; document the refusal in the docstrings. - Keep the full rule on the configuration page only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideClient-controlled pipeline and backend choices now fail closed by default and require authenticated callers, while enabled configurations receive startup warnings for default-pipeline steps that clients can bypass; documentation and regression coverage were updated to reflect the new semantics. Sequence diagram for authenticated client pipeline and backend selectionsequenceDiagram
participant Caller
participant Host as PluginHost
participant Selection as Selection
participant Pipeline as PipelineResolver
Caller->>Host: start(tags, principal)
Host->>Selection: parse choices
alt backend choice and caller has no subject
Host-->>Caller: InvalidSelection
else pipeline choice and caller has no subject
Host->>Pipeline: resolve(value, principal)
Pipeline-->>Caller: InvalidSelection
else authenticated caller
Host->>Pipeline: resolve(value, principal)
Pipeline-->>Host: ResolvedPipeline
Host-->>Caller: PipelineRun
end
Flow diagram for fail-closed client choice eligibilityflowchart LR
Config["client_pipelines.enabled"] --> PipelineChoice{"Pipeline choice allowed?"}
Subject["Principal.subject"] --> PipelineChoice
Roles["_has_role"] --> PipelineChoice
PipelineChoice -->|yes| Choose["Select pipeline or preset"]
PipelineChoice -->|no| Reject["Reject client pipeline choice"]
BackendConfig["client_backends.enabled"] --> BackendChoice{"Backend choice allowed?"}
Subject --> BackendChoice
BackendChoice -->|yes| Backends["Select configured backend candidates"]
BackendChoice -->|no| RejectBackends["Reject backend choice"]
Flow diagram for startup warnings on skippable pipeline stepsflowchart TD
Start["PluginHost startup"] --> Enabled{"client_pipelines.enabled?"}
Enabled -->|no| Done["No warning"]
Enabled -->|yes| Steps["Inspect plugins.pipeline steps"]
Steps --> Frame["Compare client_pipelines.prepend and append"]
Frame --> Presets["Check presets when inline choices are unavailable"]
Presets --> Exempt["Ignore default route step without params"]
Exempt --> Warning{"Any step clients can skip?"}
Warning -->|yes| Log["logger.warning"]
Warning -->|no| Done
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #526 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 55 55
Lines 6616 6636 +20
=========================================
+ Hits 6616 6636 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="foca/plugins/engine.py" line_range="235" />
<code_context>
+ """
+ return any(
+ kept.alternatives == step.alternatives and kept.on_failure == step.on_failure
+ for kept in steps
+ )
+
</code_context>
<issue_to_address>
**Timed-out policies go unnoticed**
When the plugin exceeds the shorter timeout of a frame step matching a default policy step with the same alternatives and `on_failure: skip`, `_has_step` compares alternatives and `on_failure` but not timeout, so it treats the frame as covering the default step; the frame copy times out and skips the policy without a startup warning, letting clients bypass it.
Include timeout when comparing steps in `_has_step`.
</issue_to_address>
### Comment 2
<location path="foca/plugins/engine.py" line_range="390" />
<code_context>
+ skippable = [
+ step.id
+ for step in self.default_pipeline.steps
+ if not _is_default_route_step(step)
+ and any(not _has_step([*frame, *steps], step) for steps in choices)
+ ]
</code_context>
<issue_to_address>
**Default routing bypass goes unwarned**
When client pipelines are enabled, `client_pipelines.append` is empty, and a client selects an inline pipeline without a route step, `_warn_skippable_steps` exempts the default router without checking whether the frame still appends one. With no append route, an inline client pipeline without a route step skips the default router’s ordering behavior, but startup reports no skippable step.
Exempt the default route only when the frame guarantees a fallback route step, or when every selectable choice supplies an equivalent route step.
</issue_to_address>
### Comment 3
<location path="foca/plugins/engine.py" line_range="234-235" />
<code_context>
+ `on_failure` (identifiers and timeouts may differ).
+ """
+ return any(
+ kept.alternatives == step.alternatives and kept.on_failure == step.on_failure
+ for kept in steps
+ )
+
</code_context>
<issue_to_address>
**Repeated steps evade warning**
When the default pipeline contains multiple equivalent steps with distinct IDs, while a frame or a selectable preset contains fewer equivalent copies, `_has_step` reuses the same matching frame or preset step for every identical default step, so a single copy can suppress warnings for multiple default steps and admins are not alerted that client choices run fewer copies.
Match equivalent steps as a multiset, consuming each match once, and warn when a choice has fewer copies than the default pipeline.
</issue_to_address>
### Comment 4
<location path="foca/plugins/engine.py" line_range="206-219" />
<code_context>
return not roles or bool(set(roles) & set(principal.groups))
+def _is_default_route_step(step: ResolvedStep) -> bool:
+ """Check whether a step is the default route step without params.
+
+ Args:
+ step: Resolved step.
+
+ Returns:
+ Whether all alternatives are the default router with default params.
+ """
+ return all(
+ alternative.plugin == DEFAULT_ROUTER
+ and not alternative.params.model_dump(exclude_defaults=True)
+ for alternative in step.alternatives
+ )
+
+
</code_context>
<issue_to_address>
**Changed routing behavior goes unnoticed**
When the default pipeline has a route step with default router params but a customized timeout or `on_failure`, and client pipelines are enabled, `_is_default_route_step` exempts that step based only on plugin and params, so startup emits no warning when a client route phase replaces its configured timeout or failure behavior.
Include timeout and `on_failure` when deciding whether the default route step is exempt.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and if the authentication check or the default is wrong, a caller could select a replacement pipeline or backend and bypass steps the default pipeline was meant to enforce. Reverting would restore the old behavior, but requests already processed under the wrong selection could have effects that cannot be undone.
Blocking findings: foca/plugins/engine.py:235, foca/plugins/engine.py:390, foca/plugins/engine.py:235, foca/plugins/engine.py:219
A frame copy of a policy step with a shorter timeout (and on_failure: skip) can let clients skip the policy, so the startup warning now compares timeouts too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Client pipelines now fail closed (pre-release review of v0.18.0, finding 3 and the low finding on anonymous callers).
Default off:
plugins.client_pipelines.enablednow defaults tofalse.Authentication: only authenticated callers (a
Principalwith a subject) may choose pipelines (gateway.pipeline) or backends (gateway.backends). The plugin listing shows nothing to choose for anonymous callers.Startup warning: when client pipelines are enabled, the app warns about steps of
plugins.pipelinethat clients can skip. A step counts as covered only if one of these holds:client_pipelines.prepend, or inappendwithoutif_missing_phase, has the same alternatives (plugins and params) and the sameon_failure;The default route step without params is exempt.
Docs: I fixed the
ClientPipelinesConfigdocstring and both warning boxes. They said the frame runs for every request, but requests without the pipeline tag getplugins.pipelinewithout the frame. The full rule is now on the configuration page, anddocs/plugins.mdlinks to it.Why I chose "default off"
The review offered three options:
enabled: false(chosen). This fails closed for every configuration, including ones whose admins never thought about the frame. Admins who enable client pipelines opt in on purpose, and the new startup warning tells them which steps clients could skip.prependto the default pipeline. I rejected this. While client pipelines stay enabled by default, a policy that sits only inplugins.pipelinecould still be skipped, so this alone does not fail closed. It would also change what the frame means, and configurations that list a policy in both places (the pattern the guide shows) would run it twice.requiredorpolicyflag on steps. I rejected this as well. It adds a new configuration concept and new semantics shortly before the release. If it is wanted later, it can come as an addition.Backend choices stay enabled by default: they can only narrow or reorder the configured candidates, never add backends, so they cannot bypass policies. They now need an authenticated caller too.
Plugins are new in 0.18 (they are in no released tag), so the changed default needs no migration note. proTES, which is planned to use these settings, must set
client_pipelines.enabled: trueexplicitly if it wants client pipelines, and should list its policies in bothpipelineandprepend.Closes #518
Verification
pytest tests/plugins: 394 passed. Coverage offoca/pluginsis 100%.pytestbefore the review fixes: 2794 passed, 1 skipped. The 131 errors are allmongodb-marked tests, because no MongoDB server was running locally; CI runs them.ruff check,ruff format --check,mypy,ast-grep scan,ast-grep test, semgrep (.semgrep) andmkdocs build --strictare all clean.Declined review findings
client_backends.enabledfor callers without a subject (low). The listing endpoints require authentication. A validated token without an identity claim is also rejected by access control, so I did not add a per-caller flag to the listing schema.may chooserule of the listing and ofresolve(optional, low). The listing helper already composes the same two predicates (_is_authenticated,_has_role), and the listing tests compare it with selection.🤖 Generated with Claude Code
Summary by Sourcery
Fail closed for client-selected pipelines by disabling them by default and restricting pipeline and backend choices to authenticated callers.
Bug Fixes:
Enhancements:
Documentation:
Tests: