Skip to content

Modern Docker Management, Designed for Everyone

fix: standard users able to perform admin only actions (#1344)

Kyle Mendell9ed1a18fb6cb
diff --git a/backend/internal/huma/handlers/apikeys.go b/backend/internal/huma/handlers/apikeys.go
index c1d9d2fc8..6ed30749d 100644
--- a/backend/internal/huma/handlers/apikeys.go
+++ b/backend/internal/huma/handlers/apikeys.go
@@ -152,8 +152,8 @@ func (h *ApiKeyHandler) ListApiKeys(ctx context.Context, input *ListApiKeysInput
}
// Check admin access
- if !humamw.IsAdminFromContext(ctx) {
- return nil, huma.Error403Forbidden("admin access required")
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
}
params := pagination.QueryParams{
@@ -202,8 +202,8 @@ func (h *ApiKeyHandler) CreateApiKey(ctx context.Context, input *CreateApiKeyInp
}
// Check admin access
- if !humamw.IsAdminFromContext(ctx) {
- return nil, huma.Error403Forbidden("admin access required")
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
}
apiKey, err := h.apiKeyService.CreateApiKey(ctx, user.ID, input.Body)
@@ -226,8 +226,8 @@ func (h *ApiKeyHandler) GetApiKey(ctx context.Context, input *GetApiKeyInput) (*
}
// Check admin access
- if !humamw.IsAdminFromContext(ctx) {
- return nil, huma.Error403Forbidden("admin access required")
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
}
apiKey, err := h.apiKeyService.GetApiKey(ctx, input.ID)
@@ -250,8 +250,8 @@ func (h *ApiKeyHandler) UpdateApiKey(ctx context.Context, input *UpdateApiKeyInp
}
// Check admin access
- if !humamw.IsAdminFromContext(ctx) {
- return nil, huma.Error403Forbidden("admin access required")
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
}
apiKey, err := h.apiKeyService.UpdateApiKey(ctx, input.ID, input.Body)
@@ -277,8 +277,8 @@ func (h *ApiKeyHandler) DeleteApiKey(ctx context.Context, input *DeleteApiKeyInp
}
// Check admin access
- if !humamw.IsAdminFromContext(ctx) {
- return nil, huma.Error403Forbidden("admin access required")
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
}
if err := h.apiKeyService.DeleteApiKey(ctx, input.ID); err != nil {
diff --git a/backend/internal/huma/handlers/container_registries.go b/backend/internal/huma/handlers/container_registries.go
index 8d0c57963..276a29395 100644
--- a/backend/internal/huma/handlers/container_registries.go
+++ b/backend/internal/huma/handlers/container_registries.go
@@ -230,6 +230,10 @@ func (h *ContainerRegistryHandler) CreateRegistry(ctx context.Context, input *Cr
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
reg, err := h.registryService.CreateRegistry(ctx, input.Body)
if err != nil {
apiErr := models.ToAPIError(err)
@@ -280,6 +284,10 @@ func (h *ContainerRegistryHandler) UpdateRegistry(ctx context.Context, input *Up
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
reg, err := h.registryService.UpdateRegistry(ctx, input.ID, input.Body)
if err != nil {
apiErr := models.ToAPIError(err)
@@ -305,6 +313,10 @@ func (h *ContainerRegistryHandler) DeleteRegistry(ctx context.Context, input *De
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if err := h.registryService.DeleteRegistry(ctx, input.ID); err != nil {
apiErr := models.ToAPIError(err)
return nil, huma.NewError(apiErr.HTTPStatus(), (&common.RegistryDeletionError{Err: err}).Error())
@@ -326,6 +338,10 @@ func (h *ContainerRegistryHandler) TestRegistry(ctx context.Context, input *Test
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
reg, err := h.registryService.GetRegistryByID(ctx, input.ID)
if err != nil {
apiErr := models.ToAPIError(err)
@@ -358,6 +374,10 @@ func (h *ContainerRegistryHandler) SyncRegistries(ctx context.Context, input *Sy
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if err := h.registryService.SyncRegistries(ctx, input.Body.Registries); err != nil {
apiErr := models.ToAPIError(err)
return nil, huma.NewError(apiErr.HTTPStatus(), (&common.RegistrySyncError{Err: err}).Error())
diff --git a/backend/internal/huma/handlers/customize.go b/backend/internal/huma/handlers/customize.go
index 086c8c46c..f60d86ec2 100644
--- a/backend/internal/huma/handlers/customize.go
+++ b/backend/internal/huma/handlers/customize.go
@@ -7,6 +7,7 @@ import (
"github.com/danielgtaylor/huma/v2"
"github.com/getarcaneapp/arcane/backend/internal/common"
+ humamw "github.com/getarcaneapp/arcane/backend/internal/huma/middleware"
"github.com/getarcaneapp/arcane/backend/internal/services"
"github.com/getarcaneapp/arcane/types/category"
"github.com/getarcaneapp/arcane/types/search"
@@ -78,6 +79,17 @@ func (h *CustomizeHandler) Search(ctx context.Context, input *SearchCustomizeInp
results := h.customizeSearchService.Search(input.Body.Query)
+ if !humamw.IsAdminFromContext(ctx) {
+ filtered := []category.Category{}
+ for _, cat := range results.Results {
+ if cat.ID != "registries" && cat.ID != "variables" {
+ filtered = append(filtered, cat)
+ }
+ }
+ results.Results = filtered
+ results.Count = len(filtered)
+ }
+
return &SearchCustomizeOutput{
Body: results,
}, nil
@@ -91,6 +103,16 @@ func (h *CustomizeHandler) GetCategories(ctx context.Context, input *GetCustomiz
categories := h.customizeSearchService.GetCustomizeCategories()
+ if !humamw.IsAdminFromContext(ctx) {
+ filtered := []category.Category{}
+ for _, cat := range categories {
+ if cat.ID != "registries" && cat.ID != "variables" {
+ filtered = append(filtered, cat)
+ }
+ }
+ categories = filtered
+ }
+
return &GetCustomizeCategoriesOutput{
Body: categories,
}, nil
diff --git a/backend/internal/huma/handlers/environments.go b/backend/internal/huma/handlers/environments.go
index 27688c6ee..10cee4361 100644
--- a/backend/internal/huma/handlers/environments.go
+++ b/backend/internal/huma/handlers/environments.go
@@ -376,6 +376,10 @@ func (h *EnvironmentHandler) CreateEnvironment(ctx context.Context, input *Creat
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
user, exists := humamw.GetCurrentUserFromContext(ctx)
if !exists {
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
@@ -514,6 +518,10 @@ func (h *EnvironmentHandler) UpdateEnvironment(ctx context.Context, input *Updat
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
isLocalEnv := input.ID == localDockerEnvironmentID
updates := h.buildUpdateMap(&input.Body, isLocalEnv)
@@ -601,6 +609,10 @@ func (h *EnvironmentHandler) DeleteEnvironment(ctx context.Context, input *Delet
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if input.ID == localDockerEnvironmentID {
return nil, huma.Error400BadRequest((&common.LocalEnvironmentDeletionError{}).Error())
}
@@ -631,6 +643,10 @@ func (h *EnvironmentHandler) TestConnection(ctx context.Context, input *TestConn
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
var apiUrl *string
if input.Body != nil {
apiUrl = input.Body.ApiUrl
@@ -683,6 +699,10 @@ func (h *EnvironmentHandler) PairAgent(ctx context.Context, input *PairAgentInpu
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if input.ID != localDockerEnvironmentID {
return nil, huma.Error404NotFound("Not found")
}
@@ -712,6 +732,10 @@ func (h *EnvironmentHandler) SyncRegistries(ctx context.Context, input *SyncRegi
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if err := h.environmentService.SyncRegistriesToEnvironment(ctx, input.ID); err != nil {
return nil, huma.Error500InternalServerError((&common.RegistrySyncError{Err: err}).Error())
}
@@ -858,6 +882,10 @@ func (h *EnvironmentHandler) GetDeploymentSnippets(ctx context.Context, input *G
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
env, err := h.environmentService.GetEnvironmentByID(ctx, input.ID)
if err != nil {
return nil, huma.Error404NotFound("Environment not found")
diff --git a/backend/internal/huma/handlers/events.go b/backend/internal/huma/handlers/events.go
index 0ae5a415d..ec9590d4c 100644
--- a/backend/internal/huma/handlers/events.go
+++ b/backend/internal/huma/handlers/events.go
@@ -142,6 +142,10 @@ func (h *EventHandler) ListEvents(ctx context.Context, input *ListEventsInput) (
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
params := buildPaginationParams(0, input.Start, input.Limit, input.Sort, input.Order, input.Search)
if input.Severity != "" {
@@ -177,6 +181,10 @@ func (h *EventHandler) GetEventsByEnvironment(ctx context.Context, input *GetEve
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if input.EnvironmentID == "" {
return nil, huma.Error400BadRequest((&common.EnvironmentIDRequiredError{}).Error())
}
@@ -216,6 +224,10 @@ func (h *EventHandler) CreateEvent(ctx context.Context, input *CreateEventInput)
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
evt, err := h.eventService.CreateEventFromDto(ctx, input.Body)
if err != nil {
return nil, huma.Error500InternalServerError((&common.EventCreationError{Err: err}).Error())
@@ -235,6 +247,10 @@ func (h *EventHandler) DeleteEvent(ctx context.Context, input *DeleteEventInput)
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if input.EventID == "" {
return nil, huma.Error400BadRequest((&common.EventIDRequiredError{}).Error())
}
diff --git a/backend/internal/huma/handlers/helpers.go b/backend/internal/huma/handlers/helpers.go
index a99cb392c..673265fb1 100644
--- a/backend/internal/huma/handlers/helpers.go
+++ b/backend/internal/huma/handlers/helpers.go
@@ -1,9 +1,21 @@
package handlers
import (
+ "context"
+
+ "github.com/danielgtaylor/huma/v2"
+ humamw "github.com/getarcaneapp/arcane/backend/internal/huma/middleware"
"github.com/getarcaneapp/arcane/backend/internal/utils/pagination"
)
+// checkAdmin checks if the current user is an admin and returns a 403 error if not.
+func checkAdmin(ctx context.Context) error {
+ if !humamw.IsAdminFromContext(ctx) {
+ return huma.Error403Forbidden("admin access required")
+ }
+ return nil
+}
+
// buildPaginationParams converts query parameters to pagination.QueryParams.
// It supports both the legacy nested style (page/limit) and the standard style (start/limit).
func buildPaginationParams(page, start, limit int, sortCol, sortDir, search string) pagination.QueryParams {
diff --git a/backend/internal/huma/handlers/notifications.go b/backend/internal/huma/handlers/notifications.go
index 1c72727f0..c9b04b8a2 100644
--- a/backend/internal/huma/handlers/notifications.go
+++ b/backend/internal/huma/handlers/notifications.go
@@ -168,6 +168,9 @@ func RegisterNotifications(api huma.API, notificationSvc *services.NotificationS
}
func (h *NotificationHandler) GetAllNotificationSettings(ctx context.Context, input *GetAllNotificationSettingsInput) (*GetAllNotificationSettingsOutput, error) {
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
settings, err := h.notificationService.GetAllSettings(ctx)
if err != nil {
return nil, huma.Error500InternalServerError((&common.NotificationSettingsListError{Err: err}).Error())
@@ -187,6 +190,9 @@ func (h *NotificationHandler) GetAllNotificationSettings(ctx context.Context, in
}
func (h *NotificationHandler) GetNotificationSettings(ctx context.Context, input *GetNotificationSettingsInput) (*GetNotificationSettingsOutput, error) {
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
provider := models.NotificationProvider(input.Provider)
settings, err := h.notificationService.GetSettingsByProvider(ctx, provider)
@@ -205,6 +211,9 @@ func (h *NotificationHandler) GetNotificationSettings(ctx context.Context, input
}
func (h *NotificationHandler) CreateOrUpdateNotificationSettings(ctx context.Context, input *CreateOrUpdateNotificationSettingsInput) (*CreateOrUpdateNotificationSettingsOutput, error) {
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
provider := models.NotificationProvider(input.Body.Provider)
if provider != models.NotificationProviderDiscord && provider != models.NotificationProviderEmail {
return nil, huma.Error400BadRequest((&common.InvalidNotificationProviderError{}).Error())
@@ -231,6 +240,9 @@ func (h *NotificationHandler) CreateOrUpdateNotificationSettings(ctx context.Con
}
func (h *NotificationHandler) DeleteNotificationSettings(ctx context.Context, input *DeleteNotificationSettingsInput) (*DeleteNotificationSettingsOutput, error) {
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
provider := models.NotificationProvider(input.Provider)
if err := h.notificationService.DeleteSettings(ctx, provider); err != nil {
@@ -246,6 +258,9 @@ func (h *NotificationHandler) DeleteNotificationSettings(ctx context.Context, in
}
func (h *NotificationHandler) TestNotification(ctx context.Context, input *TestNotificationInput) (*TestNotificationOutput, error) {
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
provider := models.NotificationProvider(input.Provider)
if err := h.notificationService.TestNotification(ctx, provider, input.Type); err != nil {
@@ -261,6 +276,9 @@ func (h *NotificationHandler) TestNotification(ctx context.Context, input *TestN
}
func (h *NotificationHandler) GetAppriseSettings(ctx context.Context, input *GetAppriseSettingsInput) (*GetAppriseSettingsOutput, error) {
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
settings, err := h.appriseService.GetSettings(ctx)
if err != nil {
return nil, huma.Error404NotFound((&common.AppriseSettingsNotFoundError{}).Error())
@@ -278,6 +296,9 @@ func (h *NotificationHandler) GetAppriseSettings(ctx context.Context, input *Get
}
func (h *NotificationHandler) CreateOrUpdateAppriseSettings(ctx context.Context, input *CreateOrUpdateAppriseSettingsInput) (*CreateOrUpdateAppriseSettingsOutput, error) {
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
if input.Body.Enabled && input.Body.APIURL == "" {
return nil, huma.Error400BadRequest("API URL is required when Apprise is enabled")
}
@@ -305,6 +326,9 @@ func (h *NotificationHandler) CreateOrUpdateAppriseSettings(ctx context.Context,
}
func (h *NotificationHandler) TestAppriseNotification(ctx context.Context, input *TestAppriseNotificationInput) (*TestAppriseNotificationOutput, error) {
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
if err := h.appriseService.TestNotification(ctx); err != nil {
return nil, huma.Error500InternalServerError((&common.AppriseTestError{Err: err}).Error())
}
diff --git a/backend/internal/huma/handlers/settings.go b/backend/internal/huma/handlers/settings.go
index 5497f9edc..b278515ab 100644
--- a/backend/internal/huma/handlers/settings.go
+++ b/backend/internal/huma/handlers/settings.go
@@ -10,6 +10,7 @@ import (
"github.com/danielgtaylor/huma/v2"
"github.com/getarcaneapp/arcane/backend/internal/common"
"github.com/getarcaneapp/arcane/backend/internal/config"
+ humamw "github.com/getarcaneapp/arcane/backend/internal/huma/middleware"
"github.com/getarcaneapp/arcane/backend/internal/services"
"github.com/getarcaneapp/arcane/backend/internal/utils/mapper"
"github.com/getarcaneapp/arcane/types/base"
@@ -189,6 +190,8 @@ func (h *SettingsHandler) GetSettings(ctx context.Context, input *GetSettingsInp
return nil, huma.Error500InternalServerError("service not available")
}
+ isAdmin := humamw.IsAdminFromContext(ctx)
+
if input.EnvironmentID != "0" {
if h.environmentService == nil {
return nil, huma.Error500InternalServerError("environment service not available")
@@ -207,7 +210,7 @@ func (h *SettingsHandler) GetSettings(ctx context.Context, input *GetSettingsInp
return &GetSettingsOutput{Body: settingsDto}, nil
}
- showAll := input.EnvironmentID == "0"
+ showAll := isAdmin
settingsList := h.settingsService.ListSettings(showAll)
var settingsDto []settings.PublicSetting
@@ -235,6 +238,10 @@ func (h *SettingsHandler) UpdateSettings(ctx context.Context, input *UpdateSetti
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if input.EnvironmentID != "0" {
if h.environmentService == nil {
return nil, huma.Error500InternalServerError("environment service not available")
@@ -303,6 +310,10 @@ func (h *SettingsHandler) Search(ctx context.Context, input *SearchSettingsInput
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if strings.TrimSpace(input.Body.Query) == "" {
return nil, huma.Error400BadRequest((&common.QueryParameterRequiredError{}).Error())
}
@@ -317,6 +328,10 @@ func (h *SettingsHandler) GetCategories(ctx context.Context, input *struct{}) (*
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
categories := h.settingsSearchService.GetSettingsCategories()
return &GetCategoriesOutput{Body: categories}, nil
}
diff --git a/backend/internal/huma/handlers/system.go b/backend/internal/huma/handlers/system.go
index 82bb49710..9d444eb99 100644
--- a/backend/internal/huma/handlers/system.go
+++ b/backend/internal/huma/handlers/system.go
@@ -319,6 +319,10 @@ func (h *SystemHandler) PruneAll(ctx context.Context, input *PruneAllInput) (*Pr
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
slog.InfoContext(ctx, "System prune operation initiated",
"containers", input.Body.Containers,
"images", input.Body.Images,
@@ -354,6 +358,10 @@ func (h *SystemHandler) StartAllContainers(ctx context.Context, input *StartAllC
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
result, err := h.systemService.StartAllContainers(ctx)
if err != nil {
return nil, huma.Error500InternalServerError((&common.ContainerStartAllError{Err: err}).Error())
@@ -373,6 +381,10 @@ func (h *SystemHandler) StartAllStoppedContainers(ctx context.Context, input *St
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
result, err := h.systemService.StartAllStoppedContainers(ctx)
if err != nil {
return nil, huma.Error500InternalServerError((&common.ContainerStartStoppedError{Err: err}).Error())
@@ -392,6 +404,10 @@ func (h *SystemHandler) StopAllContainers(ctx context.Context, input *StopAllCon
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
result, err := h.systemService.StopAllContainers(ctx)
if err != nil {
return nil, huma.Error500InternalServerError((&common.ContainerStopAllError{Err: err}).Error())
@@ -437,6 +453,10 @@ func (h *SystemHandler) CheckUpgradeAvailable(ctx context.Context, input *CheckU
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
canUpgrade, err := h.upgradeService.CanUpgrade(ctx)
if err != nil {
slog.Debug("System upgrade check failed", "error", err)
@@ -464,6 +484,10 @@ func (h *SystemHandler) TriggerUpgrade(ctx context.Context, input *TriggerUpgrad
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
user, exists := humamw.GetCurrentUserFromContext(ctx)
if !exists {
return nil, huma.Error401Unauthorized((&common.NotAuthenticatedError{}).Error())
diff --git a/backend/internal/huma/handlers/users.go b/backend/internal/huma/handlers/users.go
index ef75fb885..efd0a2085 100644
--- a/backend/internal/huma/handlers/users.go
+++ b/backend/internal/huma/handlers/users.go
@@ -158,6 +158,10 @@ func (h *UserHandler) ListUsers(ctx context.Context, input *ListUsersInput) (*Li
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
params := buildPaginationParams(0, input.Start, input.Limit, input.Sort, input.Order, input.Search)
users, paginationResp, err := h.userService.ListUsersPaginated(ctx, params)
@@ -186,6 +190,10 @@ func (h *UserHandler) CreateUser(ctx context.Context, input *CreateUserInput) (*
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
hashedPassword, err := h.userService.HashPassword(input.Body.Password)
if err != nil {
return nil, huma.Error500InternalServerError((&common.PasswordHashError{Err: err}).Error())
@@ -231,6 +239,10 @@ func (h *UserHandler) GetUser(ctx context.Context, input *GetUserInput) (*GetUse
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
userModel, err := h.userService.GetUserByID(ctx, input.UserID)
if err != nil {
return nil, huma.Error404NotFound((&common.UserNotFoundError{}).Error())
@@ -255,6 +267,10 @@ func (h *UserHandler) UpdateUser(ctx context.Context, input *UpdateUserInput) (*
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
userModel, err := h.userService.GetUserByID(ctx, input.UserID)
if err != nil {
return nil, huma.Error404NotFound((&common.UserNotFoundError{}).Error())
@@ -308,6 +324,10 @@ func (h *UserHandler) DeleteUser(ctx context.Context, input *DeleteUserInput) (*
return nil, huma.Error500InternalServerError("service not available")
}
+ if err := checkAdmin(ctx); err != nil {
+ return nil, err
+ }
+
if err := h.userService.DeleteUser(ctx, input.UserID); err != nil {
return nil, huma.Error500InternalServerError((&common.UserDeletionError{Err: err}).Error())
}
diff --git a/backend/internal/huma/middleware/auth.go b/backend/internal/huma/middleware/auth.go
index fe7dde6bf..d4218e676 100644
--- a/backend/internal/huma/middleware/auth.go
+++ b/backend/internal/huma/middleware/auth.go
@@ -238,6 +238,17 @@ func setUserInContext(ctx context.Context, user *models.User) context.Context {
return ctx
}
+// RequireAdmin is a Huma middleware that ensures the current user is an admin.
+func RequireAdmin(api huma.API) func(ctx huma.Context, next func(huma.Context)) {
+ return func(ctx huma.Context, next func(huma.Context)) {
+ if !IsAdminFromContext(ctx.Context()) {
+ _ = huma.WriteErr(api, ctx, http.StatusForbidden, "Forbidden: admin access required")
+ return
+ }
+ next(ctx)
+ }
+}
+
func userHasRole(user *models.User, role string) bool {
for _, r := range user.Roles {
if r == role {
diff --git a/frontend/src/lib/components/quick-actions.svelte b/frontend/src/lib/components/quick-actions.svelte
index 4ec6dd570..955c17e62 100644
--- a/frontend/src/lib/components/quick-actions.svelte
+++ b/frontend/src/lib/components/quick-actions.svelte
@@ -5,6 +5,7 @@
import type { DockerInfo } from '$lib/types/docker-info.type';
import { StartIcon, StopIcon, TrashIcon } from '$lib/icons';
import { cn } from '$lib/utils';
+ import type { User } from '$lib/types/user.type';
type IsLoadingFlags = {
starting: boolean;
@@ -13,6 +14,7 @@
};
let {
+ user = null,
dockerInfo,
stoppedContainers,
runningContainers,
@@ -26,6 +28,7 @@
compact = false,
class: className
}: {
+ user?: User | null;
dockerInfo: DockerInfo | null;
stoppedContainers: number;
runningContainers: number;
@@ -42,42 +45,46 @@
const isAnyActionLoading = $derived(isLoading.starting || isLoading.stopping || isLoading.pruning);
- const actionButtons: ActionButton[] = $derived([
- {
- id: 'start-all',
- action: 'start_all',
- label: m.quick_actions_start_all(),
- onclick: onStartAll,
- loading: isLoading.starting,
- disabled: !dockerInfo || stoppedContainers === 0 || isAnyActionLoading,
- badge: stoppedContainers
- },
- {
- id: 'stop-all',
- action: 'stop_all',
- label: m.quick_actions_stop_all(),
- onclick: onStopAll,
- loading: isLoading.stopping,
- disabled: !dockerInfo || (dockerInfo?.ContainersRunning ?? 0) === 0 || isAnyActionLoading,
- badge: runningContainers
- },
- {
- id: 'prune',
- action: 'prune',
- label: m.quick_actions_prune_system(),
- onclick: onOpenPruneDialog,
- loading: isLoading.pruning,
- disabled: !dockerInfo || isAnyActionLoading
- },
- {
- id: 'refresh',
- action: 'refresh',
- label: m.common_refresh(),
- onclick: onRefresh,
- loading: refreshing,
- disabled: isAnyActionLoading || refreshing
- }
- ]);
+ const currentUserIsAdmin = $derived(!!user?.roles?.includes('admin'));
+
+ const actionButtons: ActionButton[] = $derived(
+ [
+ {
+ id: 'start-all',
+ action: 'start_all' as const,
+ label: m.quick_actions_start_all(),
+ onclick: onStartAll,
+ loading: isLoading.starting,
+ disabled: !dockerInfo || stoppedContainers === 0 || isAnyActionLoading,
+ badge: stoppedContainers
+ },
+ {
+ id: 'stop-all',
+ action: 'stop_all' as const,
+ label: m.quick_actions_stop_all(),
+ onclick: onStopAll,
+ loading: isLoading.stopping,
+ disabled: !dockerInfo || (dockerInfo?.ContainersRunning ?? 0) === 0 || isAnyActionLoading,
+ badge: runningContainers
+ },
+ {
+ id: 'prune',
+ action: 'prune' as const,
+ label: m.quick_actions_prune_system(),
+ onclick: onOpenPruneDialog,
+ loading: isLoading.pruning,
+ disabled: !dockerInfo || isAnyActionLoading
+ },
+ {
+ id: 'refresh',
+ action: 'refresh' as const,
+ label: m.common_refresh(),
+ onclick: onRefresh,
+ loading: refreshing,
+ disabled: isAnyActionLoading || refreshing
+ }
+ ].filter((b) => currentUserIsAdmin || b.id === 'refresh')
+ );
</script>
<section class={cn(compact ? 'flex min-w-0 flex-1 items-center justify-end' : '', className)}>
@@ -92,7 +99,7 @@
{:else}
<ActionButtonGroup buttons={actionButtons} />
{/if}
- {:else}
+ {:else if currentUserIsAdmin}
<h2 class="mb-3 text-lg font-semibold tracking-tight">{m.quick_actions_title()}</h2>
{#if loadingDockerInfo}
diff --git a/frontend/src/lib/stores/user-store.ts b/frontend/src/lib/stores/user-store.ts
index 2a9c0a978..e8ddf208e 100644
--- a/frontend/src/lib/stores/user-store.ts
+++ b/frontend/src/lib/stores/user-store.ts
@@ -1,5 +1,5 @@
import type { User } from '$lib/types/user.type';
-import { writable } from 'svelte/store';
+import { writable, get } from 'svelte/store';
import { setLocale } from '$lib/utils/locale.util';
const userStore = writable<User | null>(null);
@@ -15,8 +15,14 @@ const clearUser = () => {
userStore.set(null);
};
+const isAdmin = () => {
+ const user = get(userStore);
+ return !!user?.roles?.includes('admin');
+};
+
export default {
subscribe: userStore.subscribe,
setUser,
- clearUser
+ clearUser,
+ isAdmin
};
diff --git a/frontend/src/lib/utils/redirect.util.ts b/frontend/src/lib/utils/redirect.util.ts
index e4c6bc3be..efed3c49b 100644
--- a/frontend/src/lib/utils/redirect.util.ts
+++ b/frontend/src/lib/utils/redirect.util.ts
@@ -1,52 +1,50 @@
import type { User } from '$lib/types/user.type';
const PROTECTED_PREFIXES = [
- 'dashboard',
- 'compose',
- 'containers',
- 'customize',
- 'events',
- 'environments',
- 'images',
- 'volumes',
- 'networks',
- 'settings'
+ '/dashboard',
+ '/compose',
+ '/containers',
+ '/customize',
+ '/events',
+ '/environments',
+ '/images',
+ '/volumes',
+ '/networks',
+ '/settings'
];
-const escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
-const PROTECTED_RE = new RegExp(`^/(?:${PROTECTED_PREFIXES.map(escapeRe).join('|')})(?:/.*)?$`);
+const UNAUTHENTICATED_ONLY_PREFIXES = ['/login', '/oidc/login', '/oidc/callback', '/auth/oidc/callback', '/img', '/favicon.ico'];
-const isProtectedPath = (path: string) => {
- const result = PROTECTED_RE.test(path);
- return result;
-};
+const ADMIN_ONLY_PREFIXES = ['/settings', '/events', '/customize/registries', '/customize/variables'];
+
+/**
+ * Checks if a path matches a prefix exactly or as a parent directory
+ */
+const matchesAny = (path: string, prefixes: string[]) =>
+ prefixes.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
export function getAuthRedirectPath(path: string, user: User | null) {
const isSignedIn = !!user;
+ const isAdmin = user?.roles.includes('admin');
+
+ // 1. Handle root path
+ if (path === '/') {
+ return isSignedIn ? '/dashboard' : '/login';
+ }
- const isUnauthenticatedOnlyPath =
- path === '/login' ||
- path.startsWith('/login/') ||
- path === '/oidc/login' ||
- path.startsWith('/oidc/login') ||
- path === '/oidc/callback' ||
- path.startsWith('/oidc/callback') ||
- path === '/auth/oidc/callback' ||
- path.startsWith('/auth/oidc/callback') ||
- path === '/img' ||
- path.startsWith('/img') ||
- path === '/favicon.ico';
-
- if (!isSignedIn && isProtectedPath(path)) {
+ // 2. Redirect unauthenticated users away from protected areas
+ if (!isSignedIn && matchesAny(path, PROTECTED_PREFIXES)) {
return '/login';
}
- if (isUnauthenticatedOnlyPath && isSignedIn) {
+ // 3. Redirect signed-in users away from login/auth pages
+ if (isSignedIn && matchesAny(path, UNAUTHENTICATED_ONLY_PREFIXES)) {
return '/dashboard';
}
- if (path === '/') {
- return isSignedIn ? '/dashboard' : '/login';
+ // 4. Redirect non-admins away from restricted management areas
+ if (isSignedIn && !isAdmin && matchesAny(path, ADMIN_ONLY_PREFIXES)) {
+ return '/dashboard';
}
return null;
diff --git a/frontend/src/routes/(app)/dashboard/+page.svelte b/frontend/src/routes/(app)/dashboard/+page.svelte
index 18cc0ba6c..626f909eb 100644
--- a/frontend/src/routes/(app)/dashboard/+page.svelte
+++ b/frontend/src/routes/(app)/dashboard/+page.svelte
@@ -284,6 +284,7 @@
<QuickActions
class="min-w-0 flex-1"
compact
+ user={data.user}
{dockerInfo}
{stoppedContainers}
{runningContainers}
diff --git a/frontend/src/routes/(app)/environments/+page.svelte b/frontend/src/routes/(app)/environments/+page.svelte
index f3ce22535..a02fb723b 100644
--- a/frontend/src/routes/(app)/environments/+page.svelte
+++ b/frontend/src/routes/(app)/environments/+page.svelte
@@ -29,6 +29,8 @@
);
}
+ const currentUserIsAdmin = $derived(!!data.user?.roles?.includes('admin'));
+
async function handleBulkDelete() {
if (selectedIds.length === 0) return;
@@ -79,7 +81,7 @@
}
const actionButtons: ActionButton[] = $derived([
- ...(selectedIds.length > 0
+ ...(selectedIds.length > 0 && currentUserIsAdmin
? [
{
id: 'remove-selected',
@@ -91,12 +93,16 @@
}
]
: []),
- {
- id: 'create',
- action: 'create' as const,
- label: m.common_add_button({ resource: m.resource_environment_cap() }),
- onclick: () => (showEnvironmentSheet = true)
- },
+ ...(currentUserIsAdmin
+ ? [
+ {
+ id: 'create',
+ action: 'create' as const,
+ label: m.common_add_button({ resource: m.resource_environment_cap() }),
+ onclick: () => (showEnvironmentSheet = true)
+ }
+ ]
+ : []),
{
id: 'refresh',
action: 'restart' as const,