eca icon indicating copy to clipboard operation
eca copied to clipboard

More granular permissions for external workspace paths

Open noctuid opened this issue 9 months ago • 21 comments

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

There are a copule relevant issues open: https://github.com/editor-code-assistant/eca/issues/36 and https://github.com/editor-code-assistant/eca/issues/153

It would be nice if permissions in general were more granular like in opencode. Opencode lets you configure for specific commands with wildcards as well as what files can be read/edited/etc.

I think particularly useful the external_directory config, which lets you blacklist or whitelist directories. I'd like to let eca ask for permission to look at other code repos, but I'd prefer if it couldn't even ask for permission to read anything else.

"external_directory": {
      "*": "deny",
      "~/src/**": "ask",
}

noctuid avatar Feb 22 '26 15:02 noctuid

Currently ECA alreayd ask for permissions for anything other than workspaceRoot, like other repos, unless you "approve and remember", so maybe you want some way to configure that like in that config and/or we could improve approve and remember like in those issues. tagging @zikajk as this is no easy issue to solve as there are multiple ways to solve it

ericdallo avatar Feb 23 '26 12:02 ericdallo

Recently adopted ECA on Emacs, amazing tool, thank you for the amazing work. As @noctuid, I would greatly value an option telling ECA not even to try to climb up the tree. While I ll try the @noctuid sandboxing suggestion, having more granular permissions would be a pretty good middle-ground option.

Edit: maybe something in the spirit of {"argsMatchers": {"path": ...?

maxecharel avatar Feb 28 '26 00:02 maxecharel

@maxecharel Thank you!

I'm not sure I get what ECA lacks that toolCall approval cannot solve, especially argsMatchers, can you elaborate?

ericdallo avatar Feb 28 '26 16:02 ericdallo

I think the meaning is the same as my original comment. I don't think there is any way to use argMatchers to deny external directories completely. There would need to be a way to:

  • deny by default for specific tools only (e.g. a different default for read_file than the global "byDefault") then whitelist specific directories
  • have e.g. some placeholder for the eca starting directory

It would also be a little inconvenient to need to do this for all of eca's tools that work with paths, which why I like the opencode external_directories syntax I mentioned.

Also about argsMatchers in general, is it just looking at the entire string? It seems like it would be very difficult to use for shell commands if that's the case because LLMs frequently use | and &&. Claude code is aware of shell operators and e.g. allowing Bash(mv *) won't also allow mv ... && rm ....

noctuid avatar Feb 28 '26 22:02 noctuid

@maxecharel Thank you!

I'm not sure I get what ECA lacks that toolCall approval cannot solve, especially argsMatchers, can you elaborate?

Hi @ericdallo, thank you for the feedback. Actually, I am in line with @noctuid. One could try to exclude everything outside of the ECA workspace directory with argsMatchers, but they would have to do that properly for both relative and absolute paths, possibly considering corner cases, testing, likely failing, testing again, you see my point. I think that a simple 'option' handling this in config.json would be a huge plus. Do you think it would be reasonable?

maxecharel avatar Mar 01 '26 12:03 maxecharel

@maxecharel I think the other problem is that eca could offer this as a setting for its own builtin tools, but then trying to detect what is a path (and what is a path outside the workspace directory) in any shell commands would be so complicated I don't think it's feasible. I've even been seeing LLMs sometimes generate python scripts with heredocs that act on paths. Makes more sense to me to sandbox or review there, but I still think it makes sense to allow more granular configuration where you can have different "ask"/"deny"/"allow" defaults for different tools and to be able to blacklist everything but certain directories for any builtin tool other than shell_command that operates on paths.

noctuid avatar Mar 01 '26 13:03 noctuid

Hi @noctuid, I think I see your point, and I tend to agree with it ('tend' since I haven't examined the internals of the builtin tools). And it's up to @ericdallo and other contributors to determine whether it would be worth implementing such features given the effort. Personally I would be more keen to use ECA (that I really like) if I know that with some simple (possibly default) settings the LLM would be soft-confined to its lane, and I can only guess that other users share our point of view. @ericdallo what's your take on this?

maxecharel avatar Mar 01 '26 17:03 maxecharel

@noctuid @maxecharel the need makes sense, I believe we can have some config like:

```json
{
  "toolCall": {
    "approval": {
      "byDefault": "ask",
      "externalPaths": {
        "*": "deny",
        "~/src/**": "ask",
        "~/docs/reference/**": "allow"
      }
    }
  }
}

Which would solve most of the problems I believe but not the by default for toolCall, which would be harder to support, what you say? would this be enough for this issue?

ericdallo avatar Mar 02 '26 14:03 ericdallo

Thank you @ericdallo for your understanding and reactivity. However, if I am not wrong, @noctuid was also suggesting having this possibility for each tool separately. Would it be possible?

Edit: what would also be amazing is that once these limitations are set, the LLM does not even try and thus a tool use explicit denial is not necessary/does not appear as a message to the user. But I have no clue about the amount of additional work that it would imply for you @ericdallo, assuming that you would consider such a behavior relevant

maxecharel avatar Mar 02 '26 15:03 maxecharel

Yeah, the thing is that I can't think a good config API to support a default per tool, but TBH I want to know if my proposal is enough for you two because it would be much simpler and I beliebe enough for most cases

ericdallo avatar Mar 02 '26 17:03 ericdallo

Long story short: yes, it would address my main concern, but of course I can only speak for myself (@noctuid ?). Many thanks 🙏

maxecharel avatar Mar 02 '26 17:03 maxecharel

@ericdallo Maybe there is a use case where you would want to limit tools for external directories (e.g. only allow tools that read) like ~/docs/reference/**, but I don't currently have that use case. externalPaths would be fine for me if it worked like this:

{
	"toolCall": {
		"approval": {
			// default
			"byDefault": "ask",
			// *only* applies for paths for builtin tools not shell command
			"externalPaths": {
				"*": "deny",
				"~/src/**": "ask",
				"~/docs/reference/**": "allow"
			},
			"allow": {
				// applies to workspace directory only
				"read_file": {},
				"edit_file": {}
			}
		}
	}
}

Also, is there anywhere in the documentation where all builtin tools are listed? The names also don't seem to line up, e.g. on the tools page it's called shell_command, but in the default config section all tools are prefixed with eca__ (is that outdated?).

noctuid avatar Mar 02 '26 23:03 noctuid

// only applies for paths for builtin tools not shell command

Hum, yeah that doesn't help with my idea so, we can't hardcode for a specific tool, we should think in some way to limit by tool I think @zikajk

Also, is there anywhere in the documentation where all builtin tools are listed? The names also don't seem to line up, e.g. on the tools page it's called shell_command, but in the default config section all tools are prefixed with eca__ (is that outdated?).

We have it here but I agree we should have probably in config section.

ericdallo avatar Mar 03 '26 12:03 ericdallo

Is the issue with the complexity of implementation or not being able to come up with a good config format?

I think no matter what, to support limiting by tool, you need some completely new field:

{
  "toolCall": {
    "approval": {
      "byDefault": "allow",
      "toolOverrides": [
        {
          "tools": ["read_file", "directory_tree"],
          // override the global default for these tools
          "default": "deny",
          // check rules in order
          "rules": [
            {
              "action": "allow",
              // basically <workspace_dir>/.*
              "inWorkspace": "path"
            },
            {
              "action": "allow",
              "argsMatchers": { "path": ["~/src/.*"] }
            },
            {
              "action": "ask",
              "argsMatchers": { "path": ["~/\\.config/.*"] }
            }
            // anything not matched falls through to "default" above
          ]
        }
      ]
    }
  }
}

As far as precedence: Check if the specific tool has a tool override and check the rules in order. If it doesn't or none match move on to checking the existing "allow"/"deny"/"ask" sections. Fall back to "byDefault".

It could be an error if there were multiple entries in toolOverrides that mentioned the same tool.

noctuid avatar Mar 03 '26 14:03 noctuid

yes, the config API is the most important thing to me, toolCall approval is already powerful but complex with argsMatchers, I'm not sure is a good idea to add rules and lots of more complexity, maybe a easier solution for users and maintainability is having a way to override a whole :toolCall :approval for a specific tool, following the same config structure:

{
  "toolCall": {
    "approval": {
      "byDefault": "allow",
      "externalPaths": { // new key
	    "*": "deny",
	    "~/src/**": "ask",
	    "~/docs/reference/**": "allow"
	  },
      "byTool": { // new key
        "eca__read_file": { // from here, same structure
          "byDefault": "deny",
          "externalPaths": {
		    "~/foo/**": "allow"
		  },
        }
      }
    }
  }
}

Even so, this kinda add ambiguity to argsMatchers, so needs more thinking

ericdallo avatar Mar 03 '26 15:03 ericdallo

@noctuid talking with @zikajk we believe supporting externalPaths is quite enough since no one has any real use case that cannot be achieved with argsMatchers, example of externalPaths + argsMatchers for a tool:

{
  "toolCall": {
    "approval": {
      "byDefault": "ask",
      "externalPaths": {
        // deny all external paths for path-based tools
        "*": "deny",
        // but allow asking for sibling repos
        "~/src/**": "ask",
        // and auto-allow reference docs
        "~/docs/reference/**": "allow"
      },
      "allow": {
        // auto-allow read/edit within workspace (no argsMatchers = matches unconditionally)
        "read_file": {},
        "edit_file": {},
        // auto-allow safe shell commands within workspace
        "shell_command": {
          "argsMatchers": {
            "command": ["pwd", "git\\s+status(\\s+.*)?", "git\\s+diff(\\s+.*)?"]
          }
        }
      }
    }
  }
}

We know argsMatchers is not that convenient but it's more powerful/flexible than opencode so it supports multiple cases.

ericdallo avatar Mar 03 '26 16:03 ericdallo

we believe supporting externalPaths is quite enough

Is this the same as what I mentioned in https://github.com/editor-code-assistant/eca/issues/324#issuecomment-3987674981, or how is it different? Supporting just externalPaths that applies to all builtin tools that take a dedicated path argument seems fine to me.

We know argsMatchers is not that convenient but it's more powerful/flexible than opencode so it supports multiple cases.

Again, does this match against the entire shell command string (e.g. git status ; rm -rf /)? If so, I think it makes that makes it very hard to use regexps for shell_command, but that is a separate issue and not a huge deal to me.

noctuid avatar Mar 03 '26 17:03 noctuid

Yes for both questions, we can improve the path argsMatcher in a different issue indeed

ericdallo avatar Mar 03 '26 19:03 ericdallo

@noctuid The main problem here is that eca__shell doesn't know about the path. And it wouldn't really work with MCP tools. I believe that this problem is more about sandboxing, right? Something like this

{
  "toolCall": {
    "approval": {
      "byDefault": "ask",
      "externalPaths": {
        "*": "deny",
        "~/src/**": "ask",
        "~/docs/reference/**": "allow"
      },
      "allow": {
        "eca__read_file": {},
        "eca__shell_command": {
          "argsMatchers": {
            "command": ["git\\s+status.*", "ls.*"]
          }
        }
      }
    }
  }
}

would help only some of builtin tools.

zikajk avatar May 03 '26 12:05 zikajk

Yeah, you can only handle paths reliably with sandboxing, so I'm just relying on that now.

noctuid avatar May 03 '26 13:05 noctuid