Sub topic 14
Encrypting log traffic with TLS
Plain TCP forwarding sends every log line in cleartext. Anyone on the network path can read it or inject fake entries. Logs often contain usernames, IP addresses, session identifiers and sometimes secrets, so this matters. This chapter adds TLS (Transport Layer Security) to the rsyslog forwarding pipeline you built earlier.
Prerequisites
This chapter assumes you have:
- A working rsyslog client forwarding over TCP to a central receiver listening on port 514.
- Basic familiarity with certificates: a CA (certificate authority), a server certificate, and a private key.
- Root or sudo access on both machines.
- Working time sync and correct DNS names for the hosts. Certificate validity depends on both.
What TLS gives you
TLS provides three properties:
- Confidentiality. Log content is encrypted on the wire.
- Integrity. Tampering in transit is detected.
- Authentication. Each side can prove who it is. The client knows it is talking to the real log host, and the server can know which clients are allowed to send.
TLS does not protect logs at rest. It also does not stop a compromised client from sending false messages, because that client holds a valid certificate.
How rsyslog does TLS
rsyslog uses a network stream driver to wrap its TCP connections. The gtls driver uses the GnuTLS library. Another option is ossl, which uses OpenSSL and is available in newer rsyslog versions. This chapter uses gtls, matching the example configuration.
On Debian and Ubuntu, install the driver package. On RHEL-family systems it is rsyslog-gnutls.
# Debian/Ubuntu
sudo apt install rsyslog-gnutls
# RHEL, Rocky, Alma
sudo dnf install rsyslog-gnutlsIf the package is missing, rsyslog logs an error about being unable to load the lmnsd_gtls module, and TLS connections never start.
Certificates you need
Each machine needs three files:
| File | Purpose | Who needs it |
|---|---|---|
| `ca.pem` | The CA certificate used to verify the other side | Receiver and every client |
| Certificate (`loghost.pem`, `client.pem`) | The machine's own identity, signed by the CA | One per machine |
| Private key (`loghost-key.pem`) | Proves ownership of the certificate | One per machine, never shared |
The certificate's subject name must match what the peer checks. In the example, the client verifies the name loghost.example.com. That name must appear in the server certificate's subject alternative names (SAN) or common name.
Keep private keys readable only by root, or by the user rsyslog runs as:
sudo mkdir -p /etc/pki/rsyslog
sudo chmod 750 /etc/pki/rsyslog
sudo chmod 600 /etc/pki/rsyslog/*-key.pem
sudo chown root:root /etc/pki/rsyslog/*-key.pemIf rsyslog drops privileges (the default on Debian is the syslog user), make sure that user can read the key. A key it cannot read produces a startup error, not a silent downgrade.
Configuring the receiver
The receiver names its CA, certificate and key in a global() block. Then it loads imtcp with the gtls driver.
# Receiver: /etc/rsyslog.d/05-tls.conf
global(
DefaultNetstreamDriver="gtls"
DefaultNetstreamDriverCAFile="/etc/pki/rsyslog/ca.pem"
DefaultNetstreamDriverCertFile="/etc/pki/rsyslog/loghost.pem"
DefaultNetstreamDriverKeyFile="/etc/pki/rsyslog/loghost-key.pem"
)
module(load="imtcp"
StreamDriver.Name="gtls"
StreamDriver.Mode="1"
StreamDriver.AuthMode="x509/name")The key settings are:
StreamDriver.Mode="1"turns TLS on. Mode0is plain TCP.StreamDriver.AuthMode="x509/name"requires the peer to present a certificate signed by the trusted CA, and checks the name.
The input(type="imtcp" ...) line from the earlier receiver chapter stays as it was. It now accepts only TLS connections on that port, so plain TCP clients are refused.
Configuring the client
The client uses the same global() block but points at its own certificate and key. Then the forwarding action turns on TLS.
# Client: /etc/rsyslog.d/05-tls.conf
global(
DefaultNetstreamDriver="gtls"
DefaultNetstreamDriverCAFile="/etc/pki/rsyslog/ca.pem"
DefaultNetstreamDriverCertFile="/etc/pki/rsyslog/client.pem"
DefaultNetstreamDriverKeyFile="/etc/pki/rsyslog/client-key.pem"
)
# /etc/rsyslog.d/50-forward.conf
action(type="omfwd" target="loghost.example.com" port="514" protocol="tcp"
StreamDriver="gtls"
StreamDriverMode="1"
StreamDriverAuthMode="x509/name"
StreamDriverPermittedPeers="loghost.example.com"
queue.type="LinkedList"
queue.filename="fwd_queue"
queue.maxDiskSpace="1g"
queue.saveOnShutdown="on"
action.resumeRetryCount="-1")StreamDriverPermittedPeers lists the names the client will accept. Without a name check, any certificate signed by your CA would be accepted as the log host. Keep the disk-assisted queue from the previous chapter. When the TLS handshake fails or the server is down, messages wait in the queue and are delivered once the connection works.
On the receiver, you can also restrict which clients may connect by adding StreamDriver.PermittedPeers to the imtcp module. For example, use a wildcard such as *.example.com to accept only hosts in your domain.
The handshake
The sequence below shows what happens when a client connects.
If any verification step fails, the connection closes before any log data is sent. The client keeps the messages in its queue and retries.
Authentication modes
The AuthMode setting controls how strictly the peer is checked.
| AuthMode | What it checks | When to use |
|---|---|---|
| `anon` | Nothing. Traffic is encrypted but the peer is not verified | Avoid. It stops eavesdropping but not impersonation |
| `x509/certvalid` | Certificate is signed by a trusted CA | Acceptable if the CA only issues certificates for your own hosts |
| `x509/name` | Valid signature and the name matches the permitted peers | Recommended default |
| `x509/fingerprint` | Certificate fingerprint matches a pinned value | Small fleets without a CA |
Restart and firewall
Check the syntax first, then restart:
sudo rsyslogd -N1
sudo systemctl restart rsyslog
sudo systemctl status rsyslog --no-pagerPort 514 stays the same, so firewall rules from earlier chapters still apply. Some sites move TLS syslog to port 6514, which is the registered port for syslog over TLS. If you do that, change port on the client, input() on the receiver, and the firewall together.
Verifying TLS
Use openssl s_client from a client to confirm the receiver presents the right certificate:
openssl s_client -connect loghost.example.com:514 \
-CAfile /etc/pki/rsyslog/ca.pem \
-cert /etc/pki/rsyslog/client.pem \
-key /etc/pki/rsyslog/client-key.pem </dev/nullLook for Verify return code: 0 (ok) near the end of the output. Then send a test message with logger -t demo "tls test" and confirm it appears in /var/log/remote/<client>/demo.log on the receiver. To prove that encryption is active, capture traffic on the client with sudo tcpdump -A -i any port 514 and check that the message text does not appear.
Common errors
- Certificate expired or not yet valid. Unsynchronised clocks cause this. Check
timedatectlon both sides. - Name mismatch. The name in
StreamDriverPermittedPeersmust match a SAN or common name in the server certificate. Connecting by IP address rarely matches. - Unreadable key or CA file. Check permissions and SELinux or AppArmor denials. On SELinux systems, files under
/etc/pkiusually have the right context, while files copied from home directories may not. - Plain client, TLS server. A client without TLS settings connects but the handshake fails. The receiver logs a message about a failed TLS session.
- Missing gtls package. See the install step above.
- Expired certificates months later. Track expiry dates. A silent expiry stops all forwarding, and the queues fill until
queue.maxDiskSpaceis reached.
Exercise
Exercise
A client's forwarding stops after a year. The receiver is up and the network is fine. journalctl -u rsyslog on the client shows TLS handshake errors. Name two likely causes and how you would check each.
Show answer
First, an expired certificate on the client or the receiver. Check with openssl x509 -in /etc/pki/rsyslog/loghost.pem -noout -dates on each side. Second, a name mismatch or clock skew, for example after the receiver was renamed or a client's clock drifted. Check the SAN with openssl x509 -in /etc/pki/rsyslog/loghost.pem -noout -ext subjectAltName and compare it to StreamDriverPermittedPeers. Check the clock with timedatectl. Meanwhile the client queue keeps messages up to queue.maxDiskSpace, so restoring the connection delivers the backlog.
Exercise
Why is StreamDriver.AuthMode="anon" a poor choice even though it encrypts traffic?
Show answer
It does not verify who is on the other end. An attacker who can intercept the connection can present any certificate, receive the logs, or send forged messages. Encryption without authentication only protects against passive eavesdropping.