Frontend Service: Pass static config needed for login to index bootData (#110829)

add almost all config needed for login
This commit is contained in:
Ashley Harrison 2025-09-11 12:05:39 +01:00 committed by GitHub
parent d0ab6d08e6
commit 2e0fdb2a60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"html/template"
"net/http"
"strings"
"syscall"
"github.com/grafana/grafana-app-sdk/logging"
@ -34,6 +35,8 @@ type IndexViewData struct {
AppTitle string
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,
@ -71,6 +108,8 @@ func NewIndexProvider(cfg *setting.Cfg, assetsManifest dtos.EntryPointAssets) (*
IsDevelopmentEnv: cfg.Env == setting.Dev,
Assets: assetsManifest,
Settings: frontendSettings,
DefaultUser: defaultUser,
},
}, nil
}

View File

@ -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");