Administrator Guide

<!--
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: 2026 ndaal Informationstechnik GmbH & Co KG, Cologne
SPDX-FileCopyrightText: Author: Pierre Gronau <Pierre.Gronau@ndaal.eu>
-->

# Administrator Guide

Deployment, configuration and day-to-day operation of `sarif-viewer`.

## Platform support

A single self-contained binary. Built and tested on macOS and Linux (x86-64 /
aarch64). Requires no runtime services — Bootstrap, the icon font, the Roboto
faces and the SARIF schemas are embedded.

## Install

For most deployments, install the prebuilt binary rather than building from
source. Fastest first:

```bash
cargo binstall sarif-viewer    # prebuilt GitLab release asset, no compile
cargo install sarif-viewer     # compile from crates.io
```

Or fetch the release asset for the host platform directly and verify it
before deploying:

```bash
ver=0.1.4
base="https://gitlab.com/vPierre/ndaal_public_sarif_viewer/-/releases/v${ver}/downloads"
file="sarif-viewer-${ver}-x86_64-unknown-linux-musl"   # pick your platform
curl -LO "${base}/${file}" && curl -LO "${base}/SHA256SUMS"
sha256sum -c SHA256SUMS 2>&1 | grep "${file}"
install -m 0755 "${file}" /usr/local/bin/sarif-viewer
```

Prebuilt targets: Linux x86_64 / ARM64 (static musl), Windows x86_64 / ARM64,
macOS Intel / Apple Silicon. The binary is self-contained — no shared
libraries, runtime or data files to deploy alongside it. `cargo binstall`
works because the crate ships a `[package.metadata.binstall]` mapping onto
the release assets.

## Build

For development, or a platform without a prebuilt binary, compile from source:

```bash
cargo build --release          # target/release/sarif-viewer
```

A recent stable Rust toolchain is required (developed against 1.96). The build
compiles the aws-lc-rs crypto provider, which needs a C/assembler toolchain (cc
\+ a recent assembler) available on the build host.

## Deployment

The viewer is an offline, single-user desktop tool. It binds loopback
(`127.0.0.1`) by default and serves **HTTPS only** (TLS 1.3) with a self-signed
certificate that is regenerated at every start-up.

```bash
sarif-viewer serve --port 8580 --quic-port 8581
# HTTPS  on 127.0.0.1:8580  (HTTP/1.1 + HTTP/2)
# HTTP/3 on 127.0.0.1:8581  (QUIC/UDP), advertised via Alt-Svc
```

Open `https://127.0.0.1:8580`. Browsers warn once about the self-signed
localhost certificate; this is expected.

### Listen ports

A listen port must be a plain decimal number in **1025-65535**; anything else is
refused at start-up with exit status **64** before a socket is opened: the
privileged ports 0-1023, `1024` (by policy), `0` (the operating system would
choose any free port), numbers above 65535, and spellings such as `08080`,
`+8080`, `" 8080"` or `0x1f90`. The same rule applies to `--port`,
`--quic-port`, `SARIF_PORT` and `SARIF_QUIC_PORT`. Any other usage error exits
2, so a service manager can tell a misconfigured port (64) from a mistyped flag
(2) and from a port that is already in use (1).

To reach the viewer on 443, do not run it on 443: keep it on an accepted port
and let a reverse proxy listen on 443. Scripts that tested for exit status 2 on
a bad port must test for 64 (see the Troubleshooting Guide).

For any non-loopback exposure, place the viewer behind a TLS-terminating reverse
proxy with a CA-issued certificate, or replace the self-signed cert handling. Do
not expose the loopback HTTP/3 port externally without review.

## Configuration reference

| Setting                 | Flag               | Environment            | Default                      |
| ----------------------- | ------------------ | ---------------------- | ---------------------------- |
| Bind address            | `--bind`           | `SARIF_BIND`           | `127.0.0.1`                  |
| HTTPS port (1025-65535) | `--port`           | `SARIF_PORT`           | `8580`                       |
| QUIC port (1025-65535)  | `--quic-port`      | `SARIF_QUIC_PORT`      | `port + 1`                   |
| Disable QUIC            | `--no-quic`        | —                      | off                          |
| Export directory        | `--export-dir`     | `SARIF_EXPORT_DIR`     | `<home>/sarif-viewer/export` |
| Pre-load path(s)        | `--import`         | —                      | none                         |
| Skip samples            | `--no-samples`     | —                      | off                          |
| Log verbosity           | —                  | `RUST_LOG`             | `info`                       |
| Check for update        | `--check-update`   | —                      | off (one-shot, read-only)    |
| Self-update             | `--self-update`    | —                      | off (one-shot)               |
| Disable self-update     | `--no-self-update` | `SARIF_NO_SELF_UPDATE` | off                          |

## Uploads

The **Upload** page (`/upload`) sends a SARIF file from the user's browser to
the viewer (`POST /upload`, `multipart/form-data`). Import reads a path on the
machine the viewer runs on; Upload carries the file's own bytes, so it is the
way to load a log from a laptop onto a viewer running elsewhere.

- **Size.** A request body is capped at 64 MiB, a fixed limit (there is no flag
  or environment variable for it). A larger body is refused with `413`. The
  same cap applies over HTTP/1.1, HTTP/2 and HTTP/3.
- **Memory.** A body is held in memory until the file is validated and stored,
  so each upload in flight can use up to 64 MiB. Stored logs also live in
  memory and are lost on restart. Size the host for the number of people
  uploading at once.
- **Cross-site requests.** `POST /upload` is the one route that checks where a
  request came from: `Sec-Fetch-Site` decides when the browser sends it, and
  otherwise `Origin` must equal the `Host`. A cross-site request is refused
  with `403`.
- **File names.** The client's file name is shown as a label and turned into
  the log id; it never reaches a filesystem path.

Behind a reverse proxy, two settings matter:

1. Raise the proxy's body limit to at least 64 MiB. nginx defaults to 1 MiB
   (`client_max_body_size`), so a normal upload would be refused by the proxy
   itself, before the viewer sees it.
2. Forward the original `Host` (nginx: `proxy_set_header Host $http_host;`).
   Modern browsers send `Sec-Fetch-Site`, which decides on its own, but a
   client that sends only `Origin` is compared with the `Host` the viewer sees,
   and a proxy that rewrites `Host` makes that upload fail with `403`.

## Self-update

The binary can check and update itself against the project's GitLab releases,
without a package manager:

```bash
sarif-viewer --check-update   # read-only; reports whether a newer release exists
sarif-viewer --self-update    # downloads, verifies and installs it
```

`--self-update`:

1. Queries the GitLab releases API for the newest published version; never
   downgrades — a from-source build ahead of the latest release is reported
   as up to date, not "outdated".
2. Downloads the release asset matching the running binary's target triple.
3. Verifies its SHA-256 against the `SHA256SUMS` file uploaded to that same
   GitLab release (pinned to the exact release tag it checksummed — never a
   different, re-selected release), refusing to install if the asset is
   missing from the manifest or the checksum doesn't match.
4. Atomically replaces the running executable.

All network I/O goes over the same TLS 1.3 / aws-lc-rs transport the server
uses — no second HTTP or crypto stack. Checksum verification, not a
cryptographic signature: it defends against a corrupted or swapped-in-transit
download, not against a compromise of the release pipeline itself.

For package-managed installs (Homebrew, a distro package, a container image)
or any locked-down deployment where the binary must not replace itself, set
`--no-self-update` or `SARIF_NO_SELF_UPDATE=1`. This makes `--self-update`
refuse and exit non-zero; `--check-update` (read-only) is unaffected and
stays available.

## Operations

- **Pre-load logs at start-up:**
  `sarif-viewer serve --import /srv/scans --no-samples`
- **Logging:** structured `tracing` output on stderr. Increase detail with
  `RUST_LOG=debug`.
- **Shutdown:** `Ctrl-C` (graceful) or `SIGTERM`.
- **Concurrent imports:** two `/import/run` requests importing files with the
  same name are assigned distinct ids atomically (`SarifStore::insert_unique`)
  — neither can silently overwrite the other. Proven race-free under every
  thread interleaving by the `loom-harness/` permutation-testing crate (see
  `documentation/Developer_Guide.md`).

## Backup / recovery

The viewer keeps loaded logs **in memory only**; nothing is persisted unless an
operator runs an export. Back up the export directory if exported artifacts and
their checksum sidecars must be retained. There is no database to back up.

## Secret management

No secrets are stored or required. The TLS key exists only in memory for the
lifetime of the process (regenerated each start-up).

## Security posture

See the in-app **Security** page (`/security`) and
[`documentation/Developer_Guide.md`](Developer_Guide.md). Summary: TLS 1.3 with
the aws-lc-rs provider and `prefer-post-quantum` (X25519MLKEM768 first),
schema-validated import/export, capability-scoped exports, strict response
security headers, `#![forbid(unsafe_code)]`, `cargo-deny` / `cargo-audit`.
`POST /upload` is the one write route that checks `Origin` / `Sec-Fetch-Site`;
the three `GET` actions (delete, import, export) do not yet, see the arc42
risk R-3.

Report vulnerabilities to <security@ndaal.eu>.