Skip to content

fix: close the 0.6.0 review gaps - #275

Merged
uniqueg merged 6 commits into
devfrom
docs/268-review-gaps
Oct 28, 2026
Merged

uniqueg merged 6 commits into
devfrom
docs/268-review-gaps

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes the gaps that the pre-release review of 0.6.0 found in docs and config checks (M1 and lows).

  • Owners' roles of groups (M1, medium): feat: support several token issuers #264 widened owners-change-permissions to /services/:id/permissions/*, which also matches /permissions/groups/<group>, so 0.5.0 overlays that removed only owners-change-group-permissions let owners grant and revoke roles of groups again.
    • docs/upgrading.md (From 0.5.0, step 5) and docs/access-control.md: such overlays must also change owners-change-permissions; how to let owners grant roles to users but not groups (.../permissions/:user, as in 0.5.0), and what that misses with namespaced issuers (namespaces with slashes) and how to cover those.
    • Startup warning (warn_owner_rules()): if the rule of groups is changed or removed, the app warns of configured rules for owners or any user that still allow PUT/DELETE on the roles of both users and groups (checked with Casbin's keyMatch2 and the act regex, for named and list policies). Rules for groups only, other roles and GET are not warned of.
  • Admin mode with web UIs (L2): deploy a UI that sends X-Request-Roles first, or set opt_in_roles: [] until it does (docs/access-control.md#admin-mode, linked from the upgrade step).
  • Me.user_id (L1): namespaced by issuer with several issuers; users give this exact value to owners.
  • Renames vs. FOCA's permissions API (L5): the registry's permission endpoints wait for renames, FOCA's /admin/access-control/permissions doesn't; docs/api.md says to use the registry's endpoints, or not while a service is renamed.
  • Chart schema $comment (L4): FOCA 0.18.
  • mypy override for PyCasbin (a FOCA dependency without type information).

Closes #268

Verification

Tests first for the warning (tests/test_access_control.py): test_owner_rules_warning (15 configurations: unchanged, groups removed, both removed, users as in 0.5.0, users PUT only, group rule kept, users removed, list policies with and without group coverage, users GET only, maintainers, any user, users of a namespace only, groups PUT only) and test_owner_rules_groups (with only the rule of groups removed, owners still grant roles to groups: 200; with users as in 0.5.0: 403).

Locally (Python 3.13):

  • coverage run -m pytest (mongomock): 1422 passed, 257 skipped (Helm not installed), coverage 100%
  • pytest against MongoDB 7.0.34 (MONGODB_TEST_URI): 1412 passed, 255 skipped
  • pre-commit run --all-files (ruff, semgrep, gitleaks, actionlint, ast-grep, mypy): passed
  • mkdocs build --strict: passed
  • Not run locally: Helm lint and chart tests (no Helm), Docker smoke test; CI runs them.
  • CI (after merging dev with fix: keep probes independent of the database #269, and after the Sourcery fixes in 1fc1294): all checks passed, incl. Chart, Smoke test, Scan image and Test with MongoDB 7.0.

Declined review findings

  • Re-parsing the packaged config.yaml with FOCA's ConfigParser.parse_yaml to get the base rule (quality, medium): kept, so the base rule has one source; the path and the coupling are documented (BASE_CONFIG), and every app test would fail at startup if the key moved.
  • Direct unit tests of warn_owner_rules() with a patched config (quality, medium): the 13 startup cases cover the subjects, roles, methods and list form through the real config pipeline; a unit test would duplicate them.
  • Module-level rule lists in the tests as tuples (quality, low): the overlays are dumped as YAML, where tuples would need a custom representer; nothing mutates them.
  • Configured rules for a literal service ID (Sourcery, medium): configured policies are patterns for all services; roles on single services are granted via the permission endpoints, and the warning is a heuristic for the upgrade case (replied in the thread).
  • The warning doesn't check rules stored via FOCA's permissions API (adversarial, low, noted): only configured rules are overlays' concern; documented in the docstring.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 4 commits October 28, 2026 07:52
Warn on startup if the rule of owners' roles of groups is changed or
removed, but other rules (e.g., owners-change-permissions, which also
covers groups since 0.6.0) still let owners grant or revoke roles of
groups.

Refs #268

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Upgrade guide and access control: owners-change-permissions also
  covers the roles of groups; how to restrict owners to users.
- Admin mode with web UIs: deploy a UI that sends X-Request-Roles
  first, or set opt_in_roles: [] until then.
- Me.user_id: namespaced by issuer with several issuers.
- Renames: change roles via the registry's endpoints, not FOCA's
  permissions API, while services are renamed.
- Chart schema comment: FOCA 0.18.

Closes #268

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rules for the roles of groups only (e.g., the changed rule itself) are
the deployment's choice; warn only of rules that cover the roles of
both users and groups. Test other roles, any user, and GET-only rules.

Refs #268

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Name the options for issuers whose namespaces contain slashes, and
keep the details in the access control docs only.

Refs #268

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

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR closes the 0.6.0 pre-release review gaps by adding startup validation for unsafe owner permission overlays, documenting migration and admin-mode behavior, clarifying namespaced user IDs and rename-safe permission APIs, and adjusting typing and chart metadata configuration.

Sequence diagram for startup owner-permission overlay warning

sequenceDiagram
    participant App
    participant Config as ConfigParser
    participant Casbin as Casbin
    participant Logger

    App->>Config: parse_yaml(BASE_CONFIG)
    Config-->>App: OWNER_GROUP_RULE base policy
    App->>Casbin: key_match2(group_path, rule_path)
    App->>Casbin: key_match2(user_path, rule_path)
    alt group rule changed or removed
        Casbin-->>App: matching owner or wildcard PUT/DELETE rules
        App->>Logger: warning via warn_owner_rules()
    else base group rule unchanged
        App->>App: skip warning
    end
Loading

Sequence diagram for admin mode in web UIs

sequenceDiagram
    actor Admin
    participant UI
    participant Registry

    Admin->>UI: Enable admin mode
    UI->>Registry: Request with X-Request-Roles: admin
    Registry-->>UI: Process request as admin
    UI-->>Admin: Show admin operation

    alt UI does not send X-Request-Roles
        Admin->>Registry: Request without admin header
        Registry-->>Admin: Admin role unavailable
    end
Loading

Flow diagram for restricting owners to user roles

flowchart TD
    A[Change or remove owners-change-group-permissions] --> B[Also redefine owners-change-permissions]
    B --> C{Allow roles for users only?}
    C -->|Yes| D[Use permissions/:user]
    C -->|Namespaced issuers with slash| E[Add a rule per namespace]
    D --> F[Groups path permissions/groups/group is not matched]
    E --> F
    C -->|No| G[Remove or restrict the owner rule]
Loading

File-Level Changes

Change Details Files
Added startup detection for owner policies that still grant group-role changes after the group-specific rule is overridden or removed.
  • Loads the packaged base policy to detect whether the group rule changed.
  • Uses Casbin path matching and method regex checks across named and list policies.
  • Warns only for owner or wildcard rules covering both user and group permission paths, excluding read-only and group-only rules.
  • Invokes the check during application startup and covers the cases with integration tests.
cloud_registry/ga4gh/registry/permissions.py
cloud_registry/app.py
tests/test_access_control.py
Expanded access-control and upgrade documentation to explain 0.6.0 configuration hazards and migration options.
  • Documents that the widened user-permission path also matches group roles and explains the startup warning.
  • Describes the 0.5.0-style user-only path, including limitations for issuer namespaces containing slashes.
  • Adds admin-mode guidance for web UIs and the opt-in fallback.
  • Documents rename behavior differences between registry and FOCA permission APIs.
docs/access-control.md
docs/upgrading.md
docs/api.md
Clarified user identifier semantics when multiple token issuers are trusted.
  • Documents issuer-namespaced identifiers using the `
` format.
  • Requires clients to provide the exact namespaced value when requesting role grants.
  • Updated project configuration for dependency typing and chart schema metadata.
    • Allows mypy to ignore missing type information from Casbin and its submodules.
    • Updates the deployment values schema comment metadata for the supported FOCA version.
    pyproject.toml
    deployment/values.schema.json

    Assessment against linked issues

    Issue Objective Addressed Explanation
    #268 Document the widened owner-permissions rule, warn at startup when a changed or removed group-permissions rule is still bypassed by configured policies, and test the warning and behavior. ✅
    #268 Clarify that Me.user_id may be namespaced by issuer and that users should provide the exact identifier shown by the API when requesting roles. ✅
    #268 Document the LS Login admin-mode deployment order: use a UI that sends X-Request-Roles: admin, or keep opt_in_roles: [] until it does. ✅
    #268 Correct the chart schema comment to identify FOCA 0.18. ✅
    #268 Document that grants through FOCA's admin permissions API can be lost or left on an old identifier during service renames, and advise against granting roles there while a rename is running. ✅

    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 28, 2026 •

    Copy link
    Copy Markdown

    Codecov Report

    ✅ All modified and coverable lines are covered by tests.
    ✅ Project coverage is 100.00%. Comparing base (0b898c2) to head (1fc1294).

    Additional details and impacted files
    @@            Coverage Diff            @@
    ##               dev      #275   +/-   ##
    =========================================
      Coverage   100.00%   100.00%           
    =========================================
      Files           20        20           
      Lines         1989      2008   +19     
    =========================================
    + Hits          1989      2008   +19     

    ☔ 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 28, 2026 07:26

    @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 found 3 issues

    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Individual Comments
    
    ### Comment 1
    <location path="cloud_registry/ga4gh/registry/permissions.py" line_range="661" />
    <code_context>
    +            if len(rule) >= 4
    +            and rule[:2] in (["p", "owner"], ["p", "*"])
    +            and key_match2(path, rule[2])
    +            and key_match2(user_path, rule[2])
    +            and any(re.fullmatch(f"(?:{rule[3]})", method) for method in METHODS)
    +        }
    </code_context>
    <issue_to_address>
    **Group-role grants go unreported**
    
    When the group rule is changed or removed and a customized owner policy matches group paths and valid user IDs, including slash-containing issuer-namespaced IDs, but not the synthetic `/permissions/user` path, `warn_owner_rules()` tests only the synthetic user path, so `key_match2()` rejects the policy and startup emits no warning even though owners can still change those group roles.
    
    Check owner policies against valid group paths and user IDs rather than only the synthetic user path.
    </issue_to_address>
    
    ### Comment 2
    <location path="cloud_registry/ga4gh/registry/permissions.py" line_range="652" />
    <code_context>
    +    policies = get_config().security.access_control.policies or []
    +    if base in policies:
    +        return
    +    path = base[2].replace(":id", "service").replace("*", "group")
    +    user_path = path.replace("/groups/group", "/user")
    +    allowing = sorted(
    </code_context>
    <issue_to_address>
    **Service-specific grants go unreported**
    
    When an overlay changes or removes the group rule but retains an owner or `*` rule scoped to a literal service ID other than `service`, `warn_owner_rules()` checks only the sample path containing `service`, so `key_match2()` misses the rule and startup emits no warning even though owners can still change group roles on that service.
    
    Check owner policies against service-specific paths rather than only the sample path containing `service`.
    
    Also at `cloud_registry/ga4gh/registry/permissions.py:660-661`.
    </issue_to_address>
    
    ### Comment 3
    <location path="docs/api.md" line_range="201-204" />
    <code_context>
     used in URLs (as for `PUT`, see [Registrations](#registrations); also
     slashes) or in roles (commas, line breaks), with `400 Bad Request`.
    
    +The registry's permission endpoints (`/services/{serviceId}/permissions/...`)
    +wait for renames, but FOCA's permissions API (for admins:
    +`/admin/access-control/permissions`) doesn't: grant and revoke roles on
    +services via the registry's endpoints, or not while the service is renamed
    +(roles changed meanwhile may be lost, or left on the old identifier).
    +
    </code_context>
    <issue_to_address>
    **Permissions read during renames**
    
    When a permissions GET for the target runs after the service document is moved but before `_move_roles()` copies the source roles, `getServicePermissions()` checks that the target service exists and then reads roles without waiting for the rename. It returns an empty or partial permission list before `_move_roles()` copies the source roles, so callers see roles missing despite the documentation saying the endpoints wait.
    
    Make permission reads wait for renames, or narrow the documentation to say only permission writes wait.
    </issue_to_address>

    Sourcery assessment

    Approval pending. 3 findings to address first.

    Blocking findings: cloud_registry/ga4gh/registry/permissions.py:661, cloud_registry/ga4gh/registry/permissions.py:652, docs/api.md:204


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

    Comment thread docs/api.md Resolved
    Rules may cover namespaced user identifiers but not bare ones; check
    several example users. Say that only changes of roles wait for renames.
    
    Refs #268
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    @uniqueg
    uniqueg merged commit d7e015f into dev Oct 28, 2026
    19 checks passed
    @uniqueg
    uniqueg deleted the docs/268-review-gaps branch October 28, 2026 07:42
    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.

    docs: close the 0.6.0 review gaps

    1 participant