Metadata-Version: 2.4
Name: logredact
Version: 1.11.0
Summary: Scrub sensitive identifiers from diagnostic logs (syslog / terminal transcripts) before sharing them with support.
Author: Andrii Iaremenko
License: MIT
Project-URL: Homepage, https://gitlab.com/ayarema/logredact
Project-URL: Repository, https://gitlab.com/ayarema/logredact
Project-URL: Issues, https://gitlab.com/ayarema/logredact/-/issues
Project-URL: Changelog, https://gitlab.com/ayarema/logredact/-/blob/main/CHANGELOG.md
Keywords: log,redaction,privacy,pii,networkmanager,forticlient,syslog
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Security
Classifier: Topic :: System :: Logging
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-cov>=4; extra == "dev"
Requires-Dist: ruff>=0.17; extra == "dev"
Requires-Dist: hypothesis>=6; extra == "dev"
Requires-Dist: mypy>=1.8; extra == "dev"
Dynamic: license-file

# logredact

Scrub sensitive identifiers from diagnostic logs **before** you send them to
vendor support (FortiClient / NetworkManager / anything Linux), while keeping
every bit of diagnostic value intact.

Drop in a `.log` / `.txt` (syslog export or a copy-pasted terminal session) —
get out a shareable file where usernames, hostnames, SSIDs, UUIDs, MAC/IP
addresses and secrets are replaced by deterministic tokens, and the support
engineer still sees interface names, state transitions, versions and errors.

- **Zero dependencies** — Python ≥ 3.9 stdlib only
- **Local by design** — no network calls, the UI binds to 127.0.0.1 only
- **Deterministic tokens** — the same value always maps to the same token, so
  correlation across log lines survives redaction
- **Three frontends** — CLI for scripts/pipelines, tiny web UI for drag & drop
  (tokens highlighted by kind, click-to-redact, mapping hidden until you ask),
  and a tkinter desktop window (`logredact gui`)
- **Two safety levels** — readable rule-based redaction by default,
  `--strict` allow-list mode when the file must be safe to hand to anyone
- **One command for support cases** — `logredact collect` gathers, redacts and
  bundles the usual NetworkManager / Wi-Fi / VPN diagnostics

## Install

```bash
# from the repository (it is private: use your SSH key)
pipx install git+ssh://git@gitlab.com/ayarema/logredact.git
# or from a clone
git clone git@gitlab.com:ayarema/logredact.git && pipx install ./logredact
```

`pipx install logredact` from PyPI will work once a release is published
there (the CI job `publish-pypi` runs on a tag when `PYPI_API_TOKEN` is set).

Debian / Ubuntu without pip: build a dependency-free package (needs only
`dpkg-deb` and `python3 >= 3.9` on the target) and install it:

```bash
make deb                                   # -> dist/logredact_<version>_all.deb
sudo apt install ./dist/logredact_*.deb
```

Or take one file and run it anywhere python3 >= 3.9 exists:

```bash
make pyz                                   # -> dist/logredact.pyz
python3 dist/logredact.pyz mylog.log
```

Tag releases on GitLab carry the `.deb` and the `.pyz` as assets. A
`snap/snapcraft.yaml` is included for a strict-confinement snap
(`logredact collect` is limited inside the snap sandbox; prefer the `.deb`
or `pipx` for that).

Or run from the repo without installing:

```bash
PYTHONPATH=src python3 -m logredact mylog.log
```

## Usage

```bash
# one-shot: gather the usual diagnostics, redact, bundle  <- start here
logredact collect --archive
#   shareable : logredact-20260122-101500.tar.gz
#   LOCAL ONLY: logredact-20260122-101500.redaction-map.txt

# CLI — the everyday path for a log you already have
logredact nmcli-session.log
#   shareable : nmcli-session.redacted.log     <- send this to support
#   LOCAL ONLY: nmcli-session.redaction-map.txt  <- never share, chmod 600

# multiple files / explicit type / custom paths
logredact a.log b.log
logredact syslog.out --type syslog -o clean.log --map private.map

# pipe: stdin -> stdout (status + mapping path go to stderr)
journalctl -u NetworkManager -b | logredact - --map private.map > clean.log

# several files, ONE token space: <ip-1> means the same thing in every output
logredact day1.log day2.log day3.log --shared-map

# values no rule knows about: company name, internal domain, project codename
logredact vpn.log --redact-value "Acme Corp" --redact-file internal-names.txt

# self-check the output for anything that still looks sensitive (exit 3 if so)
logredact vpn.log --verify

# "give it to anyone" mode: every word not provably harmless becomes <word-N>,
# and nothing is written unless the self-check is clean
logredact vpn.log --strict --require-clean

# teach it your own names once; every later run (CLI and UI) uses them
logredact config --redact "Acme Corp" --redact falcon-9 --allow mydaemon

# prove it: a certificate anyone can re-check from the file alone
logredact vpn.log --strict --attest        # writes vpn.redacted.log.attest.txt
logredact attest vpn.redacted.log          # the receiver runs this; exit 3 if NOT CLEAN

# keep what helps support, drop what identifies you
logredact vpn.log --shift-time --keep-oui --keep-subnets

# a vendor's diagnostic export (directory, .zip, .tar.gz): every text member, one map
logredact DART-bundle.zip                  # -> DART-bundle.redacted.zip

# screen sharing with support: redact the stream as it scrolls
journalctl -f -u NetworkManager | logredact live --strict

# presets by purpose; keep a token kind readable when the receiver needs it
logredact vpn.log --profile support            # verify, shift time, keep OUI + subnets
logredact vpn.log --profile internal           # ... plus internal domains and CNs stay
logredact vpn.log --profile public             # strict + require-clean + shift time
logredact vpn.log --keep-kind serial --keep-kind domain

# a desktop window instead of a terminal
logredact gui

# copy a log excerpt, redact the clipboard in place, paste it into the chat
logredact clip --strict

# which words would --strict hide in my logs? review, then allow the harmless ones
logredact vocab-candidates /var/log/syslog | head -40

# sign the certificate with a secret shared with your auditor; they re-check it
logredact attest vpn.redacted.log --key ~/.config/logredact/attest.key --write
logredact attest --check vpn.redacted.log.attest.txt --key ~/.config/logredact/attest.key

# support replied "problem is <conn-name-3>" - put the real values back (local only)
logredact restore vpn.redacted.log --map vpn.redaction-map.txt

# what would it detect?
logredact detect something.log

# web UI — drag & drop in your browser
logredact ui              # opens http://127.0.0.1:8765
```

Before hitting "send", run `--verify` and skim the output yourself — see
[Security model](#security-model--limitations).

Exit codes: `0` ok, `1` I/O or usage error, `3` `--verify` found possible leftovers.

## What gets redacted vs kept

| Redacted (tokenized)                                  | Kept as-is                                   |
| ----------------------------------------------------- | -------------------------------------------- |
| username, hostname (incl. shell prompts, sudo)         | interface names (`wlp4s0`, `br-*`, `docker0`) |
| SSID / connection names (incl. names with spaces, e.g. `Jane's iPhone`) | commands, config paths, table layout |
| connection UUIDs, boot IDs                              | package versions (`forticlient 7.4.3.1736`)  |
| MAC addresses (classified: AP / client / randomised)    | timestamps, state transitions, pids/uids, broadcast MAC |
| IPv4 / IPv6 (leases, DNS servers, link-locals)          | error/reason/assert text, Wi-Fi signal/freq, loopback, public resolvers (8.8.8.8, 1.1.1.1) |
| internal DNS search domains, Wi-Fi country (`alpha2=`) |                                              |
| e-mails                                                 |                                              |
| secrets, destroyed as `<hidden>`: `password=`/`psk=`/`token=`/`api_key=`…, `Authorization:` headers, JWTs, AWS keys, SSH public keys, PEM private-key blocks | |
| internal host names / URL hosts (`vpn.corp.acme.com`, `nas.local`) | vendor / OS / CDN hosts (`archive.ubuntu.com`, `fortinet.com`, `google.com`) |
| `/home/<name>`, `sudo: <name> : TTY=` audit lines, `user=`/`login=` fields | system accounts (`root`, `nobody`), numeric `uid=` |
| certificate `CN=`, `serial=` / `S/N` / udev `ID_SERIAL=` values, `/dev/disk/by-id/<id>` | model names (`DMI:`), package versions |
| WireGuard peer / public keys (`<wg-key-N>`); private and preshared keys destroyed | endpoints keep their port, allowed-ips prefix length |
| OpenVPN `user/ip:port` prefixes, `username '…'`, `sid=`; FortiGate / EMS serials, `SVPNCOOKIE=` | OpenVPN cipher / TLS lines, `Initialization Sequence Completed`, FortiClient error codes |
| Windows: `Host Name`, DNS suffixes, `SSID` / `Profile`, `Registered Owner`, `Logon Server`, `host\user`, `C:\Users\<name>` | adapter descriptions, subnet masks, `(Preferred)` flags |
| config files: OpenVPN inline `<ca>`/`<cert>`/`<key>` blocks (destroyed), keyfile / wpa_supplicant `id=` / `ssid=`, WireGuard keys | option names, `remote … 1194`, `AllowedIPs`, `verb 3` |
| personal data: phone numbers, payment cards (Luhn), IBAN (mod 97), Ukrainian tax ids / waybills (labelled), car plates | pids, ports, uptime stamps, build numbers |
| NetworkManager `%3B`-encoded personal file names        |                                              |
| anything passed via `--redact-value` / `--redact-file`  |                                              |

## Choosing the level of safety

| Level | What you get | When |
| ----- | ------------ | ---- |
| default | Known shapes are tokenized: names, hosts, SSIDs, addresses, secrets, domains, serials, identities in free text. Most readable. | Logs you will skim yourself before sending to a vendor you trust |
| `--verify` / `--require-clean` | Same, plus a self-check for leftovers (original values, your `--redact-value`s, home paths, `user=` fields, keys, long hex). With `--require-clean` nothing is written unless it is clean. | The default for anything that leaves your machine |
| `--strict` | Allow-list: every word that is not a token, a known log word (`vocab.py`), an interface, a number / version / date or short hex becomes `<word-N>`. Catches the host name in a comment, the project codename, the colleague's name. Add your own harmless words with `--allow-value` or `logredact config --allow`. | "I want to give this to anyone" |

Your personal lists in `~/.config/logredact/` (`redact.txt`, `allow.txt`)
apply to every run; the web UI learns them with a click (click a word to
always redact it, click a `<word-N>` token to allow it) and can save them.

### Attestable redaction

Deny-list tools can only say "we looked for the usual things". After
`--strict`, logredact can say more: `logredact attest FILE` checks every
word of the file against the published rules and prints a certificate:

```
logredact-attestation/1
file:        vpn.redacted.log
sha256:      9fbe6c69…847401
words:       89 (11 token, 46 vocabulary, 15 numeric, 1 hex, 16 short)
vocabulary:  logredact 1.7.0, sha256 37760bac…81a8c
allow-list:  0 word(s) sha256 e3b0c442…52b855
verdict:     CLEAN - every word is a redaction token, a vocabulary word, a number,
             a version, a date, short hex, an interface name or an allow-listed word
```

The claim depends only on the file, the vocabulary hash and the printed
allow-list, never on your private mapping, so the receiver (or your own
compliance) can re-run `attest` and get the same verdict. If a word falls
outside the rules the verdict is `NOT CLEAN`, the words are listed and the
exit code is 3. With `--key` the certificate is signed (HMAC-SHA256), and
`attest --check` re-verifies file hash, vocabulary, verdict and signature.

### Keeping the diagnostic value

| Option | Keeps | Hides |
| ------ | ----- | ----- |
| `--shift-time` | every interval, ordering, retry timing (one random offset for all stamps, undone by `restore`) | when it happened |
| `--keep-oui` | the vendor half of MACs (`3c:97:0e:<mac-1>`: "an Intel adapter") | the device |
| `--keep-subnets` | subnet structure of private IPv4 (`<net-1>.5`, gateway `<net-1>.1`) | the network itself |

## How it compares

| | logredact | `sos clean` (Red Hat) | netconan | Presidio / scrubadub | ad-hoc `sed` |
| --- | --- | --- | --- | --- | --- |
| Audience | a person with a laptop and a support case | RHEL admins with sosreports | network-device configs | developers building pipelines | whoever wrote it |
| Install | stdlib only; `.deb`, `.pyz`, pipx | part of sos | pip | pip + NER models (hundreds of MB) | nothing |
| Deterministic tokens + restore | yes, per kind, shared across files | yes (hosts, IPs, MACs, keywords) | yes (IPs) | partly | no |
| Allow-list mode with a verifiable certificate | yes (`--strict`, `attest`, signable) | no | no | no | no |
| Self-check / refuse to write | `--verify`, `--require-clean` | no | no | no | no |
| Keeps diagnostic structure on purpose | interfaces, states, versions, subnets, OUI, intervals | yes | yes | no notion of it | depends |
| Learns your names with a click | yes (UI, personal lists) | keyword file | no | custom recognisers (code) | edit the script |
| VPN / Wi-Fi / Windows / config files / personal data (UA) | yes | hosts, IPs, MACs, keywords | configs only | generic PII | depends |
| Local web UI, GUI, clipboard, live stream | yes | no | no | no | no |

The honest limits are in [docs/THREAT-MODEL.md](docs/THREAT-MODEL.md).
Real-world inputs can be added as cases under `tests/corpus/` (see its README).

## Log types

| Type       | Typical input                                                          |
| ---------- | ---------------------------------------------------------------------- |
| `syslog`   | `journalctl` / syslog exports: NM, wpa_supplicant, resolvectl events (ISO `2025-01-15T10:00:00` or classic `Jan 15 10:00:00` timestamps) |
| `terminal` | copy-pasted shell sessions: `nmcli`, `find`, `apt-cache`, sudo prompts; Windows `ipconfig /all`, `netsh wlan`, `systeminfo`, `whoami` (CRLF ok) |
| `auto`     | heuristic detector (default)                                           |

## `logredact collect`

Runs a fixed, read-only set of commands and redacts every output with **one**
shared token space, so `<ssid-1>` is the same network in the journal and in
the `nmcli` table:

| File in the bundle               | Command                                              |
| -------------------------------- | ---------------------------------------------------- |
| `journal-networkmanager.log`     | `journalctl -b -o short-iso -u NetworkManager`       |
| `journal-wpa-supplicant.log`     | `journalctl -b -o short-iso -u wpa_supplicant`       |
| `journal-systemd-resolved.log`   | `journalctl -b -o short-iso -u systemd-resolved`     |
| `journal-kernel.log`             | `journalctl -b -o short-iso -k`                      |
| `journal-forticlient.log`        | `journalctl -b -o short-iso`, lines matching `forti` |
| `nmcli-connections.txt`          | `nmcli -f NAME,UUID,TYPE,DEVICE,FILENAME connection show` |
| `nmcli-devices.txt`, `nmcli-wifi.txt` | `nmcli device show`, `nmcli device wifi list`    |
| `resolvectl-status.txt`          | `resolvectl status`                                  |
| `ip-addr.txt`, `ip-route.txt`    | `ip addr`, `ip route`                                |
| `versions.txt`                   | `uname -a`                                           |
| `nmconnection-files.txt`         | `sudo -n find /etc/NetworkManager/system-connections -type f` (only with `--with-sudo`) |
| `MANIFEST.txt`                   | what ran, what was skipped and why                   |

Your login name and host name are always added to the "always redact" list,
so they vanish even from outputs without a prompt. Missing tools are skipped.
The mapping file is written **next to** the bundle, never inside it. Use
`--redact-value` / `--redact-file` here too, `--archive` for a `.tar.gz`.

## How it works

1. Detect the log type (`--type` overrides).
2. Register every sensitive value in a deterministic registry
   (`value -> <kind-N>`), longest names first to avoid partial matches.
3. Apply type-specific rules, then the shared per-line pass
   (MAC / IPv4 / IPv6 / UUID / e-mail / secrets / identities / internal domains).
   Credentials are destroyed (`<hidden>`), never written to the mapping.
   Internal domain detection uses a TLD list plus an allow-list of vendor/OS
   hosts in `patterns.py` (`PUBLIC_DOMAINS`); extend it if a harmless host
   gets tokenized.
4. Write the redacted file (0644, shareable) and a **local-only** mapping
   file (0600) so *you* can reverse tokens later (`logredact restore`).
5. With `--verify`, scan the result for leftovers: every original value from
   the mapping, your `--redact-value`s, plus heuristics for things no rule
   covers (`/home/<name>`, `user=`/`serial=` fields, SSH/PEM keys, JWTs,
   AWS keys, long hex blobs). Findings are printed, nothing is changed.

Add a new rule: pattern in `patterns.py`, logic in `redactors/`, test in
`tests/`. See [CONTRIBUTING.md](CONTRIBUTING.md).

## Security model & limitations

The full picture is in [docs/THREAT-MODEL.md](docs/THREAT-MODEL.md): what
each level promises, what a redacted file still reveals, and what is out
of scope. The short version:

- logredact **reduces** accidental PII leakage; it is not a guarantee.
  **Always skim the redacted output before sending it anywhere.**
- The mapping file is the key to everything — keep it private, delete when
  done, or pass `--no-map` to never write it.
- Values not matching a known rule (free-text comments, unusual formats) can
  survive. Put them in `--redact-value` / `--redact-file`, run `--verify`, and
  still grep the output for your hostname, username and SSIDs first:
  `grep -iE 'myhost|myname|my-ssid' clean.log`
- `--verify` is a heuristic too: a clean report is not a proof, and a finding
  is not always a leak (package checksums look like "long hex").
- The web UI hides the mapping behind a button; only reveal it when you need
  it, and never copy it together with the log.
- Contributions for more log dialects are welcome.

## Development

```bash
pip install -e ".[dev]"
ruff check src tests && ruff format --check src tests
pytest --cov=logredact
```

See `Makefile` targets: `make lint fmt test cov bench dist clean`.

Throughput is roughly 4 MB/s of journal on one core (`make bench`), so a
200 MB week of logs takes under a minute. The test suite includes
property-based checks (`hypothesis`) over generated journals.

## License

[MIT](LICENSE)
