Skip to content

feat(api-keys): add key profiles and limit customer tokens - #329

Closed
roncodes wants to merge 6 commits into
mainfrom
feat/rider-key-profile
Closed

roncodes wants to merge 6 commits into
mainfrom
feat/rider-key-profile

Conversation

@roncodes

@roncodes roncodes commented Nov 5, 2026

Copy link
Copy Markdown
Member

Summary

Published apps ship an API key that can reach the whole company. This adds an opt-in way to limit a key, so a rider app can carry one that only reaches rider routes.

  • Key profiles: adds a nullable api_credentials.profile column. A key with a profile only reaches the paths listed for it in api.key_profiles, and gets a 403 elsewhere. The first profile is rider: v1/customers, v1/service-quotes and v1/order-configs. An unknown profile allows nothing, so a typo can't leave a key unrestricted.
  • Log-only option: API_KEY_PROFILES_ENFORCE=false only logs what a profile would refuse.
  • Customer tokens: a customer's token used as a Bearer on company routes acts for the whole company. This now logs that use, and refuses it when API_CUSTOMER_TOKENS_ENFORCE=true. v1/customers and v1/socket/token stay allowed.

Production impact

  • Existing keys have no profile and aren't limited.
  • Customer token enforcement is off by default, so the gap stays open until it's switched on. Check the logs for Customer token used outside customer routes. first.
  • Includes a migration that adds one nullable column.

The matching rider routes are a separate change in fleetbase/fleetops, and neither PR needs the other to merge first. There's no console control yet, so a profile is set directly on the credential.

Testing

tests/Unit/Http/MiddlewareContractsTest.php passes, 43 tests including 2 new ones. The full suite wasn't run locally.

Against a local API, a rider key got 403 on places/search, contacts, orders, drivers, webhook endpoints and socket tokens, and a full key still reached contacts, orders and places/search. Enforcing the customer token limit is covered by unit tests only.

Add api_credentials.profile. A key with a profile only reaches the paths
listed for it in config/api.php, and the rider profile covers customer,
service quote and order config routes. Keys with no profile are unchanged,
and an unknown profile allows nothing.

Log customer tokens used as Bearer outside customer routes, and refuse
them when API_CUSTOMER_TOKENS_ENFORCE=true. This is off by default so any
integration relying on it shows up in the logs first.
Composer refuses to install illuminate/mail on Laravel 10 because of
CVE-2026-48019, which has no patch before Laravel 12. Ignore this one
advisory in PHP CI so the tests can run. Production dependencies don't
change. Remove this when the Laravel 12 upgrade lands.
symfony/http-kernel 6.4, the only version Composer will install for
Laravel 10 now, conflicts with var-dumper below 6.3. This is a dev-only
dependency, and production already runs 6.4.
Run the middleware end to end for a key outside its profile and a
customer token on a company route, so both refusals are proven and the
coverage gate is met.
@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6814ed4) to head (3e44db8).

Additional details and impacted files
@@             Coverage Diff             @@
##                main      #329   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity      9600      9609    +9     
===========================================
  Files            519       519           
  Lines          29841     29858   +17     
===========================================
+ Hits           29841     29858   +17     
Flag Coverage Δ
backend 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. 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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add the ledger route that gives a rider the invoice for their own order.
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.

1 participant