Skip to content

feat(config): make Windows cache-dir DACL hardening configurable (env var + CLI config key) — opt-out for hosts where it breaks MoveFileExW #1624

Description

@roosteer

Feature request

Make the Windows cache-directory DACL hardening configurable, via:

  1. CLI configuration: codebase-memory-mcp config set windows-dacl-hardening false (persisted)
  2. Environment variable: CBM_SKIP_DACL_HARDENING=1 (kill switch, overrides the config)

This is the opt-out path requested as fix option #2 in #1620 — on hosts where the protected owner-only DACL conflicts with local security policy (EDR/minifilter), indexing is currently impossible and there is no escape hatch.

Why this is needed (verified root cause, details in #1620)

  • Since v0.9.1-rc.1 every CBM process re-applies a protected owner-only DACL to the cache dir at startup (win_runtime_directory_secure, src/daemon/ipc.c:4121).
  • On some hosts, MoveFileExW(MOVEFILE_REPLACE_EXISTING) returns ERROR_ACCESS_DENIED inside protected-DACL directories (reproduced with cmd move /y, P/Invoke and synthetic dirs — independent of CBM).
  • CBM publishes the index DB via rename-replace (publish_writer_output, src/sqlite_writer.c) → the pipeline fails silently → generic "Pipeline failed".
  • Proof: with the dir ACL in the normal inherited state, the identical run succeeds (status:"indexed").

Analysis: points to modify

Site Function Change
src/main.c main_build_identity() Read effective setting (env > config) and gate the cbm_daemon_ipc_private_directory_secure() call
src/daemon/ipc.c win_runtime_directory_secure() Skip the unconditional SetSecurityInfo(... PROTECTED_DACL_SECURITY_INFORMATION ...) when disabled
src/daemon/ipc.c win_file_security_secure() validators When disabled, accept the OS-default (inherited) DACL instead of requiring the one-ACE owner-only form — otherwise the daemon fails closed at startup
src/foundation/compat_fs.c cbm_windows_stamp_dir_owner() Skip the protected-DACL stamp on freshly created dirs when disabled
src/ui/config.c CONFIG_KEYS[] Add windows-dacl-hardening (default true) — automatically supported by config list/get/set/reset

Notes:

  • Both sides must be gated. Disabling only the write side makes the strict validators reject the inherited DACL and the daemon refuses to start (fail-closed — observed while debugging Windows: index always fails with generic 'Pipeline failed' — protected-DACL cache dir breaks MoveFileExW(REPLACE_EXISTING) on this host #1620).
  • Owner checks (win_file_owner_secure) can stay active even when DACL hardening is off; the conflict is only with the protected-DACL shape, not with ownership validation.
  • The --index-worker process inherits the behavior for free because it also passes through main_build_identity.
  • Precedence: env var > config value. The env var is read via getenv (same pattern as CBM_CACHE_DIR, CBM_LOG_LEVEL); the config value via cbm_config_get(cfg, key, default) (same pattern as ui_port etc.). The read must happen before the hardening call; the config DB lives in the cache dir, so there is no circular dependency.

Security tradeoff (for the record)

The protected DACL defends the daemon's cache/IPC boundary against other local users. Disabling it is safe on single-user machines (the affected use case) and not recommended on multi-user/terminal-server hosts — the config default stays true.

Testing suggestions

  • config set windows-dacl-hardening false → index any repo → status:"indexed" (on an affected host; regression-check on a normal host that default behavior is unchanged)
  • CBM_SKIP_DACL_HARDENING=1 overrides true in config
  • Daemon startup: with the option off, no ui.config.write_fail reason=atomic_publish, and the walk accepts the inherited DACL
  • Unit tests: gate the win_file_security_secure relaxation path (tests exist in tests/ per Makefile.cbm)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.securitySecurity vulnerabilities, hardeningux/behaviorDisplay bugs, docs, adoption UXwindowsWindows-specific issues

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions