Observability Azure

Grafana Loki 3 on Ubuntu 26.04 on Azure User Guide

| Product: Grafana Loki 3 on Ubuntu 26.04 LTS on Azure

Overview

This guide covers deploying and using Grafana Loki 3 on Ubuntu 26.04 LTS from cloudimg on Microsoft Azure.

Loki is a log aggregation system. Agents such as Grafana Alloy, Fluent Bit or Promtail push log lines with a few labels (job, host, app), Loki stores them compressed on disk and indexes only the labels, and you search them with LogQL from Grafana, logcli or plain HTTP. Because it does not index the full text of each line, it is cheap to run and needs little memory.

An upstream Loki binary listens on every interface with no authentication. The cloudimg image changes that:

  • HTTPS from the first boot. nginx is the only network entry point and serves Loki on port 443 with a self signed certificate made on your virtual machine's first boot. Port 80 only redirects to HTTPS.
  • A password unique to your virtual machine. Every Loki path (push, query, tail, ready, metrics) needs HTTP Basic authentication as the user loki. The password is made on first boot and written to the root only file /root/loki-credentials.txt; nginx keeps only its bcrypt hash. No password is baked into the image and no two virtual machines share one.
  • Loki on loopback only. Loki's HTTP port 3100 and gRPC port 9096 are bound to 127.0.0.1. They are never reachable from the network, so never open them in a network security group.
  • Fail closed. nginx refuses to start until first boot has written the certificate and the password, so Loki is never served without a login.
  • Sandboxed service. Loki runs as its own unprivileged user in a systemd sandbox and may only talk to loopback, so it cannot reach the Azure metadata service or any other address. A state changing request from a foreign web page is refused.
  • Fully patched Ubuntu 26.04 LTS at build time, with unattended security upgrades left on.

What is on the image: Grafana Loki 3.7.11 (/usr/local/bin/loki, the unmodified upstream release binary, checked against its published SHA-256, AGPL-3.0), single tenant filesystem storage in /var/lib/loki, nginx and Ubuntu 26.04 LTS. Loki has no web interface of its own; use Grafana (Step 9) or the HTTP API to read your logs.

Default user: azureuser · Recommended size: Standard_B2s

Prerequisites

  • An Azure subscription and an SSH key pair.
  • A network security group that allows TCP 22 (SSH) from your own networks and TCP 443 (the Loki API) from the networks your log agents and Grafana run in. TCP 80 only redirects to HTTPS and is optional.

Step 1: Choose a VM size

Standard_B2s (2 vCPUs, 4 GB RAM) handles a moderate single tenant workload. Logs are stored on the OS disk under /var/lib/loki, so give the OS disk room for the log volume you expect (Step 11), or choose a larger size for heavy ingest.

Step 2: Deploy from the Azure Portal

  1. Find Grafana Loki 3 on Ubuntu 26.04 by cloudimg in the Azure Marketplace and choose Create.
  2. Choose your subscription, resource group, region and a size such as Standard_B2s.
  3. Under Administrator account, choose SSH public key and give the user name azureuser.
  4. Under Inbound port rules, allow SSH (22) and HTTPS (443), then narrow both to your own address ranges once the VM is created.
  5. Choose Review + create, then Create.

Step 3: Deploy from the Azure CLI

Replace the placeholder values with your own before running:

# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn cloudimg1647283583153:loki-3-ubuntu-26-04:default:latest

az vm create \
  --resource-group my-resource-group \
  --name loki \
  --image cloudimg1647283583153:loki-3-ubuntu-26-04:default:latest \
  --size Standard_B2s \
  --admin-username azureuser \
  --ssh-key-values ~/.ssh/id_rsa.pub \
  --public-ip-sku Standard

# Open the Loki API on 443, then limit SSH to your management network only
az vm open-port --resource-group my-resource-group --name loki --port 443 --priority 1001
az network nsg rule update --resource-group my-resource-group --nsg-name lokiNSG \
  --name default-allow-ssh --source-address-prefixes <your-mgmt-cidr>

Then connect over SSH:

ssh azureuser@<public-ip>

Step 4: Check the services

First boot makes the certificate and the password, then nginx starts in front of Loki:

systemctl is-active loki nginx loki-firstboot
sudo test -f /var/lib/cloudimg/loki-firstboot.done && echo FIRSTBOOT_DONE
/usr/local/bin/loki -version | head -1
active
active
active
FIRSTBOOT_DONE
loki, version 3.7.11 (branch: release-3.7.x, revision: 56f8c86a)

Only SSH and nginx listen on network addresses; Loki listens on loopback:

sudo ss -Hlnt | awk '{print $4}' | grep -E ':(22|80|443|3100|9096)$' | sort -u
0.0.0.0:22
0.0.0.0:443
0.0.0.0:80
127.0.0.1:3100
127.0.0.1:9096
[::]:22
[::]:443
[::]:80

loki, nginx and loki-firstboot report active, loki -version reports 3.7.11, and ss shows SSH and nginx listening on ports 22, 80 and 443 while Loki's 3100 and 9096 are bound to 127.0.0.1 only

Step 5: Get your endpoints and password

The endpoints are in the root only credentials file:

sudo grep -E '^LOKI_(URL|PUSH_URL|QUERY_URL|USER|CA_CERT)=' /root/loki-credentials.txt
LOKI_URL=https://<public-ip>/
LOKI_PUSH_URL=https://<public-ip>/loki/api/v1/push
LOKI_QUERY_URL=https://<public-ip>/loki/api/v1/query_range
LOKI_USER=loki
LOKI_CA_CERT=/etc/ssl/loki/loki.crt

The password is the LOKI_PASSWORD line of the same file: sudo grep '^LOKI_PASSWORD=' /root/loki-credentials.txt. Store it in your password manager or secrets store; it is unique to this virtual machine.

The URLs use the public IP address Azure reported to the virtual machine on its first boot. The certificate names that address, the virtual machine's private address, 127.0.0.1, ::1 and localhost:

openssl x509 -in /etc/ssl/loki/loki.crt -noout -subject -ext subjectAltName
subject=CN=<public-ip>
X509v3 Subject Alternative Name: 
    IP Address:0:0:0:0:0:0:0:1, IP Address:<public-ip>, IP Address:<private-address>, IP Address:127.0.0.1, DNS:localhost

If the URLs show <your-vm-public-ip> (Azure reported no public IP when the virtual machine first booted), or you want agents to use a DNS name, see Step 10.

Step 6: Check the login

Without the password every path is refused, a wrong password is refused, and port 80 redirects to HTTPS. With the password, /ready answers. The commands read the password into a shell variable and hand it to curl through a file descriptor, so it never appears in the process list or your shell history:

PW=$(sudo sed -n 's/^LOKI_PASSWORD=//p' /root/loki-credentials.txt)
CA=/etc/ssl/loki/loki.crt
curl -s -o /dev/null -w 'http://  -> HTTP %{http_code}\n' http://127.0.0.1/ready
curl -s -o /dev/null -w 'no login -> HTTP %{http_code}\n' --cacert $CA https://127.0.0.1/ready
curl -s -o /dev/null -w 'wrong password -> HTTP %{http_code}\n' --cacert $CA -u loki:not-the-password https://127.0.0.1/ready
curl -s -w ' <- HTTP %{http_code}\n' --cacert $CA -K <(printf 'user = "loki:%s"\n' "$PW") https://127.0.0.1/ready
http://  -> HTTP 301
no login -> HTTP 401
wrong password -> HTTP 401
ready
 <- HTTP 200

port 80 answers 301, a request with no login and one with a wrong login are refused with 401, and the per-VM login (here kept in a root only curl config file) gets ready with HTTP 200

From another machine, use the LOKI_URL host instead of 127.0.0.1, with a copy of /etc/ssl/loki/loki.crt as the CA.

Step 7: Push a log line and query it back

Loki's push API takes JSON streams: a set of labels and a list of [timestamp in nanoseconds, line] pairs. Push one line, then read it back with a LogQL query:

PW=$(sudo sed -n 's/^LOKI_PASSWORD=//p' /root/loki-credentials.txt)
CA=/etc/ssl/loki/loki.crt
TS=$(date +%s%N)
curl -s -o /dev/null -w 'push -> HTTP %{http_code}\n' --cacert $CA \
  -K <(printf 'user = "loki:%s"\n' "$PW") -H 'Content-Type: application/json' \
  -d "{\"streams\":[{\"stream\":{\"job\":\"guide-test\",\"host\":\"$(hostname)\"},\"values\":[[\"$TS\",\"hello from the cloudimg Loki guide\"]]}]}" \
  https://127.0.0.1/loki/api/v1/push
sleep 2
curl -s --cacert $CA -K <(printf 'user = "loki:%s"\n' "$PW") -G \
  --data-urlencode 'query={job="guide-test"}' --data-urlencode 'limit=5' \
  https://127.0.0.1/loki/api/v1/query_range \
  | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d["status"]); [print(s["stream"]["job"], v[1]) for s in d["data"]["result"] for v in s["values"]]'
push -> HTTP 204
success
guide-test hello from the cloudimg Loki guide

a log line pushed over HTTPS returns 204, a LogQL query_range for job demo returns success with the line hello from cloudimg, and the labels endpoint lists host, job and service_name

List the labels Loki has seen and the values of one label:

PW=$(sudo sed -n 's/^LOKI_PASSWORD=//p' /root/loki-credentials.txt)
CA=/etc/ssl/loki/loki.crt
curl -s --cacert $CA -K <(printf 'user = "loki:%s"\n' "$PW") https://127.0.0.1/loki/api/v1/labels
curl -s --cacert $CA -K <(printf 'user = "loki:%s"\n' "$PW") https://127.0.0.1/loki/api/v1/label/job/values
{"status":"success","data":["host","job","service_name"]}
{"status":"success","data":["guide-test"]}

Step 8: Send logs from your servers

Any agent that speaks the Loki push API works. Give it the push URL, the user loki, the password, and the virtual machine's certificate so it can verify the connection. Copy the certificate to each agent host first (it is public, not a secret):

scp azureuser@<loki-host>:/etc/ssl/loki/loki.crt ./loki.crt

Grafana Alloy (/etc/alloy/config.alloy on the agent host), shipping the systemd journal:

loki.source.journal "system" {
  forward_to = [loki.write.cloudimg.receiver]
  labels     = { job = "systemd-journal", host = constants.hostname }
}

loki.write "cloudimg" {
  endpoint {
    url = "https://<loki-host>/loki/api/v1/push"
    basic_auth {
      username = "loki"
      password = "<LOKI_PASSWORD>"
    }
    tls_config {
      ca_file = "/etc/alloy/loki.crt"
    }
  }
}

Fluent Bit ([OUTPUT] section):

[OUTPUT]
    Name        loki
    Match       *
    Host        <loki-host>
    Port        443
    tls         On
    tls.verify  On
    tls.ca_file /etc/fluent-bit/loki.crt
    http_user   loki
    http_passwd <LOKI_PASSWORD>
    labels      job=fluent-bit, host=${HOSTNAME}

Keep the password in the agent's own secret store or a root only file rather than in a world readable configuration. Agents send no browser Origin header, so the image's cross site request guard does not affect them.

Step 9: Read your logs in Grafana

Loki has no user interface of its own; Grafana is the usual way to explore it. In Grafana open Connections, Data sources, Add data source, Loki, and set:

  • URL: https://<loki-host>/ (the LOKI_URL from Step 5)
  • Authentication: Basic authentication, user loki, password LOKI_PASSWORD
  • TLS settings: turn on Add self-signed certificate and paste the contents of /etc/ssl/loki/loki.crt as the CA certificate (or install a CA issued certificate, Step 10)

Choose Save & test, then use Explore with a query such as {job="systemd-journal"} |= "error".

Step 10: Use your own DNS name or certificate

To serve Loki under your own DNS name, point the name at the virtual machine's public IP and run the helper. It records the name, makes a new self signed certificate for it, updates the URLs in the credentials file and reloads nginx; the password does not change:

sudo loki-set-hostname <your-dns-name>

With no name, the helper makes the certificate for the virtual machine's own addresses again. Run it with the new address if the public IP changes (a static public IP avoids that).

To use a certificate from your own CA or a public CA instead, replace /etc/ssl/loki/loki.crt (full chain) and /etc/ssl/loki/loki.key (mode 0600, owner root), then run sudo nginx -t && sudo systemctl reload nginx. Alternatively, put the virtual machine behind an Azure Application Gateway that holds your certificate and forwards to port 443.

Step 11: Storage and retention

Loki writes chunks, the write ahead log and its index under /var/lib/loki on the OS disk:

sudo du -sh /var/lib/loki
df -h /var/lib/loki | tail -1 | awk '{print $2" total, "$4" free on "$6}'
84K /var/lib/loki
28G total, 26G free on /

By default Loki keeps logs until you delete them. To expire old logs automatically, add a retention period to /etc/loki/loki.yaml, for example 31 days, and restart Loki with sudo systemctl restart loki:

compactor:
  working_directory: /var/lib/loki/compactor
  retention_enabled: true
  delete_request_store: filesystem

limits_config:
  retention_period: 744h

Grow the OS disk (or attach a data disk mounted at /var/lib/loki) as your log volume grows. For larger or multi node deployments, Loki can also store chunks in Azure Blob Storage; see the Loki storage documentation.

Step 12: Security notes

The Loki service is sandboxed and may only talk to loopback:

systemctl show loki -p User -p IPAddressAllow -p IPAddressDeny -p ProtectSystem -p NoNewPrivileges
IPAddressAllow=127.0.0.0/8 ::1/128
IPAddressDeny=0.0.0.0/0 ::/0
User=loki
ProtectSystem=strict
NoNewPrivileges=yes

A state changing request carrying a foreign browser Origin is refused, even with the right password, so a web page cannot push or tail through a signed in browser:

PW=$(sudo sed -n 's/^LOKI_PASSWORD=//p' /root/loki-credentials.txt)
CA=/etc/ssl/loki/loki.crt
curl -s -o /dev/null -w 'Origin evil.example push -> HTTP %{http_code}\n' --cacert $CA -K <(printf 'user = "loki:%s"\n' "$PW") -H 'Origin: https://evil.example' -H 'Content-Type: application/json' -d '{"streams":[]}' https://127.0.0.1/loki/api/v1/push
Origin evil.example push -> HTTP 403

systemctl show reports Loki running as the loki user with IPAddressAllow limited to loopback, IPAddressDeny everything else, ProtectSystem strict and NoNewPrivileges yes, and a push carrying a foreign browser Origin is refused with 403

Other points:

  • Loki runs single tenant (auth_enabled: false): anyone with the password can push and read every stream. Give each team its own virtual machine if they must not see each other's logs.
  • nginx logs the real client address of every request; X-Forwarded-For headers sent by clients are ignored.
  • Restrict port 443 to the networks your agents and Grafana use, and never open 3100 or 9096.
  • To rotate the password, make a new one, write its bcrypt hash to /etc/nginx/loki.htpasswd (sudo htpasswd -B -C 12 /etc/nginx/loki.htpasswd loki), update LOKI_PASSWORD in /root/loki-credentials.txt, reload nginx and update your agents.

Service management

sudo systemctl status loki --no-pager | head -3
● loki.service - Grafana Loki 3 — log aggregation (loopback only, behind nginx HTTPS)
     Loaded: loaded (/etc/systemd/system/loki.service; enabled; preset: enabled)
     Active: active (running) since <date>; <time> ago

Restart Loki with sudo systemctl restart loki and nginx with sudo systemctl restart nginx. Loki's own log is in the journal: sudo journalctl -u loki -n 50.

Support and licensing

Loki is open source under the GNU Affero General Public License v3.0 (AGPL-3.0); the image ships the unmodified upstream binary and there is no per user or per CPU licence fee. Additional charges apply for build, maintenance and support.

Support by email from cloudimg's team, on hand 24 hours a day, with a guaranteed response within 24 hours.

  • Email: support@cloudimg.co.uk
  • Website: https://www.cloudimg.co.uk

Loki is developed by Grafana Labs; for Loki features and LogQL, see the upstream Loki documentation.

Grafana Loki is a trademark of Grafana Labs. cloudimg is not affiliated with or endorsed by Grafana Labs; the name is used only to identify the unmodified upstream software.