Skip to content

feat: allow reads by policy for login setups - #187

Merged
uniqueg merged 5 commits into
devfrom
feat/read-policies
Oct 23, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/read-policies

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR lets deployments require login for reads, so that any logged-in user can read and anonymous users get 401 (instead of "admins only"). It uses FOCA 0.17's spec patches and named entries, from the FOCA dev pin of #184.

  • Named entries: api.specs is now a named spec, registry. security.access_control.policies are now named rules, so overlays can change, add or remove single rules by name (null removes one).

  • Default read rules allow GET for any authenticated user (*) on the read endpoints:

    • list-services
    • get-service, which also covers /services/types, since keyMatch2 matches it with /services/:id
    • get-service-verification
    • list-verifications

    There is no rule for /services/:id/permissions. FOCA only evaluates these rules for operations that require authentication, so nothing changes while reads are public, which is the default.

  • Shipped patch: cloud_registry/api/patches/login-for-reads.yaml, installed as package data. It sets security: [bearerAuth: []] on all public reads except GET /service-info. Operators apply it with a 5-line overlay, or with the chart's config value: api.specs.registry.patches: [api/patches/login-for-reads.yaml]. Relative paths resolve against the base config directory, so no file needs to be mounted.

  • Docs:

    • a "Requiring login for reads" recipe in docs/access-control.md (the patch is included via snippets), with FOCA's "With great power comes great responsibility" warning;
    • an example that limits reads to a mapped reader role;
    • a note on overlays that give policies as a list;
    • updates in configuration.md, api.md, README.md and the 0.3.0 notes.
  • Tests: the docs tests parse the overlays from the docs and apply them:

    • anonymous reads get 401;
    • authenticated users get 200;
    • /service-info, /openapi.json and /ui/ stay public;
    • permissions and updates keep their protection;
    • FOCA logs the patch and warns of nothing.

    The readers example is tested too, and so are public reads by default.

Closes #168

How it was verified

  • coverage run -m pytest: 1066 passed, 100% coverage (rebased on dev with build: test against FOCA 0.17 from dev #184).
  • pre-commit run --all-files: passed.
  • mkdocs build --strict: passed.
  • docker build: the patch is installed in the image.
  • helm template with the overlay in config: rendered as given.
  • CI: all checks passed (tests with mongomock and MongoDB 7.0, Docker Compose, Helm chart, image scan, CodeQL, codecov, Read the Docs).

Review

  • Adversarial review, 2 rounds, no high or medium findings. Two lows were fixed. The docs' readers example now maps only the readers group, so copying it adds no registry-admins mapping. The recipe now notes that overlays giving the policies as a list must include the read rules. The reviewer also probed:
    • HEAD, trailing slashes and encoded slashes in login-for-reads mode;
    • keyMatch2 against /permissions;
    • packaging, the chart and the overlay semantics.
  • Quality review, 2 rounds. All findings were fixed: rule names by operation, docs tests anchored on titled YAML blocks, docs wording and layout.

Declined review findings

None.

Open questions

None.

Notes for the user and deployers

  • Overlays that set security.access_control.policies or api.specs as lists still work, and replace the base config's entries completely, as before. FOCA refuses to start if a later overlay gives named entries for them. Such deployments must add the read rules to their list if they require login for reads.
  • The rule names are now part of the overlay interface; renaming them later breaks overlays.

🤖 Generated with Claude Code

Summary by Sourcery

Enable deployments to require login for read operations through a documented API specification overlay while preserving public reads by default.

New Features:

  • Add an optional deployment configuration that requires authentication for public read endpoints while keeping service information and API documentation public.
  • Ship a reusable API specification patch and document overlays for authenticated reads and role-restricted readers.

Enhancements:

  • Convert the API specification and access-control policies to named entries so overlays can modify individual entries without replacing the full configuration.
  • Clarify default and configurable read access behavior across the deployment and release documentation.

Build:

  • Package the login-for-reads API patch with the application distribution.

Documentation:

  • Document the login-for-reads recipe, reader-role example, named policy overlays, and configuration compatibility.

Tests:

  • Add coverage for public reads by default, authenticated-read overlays, role-restricted reads, preserved endpoint protections, and packaged patch files.

uniqueg and others added 3 commits October 23, 2026 02:09
Name the API specification (`registry`) and the policies, so that
overlays change single entries by name (FOCA 0.17 named entries), and
add policies that allow GET on the read endpoints for any authenticated
user. They are only evaluated once a deployment requires login for
reads, which the patch shipped with the app does
(`api/patches/login-for-reads.yaml`). Document the recipe, with a test
that applies it from the docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Name the read rules by operation (list-services, get-service,
get-service-verification, list-verifications), anchor the docs tests on
titled YAML blocks, reuse one verified service per test, map only
readers in the docs example (keeping the deployment's admin groups),
note that list policies need the read rules, and tidy the docs.

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

sourcery-ai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces an opt-in FOCA spec-patch workflow for requiring login on registry reads, backed by named API and policy entries that overlays can modify individually. The default remains publicly readable; when enabled, authenticated users can read through new default policies, while metadata and existing protected operations retain their prior access behavior. Documentation, package installation, and end-to-end tests cover the new deployment model.

Sequence diagram for requiring login on registry reads

sequenceDiagram
    participant Client
    participant RegistryAPI
    participant FOCA
    participant PolicyEngine

    Client->>RegistryAPI: GET /services
    RegistryAPI->>FOCA: Validate operation security
    alt Login-for-reads patch enabled
        FOCA-->>Client: 401 Unauthorized
        FOCA->>PolicyEngine: Evaluate list-services
        PolicyEngine-->>FOCA: Authenticated user allowed
        FOCA-->>Client: 200 OK
    else Public reads
        FOCA-->>Client: 200 OK
    end
Loading

Entity relationship diagram for named API and access-control entries

erDiagram
    API_SPEC ||--o{ SPEC_PATCH : receives
    API_SPEC {
        string name_registry
    }
    SPEC_PATCH {
        string path_login_for_reads
        string security_bearerAuth
    }
    ACCESS_CONTROL ||--o{ POLICY_RULE : contains
    ACCESS_CONTROL {
        string policies_named
    }
    POLICY_RULE {
        string name_list_services
        string name_get_service
        string name_get_service_verification
        string name_list_verifications
    }
Loading

File-Level Changes

Change Details Files
Adds configurable authentication for public read operations while preserving public metadata endpoints and default behavior.
  • Adds named authenticated-read policies for service and verification GET operations.
  • Ships a reusable OpenAPI patch that applies bearer authentication to all public reads except service info.
  • Keeps /service-info, OpenAPI, and Swagger UI public while retaining existing protection for permissions and updates.
  • Adds package-data inclusion and updates the Docker health-check/config references for named API specs.
cloud_registry/config.yaml
cloud_registry/api/patches/login-for-reads.yaml
pyproject.toml
Dockerfile
Refactors configuration entries to support targeted overlay changes and documents deployment recipes and compatibility rules.
  • Names the API specification registry and access-control policies, with null-based removal of individual rules.
  • Documents the login-for-reads overlay, role-restricted readers example, list-overlay replacement semantics, and operational warnings.
  • Updates API, configuration, README, and release documentation.
docs/access-control.md
docs/api.md
docs/configuration.md
docs/releases/0.3.0.md
README.md
Adds integration and configuration tests that validate documented overlays and end-to-end authorization behavior.
  • Parses titled YAML overlays from the access-control documentation and applies them to test app instances.
  • Verifies anonymous 401 responses, authenticated read access, role-restricted readers, public metadata endpoints, and unchanged write/permission protections.
  • Verifies default public reads, installed patch/package data, and named-spec configuration handling.
tests/test_access_control.py
tests/test_config.py

Assessment against linked issues

Issue Objective Addressed Explanation
#168 Add default access-control rules that allow any authenticated user to perform GET reads on the service, service-type, and verification endpoints when a deployment makes those reads require authentication, without changing the default public-read behavior. ✅
#168 Provide a ready-to-use configuration recipe and shipped API-spec patch for requiring login on reads except GET /service-info, with documentation of named policies and FOCA patch risks. ✅
#168 Test the login-for-reads recipe to verify anonymous reads are rejected, authenticated reads succeed, and /service-info remains public, while protecting existing authorization behavior. ✅

Possibly linked issues


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

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5f89c57) to head (14ad8d3).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #187   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           14        14           
  Lines          906       906           
=========================================
  Hits           906       906           

☔ 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 October 23, 2026 00:46
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Oct 23, 2026

@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

Approved.


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

@sourcery-ai
sourcery-ai Bot dismissed their stale review October 23, 2026 00:55

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@uniqueg
uniqueg merged commit f4a8acd into dev Oct 23, 2026
15 checks passed
@uniqueg
uniqueg deleted the feat/read-policies branch October 23, 2026 00:59
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: allow reads by policy for login setups

1 participant