You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "lizardoluis (via GitHub)" <gi...@apache.org> on 2025/03/28 10:10:29 UTC

[I] Add allow-list to restrict access to local files with LocalFileSystem [arrow-rs-object-store]

lizardoluis opened a new issue, #312:
URL: https://github.com/apache/arrow-rs-object-store/issues/312

   **Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
   
   With `LocalFileSystem`, a (malicious) user could access any file in the system without restriction, giving that symlinks that resolve to paths outside the root are followed.
   
   **Describe the solution you'd like**
   
   I propose enhancing `LocalFileSystem` by introducing an allow-list mechanism to restrict file operations to specified path prefixes. The idea is to define a list of allowed paths when constructing `LocalFileSystem`, ensuring that operations such as `put`, `delete`, `copy` etc, are only executed within these paths.
   
   #### Implementation Proposal
   
   1. Allow-List for Paths
   
   - Introduce an allow-list of path prefixes. If a directory is allowed, all its subdirectories should also be allowed.
   - To prevent bypassing this restriction via symbolic links, paths must be verified against their canonical form.
   
   2. Two Possible Approaches:
   
   - Modify `LocalFileSystem` to accept an allow-list as a parameter. (Breaking change)
   - Alternatively, introduce a separate `SecureLocalFileSystem` object that implements this security mechanism while keeping `LocalFileSystem` unchanged.
   
   3. Path Verification Logic
   
   - Introduce a `LocalPathPrefixVerification` enum to handle verification:
   
   ```
   pub enum LocalPathPrefixVerification {
       Unverified, // Verification will be skipped
       Verify(Vec<String>),  // Allowed list
   }
   ``` 
   
   - Implement a validation function that ensures the user-specified path belongs to an allowed prefix. The function canonicalizes paths to prevent symlink-based escapes.
   
   ```
   fn validate_path_within_root(
       path: &PathBuf,
       verification: &LocalPathPrefixVerification,
   ) -> Result<(), object_store::Error> {
       match verification {
           LocalPathPrefixVerification::Unverified => Ok(()),
           LocalPathPrefixVerification::Verify(allowed_paths) => {
               let canonical_prefix = get_longest_canonical_prefix(path);
               for path in allowed_paths {
                   let allowed_root_canonical = canonicalize(path)?;
                   if canonical_prefix.starts_with(&allowed_root_canonical) {
                       return Ok(());
                   }
               }
   
               Err(object_store::Error::Generic {
                   store: "path_not_allowed",
                   source: format!(
                       "path is not allowed: {:?}. Must be under one of {:?}",
                       path, allowed_paths
                   )
                   .into(),
               })
           }
       }
   }
   
   fn get_longest_canonical_prefix(path: &PathBuf) -> PathBuf {
       let mut current_path = path.clone();
       
       // could be implemented with a binary search too. 
       loop { 
           if let Ok(canonical_path) = canonicalize(current_path.to_str().unwrap()) {
               return canonical_path;
           }
           if !current_path.pop() {
               break;
           }
       }
       current_path
   }
   ```
   
   #### Alternative Proposal
   
   An alternative approach is to introduce a `disable_symlink` flag. When enabled, all subdirectories within the `LocalFileSystem` `prefix` would be allowed, but any symlink resolving to a path outside the `prefix` would trigger an error.
   
   **Describe alternatives you've considered**
   
   As a workaround, we currently wrap `LocalFileSystem` in our own implementation, adding the necessary security checks.
   
   **Additional context**
   
   I am happy to contribute with a pull request implementing this enhancement if accepted.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Add allow-list to restrict access to local files with LocalFileSystem [arrow-rs-object-store]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on issue #312:
URL: https://github.com/apache/arrow-rs-object-store/issues/312#issuecomment-2764434256

   Is there a reason you don't want to use normal operating system primitives to achieve this, e.g. chroot, some MAC system like AppArmor or SELinux, or chroot?
   
   Providing safe access to filesystems is notoriously fraught, and it seems unwise to attempt to DIY it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Add allow-list to restrict access to local files with LocalFileSystem [arrow-rs-object-store]

Posted by "lizardoluis (via GitHub)" <gi...@apache.org>.
lizardoluis closed issue #312: Add allow-list to restrict access to local files with LocalFileSystem
URL: https://github.com/apache/arrow-rs-object-store/issues/312


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org