Skip to content

feat(plugins): let registry reads trust other CAs - #795

Merged
uniqueg merged 3 commits into
devfrom
feat/793-registry-ca-bundle
Nov 19, 2026
Merged

uniqueg merged 3 commits into
devfrom
feat/793-registry-ca-bundle

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Registries behind a private certificate authority (e.g., an internal Cloud Registry) can now be read by backend lists. Verification can't be turned off anywhere.

  • fetch_json(..., ca_bundle=None): passed to GuardedClient (feat(http): let guarded clients trust other CAs #792), with its checks (TypeError for False, True, bytes and other non-paths, ValueError for empty paths).
  • RegistryEntry.registry_ca_bundle (next to registry_allow_private_addresses): a file (PEM) or directory (hashed names) of CAs that the registry's certificate is verified with, instead of the public ones. Typed Annotated[str, Field(min_length=1, strict=True)] | None, so booleans, numbers, bytes and empty strings are refused at config validation; stored as an absolute path (relative to the working directory at startup), so the per-process cache key (model_dump_json()) and the path don't change with the working directory. It applies to the registry only, not to the backends discovered there.
  • RegistryCache reads the registry through a small _fetch() helper that passes the options explicitly instead of as **dict[str, bool] (the mypy problem named in the issue).
  • A missing or empty bundle fails each read with tls_error (RequestNotSent, an HttpError), which is logged as a warning; the registry then counts as unreachable, as for other failed reads.
  • Helm chart: registryCaBundle in <backendsKey>.backends is rendered as registry_ca_bundle by the existing generic key conversion (no template change); the chart's backend-list test covers it, and docs/helm-chart.md says the app chart must mount the bundle (the library chart mounts no CA bundles).
  • Docs: "Backend lists" in docs/plugins.md (example and a paragraph on TLS verification of registries), docs/utilities.md (fetch_json() with ca_bundle; ctx.http still uses the public CAs only), the package docstring of foca.plugins.backends, and docs/helm-chart.md.

Verification

  • New tests, failing before the change: fetch_json() over real TLS with its own CA (trusted with the bundle; with another CA's bundle the default-trusted CA isn't used, tls_error; False/True/"" refused); an end-to-end registry over TLS with its own CA (no candidates with the public CAs, another CA's bundle or a missing bundle, each logged as tls_error; the TES backend is discovered with the right bundle); config tests for refused values (False, True, 0, "", bytes, list), relative paths stored as absolute, and the options passed to fetch_json().
  • pytest -m "not mongodb": 5066 passed, 2 skipped; pytest charts/foca-common/tests (Helm 3.22.1): 504 passed; coverage of foca/utils/http.py and foca/plugins/backends/*: 100%.
  • The first CI run failed in tests/test_chart_gateway_keys.py::test_backend_keys_rendered (new backend fields must appear in the chart's backend-list test); fixed in 6a3c2e5.
  • ruff check, ruff format --check, mypy (187 files), ast-grep scan --error=flask-import, semgrep scan --config .semgrep --error (0 findings), mkdocs build --strict: all clean.
  • Not run locally: the MongoDB tests (they need port 12345, which is reserved on this machine for other work); CI runs them.

Review

Full lane (security): adversarial-reviewer and quality-reviewer, one round. No high findings, and the adversarial review found no input that turns verification off (config values are refused; a value forced past validation with model_copy() makes GuardedClient raise TypeError, so the read fails closed). Fixed: the TLS registry test now checks that its failures are tls_error (also for a missing bundle) rather than any read error (quality, medium); a comment links the config rule to _ca_bundle_path (quality, medium); docs recommend absolute paths, since BackendList is validated per request (adversarial, low); the package docstring names the option (adversarial, low). The fixes touch only tests, docs and comments, so there was no second round.

Declined review findings

  • Quality (medium): reuse _ca_bundle_path in the pydantic validator instead of strict=True + min_length=1. Declined: pydantic's own type check gives operators a ValidationError at startup with the field's location, like the other fields; GuardedClient checks again, so the two layers fail closed independently. A comment links them.
  • Adversarial (low): check at startup that the bundle exists. Declined: GuardedClient deliberately checks at use (no race with a pre-check, and bundles can be rotated); a missing bundle fails each read with a logged tls_error, which the docs state.
  • Quality (low): move the registry TLS test to test_plugin_backends.py. Kept in test_http_tls.py, which has the TLS fixtures; its module docstring now says so.
  • Quality (low): _fetch() returns object, fetch_json() Any. Kept: callers treat documents as untrusted objects.

Open questions

None.

Closes #793

🤖 Generated with Claude Code

Summary by Sourcery

Enable securely verified backend registry reads using configurable private certificate authorities.

New Features:

  • Allow backend registry reads to trust a configured private CA bundle while retaining mandatory TLS verification.

Bug Fixes:

  • Ensure invalid, empty, missing, or unusable CA bundles fail closed and mark registry reads as unreachable with a TLS error.

Enhancements:

  • Normalize configured registry CA bundle paths to absolute paths and pass registry fetch options through a dedicated helper.
  • Document private CA bundle configuration and application-chart mounting requirements for backend registries.

Documentation:

  • Document registry CA bundles in backend-list, utility, package, and Helm chart documentation.

Tests:

  • Add TLS, configuration, registry integration, and Helm rendering coverage for CA bundle support and verification failures.

uniqueg and others added 2 commits November 19, 2026 00:14
`fetch_json()` takes `ca_bundle` and passes it to `GuardedClient`, and
registry entries of backend lists get `registry_ca_bundle`, so that
registries with certificates of a private certificate authority can be
read. The bundle is a path only (strict string, not empty), stored as
an absolute path; verification can't be turned off. Registry reads pass
their options explicitly instead of as `**dict[str, bool]`.

Closes #793

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The TLS registry test now checks that failed reads are TLS verification
failures (`tls_error`), also for a missing bundle. Docs recommend
absolute bundle paths, and the package docstring names the option.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add registry_ca_bundle to registry entries, validate it as a non-empty strict string, and normalize it to an absolute path for stable cache keys.

  • foca/plugins/backends/config.py L270-276, L314-317 (+4 small edits)

API

Extend the public fetch_json() interface to accept a CA bundle and pass it to GuardedClient, preserving mandatory verification.

  • foca/utils/http.py L1220-1223 (+3 small edits)

Uses of the API

Route registry resource reads through _fetch() so both verification and service documents use the entry’s address, scheme, and CA-bundle options.

  • foca/plugins/backends/registry.py L472-474, L520-538

Update the backend package description to explain that registry TLS can trust a configured CA bundle but is never unverified.

  • foca/plugins/backends/__init__.py L36-38

Configuration

Render registryCaBundle in chart backend values and assert the rendered setting.

  • charts/foca-common/tests/test_templates.py L3404, L3434

Documentation

Document the registry CA-bundle option, its verification behavior and limitations, and how chart deployments must mount the bundle.

  • docs/helm-chart.md L625-627
  • docs/plugins.md L216, L276-288

Update utility documentation to describe fetch_json() CA-bundle support and clarify that ctx.http still uses public CAs.

  • docs/utilities.md L401-407

Tests

Cover registry option propagation and ensure invalid CA-bundle values are refused while relative paths normalize to absolute paths.

  • tests/plugins/test_plugin_backends.py L9, L960-964, L970-999

Test fetch_json() and end-to-end registry TLS behavior with trusted, untrusted, missing, and invalid CA bundles.

  • tests/utils/test_http_tls.py L1-6, L462-597 (+4 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

The chart's test of backend lists covers every field with several words
(checked by test_chart_gateway_keys.py), so it gets registryCaBundle.
The chart docs say that the app chart mounts the bundle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c5b19c7) to head (6a3c2e5).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #795   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           75        75           
  Lines        10076     10082    +6     
=========================================
+ Hits         10076     10082    +6     
Flag Coverage Δ
test_unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 19, 2026 00:44
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit 6a3c2e5

#793 feat: let registry reads trust other CAs · 4 of 4 met

# Requirement Status Notes
1 Add ca_bundle to fetch_json() and pass it to GuardedClient. ✅ Met fetch_json() accepts the requested path-or-None argument and forwards it to GuardedClient.
2 Add a registry entry CA-bundle option and pass it to fetch_json(). ✅ Met RegistryEntry.registry_ca_bundle is normalized to an absolute path and passed explicitly by RegistryCache._fetch().
3 Test a TLS registry with its own CA and document the backend-list and utility behavior. ✅ Met The tests exercise registry reads with trusted, untrusted, and missing bundles; docs/plugins.md and docs/utilities.md describe the options.
4 Allow reading a registry with a private CA bundle without allowing verification to be turned off. ✅ Met TLS tests verify successful reads with the configured CA and failures with untrusted or missing bundles; invalid empty and non-path values are rejected.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. For a registry configured with this bundle, TLS verification trusts its listed authorities instead of the public ones; a wrong or compromised CA could let an impostor registry supply backend listings, and any downstream requests or exposure cannot be undone by reverting. The default trust behavior is unchanged, and reverting removes the custom trust bundle.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit 05deb3d into dev Nov 19, 2026
108 checks passed
@uniqueg
uniqueg deleted the feat/793-registry-ca-bundle branch November 19, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: let registry reads trust other CAs

1 participant