Package to manage access control using POSIX ACLs
Project description
PyFACL
A Python library for parsing and checking POSIX File Access Control Lists (FACL).
Documentation: https://pyfacl.readthedocs.io/en/latest/
Installation
From PyPI
pip install pyfacl
Usage
CLI
The CLI tool checks permissions through the entire directory hierarchy, checks whether the permissions are met and identifies which permission rule applies at each level.
pyfacl trace /path/to/file user:<user2>:r-x --mode exact
Example output:
$ pyfacl trace /data1/collab002/sail/example/permission/folder user:user2:r-x
0) ✅ other::r-x /
1) ✅ other::r-x /data1
2) ✅ group::rwx /data1/collab002
3) ✅ group::r-x /data1/collab002/sail
4) ✅ group::r-x /data1/collab002/sail/example
5) ❌ user:user2:--x /data1/collab002/sail/example/permission
6) ✅ group::r-x /data1/collab002/sail/example/permission/folder
In this trace, items 0-4 and 6 show ✅ passing permissions, while item 5 shows ❌ failing permissions where the user only has execute (--x) but needs read+execute (r-x).
However, often we only care about if the user has the required permission for the final file/directory, not the full trace. For that, we can use the has command:
$ pyfacl has /path/to/file user:<user2>:r-x --mode exact
0) ✅ other::r-x /
1) ✅ other::r-x /data1
2) ✅ group::rwx /data1/collab002
3) ✅ group::r-x /data1/collab002/sail
4) ✅ group::r-x /data1/collab002/sail/example
5) ✅ user:user2:--x /data1/collab002/sail/example/permission
6) ✅ group::r-x /data1/collab002/sail/example/permission/folder
Python
Check one file/folder permission
from pyfacl import FACL
# Initialize and parse FACL for a file/directory
facl = FACL(path="/path/to/file")
# Check permissions with different modes
facl.has_permission("user:user2:r-x", mode="exact") # exact match
facl.has_permission("user:user2:r--", mode="at_least") # has at least read
facl.has_permission("user:user2:rwx", mode="at_most") # has at most rwx
Check trace through directory hierarchy
from pyfacl import FACLTrace
# Initialize FACLTrace for a directory
facl_trace = FACLTrace(path="/path/to/directory", v=1)
# Trace permissions for a specific user
trace_result = facl_trace.has_permission("user:user2:r-x", mode="at_least")
Check if user/group has permission for a file/directory
from pyfacl import FACLHas
# Initialize FACLHas for a file/directory
facl_has = FACLHas(path="/path/to/file")
# Check if user/group has the specified permission
has_permission = facl_has.has_permission("user:user2:r-x", mode="at_least")
Permission Modes
exact: Permissions must match exactlyat_least: Must have at least the specified permissionsat_most: Must have at most the specified permissions
Development
Setup Development Environment
pip install -e ".[dev]"
pre-commit install
Run Pre-commit Checks
pre-commit run --all-files
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfacl-1.4.0.tar.gz.
File metadata
- Download URL: pyfacl-1.4.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.9 Linux/4.18.0-425.19.2.el8_7.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6efaa20986630a395cd3a5abb3a88df252d12c71d9481cbeae5fe2522938cf98
|
|
| MD5 |
2d8a6fa3dd66d67e188ee962cf561555
|
|
| BLAKE2b-256 |
b886b27a2f2ba5f7600ef0872355372574581ef8d58bdef34690090a69c45854
|
File details
Details for the file pyfacl-1.4.0-py3-none-any.whl.
File metadata
- Download URL: pyfacl-1.4.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.9 Linux/4.18.0-425.19.2.el8_7.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fead2beab116239c21bbcbe823f292af1548e04c73977e26d338e00c2657c83
|
|
| MD5 |
aa08476f6f67355f1e585256dcc5bb34
|
|
| BLAKE2b-256 |
68f42ab8f65ae5785618defdad9c55acbd37166c4a0e59712d254634c99755f4
|