Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]

## [1.27.0] - 2026-06-24

### Added

- **No-egress / air-gap support — the offline-enclave stack lands for real (#98, #80).** A 4-deep stacked-PR chain (#83/#84/#85/#93) had squash-merged out of order, leaving it incompletely on main (`[air_gap]` config absent despite "#85 merged"; #84/#93 auto-closed). Reconstructed by rebasing the full stack tip onto current main:
- **`KIT_AIRGAP=1` offline scan mode (#83)** — runs only offline-capable scanners; no network.
- **Signed offline threat-data bundle (#84)** — Ed25519 + SHA-256 verified local threat data; fail-closed on a bad signature.
- **Declarative `[air_gap]` config in `.kit.toml` (#85)** — internal mirror endpoints honored by the triage subprocess even when the env var isn't exported (`process.env` still wins); `air_gap` added to the config schema.
- **Offline provenance verification — `kit verify-provenance` (#93)** — cosign `--offline` against a shipped-in trusted root; fail-closed.

Net: link triage at internal mirrors (#73), scan against signed local DBs, verify artifact provenance offline, with a tamper-evident + SIEM-exportable audit trail (1.24.0) — nothing reaches the public internet. Pure helpers fixture-tested (33 airgap+triage tests). The cloud scanners (Socket/Snyk) are deliberately out of this path — neither is air-gappable (#103).

## [1.26.1] - 2026-06-24

### Changed
Expand Down
115 changes: 109 additions & 6 deletions docs/AIR_GAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ queries at your **internal mirrors** instead, and run the heavy scanners against
> install rather than waving it through. Point the endpoints at reachable
> internal mirrors so triage can actually evaluate targets.

## Declarative config (recommended)

Everything below can be set with `KIT_*` env vars **or** checked into
`.kit.toml` so the enclave posture is reproducible and versioned. Env vars
override the file when both are set.

```toml
[air_gap]
enabled = true # turns on offline scan mode
npm_registry = "https://npm.corp.internal"
pypi_index = "https://pypi.corp.internal"
github_api = "https://ghe.corp.internal/api/v3"
docker_registry = "https://registry.corp.internal"
threat_data_dir = "/opt/kit/threat-data"
threat_data_pubkey = "/etc/kit/threat-data.pub"
```

## 1. Point the triage gate at internal mirrors

The triage script reads its registry hosts from the environment, defaulting to
Expand Down Expand Up @@ -62,20 +79,106 @@ What the mode does per scanner:
Install the scanners through your internal package mirror or an approved binary
cache; kit never downloads them itself.

### Verified offline threat-data bundle (signed)

Stale or tampered threat data silently degrades every verdict. To give the
sync-in a trust chain that is **fully offline-verifiable** (no Fulcio/Rekor),
ship the DBs as a _signed bundle_ and point kit at it:

```bash
export KIT_AIRGAP=1
export KIT_THREAT_DATA_DIR=/opt/kit/threat-data
export KIT_THREAT_DATA_PUBKEY=/etc/kit/threat-data.pub # PEM (path or inline)
kit scan
```

The bundle dir contains:

- `manifest.json` — `{ version, artifacts: [{ path, sha256, env? }] }`
- `manifest.json.sig` — a base64 **Ed25519** signature over `manifest.json`, made
on the connected host with the key whose public half is `KIT_THREAT_DATA_PUBKEY`
- the artifacts themselves (e.g. `grype.db`, `osv.db`, a bumblebee catalog)

kit verifies the manifest **signature**, then the **SHA-256** of every artifact,
then sets each artifact's declared `env` var to its absolute path (e.g.
`GRYPE_DB_CACHE_DIR`) so the scanner uses the verified local DB. **Any failure —
bad signature, checksum mismatch, missing/extra-path artifact — rejects the whole
bundle and `kit scan` refuses to run (fail-closed).** The bundle author declares
the `env` wiring per artifact, so kit hard-codes no scanner-version specifics.

Build the bundle on a connected host (sync DBs → write manifest with SHA-256 →
`openssl pkeyutl -sign` / equivalent Ed25519 signing), then transfer it in.

## 3. Bumblebee (known-compromise scan) offline

- `KIT_BUMBLEBEE_BIN` — use a pre-installed, internally-vetted bumblebee binary
instead of letting kit fetch the pinned release from GitHub.
- `KIT_BUMBLEBEE_CATALOG` — point at an internally-mirrored exposure catalog.
- `KIT_BUMBLEBEE=0` — disable the download/scan entirely where policy forbids it.

## 4. Known limitation: provenance verification
## 4. Offline provenance verification

cosign/SLSA verification normally reaches Sigstore's Fulcio CA + Rekor log
(public). `kit verify-provenance` runs cosign **fully offline** instead: it uses
the bundle's inclusion proof (`--offline`) and a **shipped-in** Sigstore
`trusted_root.json` (`--trusted-root`) that you distribute and refresh into the
enclave — no Fulcio/Rekor egress. kit does not reimplement the crypto; it
orchestrates cosign and is **fail-closed** (missing cosign, missing trust root,
missing identity constraints, or any non-zero cosign exit ⇒ NOT verified).

```bash
kit verify-provenance dist/app.tar.gz \
--bundle dist/app.sigstore \
--trusted-root /etc/kit/trusted_root.json \
--identity "/org/repo/.github/workflows/release.yml@refs/tags/v1" \
--issuer "https://token.actions.githubusercontent.com"
```

cosign/SLSA provenance verification depends on Sigstore's Fulcio CA + Rekor
transparency log, which are public services. Full online verification is not
possible in a no-egress enclave today; use offline-bundle verification where
your toolchain supports it, or treat provenance as an out-of-band, connected-host
check. (Tracked as an air-gap follow-up.)
Defaults for `--trusted-root` / `--identity` / `--issuer` can live in
`.kit.toml [air_gap]` (`provenance_trusted_root` / `provenance_cert_identity` /
`provenance_cert_issuer`) or the matching `KIT_PROVENANCE_*` env vars, so the
command is just `kit verify-provenance <artifact> --bundle <file>`.

**Operational note:** the enclave owner is responsible for distributing and
periodically refreshing `trusted_root.json` (a TUF mirror snapshot or pinned
roots) from a connected host — that is the trust anchor for offline
verification.

## 5. Memory in a classified enclave

kit's memory store inherits the **classification of the machine it runs on**.
There is intentionally **no per-row classification column**, for two reasons:

1. **Under system-high it is redundant.** A workstation accredited at one level
(e.g. SECRET) treats everything on it at that level — every captured row is
already SECRET, so a column adds no information.
2. **kit cannot enforce it.** Multi-level separation is the job of a trusted
reference monitor in the OS (SELinux MLS, labeled IPC/filesystems), not a CLI
reading and writing its own SQLite file. A classification field that kit
manages itself would be advisory metadata dressed up as a control — it would
imply a separation guarantee kit cannot keep. kit does not claim to separate
classification levels internally.

The operational posture instead:

- **The whole `memory.db` carries the enclave's level.** Run kit at system-high;
treat the database, its WAL, and any backups at the accredited level.
- **File handling is already conservative.** Encrypted backups and restores are
written `0o600` (owner-only); store `memory.db` on the same labeled volume as
the rest of the enclave's data at that level.
- **Purge = delete the database.** On a system-high machine there is no lower
level to preserve, so spill or decommission response is to destroy `memory.db`
(and backups) per your media-handling procedure, not to filter a column.
- **Capture-time redaction still applies.** `KIT_MEMORY_REDACT` strips secrets
before they ever reach the store (see redaction docs); that is orthogonal to
classification and worth enabling regardless of level.
- **Spill (wrong-level content pasted into a higher machine) is a procedural
matter**, handled by your incident process — not something an application-level
tag can prevent or remediate.

If you genuinely need a single install to span multiple levels, that is an
OS/MLS platform requirement: accredit the platform for multi-level operation and
run kit on top of it. It is not, and should not be, a kit feature.

## What still never leaves the enclave

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sandstream-kit",
"version": "1.26.1",
"version": "1.27.0",
"description": "developer kit. zero LLM, local-first, multi-vault. one command from git clone to working dev environment.",
"license": "MIT",
"funding": "https://buymeacoffee.com/sandstream",
Expand Down
64 changes: 64 additions & 0 deletions src/airgap/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { resolveAirGap, airGapTriageEnv } from "./config.js";

describe("resolveAirGap", () => {
it("reads settings from .kit.toml [air_gap] when no env is set", () => {
const s = resolveAirGap(
{
enabled: true,
npm_registry: "https://npm.corp",
threat_data_dir: "/opt/td",
threat_data_pubkey: "/etc/k.pub",
},
{},
);
assert.equal(s.enabled, true);
assert.equal(s.npmRegistry, "https://npm.corp");
assert.equal(s.threatDataDir, "/opt/td");
assert.equal(s.threatDataPubkey, "/etc/k.pub");
});

it("env overrides the checked-in config value", () => {
const s = resolveAirGap(
{ npm_registry: "https://npm.corp" },
{ KIT_NPM_REGISTRY: "https://npm.override" },
);
assert.equal(s.npmRegistry, "https://npm.override");
});

it("KIT_AIRGAP truthy enables even if config is silent", () => {
assert.equal(resolveAirGap(undefined, { KIT_AIRGAP: "1" }).enabled, true);
assert.equal(resolveAirGap(undefined, { KIT_AIRGAP: "true" }).enabled, true);
assert.equal(resolveAirGap(undefined, {}).enabled, false);
});

it("config enabled=true holds even without the env var", () => {
assert.equal(resolveAirGap({ enabled: true }, {}).enabled, true);
});

it("is all-undefined / disabled with empty inputs", () => {
const s = resolveAirGap(undefined, {});
assert.equal(s.enabled, false);
assert.equal(s.npmRegistry, undefined);
assert.equal(s.threatDataDir, undefined);
});
});

describe("airGapTriageEnv", () => {
it("emits only the mirror vars that resolved to a value", () => {
const env = airGapTriageEnv({
enabled: true,
npmRegistry: "https://npm.corp",
githubApi: "https://ghe.corp/api/v3",
});
assert.deepEqual(env, {
KIT_NPM_REGISTRY: "https://npm.corp",
KIT_GITHUB_API: "https://ghe.corp/api/v3",
});
});

it("is empty when no mirrors are configured", () => {
assert.deepEqual(airGapTriageEnv({ enabled: true }), {});
});
});
69 changes: 69 additions & 0 deletions src/airgap/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Resolve the effective air-gap posture from `.kit.toml [air_gap]` + env.
*
* The checked-in `.kit.toml` makes the enclave config reproducible; env vars
* (KIT_AIRGAP, KIT_NPM_REGISTRY, …) override it for one-off/CI runs. Pure +
* deterministic so it is fully testable.
*/
import type { kitConfig } from "../config.js";

export interface AirGapSettings {
enabled: boolean;
npmRegistry?: string;
pypiIndex?: string;
githubApi?: string;
dockerRegistry?: string;
threatDataDir?: string;
/** Trusted Ed25519 public key — a file path or an inline PEM. */
threatDataPubkey?: string;
/** Offline provenance: shipped-in Sigstore trusted_root.json + identity constraints. */
provenanceTrustedRoot?: string;
provenanceCertIdentity?: string;
provenanceCertIssuer?: string;
}

function envTrue(v: string | undefined): boolean {
return ["1", "true", "yes"].includes((v ?? "").trim().toLowerCase());
}

/** env value wins when set (non-empty); otherwise the checked-in config value. */
function pick(envVal: string | undefined, cfgVal: string | undefined): string | undefined {
const e = envVal?.trim();
return e ? e : (cfgVal ?? undefined);
}

export function resolveAirGap(
cfg: kitConfig["air_gap"],
env: NodeJS.ProcessEnv = process.env,
): AirGapSettings {
const ag = cfg ?? {};
return {
// env KIT_AIRGAP (truthy) OR config enabled; an explicit KIT_AIRGAP=0 does
// NOT force-disable a config-enabled posture (env only adds), keeping the
// checked-in enclave config authoritative unless the operator opts in.
enabled: envTrue(env.KIT_AIRGAP) || ag.enabled === true,
npmRegistry: pick(env.KIT_NPM_REGISTRY, ag.npm_registry),
pypiIndex: pick(env.KIT_PYPI_INDEX, ag.pypi_index),
githubApi: pick(env.KIT_GITHUB_API, ag.github_api),
dockerRegistry: pick(env.KIT_DOCKER_REGISTRY, ag.docker_registry),
threatDataDir: pick(env.KIT_THREAT_DATA_DIR, ag.threat_data_dir),
threatDataPubkey: pick(env.KIT_THREAT_DATA_PUBKEY, ag.threat_data_pubkey),
provenanceTrustedRoot: pick(env.KIT_PROVENANCE_TRUSTED_ROOT, ag.provenance_trusted_root),
provenanceCertIdentity: pick(env.KIT_PROVENANCE_CERT_IDENTITY, ag.provenance_cert_identity),
provenanceCertIssuer: pick(env.KIT_PROVENANCE_CERT_ISSUER, ag.provenance_cert_issuer),
};
}

/**
* The `KIT_*` mirror env vars to inject into the triage subprocess so a
* config-declared mirror is honored (triage.py reads these from its env).
* Only includes keys that resolved to a value.
*/
export function airGapTriageEnv(s: AirGapSettings): Record<string, string> {
const e: Record<string, string> = {};
if (s.npmRegistry) e.KIT_NPM_REGISTRY = s.npmRegistry;
if (s.pypiIndex) e.KIT_PYPI_INDEX = s.pypiIndex;
if (s.githubApi) e.KIT_GITHUB_API = s.githubApi;
if (s.dockerRegistry) e.KIT_DOCKER_REGISTRY = s.dockerRegistry;
return e;
}
78 changes: 78 additions & 0 deletions src/airgap/provenance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
buildCosignArgs,
missingField,
verifyProvenance,
type ProvenanceVerifyOptions,
type ProvenanceDeps,
} from "./provenance.js";

const full: ProvenanceVerifyOptions = {
artifact: "dist/app.tar.gz",
bundle: "dist/app.sigstore",
trustedRoot: "/etc/kit/trusted_root.json",
certIdentity: "/org/repo/.github/workflows/release.yml@refs/tags/v1",
certIssuer: "https://token.actions.githubusercontent.com",
};

describe("missingField", () => {
it("returns null when all required fields are present", () => {
assert.equal(missingField(full), null);
});
it("flags the first missing/empty field", () => {
assert.equal(missingField({ ...full, bundle: "" }), "bundle");
assert.equal(missingField({ artifact: "a" }), "bundle");
});
});

describe("buildCosignArgs", () => {
it("builds an offline verify-blob argv with trust root + identity constraints", () => {
assert.deepEqual(buildCosignArgs(full), [
"verify-blob",
"--offline",
"--trusted-root",
"/etc/kit/trusted_root.json",
"--bundle",
"dist/app.sigstore",
"--certificate-identity",
full.certIdentity,
"--certificate-oidc-issuer",
full.certIssuer,
"dist/app.tar.gz",
]);
});
});

describe("verifyProvenance (fail-closed)", () => {
const okRun = async () => ({ ok: true, stdout: "Verified OK", stderr: "" });

it("verifies when cosign exits 0", async () => {
const deps: ProvenanceDeps = { resolveBin: async () => "/usr/bin/cosign", run: okRun };
assert.deepEqual(await verifyProvenance(full, deps), { ok: true });
});

it("refuses (fail-closed) when a required field is missing", async () => {
const deps: ProvenanceDeps = { resolveBin: async () => "/usr/bin/cosign", run: okRun };
const r = await verifyProvenance({ ...full, certIdentity: "" }, deps);
assert.equal(r.ok, false);
assert.match(r.ok === false ? r.reason : "", /certIdentity/);
});

it("refuses when cosign is not installed", async () => {
const deps: ProvenanceDeps = { resolveBin: async () => null, run: okRun };
const r = await verifyProvenance(full, deps);
assert.equal(r.ok, false);
assert.match(r.ok === false ? r.reason : "", /cosign not found/);
});

it("refuses when cosign rejects the bundle (non-zero)", async () => {
const deps: ProvenanceDeps = {
resolveBin: async () => "/usr/bin/cosign",
run: async () => ({ ok: false, stdout: "", stderr: "error: no matching signatures" }),
};
const r = await verifyProvenance(full, deps);
assert.equal(r.ok, false);
assert.match(r.ok === false ? r.reason : "", /cosign rejected the bundle/);
});
});
Loading
Loading