Skip to content

fix(access-control): replace configured policies atomically #418

Closed

Description

@uniqueg

Problem

A. Mixed rule sets during reconciliation. At startup, every app instance reconciles the configured policies (security.access_control.policies) into the shared policy collection, rule by rule and without a transaction (foca/security/access_control/register_access_control.py, Adapter.set_configured_policies()). Requests are enforced against whatever the collection holds at that moment. So during a rolling update that changes the policies, or after a database error midway, requests can be authorized against a mix of old and new rules. Sourcery raised this on PR #409; it was declined there to keep that PR focused.

B. Configured rules outlive their removal. An overlay can add a named policy even if the base config has none. Removing it later does not work:

  • Setting it to null fails, as named entries can only remove entries the base config has.
  • Deleting the overlay line leaves policies unset (default None, foca/models/config.py), so no reconciliation runs.

The rule stays stored with configured: True. It keeps granting access, and the permissions API answers 409 Conflict to deleting it. Reproduced on MongoDB 7.0.

Expected

  • Requests see either the previous complete set of configured rules or the new one, never a mix.
  • No transactions: FOCA supports standalone MongoDB servers.
  • Stored configured rules do not outlive their removal from the config.

Suggested design: store the new set under a new generation ID, switch a single marker document to it in one write, then delete the old generation. Enforcement loads only the active generation, plus the rules that are not configured.

For B, either (i) warn at startup about stale configured rules and tell the operator to set policies: {} or [], or (ii) manage stored configured rules whenever any exist, so that an unset policies removes them. (ii) is preferred if it is safe and simple. Apps that never configure policies and data from 0.16.0 must keep working. The choice is documented.

Activity

  1. uniqueg commented on Oct 23, 2026

    @uniqueg
    MemberAuthor

    Done in #423.

  2. added
    priority: high
    type: bug
    type: security
    type flag: breaking change
    workload: days
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: hightype flag: breaking changetype: bugtype: securityworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions