Skip to content

Commit 2ff0233

Browse files
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>
1 parent 2692496 commit 2ff0233

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.env.development.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ RAY_ENABLED=false
2424
# Enable Laravel Telescope for debugging
2525
TELESCOPE_ENABLED=false
2626

27+
# Laravel Horizon Admin Access
28+
# Comma-separated list of email addresses allowed to access /horizon dashboard
29+
# The root user (User ID 0) always has access
30+
# HORIZON_ALLOWED_EMAILS=admin@example.com,devops@example.com
31+
2732
# Enable Laravel Nightwatch monitoring
2833
NIGHTWATCH_ENABLED=false
2934
NIGHTWATCH_TOKEN=

app/Providers/HorizonServiceProvider.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,18 @@ protected function gate(): void
5555
Gate::define('viewHorizon', function ($user) {
5656
$root_user = User::find(0);
5757

58-
return in_array($user->email, [
59-
$root_user->email,
60-
]);
58+
// Get additional allowed emails from environment variable
59+
$allowedEmails = array_filter(
60+
array_map('trim', explode(',', env('HORIZON_ALLOWED_EMAILS', '')))
61+
);
62+
63+
// Merge root user email with additional allowed emails
64+
$authorizedEmails = array_merge(
65+
[$root_user->email],
66+
$allowedEmails
67+
);
68+
69+
return in_array($user->email, $authorizedEmails);
6170
});
6271
}
6372
}

0 commit comments

Comments
 (0)