Repository navigation
refactor!: use FOCA 0.18 features - #338
Conversation
Upgrade to FOCA 0.18 (foca>=0.18.0,<0.19, base image 0.18.0-py3.13) and replace proTES's copies of what FOCA now provides, as Cloud Registry did (elixir-cloud-aai/cloud-registry#261): - require_admin moves from custom.access_control to FOCA's security.access_control.require_admin; the old key stops the app and the chart with a hint - FOCA's startup checks replace the admin and group claim checks and the placeholder warning of the service info; proTES keeps its check of enforced access control and the warning without user groups - service clients are refused by require_no_service_clients() - the image runs Gunicorn with foca.gunicorn_config (same settings); pro_tes.gunicorn_config is gone - foca.get_custom_config(CustomConfig) replaces proTES's own - validation details are set explicitly (FOCA's new default) Tests apply rules changed in the database directly with mark_changed(), and the docs tell operators to restart proTES after such changes (FOCA 0.18 caches the enforcer). BREAKING CHANGE: custom.access_control.require_admin is now security.access_control.require_admin; the image loads foca.gunicorn_config; rejected requests get the validation reason as detail. Closes #331 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document subjects namespaced by issuer and the restart after a rolling update, refuse all of custom.access_control in the chart, test the model's refusal directly, and fix the ast-grep note and docstrings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideUpgrades proTES to FOCA 0.18 and replaces duplicated configuration, security validation, Gunicorn, and custom-config functionality with FOCA-provided implementations, while updating application behavior, Helm validation, tests, and migration documentation for the resulting breaking changes. Sequence diagram for FOCA 0.18 startup validationsequenceDiagram
participant Image as Container image
participant Foca as FOCA
participant App as proTES
participant Config as Configuration
Image->>Foca: load foca.gunicorn_config
App->>Foca: Foca(config_file)
Foca->>Config: validate security.access_control
alt invalid configuration
Config-->>Foca: raise validation error
Foca-->>App: refuse startup
else valid configuration
Foca-->>App: initialized application
App->>Foca: require_no_service_clients(app)
App->>App: check_task_ownership()
App->>App: check_user_groups()
App-->>Image: serve application
end
Flow diagram for FOCA 0.18 access-control rule changesflowchart LR
Operator[Operator changes rules in MongoDB] --> Mongo[(MongoDB policy_rules)]
Mongo --> Cached[In-memory FOCA enforcer]
Cached -->|unchanged until restart| API[proTES API]
Operator -->|kubectl rollout restart| Restart[Restart all proTES instances]
Restart --> Reload[Reload rules into memory]
Reload --> API
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #338 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 28 -1
Lines 2470 2420 -50
=========================================
- Hits 2470 2420 -50 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deployment/templates/_helpers.tpl" line_range="160" />
<code_context>
-{{- end -}}
{{- if and (eq $requireAdmin "true") (not (has "admin" (values $mapping))) -}}
-{{- fail "config.security.access_control.group_mapping must map a group to the role admin (e.g., the admin group of the identity provider), or set config.custom.access_control.require_admin to false" -}}
+{{- fail "config.security.access_control.group_mapping must map a group to the role admin (e.g., the admin group of the identity provider), or set config.security.access_control.require_admin to false" -}}
{{- end -}}
{{- end -}}
</code_context>
<issue_to_address>
**Helm rejects policy-granted admin**
When `require_admin` is true, no group mapping grants `admin`, and a configured policy grants the admin role, `deployment/templates/_helpers.tpl` checks only whether `group_mapping` contains `admin`, so Helm fails rendering even though FOCA accepts the policy and satisfies `require_admin`; the deployment cannot be installed through Helm.
Update the chart check to accept an admin role granted by a configured access-control policy.
</issue_to_address>
### Comment 2
<location path="docs/upgrading.md" line_range="50" />
<code_context>
+ `issuers: [{issuer: "https://login.example.org/oidc/", namespace: ""},
+ "https://other.example.org/"]`; not supported by the Helm chart yet,
+ which accepts issuers as URLs only, see [#337](https://github.com/elixir-cloud-aai/proTES/issues/337)), or rewrite the stored subjects to the
+ namespaced form (see FOCA's [migration
+ guide](https://foca.readthedocs.io/en/latest/migration-0.18/#subjects-of-several-issuers)).
+ Deployments with a single trusted issuer are not affected.
</code_context>
<issue_to_address>
**Owner metadata stays ambiguous**
When a deployment trusts several issuers and chooses the rewrite route rather than configuring an issuer with `namespace: ""`, `tasks.user_id` remains the old bare subject if operators rewrite only the stored access-control subjects; the new namespaced identity then does not match the owner recorded on existing task rows, so owner lookups using the documented `user_id` query miss or misidentify those tasks.
Include updating existing `tasks.user_id` values in the namespacing migration instructions, or state explicitly that the field remains historical and must be queried by its old value.
</issue_to_address>
### Comment 3
<location path="pyproject.toml" line_range="120" />
<code_context>
# FOCA minors are bumped by hand, together with the base image in the
# `Dockerfile` (`.github/dependabot.yml`).
- "foca>=0.17.0,<0.18",
+ "foca>=0.18.0,<0.19",
"geopy>=2.2.0,<3",
"gunicorn>=26.2.0,<27",
</code_context>
<issue_to_address>
**Owners temporarily lose task access**
When a rolling upgrade has both 0.17 and 0.18 replicas serving requests, an older replica can create a task and its owner rule after a FOCA 0.18 replica has cached the rules. The 0.18 replica then rejects that owner’s requests for the task until the post-rollout restart refreshes its cache.
Drain or stop old replicas from creating tasks before 0.18 replicas begin serving, or otherwise prevent requests from reaching stale 0.18 caches until the post-upgrade refresh.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and with multiple trusted issuers, FOCA now namespaces subjects, so existing task owners and permission grants stored with bare subjects may stop matching; tasks or grants created during the rollout can also remain in the new format. Reverting restores the old interpretation for old records, but may not restore access to records written with namespaced subjects without a data repair.
Blocking findings: deployment/templates/_helpers.tpl:160, docs/upgrading.md:50, pyproject.toml:120
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deployment/templates/_helpers.tpl" line_range="111-116" />
<code_context>
{{- if hasKey $securityAccessControl "group_mapping" -}}
{{- $mapping = get $securityAccessControl "group_mapping" -}}
{{- end -}}
+{{- if hasKey $securityAccessControl "require_admin" -}}
+{{- $requireAdmin = include "protes.parseBool" (dict
+ "value" (get $securityAccessControl "require_admin")
+ "key" "config.security.access_control.require_admin"
+) -}}
+{{- end -}}
{{- if hasKey $securityAccessControl "claim_groups" -}}
{{- $claimGroups = get $securityAccessControl "claim_groups" -}}
</code_context>
<issue_to_address>
**Policy-granted admins are rejected**
When an admin role is granted through `security.access_control.policies` without a group mapping while `require_admin` remains true, `protes.checkSecurity` checks only `$mapping` for `admin`, so Helm fails during rendering even though FOCA accepts the policy-based grant; the deployment cannot start.
Include roles granted by `security.access_control.policies` when validating that `require_admin` is satisfied.
Also at `deployment/templates/_helpers.tpl:160`.
</issue_to_address>
### Comment 2
<location path="pyproject.toml" line_range="120" />
<code_context>
# FOCA minors are bumped by hand, together with the base image in the
# `Dockerfile` (`.github/dependabot.yml`).
- "foca>=0.17.0,<0.18",
+ "foca>=0.18.0,<0.19",
"geopy>=2.2.0,<3",
"gunicorn>=26.2.0,<27",
</code_context>
<issue_to_address>
**Owner queries miss namespaced users**
When a multi-issuer deployment chooses the documented option to rewrite stored subjects to the namespaced form rather than configuring an issuer with an empty namespace, the task-owner lookup and repair examples in `docs/operations.md` use a bare `<sub>`, so operators following them cannot find newly created tasks by their stored `user_id` or grant their owner roles to the namespaced subject. The affected tasks remain inaccessible to the intended user.
Update the task-owner lookup and repair examples to use the issuer-namespaced subject, and explain the empty-namespace alternative.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and FOCA 0.18 keeps access-control rules in memory, so a rule removed directly from the database may continue granting access until every proTES instance is restarted; any access during that window cannot be undone by reverting. In deployments with multiple trusted issuers, the new issuer-prefixed subjects also stop matching existing task owners and permissions unless those stored subjects are migrated or configured for compatibility.
Blocking findings: deployment/templates/_helpers.tpl:116, pyproject.toml:120
Rewrite user_id along with the owner roles, show owners in their namespaced form in the operations examples, and say how to avoid the window of rolling updates from 0.17. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Upgrades proTES to FOCA 0.18 and replaces proTES's own copies of features that FOCA now provides, as Cloud Registry did (elixir-cloud-aai/cloud-registry#261). This is the first child of #321 (the plugin engine). The plugin engine itself, the public URL and the backend lists are not part of this PR; they come in #332 to #335.
Closes #331
What changes
foca>=0.18.0,<0.19; base imageelixircloud/foca:0.18.0-py3.13, pinned by digest.custom.access_control.require_adminmoves to FOCA'ssecurity.access_control.require_admin(truein the base config,falseinconfig.dev.yaml). The app refusescustom.access_controlwith a hint, and the chart refusesconfig.custom.access_control.require_adminwith a hint.check_role_groups()andwarn_placeholder_service_info()are deleted.user(check_user_groups()).require_no_service_clients(). FOCA's config validation already refuses aclient_mappingthat isn't for a configured service client.--config python:foca.gunicorn_config, which has the same settings.pro_tes/gunicorn_config.pyand its tests are deleted, andtests/test_image_command.pychecks the image's command.foca.get_custom_config(CustomConfig)replacespro_tes.utils.misc.get_custom_config().exceptions.validation_details: Trueis set explicitly. This is FOCA's new default.mark_changed().mark_changed()after such changes, anddocs/operations.mdtells operators to restart proTES.docs/upgrading.md(Configuration, Authentication, Image),docs/configuration.md(Server),docs/access-control.md,docs/operations.md,docs/reference.md, chart README andvalues.yaml.Breaking changes (for the release notes)
custom.access_control.require_admin→security.access_control.require_admin. The old key stops the app and fails chart rendering. The chart needs images built with FOCA 0.18.foca.gunicorn_config(same settings). Custom commands that loadpro_tes.gunicorn_configmust change.detail(e.g.,'none' is not of type 'array' - 'executors') instead ofThe request is malformed.claim_groupsare now a FOCA startup error.Verification
Local, Python 3.13, FOCA 0.18.0 from PyPI:
coverage run -m pytest(mongomock, Helm 3.19 on PATH, so the chart tests ran too): 1123 passed, 1 skipped; coverage 100%.ruff check,ruff format --check,mypy,ast-grep scanandast-grep test: clean.mkdocs build --strict: clean.pre-commit run --all-files: passed.python -m build: passed.custom.access_control.CI: all checks passed (Lint, Test on mongomock and MongoDB 7.0, Chart, Docs, Smoke test with the FOCA 0.18 image, Scan image, Release readiness, CodeQL, Read the Docs; gate
CI passed).Declined review findings
namespace: ""). This is a new chart feature, not part of the upgrade. Cloud Registry declined it likewise. Follow-up: feat(chart): accept issuer settings #337. The upgrade notes say that the chart doesn't support issuer maps yet.docs/upgrading.mdanddocs/operations.md. It is kept in both places: one is for the upgrade, the other for day-to-day operations.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Adopt FOCA 0.18 throughout proTES, replacing duplicated configuration, validation, startup, and server behavior while documenting the resulting migration requirements.
Enhancements:
security.access_control.require_adminand reject the removedcustom.access_controlconfiguration.Build:
Deployment:
Documentation:
Tests:
Chores: