Commit Graph
18 Commits
Author SHA1 Message Date
Timothy Jaeryang Baek a8ea18e391 refac 2026-10-31 05:58:40 +09:00
Timothy Jaeryang Baek 6852d4d663 refac 2026-10-19 04:00:34 +09:00
Timothy Jaeryang Baek f3d321fa4d refac 2026-10-19 03:49:20 +09:00
Timothy Jaeryang Baek d09d027e06 refac 2026-10-19 03:40:42 +09:00
Timothy Jaeryang Baek a0ef1c0af8 refac 2026-10-19 03:38:17 +09:00
Timothy Jaeryang Baek 4240b4e934 refac 2026-10-19 03:32:20 +09:00
Alan Chow 613c0431d0 Fix _is_writable_sync Windows compatibility (NotImplementedError) (#179)
- Catch NotImplementedError as the primary fallback since os.access(..., effective_ids=True) is not implemented on Windows
- Also catch AttributeError, OSError, and TypeError as supplementary guards
- Prevents crashes when checking file writability on Windows platforms, primarily fixing directory listing operations (/files/list, stat, listdir)

Fixes #174
2026-10-10 19:18:15 +04:00
Timothy Jaeryang Baek 690c5681c9 refac 2026-08-08 19:35:47 -06:00
Timothy Jaeryang Baek 4db47e8cee feat: resolve relative paths against session cwd in all file endpoints
All LLM-exposed file endpoints (list_files, read_file, write_file,
display_file, replace_file_content, grep_search, glob_search) now
read the X-Session-Id header and resolve relative paths against the
session's working directory instead of always using fs.home.

- Added optional cwd parameter to UserFS.resolve_path()
- Relative paths join against cwd if provided, else fs.home
- Absolute paths are unaffected
- execute endpoint also resolves relative cwd param against session cwd
2026-03-29 21:22:28 -05:00
Timothy Jaeryang Baek 952c3f1314 fix: set group-write permission on files after chown in multi-user mode
_chown() transferred file ownership to the provisioned user but didn't
set group-write permission, leaving files at 644. The server process
(a group member) could create new files but couldn't overwrite them on
subsequent saves, returning PermissionError. Now sets chmod g+w after
chown, matching the 2770 treatment already applied to directories.

Fixes #93
2026-03-24 16:53:28 -05:00
Timothy Jaeryang Baek 4ab451d27b fix: write_file permission denied in multi-user subdirectories (#70)
Directories created by run_command (as the provisioned user via sudo -u)
get default 755 permissions, leaving the server process without group-write.
Both makedirs (creating subdirs) and aiofiles.open (creating files) fail
with EPERM.

UserFS._ensure_parents now:
- Creates directories as the provisioned user (sudo -u mkdir -p) to bypass
  755 restrictions on existing parent directories
- Sets 2770 (setgid + group rwx) on all intermediate directories up to the
  user's home, matching the home directory's permissions
- Falls through to plain makedirs in single-user mode (no behavior change)

Closes #70
2026-03-15 16:40:46 -05:00
Timothy Jaeryang Baek abbface95a fix: remove misleading user from system info in multi-user mode, catch /home/usr hallucination
- get_system_info() no longer includes 'as user user' when MULTI_USER is
  active, removing the hint that caused smaller LLMs to hardcode /home/user
- resolve_path() now rewrites /home/usr → actual user home, matching the
  existing /home/user rewrite

Closes #57
2026-03-13 17:21:05 -05:00
Timothy Jaeryang Baek 34054e5052 fix: multi-user search isolation for glob_search, grep_search, listdir, walk (#46)
Added is_path_allowed() to UserFS and wired it into all directory
traversal code paths. In multi-user mode, entries belonging to other
users' home directories are now filtered out during os.walk/os.listdir,
preventing file listing leaks when searching parent directories like
/home. Single-user mode is unaffected (early return on username=None).
2026-03-11 15:16:05 -05:00
Timothy Jaeryang Baek eaf7cb7812 fix: resolve relative paths against user home in multi-user mode (#47)
- Add resolve_path() to UserFS that resolves relative paths against
  self.home instead of os.getcwd()
- Replace all os.path.abspath() calls in route handlers with
  fs.resolve_path()
- Auto-swap /home/user → provisioned user home for hardcoded paths
- Add fs dependency to grep_search and glob_search endpoints
2026-03-11 15:09:32 -05:00
Timothy Jaeryang Baek 7d1584d4bf refactor: native Python I/O for all UserFS operations
Replace all subprocess-based writes (sudo tee, mkdir -p, rm -rf, mv)
with native Python I/O. The only subprocess left is 'sudo chown' for
ownership fixup after writes.

- chmod 2770 (setgid + group rwx) on home dirs so native writes work
- write/write_bytes: aiofiles.open + chown
- mkdir: os.makedirs + chown
- remove: shutil.rmtree / os.remove (no chown needed)
- move: shutil.move + chown
2026-03-09 18:21:14 -05:00
Timothy Jaeryang Baek c948b266c9 fix: cross-user path validation and terminal spawn directory
- UserFS._check_path blocks access to other users' /home/<user>/ paths
- PermissionError → 403 Forbidden (global exception handler)
- Terminal spawn uses 'sudo -i -u' with cwd=fs.home so the shell
  starts in the user's own home directory
- System paths (/etc, /usr, etc.) remain accessible to all users
2026-03-09 18:17:49 -05:00
Timothy Jaeryang Baek 0aeda7392c refactor: native Python I/O for multi-user reads
Replace subprocess-based reads (cat, find, stat, test) with native
Python file I/O. Uses chmod 750 + group membership so the server
process can read user directories directly. Writes still use sudo -u
for correct ownership.

- Dockerfile: add CAP_SETGID to Python binary via setcap
- user_isolation: chmod 750, usermod -aG, os.setgroups() refresh
- utils/fs.py: all reads now use aiofiles/os (no subprocess branching)
2026-03-09 18:05:55 -05:00
Timothy Jaeryang Baek 18b3bc941d refactor: UserFS abstraction for multi-user file operations
Replace per-endpoint sudo wrappers with a unified UserFS class in
utils/fs.py. All file endpoints now receive a UserFS instance via
FastAPI dependency injection. Single-user mode uses stdlib/aiofiles,
multi-user mode routes all I/O through sudo -u.

- New: open_terminal/utils/fs.py (UserFS class)
- Simplified: user_isolation.py (provisioning only, sudo helpers removed)
- Updated: all 16 file endpoints in main.py (no more if-branches)
- Removed: user_fs.py (moved to utils/fs.py)
2026-03-09 17:56:00 -05:00