# Citrix session auditing, from NetScaler to an encrypted archive

- Link: https://www.silviobalduzzi.com/en/projects/citrix-session-audit-netscaler/
- Published: 2026-10-25T10:14:52+01:00

## Context

The customer’s audit team needed to know who opens Citrix sessions through NetScaler
Gateway, from which address and for how long, and to receive that information every
day in a form only they could read. NetScaler knows all of this, but it sends it
as raw AppFlow records: there are no sessions yet, no complete usernames, no files
to deliver.

I designed and built the service, N.U.S.A. (NetScaler User Session Auditor), and
wrote the operations manual for first- and second-level support.

## The challenge

 * **From records to sessions.** IPFIX records have to be correlated into sessions
   with login, logout and duration, telling closed sessions apart from those that
   never got a close event and from the technical placeholders NetScaler generates.
 * **Incomplete usernames.** NetScaler truncates longer usernames and sometimes 
   loses the domain: the username has to be rebuilt before it goes into the file.
 * **A contractual format.** Columns, order, separator and the meaning of every 
   field are agreed with the customer: the file must not change by mistake.
 * **Confidentiality and proof of delivery.** Only the customer may read the package,
   and it must be possible to prove whether and when it was collected.
 * **Five years of history.** The disk has to last for the whole retention period,
   and the service has to run on its own, looked after by a support team that does
   not write software.

## The architecture

On a dedicated Linux server, RHEL or Rocky Linux 9, every link in the chain is a
separate systemd service. The ipfixcol2 collector receives the records from NetScaler
on UDP port 4739 and writes them as JSON; the session tracker correlates them into
sessions; every night at 00:30 UTC the export turns the previous day’s closed sessions
into a CSV, compresses it, encrypts it with the customer’s public PGP key and files
it by year and month.

The customer collects the packages with a dedicated SFTP account, read-only and 
limited to the archive, and a calendar in the portal shows for each day whether 
the package was produced and whether it was collected. The web portal, over HTTPS
with administrator and user roles, brings together session lookup, file format, 
PGP keys, VPN subnets, username correction rules, disk space forecast and service
status.

## Key decisions

 * **The database is not the archive.** The session database is a working window
   of a few days; the history lives only in the encrypted packages, which no maintenance
   operation touches.
 * **Only the public key on the server.** Packages are encrypted with the customer’s
   key: once produced, only the customer can open them. Changing the key follows
   a procedure with a fingerprint check over a separate channel and a test package.
 * **Independent links.** If the portal stops, collection and export carry on. Every
   service has its own page and its own symptom, and the manual leads from the symptom
   to the fix.
 * **The agreed configuration is a contract.** File format, VPN subnets and username
   rules change what gets delivered: they change only at the customer’s request,
   and the default format is the agreed one.
 * **Disk space forecast, not discovered.** Raw data stops at 30 days, the archive
   grows for five years: the portal estimates when the disk would fill up and whether
   it lasts for the whole retention period.
 * **Updates without surprises.** A single package with a SHA-256 fingerprint, an
   idempotent script that keeps database, archive and configuration, and a six-step
   check that closes only with the first successful nightly export.

## A product today

The same software is now NetScaler-UserLogging, one of the solutions of Corellix
Software Engineering, the startup I co-founded.

 [   Corellix · the startup I co-founded NetScaler-UserLogging Records who opened which Citrix session, from where and for how long, from the AppFlow data of NetScaler Gateway, and keeps it encrypted for five years.  Discover NetScaler-UserLogging  ](https://corellix.io/solutions/netscaler-userlogging?utm_source=silviobalduzzi.com&utm_medium=block&utm_campaign=netscaler-userlogging)
