Overview
Grafana supports TLS/SSL for:- HTTPS server configuration
- gRPC server communication
- LDAP connections
- OAuth provider connections
- Database connections
- SMTP email delivery
- Datasource connections
HTTPS Server Configuration
Configure Grafana to serve content over HTTPS.Basic HTTPS Setup
conf/defaults.ini:40-80
TLS Version Configuration
Specify minimum TLS version:conf/defaults.ini:44
Certificate Formats
Grafana supports:- PEM format: Standard ASCII-armored certificates (most common)
- PKCS#12: Binary format (requires conversion to PEM)
Self-Signed Certificates
For development environments:Certificate Reload
Grafana can automatically reload certificates without restart:conf/defaults.ini:80
HTTP Strict Transport Security (HSTS)
Enforce HTTPS connections with HSTS headers.HSTS Configuration
conf/defaults.ini:422-433
HSTS tells browsers to:
- Always use HTTPS for the domain
- Reject invalid certificates
- Prevent SSL stripping attacks
HSTS Best Practices
- Start with short max-age: Test with 300 seconds initially
- Increase gradually: Move to 86400 (1 day), then 31536000 (1 year)
- Enable preload carefully: Only for production domains you control
- Test thoroughly: HSTS can’t be easily reverted
gRPC Server TLS
Secure gRPC communication between Grafana components.gRPC TLS Configuration
conf/defaults.ini:113-121
LDAP TLS Configuration
Secure LDAP connections with TLS/SSL.LDAPS Configuration
Inldap.toml:
pkg/services/ldap/settings.go:35-52
LDAP TLS Options
- use_ssl: Connect via LDAPS (port 636)
- start_tls: Upgrade connection to TLS (port 389)
- ssl_skip_verify: Skip certificate verification (insecure)
- min_tls_version: Minimum TLS version (TLS1.2, TLS1.3)
- tls_ciphers: Allowed cipher suites
- root_ca_cert: CA certificate for server verification
- client_cert/client_key: Client certificate for mutual TLS
pkg/services/ldap/settings.go:39-52
Cipher Suite Configuration
The TLS cipher configuration is handled by utility functions:pkg/services/ldap/settings.go:182-194
OAuth Provider TLS
Secure communication with OAuth identity providers.OAuth TLS Settings
conf/defaults.ini:937-940
The OAuth strategy loads TLS settings from configuration:
pkg/services/ssosettings/strategies/oauth_strategy.go:99-102
Mutual TLS (mTLS) for OAuth
Some OAuth providers require client certificates:Database TLS
Secure database connections with TLS.PostgreSQL TLS
conf/defaults.ini:174-190
MySQL TLS
conf/defaults.ini:175-190
SMTP TLS
Secure email delivery with TLS.SMTP TLS Configuration
conf/defaults.ini:1137-1150
StartTLS Policies
- NoStartTLS: No TLS (insecure)
- OpportunisticStartTLS: Use TLS if available
- MandatoryStartTLS: Require TLS, fail if unavailable
Datasource TLS
Secure connections to datasources.Datasource TLS Settings
Most datasources support TLS configuration in their settings:Common Datasource TLS Options
- tlsAuth: Enable TLS client authentication
- tlsAuthWithCACert: Verify server certificate with CA
- tlsSkipVerify: Skip certificate verification (insecure)
- serverName: Expected server name in certificate
- tlsClientCert: Client certificate (PEM)
- tlsClientKey: Client private key (PEM)
- tlsCACert: CA certificate (PEM)
HTTP Client TLS
Grafana’s HTTP client provider handles TLS for outgoing requests. Implementation:pkg/infra/httpclient/httpclientprovider/
TLS Configuration
The HTTP client supports:- Custom CA certificates
- Client certificates (mTLS)
- TLS version restrictions
- Cipher suite selection
- Certificate verification
TLS Handshake Timeout
conf/defaults.ini:264
Content Security Policy
Control resource loading with CSP headers.CSP Configuration
conf/defaults.ini:444-460
CSP for HTTPS
Ensure CSP allows secure WebSocket connections:Certificate Management
Certificate Generation
Self-Signed Certificate
Certificate with SAN
Certificate Verification
Certificate Renewal
With certificate watching enabled, Grafana automatically reloads certificates:CSRF Protection
Cross-Site Request Forgery protection works with TLS.CSRF Configuration
conf/defaults.ini:462-463
Implementation: pkg/middleware/csrf/csrf.go
The CSRF middleware validates the Origin header:
pkg/middleware/csrf/csrf.go:71-141
Security Headers
Additional security headers for HTTPS deployments.X-Content-Type-Options
conf/defaults.ini:438
X-XSS-Protection
conf/defaults.ini:442
Best Practices
1. Always Use TLS in Production
2. Use Strong Cipher Suites
Prefer modern, secure cipher suites:3. Verify Certificates
Never skip certificate verification in production:4. Use Certificate Watching
Enable automatic certificate reload:5. Implement HSTS
Enforce HTTPS in browsers:6. Secure Cookie Settings
conf/defaults.ini:414-417
7. Monitor Certificate Expiration
Set up alerts for certificate expiration:8. Use Mutual TLS (mTLS) for Services
For service-to-service communication:Troubleshooting
Certificate Issues
TLS Handshake Errors
Common causes:- Certificate expired
- Wrong certificate hostname
- Missing intermediate certificates
- Cipher suite mismatch
- TLS version not supported
Debug Logging
OpenSSL Debugging
Related Topics
- Authentication - User authentication
- Security Best Practices - Comprehensive security guide
- Reverse Proxy Setup - Proxy TLS termination