From 2e0fdb2a6050b5429dead6fc87855ac76abcc4a2 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Thu, 11 Sep 2025 12:05:39 +0100 Subject: [PATCH] Frontend Service: Pass static config needed for login to index bootData (#110829) add almost all config needed for login --- pkg/services/frontend/index.go | 43 ++++++++++++++++++++++++++++++-- pkg/services/frontend/index.html | 15 ++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/pkg/services/frontend/index.go b/pkg/services/frontend/index.go index 18b422c987b..76508052cf6 100644 --- a/pkg/services/frontend/index.go +++ b/pkg/services/frontend/index.go @@ -6,6 +6,7 @@ import ( "fmt" "html/template" "net/http" + "strings" "syscall" "github.com/grafana/grafana-app-sdk/logging" @@ -33,7 +34,9 @@ type IndexViewData struct { BuildCommit string AppTitle string - Assets dtos.EntryPointAssets // Includes CDN info + Assets dtos.EntryPointAssets // Includes CDN info + Settings dtos.FrontendSettingsDTO + DefaultUser dtos.CurrentUser // Nonce is a cryptographic identifier for use with Content Security Policy. Nonce string @@ -54,6 +57,40 @@ func NewIndexProvider(cfg *setting.Cfg, assetsManifest dtos.EntryPointAssets) (* return nil, fmt.Errorf("missing index template") } + // subset of frontend settings needed for the login page + // TODO what about enterprise settings here? + frontendSettings := dtos.FrontendSettingsDTO{ + AnalyticsConsoleReporting: cfg.FrontendAnalyticsConsoleReporting, + AnonymousEnabled: cfg.Anonymous.Enabled, + ApplicationInsightsConnectionString: cfg.ApplicationInsightsConnectionString, + ApplicationInsightsEndpointUrl: cfg.ApplicationInsightsEndpointUrl, + AuthProxyEnabled: cfg.AuthProxy.Enabled, + AutoAssignOrg: cfg.AutoAssignOrg, + CSPReportOnlyEnabled: cfg.CSPReportOnlyEnabled, + DisableLoginForm: cfg.DisableLoginForm, + DisableUserSignUp: !cfg.AllowUserSignUp, + GoogleAnalytics4Id: cfg.GoogleAnalytics4ID, + GoogleAnalytics4SendManualPageViews: cfg.GoogleAnalytics4SendManualPageViews, + GoogleAnalyticsId: cfg.GoogleAnalyticsID, + GrafanaJavascriptAgent: cfg.GrafanaJavascriptAgent, + Http2Enabled: cfg.Protocol == setting.HTTP2Scheme, + JwtHeaderName: cfg.JWTAuth.HeaderName, + JwtUrlLogin: cfg.JWTAuth.URLLogin, + LdapEnabled: cfg.LDAPAuthEnabled, + LoginHint: cfg.LoginHint, + PasswordHint: cfg.PasswordHint, + ReportingStaticContext: cfg.ReportingStaticContext, + RudderstackConfigUrl: cfg.RudderstackConfigURL, + RudderstackDataPlaneUrl: cfg.RudderstackDataPlaneURL, + RudderstackIntegrationsUrl: cfg.RudderstackIntegrationsURL, + RudderstackSdkUrl: cfg.RudderstackSDKURL, + RudderstackWriteKey: cfg.RudderstackWriteKey, + TrustedTypesDefaultPolicyEnabled: (cfg.CSPEnabled && strings.Contains(cfg.CSPTemplate, "require-trusted-types-for")) || (cfg.CSPReportOnlyEnabled && strings.Contains(cfg.CSPReportOnlyTemplate, "require-trusted-types-for")), + VerifyEmailEnabled: cfg.VerifyEmailEnabled, + } + + defaultUser := dtos.CurrentUser{} + return &IndexProvider{ log: logging.DefaultLogger.With("logger", "index-provider"), index: t, @@ -70,7 +107,9 @@ func NewIndexProvider(cfg *setting.Cfg, assetsManifest dtos.EntryPointAssets) (* IsDevelopmentEnv: cfg.Env == setting.Dev, - Assets: assetsManifest, + Assets: assetsManifest, + Settings: frontendSettings, + DefaultUser: defaultUser, }, }, nil } diff --git a/pkg/services/frontend/index.html b/pkg/services/frontend/index.html index 10cc7234b78..15c0c26ab08 100644 --- a/pkg/services/frontend/index.html +++ b/pkg/services/frontend/index.html @@ -249,13 +249,22 @@ } async function initGrafana() { - const rawBootData = await loadBootData(); - + // global config window.grafanaBootData = { _femt: true, // isFrontendService() needs this - ...rawBootData, + assets: [[.Assets]], + navTree: [], + settings: [[.Settings]], + user: [[.DefaultUser]], } + // tenant-specific config + // TODO split this into separate API calls + const { navTree, settings, user } = await loadBootData(); + window.grafanaBootData.settings = settings; + window.grafanaBootData.navTree = navTree; + window.grafanaBootData.user = user; + // The per-theme CSS still contains some global styles needed // to render the page correctly. const cssLink = document.createElement("link");