Skip to content

build: require FOCA 0.16 and Python 3.13 - #165

Merged
uniqueg merged 5 commits into
devfrom
feat/foca-0.16
Oct 22, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/foca-0.16

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Closes #156

Summary

  • FOCA 0.16: foca>=0.16.0,<0.17, base image elixircloud/foca:0.16.0-py3.13 (pinned by digest); idna>=3.15 (as FOCA, CVE-2026-45409).
  • One Python version, 3.13 (user decision, see the update in build: require FOCA 0.16 and Python 3.11+ #156): requires-python = ">=3.13", only the 3.13 classifier, ruff py313, mypy python_version = "3.13"; all workflows and Read the Docs use 3.13. The tomli fallback is gone, and datetime.UTC replaces timezone.utc (ruff UP017). A new test (test_python_version) checks that the Dockerfile, pyproject.toml, the workflows and Read the Docs agree.
  • CI: the test matrix (3.10, 3.12) becomes one job, "Run tests (mongomock)", without the Python version in its name, so required checks don't change on Python bumps. "Run tests (MongoDB 7.0)" stays as is (it names the MongoDB version, which is pinned to that of docker-compose.yaml); the aggregate "Run tests" still needs both. No 3.14 job.
  • Access tokens only: FOCA 0.16 rejects tokens without typ: at+jwt (RFC 9068; LS Login issues such tokens); the base config sets security.auth.verify_token_type: True explicitly, and the docs say so. The test token fixture already set typ; make_headers() takes the type now.
  • Headers of errors: tests check WWW-Authenticate: Bearer on 401 responses (also for GET /me and FOCA's permissions API), Bearer error="invalid_token" for invalid and non-access tokens, and Allow on 405 responses. The docs (API, Access control) describe them.
  • Release notes 0.3.0: FOCA 0.16, Python 3.13, access tokens only, error headers.

Not in this PR: FOCA's ownership API and URL helpers (#157), the foca-common library chart (#158). The other FOCA 0.16 breaking changes don't affect the registry: no swagger_ui_path, group_mapping maps to admin only (not a resource role), Gunicorn's control socket was already disabled, and 413 already had the title Content Too Large.

Required checks

The old jobs "Run tests (Python 3.10)" and "Run tests (Python 3.12)" no longer exist. "Run tests" (already required) now covers "Run tests (mongomock)" and "Run tests (MongoDB 7.0)". Optionally also require Run tests (mongomock) and Run tests (MongoDB 7.0) directly; neither name will change with Python bumps.

Verification

Local, Python 3.13.15, FOCA 0.16.0:

  • coverage run --source cloud_registry,scripts -m pytest (with Helm v3.22.1): 892 passed; coverage report: 100%
  • MONGODB_TEST_URI=… pytest against MongoDB 7.0: 892 passed
  • ruff check ., ruff format --check . (0.17.1), mypy, ast-grep scan, semgrep --config=.semgrep, actionlint (1.7.12): clean
  • mkdocs build --strict: OK; uv build: wheel contents as expected, Requires-Python: >=3.13
  • Probed with the test client: 401 WWW-Authenticate: Bearer / Bearer error="invalid_token", error_description=…; 405 Allow: OPTIONS, GET, HEAD

CI (run 39823030828): all jobs pass (Static code analysis, Run tests (mongomock) with 892 passed, Run tests (MongoDB 7.0), Run tests, Check Helm chart, Build documentation, Run app with Docker Compose, Read the Docs); the Codecov upload succeeded.

Declined review findings

Pre-push reviews (adversarial, quality) found no high or medium issues; the low ones about wrapping and stale comments are fixed. Declined (low):

  • Messages on each assertion of test_python_version, or splitting it: pytest's assertion rewriting already shows the compared values, which identify the place.
  • A config test pinning verify_token_type: True: it is FOCA's default, and the behaviour tests (test_other_token_types) fail if token types stop being checked.
  • Writing "3.13 or later (only 3.13 is tested)" everywhere: the contributing guide and release notes already say the app targets/is tested with the image's Python only.

Sourcery (after marking ready): the no-typ token test actually sent typ: JWT (PyJWT default); fixed in 7338bb9. Its other thread (real LS Login token format) is answered: requiring at+jwt is FOCA 0.16's default and the issue's plan; see the note below.

Before the release (not a code change): that LS Login sets typ: at+jwt on its access tokens is taken from the FOCA 0.16 migration guide; confirming it once with a real token before the release is worthwhile, as every authenticated request would get 401 otherwise.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 4 commits October 22, 2026 19:18
Require foca>=0.16.0,<0.17 and build on elixircloud/foca:0.16.0-py3.13
(pinned by digest). The app ships as an image, so it targets one Python
version, that of the image: requires-python >=3.13, the 3.13 classifier
only, ruff target py313 and mypy python_version 3.13.

CI and Read the Docs use Python 3.13 throughout. The test matrix (3.10,
3.12) becomes a single job named "Run tests (mongomock)", without the
Python version, so required checks don't change when it is bumped; the
aggregate "Run tests" check still covers it. A test checks that the
Dockerfile, pyproject.toml, the workflows and Read the Docs agree on
the Python version.

Also raise idna to >=3.15 (as FOCA 0.16, CVE-2026-45409), drop the
tomli fallback and use datetime.UTC (ruff UP017 for py311+).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FOCA 0.16 rejects bearer tokens without the RFC 9068 type (typ header
at+jwt), e.g., ID tokens; LS Login issues such access tokens. Set
security.auth.verify_token_type explicitly in the base config and
document it.

Test that access token types are accepted and other tokens rejected,
that 401 responses carry a Bearer challenge (WWW-Authenticate: Bearer,
with error="invalid_token" for invalid tokens), also for GET /me and
FOCA's permissions API, and that 405 responses carry Allow, as FOCA
0.16 keeps the headers of HTTP errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rewrap the edited paragraphs (API errors, 0.3.0 notes, docs extra
comment), drop the Python version from the Dockerfile comment and fix
the comment of the MongoDB test job (one other test job now).

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

This PR upgrades Cloud Registry to the FOCA 0.16/Python 3.13 baseline, consolidates CI around stable Python-independent check names, enforces RFC 9068 access tokens with documented error headers, and adds tests and migration documentation to keep runtime configuration consistent.

Sequence diagram for access-token validation and error headers

sequenceDiagram
    actor Client
    participant Registry
    participant FOCA

    Client->>Registry: HTTP request with Bearer token
    Registry->>FOCA: Verify token
    alt token is an RFC 9068 access token
        FOCA-->>Registry: Token accepted
        Registry-->>Client: Protected response
    else token is invalid or not an access token
        FOCA-->>Registry: Token rejected
        Registry-->>Client: 401 Unauthorized
        Registry-->>Client: WWW-Authenticate: Bearer error="invalid_token"
    end
Loading

Flow diagram for stable test checks

flowchart LR
    Mongomock["Run tests (mongomock)\nPython 3.13"] --> Aggregate["Run tests"]
    MongoDB["Run tests (MongoDB 7.0)\nPython 3.13"] --> Aggregate
    Aggregate --> Required["Stable required check"]
Loading

File-Level Changes

Change Details Files
Upgrade the runtime and dependency baseline to FOCA 0.16 on Python 3.13, with related security and compatibility updates.
  • Pin the FOCA 0.16/Python 3.13 base image by digest and require matching FOCA and idna versions.
  • Set Python 3.13 as the sole supported and tested version across packaging, Ruff, mypy, CI, release automation, and Read the Docs.
  • Remove the Python pre-3.11 tomli fallback and use Python 3.13 APIs such as datetime.UTC.
  • Add a consistency test that derives the target Python version from the Docker image and validates all configuration consumers.
Dockerfile
pyproject.toml
.github/workflows/checks.yaml
.github/workflows/release.yaml
.readthedocs.yaml
cloud_registry/ga4gh/registry/verification.py
tests/ga4gh/registry/test_verification.py
tests/test_config.py
tests/test_verification.py
tests/test_version.py
docs/contributing.md
docs/development.md
docs/releases/0.3.0.md
Require RFC 9068 access tokens and preserve standards-compliant authentication and method error headers.
  • Explicitly enable FOCA token-type verification so only access tokens with an at+jwt-compatible typ are accepted.
  • Extend token fixtures and behavior tests to cover accepted access-token type variants and rejected missing/non-access token types.
  • Verify and document WWW-Authenticate Bearer challenges, invalid_token details, and Allow headers across registry and FOCA endpoints.
cloud_registry/config.yaml
tests/conftest.py
tests/test_app.py
docs/access-control.md
docs/api.md
docs/releases/0.3.0.md
Simplify CI to a single stable Python 3.13 mongomock test job while retaining MongoDB integration coverage.
  • Replace the 3.10/3.12 test matrix with the stable-named Run tests (mongomock) job and move coverage upload there.
  • Run MongoDB, aggregate, packaging, documentation, release, and application workflow steps on Python 3.13.
  • Keep the aggregate Run tests check dependent on both mongomock and MongoDB test jobs.
.github/workflows/checks.yaml
.github/workflows/release.yaml
Update release and migration documentation for the FOCA, Python, authentication, and error-response breaking changes.
  • Document FOCA 0.16 and Python 3.13 requirements and custom configuration migration expectations.
  • Document access-token-only authentication and HTTP error headers in operational API guidance and release notes.
docs/access-control.md
docs/api.md
docs/contributing.md
docs/development.md
docs/releases/0.3.0.md

Assessment against linked issues

Issue Objective Addressed Explanation
#156 Require FOCA 0.16 and target Python 3.13 consistently across the package metadata, base image, tooling, documentation build, and CI. ✅
#156 Use FOCA 0.16's access-token type validation and verify that 401 and 405 responses preserve their relevant authentication and Allow headers. ✅
#156 Update user and contributor documentation and the 0.3.0 release notes for the FOCA, Python, token, and error-header changes. ✅

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 (8bea9ad) to head (7338bb9).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #165   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        11           
  Lines          880       880           
=========================================
  Hits           880       880           

☔ 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 17:32

@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 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="cloud_registry/config.yaml" line_range="37" />
<code_context>
+        # Only access tokens as per RFC 9068 (`typ` header `at+jwt`, as issued
+        # by LS Login); other tokens of the issuers, such as ID tokens, are
+        # rejected
+        verify_token_type: True
         # Trusted token issuers (`iss` claim); tokens of other issuers are
         # rejected
</code_context>
<issue_to_address>
**Valid provider tokens rejected**

When LS Login issues an otherwise valid access token whose `typ` header is not accepted by FOCA 0.16, fOCA rejects every authenticated request whose token header does not use the configured RFC 9068 type, and callers receive `401 Unauthorized`. The token tests create synthetic JWTs with `make_headers`; they do not verify the format of tokens actually issued by LS Login.

Verify a real LS Login access token against FOCA 0.16 before release, and align the configured validation with the issuer's actual token format.
</issue_to_address>

### Comment 2
<location path="tests/conftest.py" line_range="208" />
<code_context>
     Returns:
         Request headers.
     """
+    jwt_headers = {"kid": "rsa1"} if typ is None else {"kid": "rsa1", "typ": typ}
     now = int(time.time())
     token = jwt.encode(
</code_context>
<issue_to_address>
**Missing-type tokens escape test**

When `test_other_token_types` exercises `typ=None`, `make_headers` omits `typ`, but `jwt.encode` adds `typ: JWT`, so the test exercises the `JWT` case twice and a token with no `typ` can be accepted without failing the test.

Make `make_headers` produce a token with no `typ` header when `typ=None`.

Also at `tests/test_app.py:205`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and enabling FOCA’s token-type check means signed tokens without an RFC 9068 access-token type are rejected, while tokens incorrectly accepted as access tokens could gain authenticated access. Reverting restores the previous check, but any data or access exposed before then cannot be taken back.

Blocking findings: cloud_registry/config.yaml:37, tests/conftest.py:208


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

Comment thread cloud_registry/config.yaml Resolved
Comment thread tests/conftest.py Resolved
PyJWT sets `typ: JWT` when the headers lack `typ`, so make_headers(typ=
None) sent a JWT-typed token and the no-type case was never tested. Pass
`typ: None`, which PyJWT omits, and check the header in the test.

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

uniqueg commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

Merging because docs build on RTD passed.

image

@uniqueg
uniqueg merged commit b648b19 into dev Oct 22, 2026
11 of 12 checks passed
@uniqueg
uniqueg deleted the feat/foca-0.16 branch October 22, 2026 18:23
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.

build: require FOCA 0.16 and Python 3.11+

1 participant