Skip to main content

Package to manage access control using POSIX ACLs

Project description

PyFACL

A Python library for parsing and checking POSIX File Access Control Lists (FACL).

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:<username>:r-x --mode exact

Example output:

$ pyfacl trace /data1/collab002/sail/example/permission/folder user:moormana: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:moormana:--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).

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:username:r-x", mode="exact")     # exact match
facl.has_permission("user:username:r--", mode="at_least") # has at least read
facl.has_permission("user:username: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:username: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.2.0.tar.gz (7.0 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.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyfacl-1.2.0.tar.gz
  • Upload date:
  • Size: 7.0 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.2.0.tar.gz
Algorithm Hash digest
SHA256 0957f1967c516268ea158565a53bcc074595f2f1124f5d1c2e66c18d694245c3
MD5 40a9c9f6d4381c53f3d0785033156b06
BLAKE2b-256 ce66e7e09f3298c5e8d41c6b7c95797e04873f6b9d262d115223f07a8a8fcf6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfacl-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38884848dc7bffa439f99f342d69f5c899e47d18edb09aa1bd2e161526116ac5
MD5 044cd91cedc39080cb375333abb5bab6
BLAKE2b-256 74bdef66489b9c8b5b9a9e1933f8135d2fbe63eb1a122e756a3bc19fbeb5034b

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