feat: add configurable Horizon dashboard admin access

Add HORIZON_ALLOWED_EMAILS env var to grant additional users access to
the Horizon dashboard. Root user (User ID 0) always retains access.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Selim Salihovic 2026-03-31 12:05:37 +02:00
parent 2692496726
commit 2ff0233f47
No known key found for this signature in database
GPG key ID: BBB7C4DF42C8579C
2 changed files with 17 additions and 3 deletions

View file

@ -24,6 +24,11 @@ RAY_ENABLED=false
# Enable Laravel Telescope for debugging
TELESCOPE_ENABLED=false
# Laravel Horizon Admin Access
# Comma-separated list of email addresses allowed to access /horizon dashboard
# The root user (User ID 0) always has access
# HORIZON_ALLOWED_EMAILS=admin@example.com,devops@example.com
# Enable Laravel Nightwatch monitoring
NIGHTWATCH_ENABLED=false
NIGHTWATCH_TOKEN=

View file

@ -55,9 +55,18 @@ protected function gate(): void
Gate::define('viewHorizon', function ($user) {
$root_user = User::find(0);
return in_array($user->email, [
$root_user->email,
]);
// Get additional allowed emails from environment variable
$allowedEmails = array_filter(
array_map('trim', explode(',', env('HORIZON_ALLOWED_EMAILS', '')))
);
// Merge root user email with additional allowed emails
$authorizedEmails = array_merge(
[$root_user->email],
$allowedEmails
);
return in_array($user->email, $authorizedEmails);
});
}
}