Skip to content

feat(auth): tie service clients to issuers - #376

Merged
uniqueg merged 2 commits into
devfrom
feat/service-client-issuers
Oct 22, 2026
Merged

uniqueg merged 2 commits into
devfrom
feat/service-client-issuers

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #375.

Client IDs are only unique per issuer. With several trusted issuers, someone who registers a service client's ID at another trusted issuer could act as that service client, and with on_behalf_of could name any user. Following the maintainer decision in #375:

  • New optional security.auth.service_clients[].issuer.
  • With exactly one trusted issuer, the issuer is implied and may be omitted. If given, it must be that issuer.
  • With several trusted issuers, every service client needs an issuer that is one of issuers, or FOCA fails to start. This replaces the warning added in feat(auth): support service tokens #371.
  • A token counts as a service token only if its iss equals the client's issuer. Tokens from other issuers with the same client ID and subject are user tokens.
  • Client IDs stay unique across service clients, because client:<id> subjects and client_mapping keys are not issuer-scoped.
  • Updated docs: authentication (service token conditions, issuer binding, example), configuration, templates/config.yaml, and the 0.16 migration guide.

How it was verified

  • ruff format --check and ruff check foca tests: clean
  • mypy foca tests (strict): no issues
  • pytest (Python 3.13, with MongoDB): 1406 passed. foca/security/auth.py and foca/models/config.py at 100% coverage.
  • mkdocs build --strict: clean
  • Local review by the adversarial and quality reviewers. The adversarial reviewer found no bypass of the issuer match. Quality findings were fixed: an integration test for a token of another issuer, a multi-client config test, the implied issuer resolved once per lookup, and the docs reworded.
  • CI: all checks green (unit tests on Python 3.11-3.14 with MongoDB 7.0/8.0 and lowest dependencies, lint/type-check/build, petstore integration, charts, Read the Docs, codecov patch and project)

Declined review findings

  • Filling in the implied issuer in the config (quality, medium). I kept the configured value as given, None meaning implied, so the config the user wrote is what gets dumped. The implied issuer is now resolved once per lookup in get_service_client.
  • Migration note for 0.16 pre-release configs (quality, low). Not added: service clients are new in 0.16, which is not released yet.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Tie service-client recognition to token issuers to prevent cross-issuer client impersonation.

New Features:

  • Bind configured service clients to trusted token issuers, with issuer inference when exactly one trusted issuer exists.

Bug Fixes:

  • Prevent tokens from another trusted issuer with the same client ID and subject from being misclassified as service tokens.

Enhancements:

  • Replace the multi-issuer service-client warning with configuration validation requiring trusted, explicit issuers where necessary.
  • Update authentication and configuration documentation with issuer-binding rules and examples.

Documentation:

  • Document issuer requirements for service clients in authentication, configuration, templates, and the 0.16 migration guide.

Tests:

  • Add coverage for valid and invalid service-client issuer configurations and tokens issued by other issuers.

uniqueg and others added 2 commits October 22, 2026 03:32
Client IDs are only unique per issuer, so a client of another trusted
issuer with the same client ID could act as a service client. Service
clients now have an optional issuer, implied with a single trusted
issuer and required with several (startup error instead of the
previous warning); it must be a trusted issuer. Tokens are service
tokens only if their iss claim is the client's issuer.

Closes #375

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Test that tokens of another issuer than the service client's are user
tokens in validate_token(), and that each of several service clients
needs an issuer. Resolve the implied issuer once per lookup, and list
the conditions of service tokens in the docs.

Refs #375

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

sourcery-ai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Service clients are now explicitly tied to trusted token issuers: configuration validates issuer bindings, authentication requires an iss match before treating a token as a service token, the previous multi-issuer warning is removed, and documentation and tests cover single-issuer inference and cross-issuer isolation.

Sequence diagram for issuer-bound service token recognition

sequenceDiagram
    participant Token
    participant Auth as get_service_client
    participant Config as AuthConfig
    participant ServiceClient as ServiceClientConfig

    Auth->>Config: get_token_client(claims)
    Config-->>Auth: client_id
    Auth->>Config: resolve trusted issuers
    Auth->>ServiceClient: match client_id
    Auth->>Auth: compare claims.iss with client issuer
    Auth->>Auth: compare claim_identity with client subject
    alt issuer and subject match
        Auth-->>Token: return service client
    else issuer or subject mismatch
        Auth-->>Token: return None as user token
    end
Loading

Flow diagram for service client issuer validation

flowchart TD
    A[Load AuthConfig] --> B{Trusted issuers count}
    B -->|One| C[Allow omitted service client issuer]
    B -->|Several| D{Every service client has issuer?}
    D -->|No| E[Configuration validation fails]
    D -->|Yes| F{Each issuer is trusted?}
    C --> F
    F -->|No| E
    F -->|Yes| G[Configuration accepted]
Loading

File-Level Changes

Change Details Files
Bind service-client recognition to the token issuer and enforce valid issuer configuration.
  • Added optional per-client issuer configuration with single-issuer inference.
  • Rejected missing issuers for multi-issuer configurations and issuers outside the trusted set.
  • Required the token iss claim to match the configured or implied issuer before classifying it as a service token.
  • Removed the obsolete multi-issuer warning.
foca/models/config.py
foca/security/auth.py
Document issuer-scoped service-token behavior and configuration requirements.
  • Explained issuer matching as a service-token condition.
  • Added multi-issuer configuration examples and cross-issuer behavior.
  • Updated configuration, template, and migration guidance.
docs/authentication.md
docs/configuration/auth.md
docs/migration-0.16.md
templates/config.yaml
Expand coverage for issuer validation and cross-issuer token classification.
  • Added valid and invalid service-client issuer configuration cases.
  • Verified implied issuers, missing issuers, untrusted issuers, and no trusted issuers.
  • Verified tokens from another issuer remain user tokens and updated fixtures with issuer claims.
tests/models/test_config.py
tests/security/test_auth.py
tests/security/access_control/test_service_clients.py

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 22, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #376   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines         2120      2133   +13     
=========================================
+ Hits          2120      2133   +13     
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 October 22, 2026 01:45

@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. A token’s issuer now determines whether it receives a service client’s identity and related access-control or on-behalf-of behavior; an incorrect match could grant that treatment to the wrong issuer, or deny it to legitimate service tokens. Reverting restores the old classification, but any access or actions taken while the change was active cannot be undone.


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

@uniqueg
uniqueg merged commit 46aff3e into dev Oct 22, 2026
15 checks passed
@uniqueg
uniqueg deleted the feat/service-client-issuers branch October 22, 2026 01:47
uniqueg added a commit that referenced this pull request Oct 22, 2026
Service clients are tied to issuers since #376, so the claims of the
ownership tests name the trusted issuer.

Refs #341, #354

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant