Skip to main content

Package to manage access control using POSIX ACLs

Project description

PyFACL

PyPI version Python Documentation Status License: MIT

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 exactly
  • at_least: Must have at least the specified permissions
  • at_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfacl-1.3.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfacl-1.3.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file pyfacl-1.3.0.tar.gz.

File metadata

  • Download URL: pyfacl-1.3.0.tar.gz
  • Upload date:
  • Size: 7.6 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

Hashes for pyfacl-1.3.0.tar.gz
Algorithm Hash digest
SHA256 8cbef343580955cf6e63e4c516a06ef8efd3889045413acb9918de3778e6c669
MD5 04232c22685e1f6090d6dd2113514db7
BLAKE2b-256 d97c5425bd2b90ae0d7a61b0991d0f3a8d8291d5a7c97da5407c90ab4727d227

See more details on using hashes here.

File details

Details for the file pyfacl-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyfacl-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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

Hashes for pyfacl-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16bfbc8661f520cec5b978a8776bec925d05f59b1810d4d2a2af6118d80da353
MD5 bf2ba79f93b750c8ef59ec24bfcbaf9e
BLAKE2b-256 fc8e013a40d9f24de9a8627273a5052776636199968234e650f5fa622b673581

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page