fix: bootstrap Passport personal access client - #206
Conversation
|
Thanks for the thorough write-up and the focused tests — the underlying gap is real (fresh prod can have Passport keys + migrations without a Personal Access Client). We're going to close this PR though. A dedicated What we already have:
We've updated the self-hosting docs instead of adding runtime bootstrap. Passport setup is two one-time install steps:
Docs (live):
Those are separate concerns; regenerating keys on every boot (or from a seeder) would invalidate existing tokens, so we intentionally keep them as documented one-time install steps rather than runtime bootstrap code. Appreciate the report — docs were the right fix here. |
|
Closing in favor of documenting the one-time Passport install steps (keys + Personal Access Client) instead of adding runtime bootstrap. |
|
Follow-up: the self-hosting docs are live with the Passport + install steps. |
Summary
This change bootstraps the Laravel Passport Personal Access Client required for API key creation in production Docker deployments.
It adds a focused Artisan command,
trypost:bootstrap-passport, and invokes it from the production entrypoint after database migrations and Passport key initialization.Problem
A fresh production deployment can have:
while still having no Personal Access Client in
oauth_clients.When a user creates an API key from the workspace settings, TryPost calls
User::createToken(...). Laravel Passport then fails with HTTP 500:Reproduction
PassportSeeder.Root cause
TryPost already contains
Database\Seeders\PassportSeeder, and the mainDatabaseSeederincludes it.However, the production Docker entrypoint runs migrations and prepares Passport keys without running the focused Passport seeder.
As a result, the application can start successfully while
User::createToken(...)remains unusable because no active Personal Access Client exists.Solution
This pull request:
trypost:bootstrap-passportArtisan command;Database\Seeders\PassportSeeder;DatabaseSeeder;|| true;Idempotency and concurrency
The bootstrap is designed to be safe across repeated and concurrent production starts.
It:
reuses an existing active Personal Access Client;
supports valid clients with either a
nullprovider or theusersprovider;does not create duplicates during repeated starts;
does not revoke or replace valid clients;
does not invalidate existing access tokens;
creates a new valid client when only revoked clients exist;
serializes concurrent bootstrap attempts using:
GET_LOCK.Locks are released after execution, including failure paths.
Testing
Full test suite
The full suite was executed against a dedicated local PostgreSQL test database. No production database or production credentials were used.
Focused bootstrap tests
Related API key tests
Additional checks
git diff --check: passed;bash -n docker/entrypoint.sh: passed;The local test environment used a dedicated PostgreSQL database named
trypost_testand isolated Passport test keys. No production environment was involved.Backward compatibility
Existing installations with a valid Personal Access Client remain unchanged.
This change does not:
Scope
This pull request only addresses Passport Personal Access Client bootstrap during production Docker startup.
It does not include:
Risk
The risk is low and limited to production startup.
The entrypoint now fails explicitly when Passport bootstrap cannot complete. This is preferable to allowing the application to start successfully while API key creation remains broken with an HTTP 500 error.
Rollback
Rollback consists of reverting this commit.
Any Personal Access Client already created remains valid, and existing clients and tokens are not modified by the rollback.
Reviewer notes
The main review points are:
trypost:bootstrap-passportArtisan command;