Skip to content
Isonapse
Install

Protect files by pattern

Refuse reads or writes of files that match a pattern, such as .env.* or *.pem, in any folder.

Works with: All four agents. Supported hosts has the detail for each agent.

Steps

  1. 1. Start from your current policy

    isonapse hook policy export my-policy.lua

    This writes your active policy to my-policy.lua. Copy the rules you want from the example below into it. If the file already has a section of the same name, add the lines to that section.

  2. 2. Check that it loads

    isonapse hook policy check my-policy.lua

    This loads the file the way Isonapse does and names any file or folder pattern that can never match. It changes nothing.

  3. 3. Ask what each mode would do

    isonapse hook policy test --candidate my-policy.lua --write .env.production

    Nothing runs, and no record is written. It prints one line per mode, with the reason; here Normal and Enforce refuse it.

  4. 4. Make it active

    isonapse hook policy activate my-policy.lua

    The terminal shows the exact change, and one approval with your login password makes it active. Use a plain terminal window that runs no agent, such as macOS Terminal or Ghostty.

  5. 5. Undo it

    isonapse hook policy revisions
    isonapse hook policy rollback <revision>

    The first lists earlier policies; the second restores one, with one approval and the password you log in to this computer with. Use a plain terminal window that runs no agent, such as macOS Terminal or Ghostty.

What it does not do

  • A matching pattern refuses the action even when an action rule allows the tool.
  • Some pattern shapes never match, such as secrets/*; the check step names them.
  • The example's hidden-file list applies only to an agent in a container that Isonapse sets up to hide them, not to an agent on your machine.

The policy

The whole example, 06-file-patterns.lua, from the examples Isonapse publishes.

-- 06-file-patterns.lua — file-path matching, OverlayFS hides, payload caps.
--
-- Three filesystem-shaped fields:
--
-- 1) `blocked_file_patterns[<cap>]` — DENY if the path the capability
--    targets matches any pattern. A rule under `tool:Read` or
--    `cap:file-read` governs every file read (Read, NotebookRead); one
--    under `tool:Write`, `tool:Edit` or `cap:file-write` governs every
--    file write (Write, Edit, MultiEdit, NotebookEdit, Codex apply_patch,
--    and the writes Isonapse reads in a shell command). A matching pattern
--    denies even when an action rule permits the tool.
--
-- 2) `hidden_file_patterns` — FLAT list (not capability-keyed). At
--    container deploy time, the platform populates OverlayFS whiteouts
--    so matched paths return ENOENT (not EACCES) to the agent. The
--    agent literally cannot see they exist. A folder pattern (ending in
--    `/`) hides the folder itself; a name pattern hides files only.
--    Enforcement is `[proxy] fs_overlay_enabled = true` in the SAC
--    manifest. A policy that declares hidden_file_patterns without the
--    manifest switch parses without error but the deploy logs a WARN.
--
-- 3) `max_payload_size[<cap>]` — DENY if the capability's payload (the
--    body bytes about to be written, posted, etc.) exceeds the cap.
--    Useful for blocking accidental megabyte-scale writes from agents
--    that thought they were appending a line.
--
-- The matcher is intentionally NARROW (no full glob). It compares whole
-- path components, ignoring letter case, against every spelling of the
-- target (as written, with `.`/`..` resolved, and through symbolic links):
--
--   name, *.pem, credentials*, *secret*
--                    — the file name, in any folder (also after `**/`).
--   **/.kube/config  — a path ending with these folders and file name
--                      (also `**/invoices/*.lock`).
--   **/.ssh/         — a folder of that name anywhere, and everything in it.
--   secrets/         — a folder of that name at any depth, or a path
--   config/prod.yml    ending in these components (also `secrets/*.pem`:
--                      files directly in such a folder). In
--                      hidden_file_patterns: below the workspace root.
--   /etc/shadow      — the same, absolute; `/etc/ssl/private/` a folder.
--
-- A folder may also be written `dir/**`; `*` may appear only at the start
-- or the end of the final file name. A pattern of any other shape
-- (`secrets/*`, `src/**/key.pem`, `~/.ssh/`, `**/*`) never matches; the
-- engine logs it when the policy loads, and `isonapse hook policy import`
-- refuses it. See 08-folder-rules.lua for folder rules.

return {
  policy_version = "file-patterns-v1",

  blocked_file_patterns = {
    -- Reads: block secrets-ish files anywhere in the tree.
    ["cap:file-read"] = {
      "**/.env",
      "**/.env.local",
      "**/.env.*",
      "**/.aws/credentials",
      "**/*.pem",
      "**/credentials*",
    },
    -- Writes: block writes to policy / managed-settings files so an
    -- agent can't self-protection-bypass.
    ["cap:file-write"] = {
      "**/isonapse*",          -- isonapse-* binaries and configs
      "**/managed-settings*",  -- Claude Code managed settings
      "/etc/sudoers",
    },
    -- The cap:file-write rule above already governs the Hook's Write and
    -- Edit; tool-level keys add rules for those tools (each one governs
    -- every file write too).
    ["tool:Write"] = {
      "**/.env",
      "**/.env.*",
      "**/*.pem",
    },
    ["tool:Edit"] = {
      "**/.env",
      "**/.env.*",
      "**/*.pem",
    },
  },

  -- Hidden via OverlayFS whiteout. Same matcher; flat list, not keyed.
  -- Effective at container deploy time. The agent's `ls -la` does not
  -- show these paths at all.
  hidden_file_patterns = {
    "**/.ssh/",
    "**/.gnupg/",
    "**/.aws/",
    "/etc/shadow",
  },

  -- Payload size limits. A tool:Write of 5 MiB into the workspace is
  -- almost certainly an accident.
  max_payload_size = {
    ["tool:Write"] = 1048576,        -- 1 MiB
    ["cap:file-write"] = 1048576,    -- match the Write cap above
    ["cap:http-request"] = 524288,   -- 512 KiB — HTTP request bodies
  },
}

Stuck? Help finds the message you see.