diff --git a/CHANGELOG.md b/CHANGELOG.md index c46eee1..e430c66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,27 @@ uses [Semantic Versioning](https://semver.org/). ## [Unreleased] +### Breaking + +- Unconfined agents are refused by default (#158, lockkit#133): lockkit + v0.20.0 (from v0.19.2). Every client reports in its `hello` whether it + runs confined (in a container, no host runtime socket, no Lock Family + state, a read-only `.lockfamily/`); the console refuses one that does + not, holds a group owning a runtime socket, or sends no report (an older + client), with `CodeUnconfined` (-32009). The launcher's `mcp`, lea's + agents and the own-container recipe run confined. Client and console + must be of the same version: an older console refuses the new `hello`, + and an older client is refused by the new console. + +### Added + +- The profile key `unconfined = true` serves agents that do not run + confined on a non-production profile: a loosening approved at the + console (it changes the policy fingerprint), a red banner, and + `"unconfined":true` on every audit record and `flags.unconfined` on + every hub ticket of the connection. It is refused on a production + profile; a managed `require_confined_agent = true` overrides it. + ## [0.3.1] - 2026-11-14 A masking fix: lockkit v0.19.2. diff --git a/README.md b/README.md index f0e4817..74fd8b1 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,10 @@ account, where it could still read the logs directly): `lox add` wires Claude Code; for Codex, Cursor or Gemini CLI, also run `locklog init codex` (or `cursor`, `gemini`). On production, run the agent in [lea](https://github.com/DavidGodefroid/lea) or in its own container -([docs/setup.md](docs/setup.md#the-own-container-recipe)). +([docs/setup.md](docs/setup.md#the-own-container-recipe)). The console +serves only agents that run confined, unless a non-production profile sets +`unconfined = true` +([docs/security-model.md](docs/security-model.md#confined-agents)). ## Highlights diff --git a/docs/security-model.md b/docs/security-model.md index e3b7068..034bbba 100644 --- a/docs/security-model.md +++ b/docs/security-model.md @@ -118,6 +118,27 @@ as the image's `agent` account, launched from your own account. Your agent there can still read whatever your account can, so the trial is for non-production data. The launcher's `mcp` refuses production profiles. +### Confined agents + +Every locklog client reports in its `hello` whether it runs confined +(lockkit's `confine` check): in a container, with no host container +runtime socket it can reach, the Lock Family's state unreadable and the +project's `.lockfamily/` read-only. The console also refuses a client that +holds a group owning a runtime socket (`runtime_group`), and one too old to +send the report (`old_client`). Such an agent is refused (`-32009`, +`CodeUnconfined`), with the failed checks in the message, before any +method is served; the decision is taken again at every request. + +The launcher's `mcp`, lea's agents and the +[own-container recipe](setup.md#the-own-container-recipe) run confined. +To serve an agent that does not, set `unconfined = true` on a +non-production profile: a loosening you approve at the console, which then +prints a red banner and marks every audit record (`"unconfined":true`) and +hub ticket (`flags.unconfined`) of the connection. A production profile +with `unconfined = true` is refused at load, and a managed +`require_confined_agent = true` refuses unconfined agents whatever the +profile says. + ## The masking pipeline Order, fixed, per record and per field: diff --git a/docs/setup.md b/docs/setup.md index 418206d..8ccf228 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -204,7 +204,10 @@ and every check; the exit status is 0 exactly when no check fails. A host agent is the non-production trial: its MCP server refuses production profiles (`E_PRODUCTION_HOST_AGENT`). For a production profile, run the agent with lea, or in an image of its own, as a non-root user without sudo -that reaches the console only through its socket. Add this to the agent's +that reaches the console only through its socket. The console serves it +only when it runs confined: no container runtime socket mounted, no Lock +Family state, the project's `.lockfamily/` read-only +([security-model.md](security-model.md#confined-agents)). Add this to the agent's Dockerfile, after its packages are installed, with the locklog image pinned by digest (`docker buildx imagetools inspect ghcr.io/davidgodefroid/locklog:`): diff --git a/docs/usage.md b/docs/usage.md index 2092182..2d6fd44 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -62,6 +62,7 @@ credentials = "ask" # typed at the console, never written to disk | `strict` | `false` | Accepted and reviewed, but not applied yet (planned: every search and count becomes a ticket) | | `prefilter` | `false` | Opt-in speed-up for non-production; reveals through latency how many records hold a clear substring, and turns off the `masked_failures` count of text searches (see The agent's tools) | | `user_journals` | `false` | Also serve `user-*.journal` files | +| `unconfined` | `false` | Also serve an agent that does not run confined (see [security-model.md](security-model.md#confined-agents)): a loosening you approve at the console, shown by a red banner and recorded on every audit record and hub ticket of its connections; refused on production | | `pseudonym_rotation` | `7d` | Epoch length (`session` or a duration; `never` is refused on production) | | `pseudonym_max_age` | `30d` | How long a replaced epoch key is kept; older ones are deleted when the console opens the profile | | `limits` | see Budgets | Per-call and rolling budgets | diff --git a/go.mod b/go.mod index 251ba28..9fd135a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/DavidGodefroid/locklog go 1.26.0 require ( - github.com/DavidGodefroid/lockkit v0.19.2 + github.com/DavidGodefroid/lockkit v0.20.0 github.com/klauspost/compress v1.20.3 github.com/pierrec/lz4/v4 v4.1.33 github.com/ulikunitz/xz v0.5.17 diff --git a/go.sum b/go.sum index 4b4ac27..400c808 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ 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/policy_test.go b/internal/config/policy_test.go index 8652b88..71498be 100644 --- a/internal/config/policy_test.go +++ b/internal/config/policy_test.go @@ -121,6 +121,8 @@ func TestDiffLoosens(t *testing.T) { {name: "lookup free", approved: "[profiles.pp]\nlookup = \"approved\"\n", field: "lookup", loosens: true}, {name: "strict off", approved: "[profiles.pp]\nstrict = true\n", field: "strict", loosens: true}, {name: "prefilter on", cur: "[profiles.pp]\nprefilter = true\n", field: "prefilter", loosens: true}, + {name: "unconfined on", cur: "[profiles.pp]\nunconfined = true\n", field: "unconfined", loosens: true}, + {name: "unconfined off", approved: "[profiles.pp]\nunconfined = true\n", field: "unconfined", loosens: false}, {name: "user journals on", cur: "[profiles.pp]\nuser_journals = true\n", field: "user_journals", loosens: true}, {name: "rotation longer", cur: "[profiles.pp]\npseudonym_rotation = \"14d\"\n", field: "pseudonym_rotation", loosens: true}, {name: "rotation never", cur: "[profiles.pp]\npseudonym_rotation = \"never\"\n", field: "pseudonym_rotation", loosens: true}, diff --git a/internal/config/profile.go b/internal/config/profile.go index 6dddb62..384fbea 100644 --- a/internal/config/profile.go +++ b/internal/config/profile.go @@ -107,6 +107,7 @@ type rawLimits struct { type rawProfile struct { Production bool `toml:"production"` + Unconfined bool `toml:"unconfined"` Structured string `toml:"structured"` Text string `toml:"text"` Detectors []string `toml:"detectors"` @@ -268,7 +269,7 @@ func buildProfile(name string, r rawProfile, detectorsSet bool) (Profile, error) } prod := r.Production p := Profile{ - Name: name, Base: kconfig.Base{Production: prod}, + Name: name, Base: kconfig.Base{Production: prod, Unconfined: r.Unconfined}, Structured: r.Structured, Text: r.Text, Detectors: r.Detectors, Unmask: r.Unmask, Lookup: r.Lookup, Strict: r.Strict, Prefilter: r.Prefilter, UserJournals: r.UserJournals, } @@ -310,6 +311,9 @@ func buildProfile(name string, r rawProfile, detectorsSet bool) (Profile, error) } p.Auto = rules.sparse() } + if prod && p.Unconfined { + return Profile{}, errf("unconfined = true is refused on a production profile: an agent that does not run confined is never served on production") + } if prod && p.Prefilter { return Profile{}, errf("prefilter = true is refused on a production profile: with it, latency reveals how many records hold a clear substring") } diff --git a/internal/config/profile_test.go b/internal/config/profile_test.go index 6adcb05..1896632 100644 --- a/internal/config/profile_test.go +++ b/internal/config/profile_test.go @@ -120,9 +120,29 @@ func TestProductionRefusals(t *testing.T) { prod := strings.ReplaceAll(fileSrc, "staging", "prod") + "[profiles.prod]\nproduction = true\n" wantErr(t, prod+"prefilter = true\n", "prefilter = true is refused on a production profile") wantErr(t, prod+`pseudonym_rotation = "never"`+"\n", `"never" is refused on a production profile`) + wantErr(t, prod+"unconfined = true\n", "unconfined = true is refused on a production profile") wantErr(t, strings.ReplaceAll(fileSrc, "staging", "y")+"[profiles.y]\nproduction = true\n", "production profile needs a name") - // Non-production accepts both. - mustParse(t, fileSrc+"[profiles.staging]\nprefilter = true\npseudonym_rotation = \"never\"\n") + // Non-production accepts them. + mustParse(t, fileSrc+"[profiles.staging]\nprefilter = true\npseudonym_rotation = \"never\"\nunconfined = true\n") +} + +// TestUnconfined (#158): unconfined = true is read into the profile's +// base and changes the policy fingerprint; unset, the fingerprint is the +// one before the key existed. +func TestUnconfined(t *testing.T) { + if p := mustParse(t, fileSrc)["staging"]; p.Unconfined { + t.Error("unconfined by default") + } + if p := mustParse(t, fileSrc+"[profiles.staging]\nunconfined = true\n")["staging"]; !p.Unconfined { + t.Error("unconfined = true not read") + } + none, off := policyOf(t, "", ""), policyOf(t, "[profiles.pp]\nunconfined = false\n", "") + if none.Fingerprint() != off.Fingerprint() { + t.Error("unconfined = false changes the fingerprint") + } + if on := policyOf(t, "[profiles.pp]\nunconfined = true\n", ""); on.Fingerprint() == none.Fingerprint() { + t.Error("unconfined = true keeps the fingerprint") + } } func TestProfileValues(t *testing.T) { diff --git a/internal/logconsole/backend.go b/internal/logconsole/backend.go index 7265874..41b0e8a 100644 --- a/internal/logconsole/backend.go +++ b/internal/logconsole/backend.go @@ -318,7 +318,7 @@ func (p Policy) remote() (config.Source, bool) { func (p Policy) Profile() console.Profile { pr := p.Policy.Profile cp := console.Profile{ - Name: pr.Name, Production: pr.Production, Where: where(pr), + Name: pr.Name, Production: pr.Production, Unconfined: pr.Unconfined, Where: where(pr), Credentials: console.CredentialsNone, IdleTimeout: pr.IdleTimeout, MaxSession: pr.MaxSession, } if s, ok := p.remote(); ok { diff --git a/test/hub/confined_test.go b/test/hub/confined_test.go new file mode 100644 index 0000000..5247a11 --- /dev/null +++ b/test/hub/confined_test.go @@ -0,0 +1,61 @@ +//go:build unix + +package hub + +import ( + "context" + "errors" + "strings" + "testing" + + "github.com/DavidGodefroid/lockkit/confine" + "github.com/DavidGodefroid/lockkit/console" + "github.com/DavidGodefroid/lockkit/ipc" +) + +// TestConfinedAgent (#158, lockkit#133): over the console's socket, an +// agent that does not run confined is refused with CodeUnconfined, as is +// one whose hello carries no report (an older client); a confined one is +// served. No method is served before an accepted hello. +func TestConfinedAgent(t *testing.T) { + r := newRig(t, rigOpts{}) + path := r.serveSocket() + + early := dialRaw(t, path) + if err := early.Call(context.Background(), ipc.MethodStatus, nil, nil); err == nil || + !strings.Contains(err.Error(), "hello first") { + t.Errorf("status before hello: %v, want refused (hello first)", err) + } + + for name, conf := range map[string]*ipc.Confinement{ + "unconfined": {Reasons: []string{confine.InContainer}}, + "old client": nil, + } { + err := dialRaw(t, path).hello(conf) + var re *ipc.RPCError + if !errors.As(err, &re) || re.Code != ipc.CodeUnconfined { + t.Errorf("%s: hello = %v, want CodeUnconfined", name, err) + } + } + + s := dialSock(t, path) + if err := s.Call(context.Background(), ipc.MethodStatus, nil, nil); err != nil { + t.Errorf("confined agent: status = %v", err) + } +} + +// TestUnconfinedProfile: with unconfined = true on a non-production +// profile, an unconfined agent is served and the console says so. +func TestUnconfinedProfile(t *testing.T) { + r := newRig(t, rigOpts{extra: "unconfined = true"}) + s := dialRaw(t, r.serveSocket()) + if err := s.hello(&ipc.Confinement{Reasons: []string{confine.InContainer}}); err != nil { + t.Fatalf("hello: %v", err) + } + if err := s.Call(context.Background(), ipc.MethodStatus, nil, nil); err != nil { + t.Errorf("status: %v", err) + } + if !strings.Contains(r.io.output(), console.UnconfinedBanner) { + t.Errorf("no unconfined banner: %q", r.io.output()) + } +} diff --git a/test/hub/leak_test.go b/test/hub/leak_test.go index a53c8a9..402a557 100644 --- a/test/hub/leak_test.go +++ b/test/hub/leak_test.go @@ -78,7 +78,20 @@ type sockConn struct { next int64 } +// dialSock dials the socket and says hello as a confined agent: the console +// serves a connection once its hello is accepted, and the test dials from +// the host (lockkit#133). func dialSock(t *testing.T, path string) *sockConn { + t.Helper() + s := dialRaw(t, path) + if err := s.hello(&ipc.Confinement{Confined: true}); err != nil { + t.Fatal(err) + } + return s +} + +// dialRaw dials the socket without a hello. +func dialRaw(t *testing.T, path string) *sockConn { t.Helper() c, err := net.Dial("unix", path) if err != nil { @@ -90,6 +103,12 @@ func dialSock(t *testing.T, path string) *sockConn { return s } +// hello opens the session with the confinement report conf. +func (s *sockConn) hello(conf *ipc.Confinement) error { + hp := ipc.HelloParams{ProtocolMajor: ipc.ProtocolMajor, Client: "locklog-test", Confinement: conf} + return s.Call(context.Background(), ipc.MethodHello, hp, nil) +} + func (s *sockConn) Call(ctx context.Context, method string, params, result any) error { s.mu.Lock() defer s.mu.Unlock()