From e7d3a3dbc0195f1b228fd0e7d24a04333f86856a Mon Sep 17 00:00:00 2001 From: DavidG Date: Sat, 14 Nov 2026 15:12:51 +0000 Subject: [PATCH 1/2] feat!: lockkit v0.20.0, refuse unconfined agents (#35) Bump lockkit to v0.20.0 (lockkit#133): the console refuses an agent that does not run confined. Map the profile key `unconfined` (project, user and managed files) to config.Base.Unconfined, part of the policy fingerprint and a loosening via DiffBase, and to console.Profile.Unconfined; a production profile with it does not start. Unit test for the key, fingerprint and diff; the docker e2e checks an unconfined agent is refused by default, served with unconfined = true on a non-production profile, and that a production profile with it does not start. Docs and CHANGELOG (Breaking). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 16 ++++++++ README.md | 6 ++- docs/usage.md | 19 ++++++++- go.mod | 2 +- go.sum | 2 + internal/config/managed.go | 9 +++- internal/config/policy.go | 5 ++- internal/config/profile.go | 3 +- internal/config/profile_test.go | 32 +++++++++++++++ internal/sshconsole/policy.go | 2 +- test/docker/e2e.py | 73 +++++++++++++++++++++++++++++++-- 11 files changed, 159 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f84525..8419b14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,22 @@ All notable changes to lockssh. The format follows ## [Unreleased] +### Breaking + +- lockkit v0.20.0 (from v0.19.2): the console refuses an agent that does + not run confined (lockkit#133). Every client reports in its handshake + whether it runs in a container, with no host container runtime socket it + can reach, no Lock Family state and a read-only `.lockfamily/`; an agent + that does not, that holds the group of the host's Docker socket, or that + sends no report (an older lockssh client) is refused with + `CodeUnconfined` and audited `refused-unconfined`. The new profile key + `unconfined = true` serves it on a non-production profile: it is part of + the policy fingerprint, turning it on is a loosening the human approves, + the console shows a red banner and marks every audit record and hub + ticket of the connection unconfined. A production profile with it does + not start. Upgrade the client and the console together: an older console + refuses the new client's handshake (#35). + ## [0.2.1] - 2026-11-14 ### Changed diff --git a/README.md b/README.md index e282af5..8f54918 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,11 @@ public IPs, cards, IBANs, phones, secrets. [lockhub#133](https://github.com/DavidGodefroid/lockhub/issues/133)). It shows the profile's policy for approval, logs in over SSH (trusting the host key only on your answer), and checks the account. 2. The agent's `lockssh mcp` (or CLI) runs as another account and reaches - the console only through its socket. + the console only through its socket. The console serves it only if it + runs confined (in a container, with no reach to the host's container + runtime or Lock Family state, as lea runs agents); an agent on the host + is refused unless a non-production profile sets `unconfined = true` + ([docs/usage.md](docs/usage.md#profiles)). 3. Each request is an argv, matched against the approved allow rules: - a match runs at once; - anything else is refused, or becomes a signed ticket on lockhub that you diff --git a/docs/usage.md b/docs/usage.md index 1039c0d..b8c7276 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -35,6 +35,7 @@ credentials = "none" # key: none (unencrypted, the default) | ask vault_path = "" # with credentials = "vault" known_hosts = "" # "" = the console account's ~/.ssh/known_hosts production = false +unconfined = false # true: serve an agent that does not run confined (never on production) exec = false # true: a command outside allow may be asked allow = ["uptime", "df -h", "systemctl status *", "journalctl -u * -n * --no-pager"] detectors = ["card", "email", "iban", "ip", "phone", "secret"] # the default @@ -64,11 +65,27 @@ production the last 8 characters of its fingerprint), then recorded. With a `known_hosts` file, a key the file does not hold is refused. A changed key is always refused. +**Confined agents.** The console serves only an agent that runs confined: +every lockssh client reports it in its handshake (in a container, no host +container runtime socket it can reach, no Lock Family state, the project's +`.lockfamily/` read-only), and an agent that does not, or that holds the +group of the host's Docker socket, is refused with the reasons +(`CodeUnconfined`, audited `refused-unconfined`). Agents run by lea are +confined; an agent run on the host is not. `unconfined = true` on a +non-production profile serves it anyway: turning it on is a loosening the +human approves, the console shows a red banner, and every audit record and +hub ticket of the connection is marked unconfined. A production profile +with `unconfined = true` does not start, and a managed +`require_confined_agent = true` refuses an unconfined agent whatever the +profile says. The client and the console must be of the same lockssh +version. + **Policy.** Every security-relevant field is part of the profile's policy. The console shows it at its first start and asks the human to approve it; afterwards a change that tightens applies at once, and a change that loosens (a new allow rule, exec turned on, another host, user, key or -known_hosts, a removed detector, a larger limit, a looser auto rule) waits +known_hosts, unconfined turned on, a removed detector, a larger limit, a +looser auto rule) waits for the human in the console (`:review`). An agent that edits the file loosens nothing. diff --git a/go.mod b/go.mod index 69d26f5..e03b878 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.26.0 require ( github.com/BurntSushi/toml v1.6.0 - github.com/DavidGodefroid/lockkit v0.19.2 + github.com/DavidGodefroid/lockkit v0.20.0 github.com/modelcontextprotocol/go-sdk v1.8.0 golang.org/x/crypto v0.58.0 golang.org/x/term v0.47.0 diff --git a/go.sum b/go.sum index 18f1a8f..cfb19ed 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/DavidGodefroid/lockkit v0.19.2 h1:wKxHoV07NAzmclXnWEyba9nUMLod/jsyr2ifM1pV/5c= github.com/DavidGodefroid/lockkit v0.19.2/go.mod h1:E4k9vDNBj9yEE3a9AQarl3PI8J6V4NtKxt28TZ/vB/A= +github.com/DavidGodefroid/lockkit v0.20.0 h1:xzrVnv2MtciWFbAtbtDJENQ67LGSDpv7q+NUWnzU7UA= +github.com/DavidGodefroid/lockkit v0.20.0/go.mod h1:E4k9vDNBj9yEE3a9AQarl3PI8J6V4NtKxt28TZ/vB/A= github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ= github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/internal/config/managed.go b/internal/config/managed.go index a7d29de..dbfb9fd 100644 --- a/internal/config/managed.go +++ b/internal/config/managed.go @@ -160,6 +160,7 @@ type ( VaultPath *string `toml:"vault_path"` CredentialsTTL *string `toml:"credentials_ttl"` Production *bool `toml:"production"` + Unconfined *bool `toml:"unconfined"` Exec *bool `toml:"exec"` Allow *[]string `toml:"allow"` Detectors *[]string `toml:"detectors"` @@ -213,7 +214,7 @@ func decodeManagedProfile(f *managed.File, key ...string) (bool, rawProfile, def } t = mProfile[*mAuto]{Host: s.Host, Port: s.Port, User: s.User, Auth: s.Auth, Key: s.Key, KnownHosts: s.KnownHosts, Credentials: s.Credentials, VaultPath: s.VaultPath, CredentialsTTL: s.CredentialsTTL, Production: s.Production, - Exec: s.Exec, Allow: s.Allow, Detectors: s.Detectors, Limits: s.Limits} + Unconfined: s.Unconfined, Exec: s.Exec, Allow: s.Allow, Detectors: s.Detectors, Limits: s.Limits} if s.Auto != nil { auto = *s.Auto } @@ -242,6 +243,9 @@ func decodeManagedProfile(f *managed.File, key ...string) (bool, rawProfile, def if t.Production != nil { r.Production, set["production"] = *t.Production, true } + if t.Unconfined != nil { + r.Unconfined, set["unconfined"] = *t.Unconfined, true + } if t.Exec != nil { r.Exec, set["exec"] = *t.Exec, true } @@ -420,6 +424,9 @@ func (m *Managed) fillDefaults(r rawProfile, set definedFunc) rawProfile { if take("production") { r.Production = d.Production } + if take("unconfined") { + r.Unconfined = d.Unconfined + } if take("exec") { r.Exec = d.Exec } diff --git a/internal/config/policy.go b/internal/config/policy.go index e128ff7..7f45c51 100644 --- a/internal/config/policy.go +++ b/internal/config/policy.go @@ -55,7 +55,7 @@ func Canonical(p Policy) Policy { // detector, a larger output cap, a longer request timeout, an auto rule // made looser (deny < ask < auto), a removed PII mask rule, a new PII // allow rule, and the shared rules of the profile base (kconfig.DiffBase: -// the login, the SSH target, production, credentials). A new allow rule +// the login, the SSH target, production, unconfined, credentials). A new allow rule // the review warns on carries its warnings. func (p Policy) Diff(approved kconfig.Policy) []kconfig.Change { a, ok := approved.(Policy) @@ -108,6 +108,9 @@ func (p Policy) Describe() []string { "known_hosts: " + orDefault(pr.KnownHosts), fmt.Sprintf("production: %t · credentials: %s", pr.Production, pr.Credentials), } + if pr.Unconfined { + lines = append(lines, "unconfined: ON (an agent that does not run confined is served)") + } if len(pr.Allow) == 0 { lines = append(lines, "allow: none") } diff --git a/internal/config/profile.go b/internal/config/profile.go index 1cdf02c..96fd8c2 100644 --- a/internal/config/profile.go +++ b/internal/config/profile.go @@ -85,6 +85,7 @@ type rawProfile struct { VaultPath string `toml:"vault_path"` CredentialsTTL string `toml:"credentials_ttl"` Production bool `toml:"production"` + Unconfined bool `toml:"unconfined"` Exec bool `toml:"exec"` Allow []string `toml:"allow"` Detectors []string `toml:"detectors"` @@ -257,7 +258,7 @@ func buildProfile(name string, r rawProfile, detectorsSet bool) (Profile, error) p := Profile{ Name: name, Base: kconfig.Base{ - User: r.User, Credentials: cred, VaultPath: r.VaultPath, Production: r.Production, + User: r.User, Credentials: cred, VaultPath: r.VaultPath, Production: r.Production, Unconfined: r.Unconfined, SSH: &kconfig.SSHProfile{Host: host, Port: port, User: r.User, Auth: auth, Key: r.Key, Credentials: cred}, }, KnownHosts: r.KnownHosts, diff --git a/internal/config/profile_test.go b/internal/config/profile_test.go index 1b74331..7a63962 100644 --- a/internal/config/profile_test.go +++ b/internal/config/profile_test.go @@ -96,6 +96,7 @@ func TestDiff(t *testing.T) { "known_hosts": {func(p *Profile) { p.KnownHosts = "/tmp/kh" }, true}, "auto run ask": {func(p *Profile) { p.Auto.Run = AutoAsk }, false}, "auto exec auto": {func(p *Profile) { p.Auto.Exec = AutoAuto }, true}, + "unconfined on": {func(p *Profile) { p.Unconfined = true }, true}, } { ch := loosen(c.edit) if len(ch) == 0 { @@ -114,3 +115,34 @@ func TestDiff(t *testing.T) { t.Errorf("describe:\n%s", d) } } + +// TestUnconfined: the profile key unconfined is read into the profile base, +// changes the policy fingerprint, and turning it off is a tightening. +func TestUnconfined(t *testing.T) { + body := "host = \"h\"\nuser = \"u\"\nkey = \"k\"\n" + ps, err := parse(t, "[profiles.p]\n"+body+"\n[profiles.q]\n"+body+"unconfined = true\n") + if err != nil { + t.Fatal(err) + } + p, q := ps["p"], ps["q"] + if p.Unconfined || !q.Unconfined { + t.Fatalf("unconfined: p %t, q %t", p.Unconfined, q.Unconfined) + } + q.Name = p.Name + pp, qp := NewPolicy(p), NewPolicy(q) + if kconfig.Fingerprint(pp) == kconfig.Fingerprint(qp) { + t.Error("unconfined does not change the fingerprint") + } + loosens := func(ch []kconfig.Change) bool { + return slices.ContainsFunc(ch, func(c kconfig.Change) bool { return c.Loosens }) + } + if ch := qp.Diff(pp); len(ch) != 1 || ch[0].Field != "unconfined" || !loosens(ch) { + t.Errorf("unconfined on: %+v", ch) + } + if ch := pp.Diff(qp); len(ch) != 1 || loosens(ch) { + t.Errorf("unconfined off: %+v", ch) + } + if d := strings.Join(qp.Describe(), "\n"); !strings.Contains(d, "unconfined: ON") { + t.Errorf("describe:\n%s", d) + } +} diff --git a/internal/sshconsole/policy.go b/internal/sshconsole/policy.go index 09c39d8..1dc0980 100644 --- a/internal/sshconsole/policy.go +++ b/internal/sshconsole/policy.go @@ -31,7 +31,7 @@ func (p Policy) Diff(approved kconfig.Policy) []kconfig.Change { func (p Policy) Profile() console.Profile { pr := p.Policy.Profile return console.Profile{ - Name: pr.Name, Production: pr.Production, Where: where(pr), + Name: pr.Name, Production: pr.Production, Unconfined: pr.Unconfined, Where: where(pr), Host: pr.Host(), Port: pr.Port(), DefaultPort: kconfig.DefaultSSHPort, User: pr.User, Credentials: pr.Credentials, VaultPath: pr.VaultPath, CredentialsTTL: pr.CredentialsTTL, IdleTimeout: pr.IdleTimeout, MaxSession: pr.MaxSession, diff --git a/test/docker/e2e.py b/test/docker/e2e.py index 6edf19e..b13baf0 100644 --- a/test/docker/e2e.py +++ b/test/docker/e2e.py @@ -10,8 +10,10 @@ throwaway containers that share only the socket volume and the project. It also checks the image's accounts and modes, that the console refuses to start without its hub, that it refuses a peer that is neither lockssh -nor in lockssh-clients, and that it enforces the company's managed file -(/etc/lockfamily/managed.toml, mounted as lox mounts it). +nor in lockssh-clients, that it refuses an agent that does not run confined +unless the profile sets unconfined = true (lockkit#133), and that it +enforces the company's managed file (/etc/lockfamily/managed.toml, mounted +as lox mounts it). python3 test/docker/e2e.py IMAGE @@ -38,6 +40,11 @@ SSH_USER = "deploy" HUB_URL, INSTANCE = "http://lockssh-e2e-hub:8443", "web-e2e" KEYDIR = tempfile.mkdtemp(prefix="lockssh-e2e-key-") +# Lock Family state an unconfined agent sees ($XDG_STATE_HOME/lockfamily). +STATE_DIR = tempfile.mkdtemp(prefix="lockssh-e2e-state-") +os.mkdir(os.path.join(STATE_DIR, "lockfamily")) +os.chmod(STATE_DIR, 0o755) +os.chmod(os.path.join(STATE_DIR, "lockfamily"), 0o755) failures = [] @@ -169,6 +176,61 @@ def put_managed(body, mode="0644"): ' && chown 0:0 /etc/lockfamily/managed.toml && chmod "$2" /etc/lockfamily/managed.toml', "sh", body, mode) +def console_up(project, profile, unconfined=False): + """Whether the agent's status reaches the console within two minutes.""" + deadline = time.time() + 120 + while time.time() < deadline: + if agent(project, "status", "--profile", profile, unconfined=unconfined).returncode == 0: + return True + time.sleep(2) + return False + + +def confinement_checks(project): + """Confined agents (lockkit#133): an agent that does not run confined + (here, one that may write the project's .lockfamily/) is refused by + default; a non-production profile with unconfined = true serves it; a + production profile with it does not start.""" + cfg = os.path.join(project, ".lockssh", "config.toml") + with open(cfg) as f: + saved = f.read() + target = f'host = "{SSHD}"\nport = 2222\nuser = "{SSH_USER}"\nkey = "~/.ssh/id_e2e"\nallow = ["uname -s"]\n' + with open(cfg, "a") as f: + f.write(f"\n[profiles.unconf]\n{target}unconfined = true\n" + f"\n[profiles.production-e2e]\n{target}production = true\nunconfined = true\n") + try: + sh("docker", "wait", CONSOLE, check_=False) + con = Console(project, "--profile", "dev") + check(console_up(project, "dev"), "confinement: the console serves a confined agent") + r = agent(project, "status", "--profile", "dev", unconfined=True) + check(r.returncode != 0 and "confined" in (r.stdout + r.stderr).lower(), + f"an unconfined agent is refused by default (exit {r.returncode})\n{r.stdout}{r.stderr}") + con.stop() + if failures: + print(con.text()[-4000:]) + + sh("docker", "wait", CONSOLE, check_=False) + con = Console(project, "--profile", "unconf") + check(console_up(project, "unconf", unconfined=True), "unconfined = true on a non-production profile serves an unconfined agent") + check("unconfined" in con.text().lower(), "the console warns of unconfined") + con.stop() + if failures: + print(con.text()[-4000:]) + + sh("docker", "wait", CONSOLE, check_=False) + con = Console(project, "--profile", "production-e2e") + code = con.wait(90) + check(code not in (None, 0) and "unconfined is never allowed on a production profile" in con.text() + and "Apply these changes?" not in con.text(), + f"a production profile with unconfined = true does not start (exit {code})") + con.stop() + if failures: + print(con.text()[-4000:]) + finally: + with open(cfg, "w") as f: + f.write(saved) + + def managed_checks(project, mount): """The release image, no test tag, under a managed file: the console prints whose it is and records its fingerprint with the approval; @@ -227,10 +289,14 @@ def managed_checks(project, mount): print(con.text()[-4000:]) -def agent(project, *args, user=None, extra=()): +def agent(project, *args, user=None, extra=(), unconfined=False): + """The agent's command in a container of its own; unconfined, it sees + Lock Family state (a confine check that fails).""" cmd = ["docker", "run", "--rm", "-v", f"{project}:{project}", "-w", project, "-v", f"{RUN_VOL}:/run/lockssh"] if user: cmd += ["--user", user] + if unconfined: + cmd += ["-v", f"{STATE_DIR}:/xdg-state:ro", "-e", "XDG_STATE_HOME=/xdg-state"] cmd += list(extra) + [IMAGE] + list(args) return subprocess.run(cmd, capture_output=True, text=True, timeout=360) @@ -372,6 +438,7 @@ def lox_up_copies(why): IMAGE, "console", "--allowed-uids", "0", check_=False) check(r.returncode != 0 and "leading zero" in r.stdout + r.stderr, f"--allowed-uids 0 refused\n{r.stdout}{r.stderr}") + confinement_checks(project) managed_checks(project, mount) finally: cleanup() From 1e1a7c48ce80c150cb83e4e6378193531be23111 Mon Sep 17 00:00:00 2001 From: DavidG Date: Sat, 14 Nov 2026 15:31:48 +0000 Subject: [PATCH 2/2] chore(release): prepare v0.3.0 Move the Unreleased changelog entry to 0.3.0 (lockkit v0.20.0, confined agents by default, #35) and say v0.3.0 is the latest release in the README, FAQ and install page. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ README.md | 2 +- site/faq/index.html | 2 +- site/install/index.html | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8419b14..2c08c4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to lockssh. The format follows ## [Unreleased] +## [0.3.0] - 2026-11-14 + ### Breaking - lockkit v0.20.0 (from v0.19.2): the console refuses an agent that does diff --git a/README.md b/README.md index 8f54918..0479b42 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ It works with any MCP client (Claude Code, Codex, Cursor, Gemini CLI, …) or through the `lockssh` CLI. > [!NOTE] -> **0.x**: flags and the policy format may still change between minor versions. v0.2.1 is the latest release. `lox add lockssh` and `lox run` +> **0.x**: flags and the policy format may still change between minor versions. v0.3.0 is the latest release. `lox add lockssh` and `lox run` > serving it ship in lockhub v0.11.0 > ([lockhub#133](https://github.com/DavidGodefroid/lockhub/issues/133)); an > older `lox` does not know lockssh. diff --git a/site/faq/index.html b/site/faq/index.html index 356fd66..92a1581 100644 --- a/site/faq/index.html +++ b/site/faq/index.html @@ -112,7 +112,7 @@

What is logged?

Can I install it today?

-

v0.2.1 is released, and its launcher installs with install.sh. The console runs under lox run only, which takes lockhub’s lox v0.11.0 or later. It installs with Homebrew too: brew install davidgodefroid/tap/lockfamily installs it with lox. Where things stand.

+

v0.3.0 is released, and its launcher installs with install.sh. The console runs under lox run only, which takes lockhub’s lox v0.11.0 or later. It installs with Homebrew too: brew install davidgodefroid/tap/lockfamily installs it with lox. Where things stand.

How does it relate to the other Locks?

diff --git a/site/install/index.html b/site/install/index.html index f47898b..dcf3fb4 100644 --- a/site/install/index.html +++ b/site/install/index.html @@ -63,7 +63,7 @@

Install lockssh

Where things stand

-

lockssh v0.2.1 is the latest release. lox add lockssh and lox run serving it ship in lockhub v0.11.0 (lockhub#133); an older lox does not know lockssh and cannot start its console. lox add lockssh pins lockssh v0.2.0.

+

lockssh v0.3.0 is the latest release. lox add lockssh and lox run serving it ship in lockhub v0.11.0 (lockhub#133); an older lox does not know lockssh and cannot start its console. lox add lockssh pins lockssh v0.2.0.

lockssh has a Homebrew formula, on Linux and macOS. The lockfamily meta formula installs the whole family, lockssh and lockhub’s lox v0.11.0 included; or install lockssh by name.