Skip to content

feat(auth): enforce role annotation coverage at service startup - #5743

Merged
Yicong-Huang merged 19 commits into
apache:mainfrom
Ma77Ball:enforce-role-annotation-coverage
Jun 24, 2026
Merged

Yicong-Huang merged 19 commits into
apache:mainfrom
Ma77Ball:enforce-role-annotation-coverage

Conversation

@Ma77Ball

@Ma77Ball Ma77Ball commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

  • Add RoleAnnotationEnforcer in common/auth: a pure, reflection-based check whose findUnannotatedEndpoints flags every HTTP-mapped resource method (detected generically via the JAX-RS @HttpMethod meta-annotation, covering GET/POST/PUT/DELETE/PATCH/HEAD/OPTIONS and custom verbs) that lacks @RolesAllowed/@PermitAll/@DenyAll at either the method or its resource class.
  • Wire all five fix: enforce @RolesAllowed on microservice resources #5199 microservices (config, access-control, computing-unit-managing, workflow-compiling, file) to call enforceRoleAnnotations(environment) once every resource has been registered in run(), reading the live Jersey ResourceConfig; an unannotated endpoint now logs and throws IllegalStateException so the service fails to boot instead of exposing a silent public endpoint.
  • Add RoleAnnotationEnforcerSpec for the enforcer logic plus a per-service guard test (over each service's real registered resources) so a forgotten annotation fails in CI without needing a full boot.
  • Scope is the five microservices only; amber is intentionally left out because its pre-existing endpoints are not all annotated yet and would fail the check (a separate cleanup).

Any related issues, documentation, discussions?

Closes: #5742

How was this PR tested?

  • Run sbt "Auth/testOnly *RoleAnnotationEnforcerSpec", expect 16 cases green. Coverage of findUnannotatedEndpoints: all-annotated passes; an unannotated @GET is flagged; class-level annotation covers methods; @PermitAll/@DenyAll accepted; non-HTTP methods ignored; no resources returns empty; holes across multiple resources reported as fully-qualified Class#method; verbs beyond GET/POST/DELETE (@PUT/@PATCH/@HEAD/@OPTIONS) detected via the @HttpMethod meta-annotation; a security annotation inherited from a superclass method counts as covered; a subclass class-level annotation covers an inherited endpoint; an inherited unannotated endpoint is flagged against the scanned subclass; duplicate resources are de-duplicated. Coverage of enforce: throws (message names the service and offending method, and lists every offender) and does not throw on clean input or empty input. Verified locally.
  • Run sbt "ConfigService/testOnly *ConfigServiceRunSpec" (and the equivalent AccessControlService/ComputingUnitManagingService/WorkflowCompilingService/FileService RunSpecs); expect the new "registered resources should all declare access control" guard to pass, confirming each service's real endpoints are fully annotated.
  • Reviewer check for the regression: drop a new @GET with no role annotation onto any wired resource and start the service (or run that service's RunSpec); expect an IllegalStateException naming Class#method and a failed boot.
  • Local environment limitation: this machine runs JDK 25, where the repo's existing Mockito *RunSpec cases cannot mock JerseyEnvironment and file-service tests hit a JaCoCo 0.8.11 instrumentation crash on an unrelated class; these are pre-existing toolchain issues (baseline fails identically) and run on CI's supported JDK. The new non-mock guard tests were verified locally for config/access-control/computing-unit-managing/workflow-compiling.

Was this PR authored or co-authored using generative AI tooling?

Co-authored with Claude Opus 4.8 in compliance with ASF

@github-actions github-actions Bot added common platform Non-amber Scala service paths labels Jun 16, 2026
@codecov-commenter

codecov-commenter commented Jun 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.86486% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.58%. Comparing base (1c580e5) to head (0b2dc2d).

Files with missing lines Patch % Lines
.../texera/service/ComputingUnitManagingService.scala 0.00% 4 Missing ⚠️
...ache/texera/service/WorkflowCompilingService.scala 0.00% 4 Missing ⚠️
...cala/org/apache/texera/service/ConfigService.scala 0.00% 2 Missing ⚠️
.../scala/org/apache/texera/service/FileService.scala 0.00% 2 Missing ⚠️
...rg/apache/texera/auth/RoleAnnotationEnforcer.scala 94.44% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5743      +/-   ##
============================================
- Coverage     54.60%   54.58%   -0.02%     
+ Complexity     2927     2925       -2     
============================================
  Files          1109     1111       +2     
  Lines         42828    42837       +9     
  Branches       4608     4611       +3     
============================================
- Hits          23385    23383       -2     
- Misses        18081    18088       +7     
- Partials       1362     1366       +4     
Flag Coverage Δ *Carryforward flag
access-control-service 70.00% <100.00%> (-0.45%) ⬇️
agent-service 34.36% <ø> (ø) Carriedforward from 1c580e5
amber 56.76% <95.65%> (+0.03%) ⬆️
computing-unit-managing-service 0.00% <0.00%> (-1.66%) ⬇️
config-service 51.56% <0.00%> (-5.80%) ⬇️
file-service 59.02% <0.00%> (+0.42%) ⬆️
frontend 48.31% <ø> (ø) Carriedforward from 1c580e5
pyamber 90.20% <ø> (ø) Carriedforward from 1c580e5
python 90.76% <ø> (ø) Carriedforward from 1c580e5
workflow-compiling-service 55.14% <0.00%> (-3.55%) ⬇️

*This pull request uses carry forward flags. 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:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 0 better · 🔴 5 worse · ⚪ 10 noise (<±5%) · 0 without baseline

Compared against main 1c580e5 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 389 0.237 24,888/40,334/40,334 us 🔴 +11.1% / 🔴 +15.3%
⚪ bs=100 sw=10 sl=64 800 0.488 122,157/146,244/146,244 us ⚪ within ±5% / 🔴 -10.4%
⚪ bs=1000 sw=10 sl=64 926 0.565 1,080,422/1,116,583/1,116,583 us ⚪ within ±5% / 🔴 -11.1%
Baseline details

Latest main 1c580e5 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 389 tuples/sec 414 tuples/sec 410.82 tuples/sec -6.0% -5.3%
bs=10 sw=10 sl=64 MB/s 0.237 MB/s 0.252 MB/s 0.251 MB/s -6.0% -5.5%
bs=10 sw=10 sl=64 p50 24,888 us 22,411 us 23,785 us +11.1% +4.6%
bs=10 sw=10 sl=64 p95 40,334 us 37,449 us 34,980 us +7.7% +15.3%
bs=10 sw=10 sl=64 p99 40,334 us 37,449 us 34,980 us +7.7% +15.3%
bs=100 sw=10 sl=64 throughput 800 tuples/sec 819 tuples/sec 891.94 tuples/sec -2.3% -10.3%
bs=100 sw=10 sl=64 MB/s 0.488 MB/s 0.5 MB/s 0.544 MB/s -2.4% -10.4%
bs=100 sw=10 sl=64 p50 122,157 us 120,488 us 112,277 us +1.4% +8.8%
bs=100 sw=10 sl=64 p95 146,244 us 142,223 us 139,802 us +2.8% +4.6%
bs=100 sw=10 sl=64 p99 146,244 us 142,223 us 139,802 us +2.8% +4.6%
bs=1000 sw=10 sl=64 throughput 926 tuples/sec 901 tuples/sec 1,041 tuples/sec +2.8% -11.0%
bs=1000 sw=10 sl=64 MB/s 0.565 MB/s 0.55 MB/s 0.635 MB/s +2.7% -11.1%
bs=1000 sw=10 sl=64 p50 1,080,422 us 1,115,675 us 972,714 us -3.2% +11.1%
bs=1000 sw=10 sl=64 p95 1,116,583 us 1,166,961 us 1,023,057 us -4.3% +9.1%
bs=1000 sw=10 sl=64 p99 1,116,583 us 1,166,961 us 1,023,057 us -4.3% +9.1%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,514.17,200,128000,389,0.237,24888.17,40333.51,40333.51
1,100,10,64,20,2499.14,2000,1280000,800,0.488,122157.13,146244.45,146244.45
2,1000,10,64,20,21604.50,20000,12800000,926,0.565,1080422.05,1116582.64,1116582.64

@Ma77Ball
Ma77Ball marked this pull request as ready for review June 21, 2026 02:52
@Ma77Ball

Copy link
Copy Markdown
Contributor Author

/request-review @aglinxinyuan

@github-actions
github-actions Bot requested a review from aglinxinyuan June 21, 2026 06:52
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @Yicong-Huang
    You can notify them by mentioning @Yicong-Huang in a comment.

@Ma77Ball
Ma77Ball force-pushed the enforce-role-annotation-coverage branch from 89cc561 to 53bf102 Compare June 22, 2026 08:35
@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Jun 22, 2026
@Ma77Ball
Ma77Ball requested a review from Yicong-Huang June 22, 2026 10:46

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a shared auth startup safeguard to ensure every JAX-RS HTTP endpoint in the five Dropwizard microservices explicitly declares access control, failing service boot if any endpoint is left unintentionally public.

Changes:

  • Introduces RoleAnnotationEnforcer (reflection-based scan of HTTP-mapped methods) and wires it into service startup after resource registration.
  • Centralizes common Dropwizard/Jersey auth registrations into AuthFeatures.register(environment) and updates services to use it.
  • Adds unit tests for the enforcer and per-service “all registered resources declare access control” guard tests.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
common/auth/src/main/scala/org/apache/texera/auth/RoleAnnotationEnforcer.scala Implements reflection-based detection of unannotated HTTP endpoints and enforcement (log + throw).
common/auth/src/main/scala/org/apache/texera/auth/AuthFeatures.scala Adds a shared helper to register the standard JWT/auth stack across services.
common/auth/src/test/scala/org/apache/texera/auth/RoleAnnotationEnforcerSpec.scala Adds coverage for endpoint scanning/enforcement behavior (including ResourceConfig overload).
common/auth/src/test/scala/org/apache/texera/auth/AuthFeaturesSpec.scala Verifies shared auth feature registrations once (instead of per-service).
common/auth/build.sbt Adds provided deps for Dropwizard/Jersey types and Mockito for the new tests.
config-service/src/main/scala/org/apache/texera/service/ConfigService.scala Uses AuthFeatures.register and enforces role-annotation coverage at startup.
config-service/src/test/scala/org/apache/texera/service/ConfigServiceRunSpec.scala Replaces auth-registration mock test with “resources must be access-controlled” guard.
access-control-service/src/main/scala/org/apache/texera/service/AccessControlService.scala Uses AuthFeatures.register and enforces role-annotation coverage at startup.
access-control-service/src/test/scala/org/apache/texera/service/AccessControlServiceRunSpec.scala Keeps run-time registration assertions and adds resource access-control guard.
computing-unit-managing-service/src/main/scala/org/apache/texera/service/ComputingUnitManagingService.scala Uses AuthFeatures.register and enforces role-annotation coverage at startup.
computing-unit-managing-service/src/test/scala/org/apache/texera/service/ComputingUnitManagingServiceRunSpec.scala Replaces auth-registration mock test with resource access-control guard.
workflow-compiling-service/src/main/scala/org/apache/texera/service/WorkflowCompilingService.scala Uses AuthFeatures.register and enforces role-annotation coverage at startup.
workflow-compiling-service/src/test/scala/org/apache/texera/service/WorkflowCompilingServiceRunSpec.scala Replaces auth-registration mock test with resource access-control guard.
file-service/src/main/scala/org/apache/texera/service/FileService.scala Uses AuthFeatures.register and enforces role-annotation coverage at startup.
file-service/src/test/scala/org/apache/texera/service/FileServiceRunSpec.scala Adds a new resource access-control guard test for file-service.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Yicong-Huang
Yicong-Huang added this pull request to the merge queue Jun 24, 2026
Merged via the queue into apache:main with commit 71fce70 Jun 24, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common dependencies Pull requests that update a dependency file platform Non-amber Scala service paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce @RolesAllowed / @PermitAll / @DenyAll annotation coverage at service startup

4 participants