Skip to content

fix: read entitlements from eduperson_entitlement - #39

Merged
uniqueg merged 4 commits into
devfrom
fix/37-eduperson-entitlement
Nov 17, 2026
Merged

uniqueg merged 4 commits into
devfrom
fix/37-eduperson-entitlement

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

The node read entitlements only from the user info claim entitlements. LS Login released them to other clients of the same issuer in eduperson_entitlement (generic-issues#46), so account A could be refused with refused: entitlement, which looks exactly like a missing group release in T3.

  • New setting TESTBED_ENTITLEMENT_CLAIMS (comma-separated, default entitlements,eduperson_entitlement, mock and LS Login). The node takes the union of the values, in order, without repeats; a string counts as one value.
  • The node's report names the configured claims that were present, even if empty (entitlements.claims, entitlement_claims in the session's rows).
  • A claim of another type is skipped and named in entitlements_error; null counts as absent. The node allows only if a well-formed claim holds the entitlement, otherwise 502 if a claim couldn't be read, else 403 (still fails closed).
  • discovery also shows scopes_supported and claims_supported, so that T1 records which entitlement scope and claim LS Login advertises.
  • Docs: configuration, lslogin.env.example, assumptions (what gi#46 observed, that both claims are trusted equally, and to narrow the setting after T3), T1 (record the advertised scopes and claims), T3 (record the claim and scope; one login with the scope eduperson_entitlement if user info shows neither claim), client registration, troubleshooting, design, command reference.

Must be merged before the live LS Login session on Thursday 19 November.

Verification

  • pytest: 253 passed, coverage 100%. The regression tests cover values only in eduperson_entitlement, only in entitlements, in both (union, no duplicates), a single string, neither (403), one malformed claim with the entitlement in the other (200) and without (502), null as absent, a custom setting, settings parsing, discovery fields and session rows.
  • pre-commit run --all-files: all hooks passed except gitleaks and actionlint, which were skipped locally (their Go toolchain can't be downloaded in the sandbox; no workflow changed). CI runs them.
  • mkdocs build --strict: passed.
  • End-to-end tests (docker compose run --rm e2e): not run locally (no Docker in this setup); CI runs them.
  • Reviews: adversarial and quality reviewers, two rounds. Round 1 mediums (a malformed claim discarded the other claim's values; missing docs and row test) and round 2 findings were fixed.
  • CI: all checks passed (Lint, Test, Docs, End-to-end tests, CI passed, Read the Docs), run 44192200192.

Declined review findings

  • Rename the first commit's subject (quality, low): it is 49 characters and says what the fix does.
  • Factor the error results of _entitlements into a helper (quality, low): four short literals, kept readable as they are.
  • Split the review-fix commit into fix and docs (quality, low): it changes one behaviour together with its docs and tests.
  • Sourcery: "unassigned users gain access" via eduperson_entitlement (high), "alternate claim scope is never requested" (high), "empty claims appear as sources" (medium): answered in their threads; the union and the default scope follow the plan of fix: read entitlements from eduperson_entitlement too #37, the trust question is documented in the assumptions, and a present but empty claim is what T3 needs to see.

Open questions

None.

Closes #37

🤖 Generated with Claude Code

uniqueg and others added 4 commits November 17, 2026 22:43
The node read entitlements only from the user info claim
`entitlements`, as the operator's docs say. LS Login released them to
other clients of the same issuer in `eduperson_entitlement`
(generic-issues#46). The node would then refuse account A with
`refused: entitlement`, which looks exactly like a missing group
release in T3.

The node now reads every claim in `TESTBED_ENTITLEMENT_CLAIMS`
(default `entitlements,eduperson_entitlement`) and takes the union of
their values. Its report names the claims it found
(`entitlement_claims` in the session's rows), and `discovery` shows
`scopes_supported` and `claims_supported`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document `TESTBED_ENTITLEMENT_CLAIMS` (configuration, template), what
generic-issues#46 observed, and what T1 and T3 record: the entitlement
scopes and claims the provider lists, the claim and scope the values
came with, and a one-off login with the scope `eduperson_entitlement`
if user info shows neither claim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A claim of another type made the whole result an error, so a user
whose entitlement was in the other claim got 502. Now such a claim is
skipped and named in `error`, `null` counts as absent, and `claims` is
in every result. Document the behaviour, the trust in both claims, and
the claim fields of `discovery` and `call` (review findings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A skipped claim now shows as `entitlements_error` on an allowed
request, too. Say so in troubleshooting and the command reference, test
that the session's rows carry it, and update the policy's docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@uniqueg uniqueg added this to the BioHackEU26 milestone Nov 17, 2026
@uniqueg uniqueg self-assigned this Nov 17, 2026
@read-the-docs-community

Copy link
Copy Markdown

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define the default entitlement claim names and add the setting field that carries the configured claims for other code to use.

  • src/testbed/settings.py L29-31, L66-67, L83

API

Expose which entitlement claims supplied values in hop rows and include supported scopes and claims in discovery output.

  • src/testbed/session.py L132, L674-675

Implementation

Read and union configured user-info claims, report malformed claims without discarding valid values, and treat incomplete reads as unknown rather than denying access.

  • src/testbed/service.py L113-118, L130-158 (+2 small edits)

Configuration

Parse and apply TESTBED_ENTITLEMENT_CLAIMS for mock and LS Login settings, defaulting to both known claim names.

  • lslogin.env.example L34-37
  • src/testbed/settings.py L155, L180-201, L248

Documentation

Document the configurable claim sources, the provider behavior that motivated them, how T1 and T3 verify releases, and how to interpret reports and troubleshoot entitlement outcomes.

  • docs/about/commands.md L51, L57-59
  • docs/setup/client-registration.md L27-28, L85
  • docs/setup/configuration.md L31
  • docs/setup/troubleshooting.md L33-37
  • docs/testbed/assumptions.md L55, L83-84
  • docs/testbed/design.md L39
  • docs/tests/t1-call-chain.md L29, L127
  • docs/tests/t3-groups.md L36-42, L110-111

Tests

Cover claim-source unions, malformed and absent claims, custom configuration, and the additional session and discovery fields.

  • tests/test_services.py L423-555
  • tests/test_session.py L103-116, L677-689
  • tests/test_settings.py L85-110

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

@uniqueg
uniqueg marked this pull request as ready for review November 17, 2026 22:44
@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit c79ad70

#37 fix: read entitlements from eduperson_entitlement too · 7 of 7 met

# Requirement Status Notes
1 Read entitlements from every claim in TESTBED_ENTITLEMENT_CLAIMS, defaulting to entitlements,eduperson_entitlement for mock and LS Login; take the union in order without repeats, with a string counting as one value. ✅ Met Both settings loaders use the shared parser, and _entitlements reads configured claims, treats strings as single values, and deduplicates while preserving order.
2 Show which claim the entitlement values came from in the node report and session rows. ✅ Met The node report includes entitlements.claims, and hop_rows exposes it as entitlement_claims.
3 Show scopes_supported and claims_supported in discovery for T1. ✅ Met Both fields are included in the discovery result and have a session test.
4 Test values in either claim, their union without duplicates, neither claim, and a non-list value in one claim. ✅ Met The service tests cover those cases, as well as a single-string value, null, and malformed-claim behavior when the other claim does or does not hold the entitlement.
5 Document the setting and the observed eduperson_entitlement claim, including the trust in both claims and narrowing the setting after T3; update T1 to record advertised entitlement scopes and claims. ✅ Met The configuration, LS Login example, assumptions, design, and T1 documentation cover these points.
6 In T3, record the claim and scope that supplied the entitlement, and try the eduperson_entitlement scope once if user info shows neither claim. ✅ Met T3 documents the alternate-scope login and asks testers to record the claim, scope, and whether the registration allows it.
7 The node allows account A whichever of the two claims LS Login uses, and CI passes. ✅ Met The node checks values from both default claims, with tests for each claim; the PR description reports CI passing.

@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="src/testbed/settings.py" line_range="31" />
<code_context>
 TARGET_PARAMS = ("audience", "resource", "resource-url", "both")
+# The claim of AARC-G069 and the operator's Entitlements page, and the one that
+# LS Login released to other clients of the same issuer
+ENTITLEMENT_CLAIMS = ("entitlements", "eduperson_entitlement")


</code_context>
<issue_to_address>
**Unassigned users gain access**

When LS Login populates `eduperson_entitlement` from home-organisation attributes with the configured required value, without that value representing the user's resource-group assignment, `Service._entitlements` unions that value with the other configured claims, and `_apply_policy` grants access when the union contains the required entitlement, so a user without the required Perun group gets access to the node.

Restrict policy matching to entitlements tied to the user's resource-group assignment instead of treating `eduperson_entitlement` values as sufficient.

Also at `src/testbed/service.py:154`.
</issue_to_address>

### Comment 2
<location path="src/testbed/settings.py" line_range="31" />
<code_context>
 TARGET_PARAMS = ("audience", "resource", "resource-url", "both")
+# The claim of AARC-G069 and the operator's Entitlements page, and the one that
+# LS Login released to other clients of the same issuer
+ENTITLEMENT_CLAIMS = ("entitlements", "eduperson_entitlement")


</code_context>
<issue_to_address>
**Alternate claim scope is never requested**

When LS Login gates `eduperson_entitlement` on requesting the `eduperson_entitlement` scope, `DEFAULT_SCOPE` in `src/testbed/session.py:43` requests `entitlements` but not `eduperson_entitlement`, and the login parser uses it by default at line 211. When LS Login releases `eduperson_entitlement` only for its matching scope, the new claim reader receives no values and account A still gets refused for a missing entitlement.

Request the alternate scope by default where appropriate, or expose and document a setting that ensures the login and exchange request the scope required for the configured claim.
</issue_to_address>

### Comment 3
<location path="src/testbed/service.py" line_range="153" />
<code_context>
+            ):
+                invalid.append(name)
+                continue
+            sources.append(name)
+            values.update(dict.fromkeys(found))
+        result: dict[str, Any] = {"values": list(values), "claims": sources}
</code_context>
<issue_to_address>
**Empty claims appear as sources**

When a configured user-info claim is a well-formed empty list, `_entitlements` adds its name to `sources` before checking whether it contributed values, so `claims` and downstream `entitlement_claims` report a source with no entitlements, misleading operators and callers.

Only add a claim to `sources` when its list contains values.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and by default, the node treats eduperson_entitlement as equally trusted with entitlements, so a value in that claim can satisfy the access policy and grant access. If that claim does not have the intended group semantics, reverting stops future grants but cannot undo data already accessed; the default trust decision has no built-in signal that it was wrong.

Blocking findings: src/testbed/settings.py:31, src/testbed/settings.py:31, src/testbed/service.py:153


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

Comment thread src/testbed/settings.py Resolved
Comment thread src/testbed/settings.py Resolved
Comment thread src/testbed/service.py Resolved
@uniqueg
uniqueg merged commit c8208dc into dev Nov 17, 2026
7 checks passed
@uniqueg
uniqueg deleted the fix/37-eduperson-entitlement branch November 17, 2026 23:24
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.

fix: read entitlements from eduperson_entitlement too

1 participant