Skip to content

feat: ask an external AuthZEN decision service - #200

Closed
uniqueg wants to merge 8 commits into
devfrom
feat/199-authzen-decision-service
Closed

uniqueg wants to merge 8 commits into
devfrom
feat/199-authzen-decision-service

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Closes #199

Summary

Adds the authorisation hook of the profile tes-authzen/1, which Poiesis and other TES implementations share. It is off by default; without its settings nothing changes, apart from the two items under "Changes for all deployments".

  • Required claim (tesk.api.authz.required-claim.{name,values,prefixes}): a claim gate (exact name first, then dotted path), enforced as an AND gate before all other rules. tesk.api.authorisation.claim stays the OR grant of the group model.
  • Decision service (tesk.api.authz.decision-service.{url,timeout,claims,credential-file} plus tesk.api.authz.issuer): one OpenID AuthZEN 1.0 Access Evaluation per decision decides CreateTask, GetTask, CancelTask and ListTasks, instead of the group model.
    • The subject comes from the user info, or from a service client's token. The access token is never sent.
    • Get and cancel also ask for missing tasks, so that a missing task and a refused one look the same (404). A refused cancel gives 403 if the caller may get the task.
    • List asks for both task sets, all and own. Page tokens are bound to the set (all: or own:); a token of the other set gives 400.
    • Any failure of the decision service gives 503.
    • URLs are stripped by the shared string rule (steps 1–6, plus steps 0, 2b and 4b). The shared golden file has 36 rows.
    • Startup checks refuse unsafe settings. List settings accept JSON arrays in environment variables.
  • Owners: <iss>|<sub> (for service clients, <iss>|<client ID>), stamped on new tasks as the annotation owner-id whenever the issuer is known. Older tasks get an owner derived from their creator, but only if no service client of another issuer could have created them.
  • OIDC timeout: the new setting tesk.api.auth.oidc.timeout (seconds, default 10) bounds the user info endpoint and the discovery and JWKS calls for service clients.
  • Docs: access control guide (new sections "Required claim" and "Decision service"), configuration reference, API reference (503, page tokens, 404), and upgrade notes for 2.1.0.

Changes for all deployments

  • The user info read timeout drops from 30 s to 10 s, and the service-client issuer timeout rises from 5 s to 10 s. Both are configurable through TESK_API_AUTH_OIDC_TIMEOUT.
  • Client-supplied id, state, creation_time and logs are dropped before the task is stored. TESK already ignored them.

Spec claim checked

"TESK names jobs itself" (marked unverified in the spec) is verified: the task ID is the generated job name, state and creation_time are derived, and logs were already nulled on GET. They are now also dropped before storing (IT case 7b).

Verification

  • mvn clean verify on Java 21 (eclipse-temurin:21-jdk): 18769 unit tests and 157 integration tests passed, all coverage checks met (100% line and branch). DecisionServiceIT covers spec cases 5–19, including 7b, 10b, 11b, 11c, 13 and 13b, with WireMock for the user info endpoint, Kubernetes and the decision service.
  • mvn spotless:apply checkstyle:check on Java 8: BUILD SUCCESS.
  • mkdocs build --strict with docs/requirements.txt: OK.
  • Two review rounds (adversarial and quality reviewers). No high findings. Medium and low findings fixed: docs gaps, the service-client owner ID, a credential with control characters gives 503 instead of 500, the issuer is trimmed, and timeout wiring tests.
  • Harness conformance suite (TES AuthZ harness main 1ba80ab; TESK adapter: jar in a container, kind cluster, mock OIDC issuer, stub/OPA/OpenFGA): 54 passed, 3 skipped, 0 failed. Skipped: case 22 (no per-TES expectation yet), the sub mismatch variant of case 20 (opaque tokens have no sub to compare), and case 21 (user info cache; TESK keeps its per-request lookup).
  • CI: all checks passed (CI passed, Test, Lint, Docs, Smoke test, Scan image, CodeQL).

Declined review findings

  • Move the required-claim gate into an interceptor or filter: declined. All four task endpoints call gate(user) first, and each is covered by controller tests. An interceptor would also run before binding and change status codes for malformed requests, which the docs now describe instead.
  • Rename listTaskmasterJobsOfCreator, whose null means all jobs: declined. The Javadoc says so, there is one call site, and a rename touches several mocks.
  • Split TesAuthz (startup checks, gate, request building): declined for this PR. It is about 470 lines with one responsibility, the profile.
  • Integration test with a service-client token reaching the decision service: declined. Unit tests now assert that ServiceClientTokenServices sets the claims and issuer, and that TesAuthz builds the subject from them (subject_serviceClient).
  • Drop the old constructors without a timeout: declined. They keep about 20 existing tests unchanged and default to 10 s.
  • Fully qualified names in a few tests, and reflection on jose4j fields: declined, style only.

Decisions

  • Owner model with the decision service off: TESK's built-in model keeps owner = creator sub. tesk.api.authz.issuer is part of the spec (§4.2) as a TESK-only key, needed because the user info doesn't name the issuer.
  • User info cache: none. TESK keeps looking up the user info on every request, so a revoked claim takes effect at the next request. The harness runs its cache case only for TESes that declare a cache.
  • Draft: this PR stays a draft until the Poiesis PRs land upstream.

🤖 Generated with Claude Code

Summary by Sourcery

Add optional TES AuthZEN authorization with required-claim gating, issuer-scoped task ownership, and updated authentication behavior while preserving existing defaults when disabled.

New Features:

  • Add optional TES AuthZEN 1.0 authorization using an external decision service for task creation, retrieval, cancellation, and listing.
  • Add an optional required-claim authorization gate that applies before existing authorization rules.
  • Record issuer-scoped task owners and use them for decision-service authorization and own-task listing.

Bug Fixes:

  • Prevent client-supplied task identifiers, states, creation timestamps, and logs from being stored.
  • Make missing and unauthorized tasks indistinguishable under decision-service authorization and return service failures as 503 responses.

Enhancements:

  • Add scoped pagination tokens, sanitized decision-service task projections, configurable credentials, and secure startup validation for authorization settings.
  • Expose caller claims and service-client issuer information to authorization decisions.
  • Provide a shared configurable timeout for user-info, OIDC discovery, and JWKS requests.

Documentation:

  • Document required-claim authorization, AuthZEN decision-service configuration and behavior, owner handling, pagination changes, timeout settings, API responses, and upgrade notes.

Tests:

  • Add unit, integration, URL-sanitization, and conformance-oriented coverage for AuthZEN authorization, claims, owners, service failures, pagination, and OIDC timeouts.

Chores:

  • Verify server-assigned task fields and tighten authorization-related request and credential handling.

uniqueg and others added 5 commits November 16, 2026 15:42
Adds the authorisation hook of the profile tes-authzen/1, as in the
sibling design for Poiesis (JaeAeich/poiesis#113), off by default:

- tesk.api.authz.required-claim.{name,values,prefixes}: a claim rule
  (exact name first, then dotted path), enforced as an AND gate before
  all other rules; tesk.api.authorisation.claim stays the OR grant of
  the group model.
- tesk.api.authz.decision-service.{url,timeout,claims,credential-file}:
  with a URL, one OpenID AuthZEN 1.0 Access Evaluation per decision
  decides create, get, cancel and list instead of the group model. The
  subject comes from the user info (opaque tokens) or the service
  client's token; the token is never sent. Get and cancel ask also for
  missing tasks; list asks for the task sets all and own and binds page
  tokens to the scope (400 on a mismatch). Any failure gives 503.
- tesk.api.authz.issuer: owners <iss>|<sub>, stamped on new tasks as
  the annotation owner-id; older tasks get an owner from their creator
  only if no service client of another issuer can have created them.
- Client-supplied id, state, creation_time and logs are dropped.
- Startup checks refuse unsafe settings; list settings take JSON
  arrays in environment variables.

Closes #199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Documents the required claim and the AuthZEN decision service in the
access control guide (settings, startup checks, what TESK API sends,
404/403/503 answers, page tokens, owners, trust implications), adds
the settings to the configuration reference, and the upgrade notes
for 2.1.0.

Refs #199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds the setting tesk.api.auth.oidc.timeout (seconds, default 10) of
the tes-authzen/1 profile: the connect and read timeout of the user
info endpoint (before: 10 s to connect, 30 s to read) and of the
discovery document and keys of service clients' issuer (before: 5 s).
Values that aren't seconds above 0 stop the app at startup.

Also, from the review: the required claim is checked before the view
is parsed; service clients own their tasks by client ID also if their
token's sub differs; the service-client issuer is trimmed before it is
compared; a credential with control characters, or a request that
can't be built, is a decision-service failure (503), not a 500; the
API reference and access control guide cover 503, scope-bound page
tokens, the view property and owner stamping.

Refs #199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Step 2c of the URL stripping of tes-authzen/1: if nothing comes
between "://" and the first "/", and the rest has an "@" before its
first "?" or "#", the URL is left out, as WHATWG parsers skip the
extra slashes (https:///u:p@h/p sends u:p to h). The golden file is
the shared one, now with 31 rows.

Refs #199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tests that tesk.api.auth.oidc.timeout reaches the clients of the user
info endpoint and of the service clients' issuer, and stops the app
if invalid; names control characters in the credential file messages;
fixes the docs on what gets 400 before the required claim and on when
the timeout setting is checked.

Refs #199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg self-assigned this Nov 16, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add claims and validated issuer data to principals, and define the task-owner annotation used to persist owner IDs.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java L80-93, L98-107, L475-486 (+5 small edits)
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java L121-126

API

Extend task-service authorization entry points for decision-based cancellation and expose the unavailable-decision-service response as HTTP 503.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/exception/AuthorisationUnavailableException.java L1-18
  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesService.java L79-89 (+3 small edits)

Apply the required-claim gate to task endpoints and route cancellation through the decision-aware service path when enabled.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/api/TasksApiController.java L65-74, L99-102 (+5 small edits)

Implementation

Build the AuthZEN subject, action and resource evaluations, enforce the required-claim rule, and handle decisions, owners and service failures.

  • src/main/java/uk/ac/ebi/tsc/tesk/authz/ClaimLookup.java L1-40
  • src/main/java/uk/ac/ebi/tsc/tesk/authz/DecisionServiceClient.java L1-144
  • src/main/java/uk/ac/ebi/tsc/tesk/authz/TaskProjection.java L1-81
  • src/main/java/uk/ac/ebi/tsc/tesk/authz/TesAuthz.java L1-469
  • src/main/java/uk/ac/ebi/tsc/tesk/authz/UrlStripper.java L1-86

Integrate decision checks into task creation, retrieval, cancellation and listing, including owner stamping, legacy-owner derivation, scoped pagination and exact ownership filtering.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapper.java L253-292 (+3 small edits)
  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/ListScope.java L1-49
  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java L216-260, L365-392, L474-489 (+7 small edits)

Configuration

Register the authorization hook and parse its authorization and decision-service settings, including startup validation.

  • src/main/java/uk/ac/ebi/tsc/tesk/authz/AuthzConfiguration.java L1-30
  • src/main/java/uk/ac/ebi/tsc/tesk/authz/AuthzSettings.java L1-164

Make the configurable OIDC timeout govern user-info and service-client issuer requests, and carry validated service-client claims and issuer into principals.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/OidcTimeout.java L1-48
  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/ResourceServerConfiguration.java L139-143 (+4 small edits)
  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/ServiceClientTokenServices.java L134-145, L153-160, L393-397 (+6 small edits)
  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/UserInfoTokenIntrospector.java L5, L46 (removed lines), L65-87

Documentation

Document the required-claim gate, decision-service protocol and trust model, plus OIDC timeout, API status and pagination changes and 2.1.0 upgrade considerations.

  • docs/access-control.md L51, L307-308, L374-496
  • docs/api.md L38-41, L366-368
  • docs/configuration.md L33, L38-39
  • docs/upgrading.md L5-10, L19-38

Tests

Exercise the decision-service workflow end to end, including request construction, authorization outcomes, missing tasks, owner handling and scoped listing.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/DecisionServiceIT.java L1-501

Test authorization settings, claim lookup, decision-service requests, task projections, URL stripping and authorization decisions.

  • src/test/java/uk/ac/ebi/tsc/tesk/authz/AuthzSettingsTest.java L1-114
  • src/test/java/uk/ac/ebi/tsc/tesk/authz/ClaimLookupTest.java L1-58
  • src/test/java/uk/ac/ebi/tsc/tesk/authz/DecisionServiceClientTest.java L1-214
  • src/test/java/uk/ac/ebi/tsc/tesk/authz/TaskProjectionTest.java L1-41
  • src/test/java/uk/ac/ebi/tsc/tesk/authz/TesAuthzTest.java L1-586
  • src/test/java/uk/ac/ebi/tsc/tesk/authz/UrlStripperTest.java L1-74

Verify OIDC timeout parsing and wiring, principal claims and issuer, service-client timeout behavior, and authorization-aware task-service and controller paths.

  • src/test/java/uk/ac/ebi/tsc/tesk/config/TraceInterceptorConfigurationTest.java L47
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/ElixirPrincipalExtractorTest.java L69-71
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/OidcTimeoutSettingTest.java L1-62
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/OidcTimeoutTest.java L1-45
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/ServiceClientTokenServicesTest.java L194-205, L220-222
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserDetailsServiceTest.java L23
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserInfoTokenIntrospectorTest.java L259, L264-283
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapperTest.java L341-354
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/api/TasksApiControllerTest.java L50, L106, L370-416
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/ListScopeTest.java L1-48
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplAuthzTest.java L1-270
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplCancelTest.java L34, L54
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplCreateTest.java L434-489 (+3 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplListTest.java L34, L59
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplSystemLogsTest.java L21, L50

Other changes

Files not grouped.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/ElixirPrincipalExtractor.java L163
  • src/test/resources/authz/hook-create.json L1-132
  • src/test/resources/authz/url-stripping.json L1-182

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 Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3574e56) to head (db49f50).

Additional details and impacted files
@@            Coverage Diff             @@
##               dev      #200    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           53        63    +10     
  Lines         2340      2853   +513     
  Branches       274       364    +90     
==========================================
+ Hits          2340      2853   +513     

☔ 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 and others added 2 commits November 16, 2026 17:57
Step 0 of the URL stripping of tes-authzen/1: a value with a tab,
line feed or carriage return anywhere is left out, as WHATWG parsers
delete them (https://<TAB>/u:p@h/p would send u:p to h). The golden
file is the shared one, now with 34 rows.

Refs #199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Step 4b of the URL stripping of tes-authzen/1 replaces step 2c: after
the user info is dropped and the query and fragment are cut, a value
whose authority is empty and whose path has an "@" is left out
(https:///u:p@h/p, https://x@/u:p@h/p). The golden file is the shared
one, now with 36 rows.

Refs #199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring in #201 (google-java-format update), #202 and #206 (removal of
the /v2/api-docs alias).

Conflicts:
- docs/upgrading.md: both PRs add items to "To 2.1.0"; the removal of
  /v2/api-docs goes first in the list of changes for all deployments.
- KubernetesClientWrapper: #201 only reformatted the creator filter
  that this branch moved into listAllTaskmasterJobsForUser; kept the
  moved version.

Files of this branch reformatted with spotless:apply for #201.

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

uniqueg commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Superseded by the TESK auth redesign: JWT validation in #221 and the access-matrix tests in #223, with the AuthZEN contract now living in elixir-cloud-aai/tes-authz. #199 stays open for its later slice.

@uniqueg uniqueg closed this Nov 25, 2026
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.

feat: ask an external AuthZEN decision service

1 participant