Host agents: set up Netlens and enrol a host

Settings → Host agents (locked-down hosts).

  1. Name or address the collectors connect to: every name or IP address that a collector uses to reach Netlens, comma separated. It goes into the server certificate, and a collector refuses a name that is not in it.
  2. Listen on / ports: 0.0.0.0 listens on every interface; give one address to listen on a single one. 4318 is the standard OTLP/HTTP port; 4319 is the enrolment port (open only during a window). Change them if they are taken.
  3. Tick Receive readings from host agents and Save. The status line shows Listening on ….
  4. Download the CA certificate (ca.pem). Every host needs it to recognise Netlens.

Network and reverse proxies

  • Firewall: allow the hosts to reach Netlens on TCP 4318 (always) and 4319 (while enrolling). Nothing inbound to the hosts is needed.
  • Docker: with the default network_mode: host the ports are reachable at once. Without host networking, publish them (ports: ["4318:4318", "4319:4319"]).
  • Reverse proxy: client certificates cannot pass through a proxy that ends TLS (the proxy would see the certificate, Netlens would not), and Netlens never trusts a header that claims who the client is. Expose the ports directly, or use TCP passthrough:

nginx # nginx, stream context: pass the TLS connection through untouched stream { server { listen 4318; proxy_pass netlens.internal:4318; } server { listen 4319; proxy_pass netlens.internal:4319; } } HAProxy: mode tcp frontends and backends. A cloud load balancer must be a layer-4 (TCP) one. * Server certificate: by default Netlens makes one from the names you gave, signed by its ingest CA (the hosts trust ca.pem). To use a certificate from your company CA instead, paste it with its key under Server certificate (the hosts then trust your CA).

Enrol a host

  1. Settings → Host agents → Open an enrolment window (default 30 minutes).
  2. Add an agent: a name, the device it reports for, how often it sends (default 60 s). Netlens shows the token once, with the commands below filled in.
  3. On the host, make a key and a certificate request, and enrol. The private key stays on the host.

Linux, BSD and other Unix (as root; ca.pem is the file downloaded from Netlens):

install -d -m 0750 /etc/netlens-agent && cd /etc/netlens-agent
# put ca.pem here
openssl ecparam -name prime256v1 -genkey -noout -out agent.key && chmod 600 agent.key
openssl req -new -key agent.key -subj "/CN=$(hostname)" -out agent.csr
curl --fail --cacert ca.pem -H "Authorization: Bearer nlt_THE_TOKEN" --data-binary @agent.csr \
     https://NETLENS:4319/enrol -o agent.crt
openssl x509 -in agent.crt -noout -subject -enddate      # CN=netlens-agent-<id>, ends in 30 days

Windows Server, in an elevated PowerShell. With PowerShell 7.4 or newer no extra software is needed:

New-Item -ItemType Directory -Force C:\ProgramData\netlens-agent | Out-Null; cd C:\ProgramData\netlens-agent
# put ca.pem here
$key = [System.Security.Cryptography.ECDsa]::Create([System.Security.Cryptography.ECCurve]::CreateFromFriendlyName("nistP256"))
$req = [System.Security.Cryptography.X509Certificates.CertificateRequest]::new("CN=$env:COMPUTERNAME", $key, [System.Security.Cryptography.HashAlgorithmName]::SHA256)
Set-Content agent.key $key.ExportPkcs8PrivateKeyPem(); Set-Content agent.csr $req.CreateSigningRequestPem()
icacls agent.key /inheritance:r /grant:r "SYSTEM:(R)" "BUILTIN\Administrators:(F)"
curl.exe --fail --cacert ca.pem -H "Authorization: Bearer nlt_THE_TOKEN" --data-binary "@agent.csr" https://NETLENS:4319/enrol -o agent.crt

(curl.exe is part of Windows 10 and Server 2019 and newer.) Windows PowerShell 5.1 cannot export the key; use OpenSSL for Windows instead (openssl ecparam ... / openssl req ... exactly as in the Linux example).

The window can be closed at any time (Close the window now); it closes by itself when it runs out. A token that was not used ends after 24 hours; Enrol again makes a new one and cancels the old certificate at once.

With a certificate from your own CA no token is needed: upload your CA certificate (Your own certificate authority), add the agent with its identity (dns:web01.example.com, uri:spiffe://example/web01 or cn:web01, as it appears in the certificate), and let the collector use that certificate. A certificate that chains to your CA but whose identity matches no agent is refused. Revoke an agent in Netlens to stop it even though the certificate itself is still valid.