Improve Grafana Security
Once your Grafana Server is installed, up and running, you can drastically improve its security and accessibility by installing an SSL Reverse Proxy, and enabling 2-Factor Authentication with Google OAuth.
Prerequisites
NGINX Reverse Proxy :
- You must have a proper domain name; and FQDN set to your grafana’s public IP address
- You can buy a domain name basically on any hosting site like namecheap.
2FA Google OAuth :
- You need to have your own domain mail address (and of course a secure mail server). For example, you could have "grafana@yourdomain.com"
- You need to create a Google account with this mail address.
Nginx Reverse Proxy
The main issue if you want to access your Grafana Dashboard from anywhere, out-of-the-box, is that you have to expose the application port (http:3000 by default) on the public address of your server. To avoid that, a popular solution is to simply create an SSH tunnel with a port forwarding option to your Grafana Server. A more elegant and still secure solution is to configure a reverse proxy, with an SSL certificate.
Nginx installation
Install nginx
sudo apt install nginx
Check nginx status
sudo systemctl status nginx
Create Firewall Rules on your server
Ports 80 and 443 need to be opened on your Grafana server. Nginx will automatically forward any HTTP requests to HTTPS, but it’s important to have both open, in order for Certbot to renew your SSL certificate every 3 month. Here is an example with UFW : deny any incoming connections, except SSH, HTTP and HTTPS, an allow any outgoing connections. Modify to suit your needs, especially if you are running Grafana on a Stake Pool Relay server, you'll need to add Cardano Port.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Now you should be able to visit your server's public IP address : http://your-ip-address which should lead to the default Nginx page.
Create and edit an nginx config file for your Grafana server
(change with your actual FQDN like grafana.yourdomain.com)
cd /etc/nginx/sites-enabled
sudo nano <your FQDN>.conf
Add this block
server {
listen 80;
server_name <your FQDN>;
location / {
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000/;
}
}
Save your file and restart Nginx
sudo systemctl restart nginx
Now access your monitoring server http://your-FQDN : you should see the Grafana login page.
Nginx cleanup : remove the default enabled site
rm /etc/nginx/sites-enabled/default