diff --git a/internal/acl/acl.go b/internal/acl/acl.go index 22891be..b7ac489 100644 --- a/internal/acl/acl.go +++ b/internal/acl/acl.go @@ -33,6 +33,10 @@ type AuthenticatedUser struct { acls []string } +func (u *AuthenticatedUser) IsGuest() bool { + return u.Username == "guest" && u.Provider == "system" +} + func logAclNotMatched(cfg *config.Config, aclFunction string, user *AuthenticatedUser, action *config.Action, acl *config.AccessControlList) { if cfg.LogDebugOptions.AclNotMatched { log.WithFields(log.Fields{ @@ -162,6 +166,7 @@ func UserFromContext(ctx context.Context, cfg *config.Config) *AuthenticatedUser "username": ret.Username, "usergroup": ret.Usergroup, "provider": ret.Provider, + "acls": ret.acls, }).Debugf("UserFromContext") return ret diff --git a/internal/config/config.go b/internal/config/config.go index 7655992..ace2bce 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -117,7 +117,7 @@ type Config struct { AuthHttpHeaderUserGroup string AuthLocalUsers AuthLocalUsersConfig AuthLoginUrl string - AuthAllowGuest bool + AuthRequireGuestsToLogin bool AuthOAuth2RedirectURL string AuthOAuth2Providers map[string]*OAuth2Provider DefaultPermissions PermissionsList @@ -214,7 +214,7 @@ func DefaultConfigWithBasePort(basePort int) *Config { config.DefaultPermissions.Logs = true config.AuthJwtClaimUsername = "name" config.AuthJwtClaimUserGroup = "group" - config.AuthAllowGuest = true + config.AuthRequireGuestsToLogin = false config.WebUIDir = "./webui" config.CronSupportForSeconds = false config.SectionNavigationStyle = "sidebar" diff --git a/internal/config/config_reloader.go b/internal/config/config_reloader.go index 0a34add..a536605 100644 --- a/internal/config/config_reloader.go +++ b/internal/config/config_reloader.go @@ -36,6 +36,14 @@ func Reload(cfg *Config) { os.Exit(1) } + if cfg.AuthRequireGuestsToLogin { + log.Infof("AuthRequireGuestsToLogin is enabled. All defaultPermissions will be set to false") + + cfg.DefaultPermissions.View = false + cfg.DefaultPermissions.Exec = false + cfg.DefaultPermissions.Logs = false + } + metricConfigReloadedCount.Inc() metricConfigActionCount.Set(float64(len(cfg.Actions))) diff --git a/internal/grpcapi/grpcApi.go b/internal/grpcapi/grpcApi.go index 17df0a0..1b23549 100644 --- a/internal/grpcapi/grpcApi.go +++ b/internal/grpcapi/grpcApi.go @@ -296,6 +296,10 @@ func (api *oliveTinAPI) Logout(ctx ctx.Context, req *pb.LogoutRequest) (*httpbod func (api *oliveTinAPI) GetDashboardComponents(ctx ctx.Context, req *pb.GetDashboardComponentsRequest) (*pb.GetDashboardComponentsResponse, error) { user := acl.UserFromContext(ctx, cfg) + if user.IsGuest() && cfg.AuthRequireGuestsToLogin { + return nil, status.Errorf(codes.PermissionDenied, "Guests are not allowed to access the dashboard.") + } + res := buildDashboardResponse(api.executor, cfg, user) if len(res.Actions) == 0 { @@ -306,13 +310,6 @@ func (api *oliveTinAPI) GetDashboardComponents(ctx ctx.Context, req *pb.GetDashb dashboardCfgToPb(res, cfg.Dashboards, cfg) - res.AuthenticatedUser = user.Username - res.AuthenticatedUserProvider = user.Provider - - if res.AuthenticatedUser == "guest" && !cfg.AuthAllowGuest { - return nil, status.Errorf(codes.PermissionDenied, "Unauthenticated") - } - return res, nil } diff --git a/internal/grpcapi/grpcApiActions.go b/internal/grpcapi/grpcApiActions.go index 2ccbef2..d4bae59 100644 --- a/internal/grpcapi/grpcApiActions.go +++ b/internal/grpcapi/grpcApiActions.go @@ -10,7 +10,10 @@ import ( ) func buildDashboardResponse(ex *executor.Executor, cfg *config.Config, user *acl.AuthenticatedUser) *pb.GetDashboardComponentsResponse { - res := &pb.GetDashboardComponentsResponse{} + res := &pb.GetDashboardComponentsResponse{ + AuthenticatedUser: user.Username, + AuthenticatedUserProvider: user.Provider, + } ex.MapActionIdToBindingLock.RLock() diff --git a/webui.dev/index.html b/webui.dev/index.html index e5008c8..a3cf646 100644 --- a/webui.dev/index.html +++ b/webui.dev/index.html @@ -164,7 +164,7 @@