Skip to content

Allow project key to be used for bencher run like API calls - #845

Merged
epompeii merged 3 commits into
develfrom
u/ep/project-key-parity
May 15, 2026
Merged

epompeii merged 3 commits into
develfrom
u/ep/project-key-parity

Conversation

@epompeii

Copy link
Copy Markdown
Member

This changeset updates API endpoints that have the same capabilities as a call to bencher run to accept a project key. For example, the /v0/run endpoint can create benchmarks. Therefore the endpoint to create a benchmark (POST) has been updated to accept a project key.

All operations permitted with a project key are non-destructive. Archiving is reversible. Branch Start Points, Testbed Specs, and Threshold Models are all stored for historical reference with their prior Reports. Dimension renames are not allowed with the project key.

@github-actions

github-actions Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Claude Code Review

PR: #845
Base: devel
Head: u/ep/project-key-parity
Commit: 975f118d0289f4651f16b0c2895bd8c2a11009b7


I've reviewed the full diff. Here's my review:


PR Review: Project Key Authentication for Write Endpoints

Summary

This PR extends project key authentication from read-only (GET) endpoints to write endpoints (POST/PATCH/PUT) across branches, benchmarks, testbeds, measures, thresholds, alerts, and reports. Project keys can now create resources and perform limited updates, with restrictions on renaming. It also refactors UpdateAlert and silence_all to use injected DateTime (clock) instead of DateTime::now().

Positive

  • Good test coverage: Comprehensive integration tests for all new capabilities and negative cases (cross-project, rename restrictions, revoked keys).
  • Proper use of Clock/DateTime: Replaces DateTime::now() calls with context.clock.now() and DateTime::TEST in tests, following the project's deterministic time guidelines.
  • Consistent pattern: All write endpoints follow the same BearerToken -> PubProjectBearerToken -> ApiActor::from_token() conversion pattern.
  • ProjectKeyActor::verify_project(): Good DRY refactor consolidating the project-matching check into one reusable method.
  • is_rename() methods: Use struct destructuring to ensure the compiler flags new fields — follows the CLAUDE.md guidance on exhaustive destructuring.

Issues

1. Security: is_allowed_actor_auth skips RBAC permission checks for project keys

lib/bencher_schema/src/model/project/mod.rs:507-513 — The ProjectKey arm of is_allowed_actor_auth only verifies the project ID and rate limiting. It ignores the permission parameter entirely. This means a project key requesting Permission::Create or Permission::Edit goes through the exact same code path — the permission level is not validated. While project keys are currently scoped to a single project so there's arguably an implicit "full access" model, the function signature accepting permission is misleading. If the intent is that project keys get all permissions on their project, this design decision should be documented. If not, this is a privilege escalation gap.

2. Security: No DELETE restriction on project keys

The PR grants project keys Create and Edit access but doesn't appear to address whether project keys could also be used with Permission::Delete through is_allowed_actor_auth. If any DELETE endpoint is ever wired to use PubProjectBearerToken + is_allowed_actor_auth, project keys would silently gain delete access. Consider either:

  • Adding explicit permission allowlisting for project keys, or
  • Documenting that project keys are intentionally full-access.

3. JsonUpdateAlert::is_status_only() is trivially always true

lib/bencher_json/src/project/alert.rs:117-120 — This method destructures self but ignores the only field (status: _) and unconditionally returns true. While the exhaustive destructuring ensures a compiler error if fields are added (good), the method name is misleading — it doesn't actually check whether the update is status-only; it asserts that JsonUpdateAlert can only ever contain status. A comment or a different name (e.g., something that reads as a compile-time assertion) would clarify intent. Right now it reads like a runtime check that does nothing.

4. Inconsistency: Threshold update (PUT) has no field restriction

Benchmarks, branches, testbeds, and measures all restrict project keys from renaming (is_rename() checks). But proj_threshold_put has no such guard. Thresholds don't have a name/slug to rename, so this may be correct — but it's worth noting the asymmetry. The alert endpoint also has a restriction (is_status_only), making threshold the only write endpoint without a project-key restriction guard. If thresholds gain restricted fields later, there's no compiler-enforced reminder to add the check.

5. Rate limiting inconsistency in is_allowed_actor_pub vs is_allowed_actor_auth

lib/bencher_schema/src/model/project/mod.rs:462-465 — In is_allowed_actor_pub, rate limiting is only applied when api_actor.is_auth(), meaning project keys on public read endpoints skip rate limiting. In contrast, is_allowed_actor_auth (line 511) does rate-limit project keys. This inconsistency could allow project-key holders to make unlimited read requests while being rate-limited on writes. If intentional, it should be documented; if not, project key reads should also be rate-limited.

6. Missing test: project key cannot perform non-status alert updates

There's a test for project_key_can_dismiss_alert but no negative test verifying that a project key is rejected when attempting a non-status-only alert update. Currently JsonUpdateAlert only has status, so this is impossible to trigger, but a test would catch regressions if fields are added.

7. Minor: removed blank lines between permission check and query

Several files (benchmarks.rs, branches.rs, measures.rs, testbeds.rs) remove the blank line between the is_allowed_actor_auth call and the next query. This is cosmetic but reduces readability slightly by making the authorization boundary less visually distinct.

Nit

  • with_token_hint is still imported in benchmarks.rs, measures.rs, and testbeds.rs but no longer used in those files (only with_auth_hint is used). The compiler will catch this, but it suggests the import cleanup was incomplete.

Verdict

The core approach is sound — project keys gaining write access with restrictions is a reasonable feature. The main concern is the silent RBAC bypass in is_allowed_actor_auth (issue #1), which should be either validated or explicitly documented as intentional. The rate-limiting inconsistency (#5) should also be addressed.


Model: claude-opus-4-6

@github-actions

github-actions Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchu/ep/project-key-parity
Testbedintel-v1
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
Adapter::Json📈 view plot
🚷 view threshold
4.51 µs
(-0.91%)Baseline: 4.55 µs
4.73 µs
(95.24%)
Adapter::Magic (JSON)📈 view plot
🚷 view threshold
4.48 µs
(+1.20%)Baseline: 4.43 µs
4.61 µs
(97.17%)
Adapter::Magic (Rust)📈 view plot
🚷 view threshold
25.49 µs
(+0.38%)Baseline: 25.40 µs
26.25 µs
(97.12%)
Adapter::Rust📈 view plot
🚷 view threshold
3.44 µs
(-0.29%)Baseline: 3.45 µs
3.54 µs
(97.23%)
Adapter::RustBench📈 view plot
🚷 view threshold
3.45 µs
(-0.03%)Baseline: 3.45 µs
3.53 µs
(97.64%)
🐰 View full continuous benchmarking report in Bencher

@epompeii
epompeii merged commit 11d186b into devel May 15, 2026
62 checks passed
@epompeii
epompeii deleted the u/ep/project-key-parity branch May 15, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant