Skip to content

feat: audit tool for allow_functions#9463

Draft
pjwerneck wants to merge 4 commits into
devfrom
pjwerneck/restrict-allowed-audit
Draft

feat: audit tool for allow_functions#9463
pjwerneck wants to merge 4 commits into
devfrom
pjwerneck/restrict-allowed-audit

Conversation

@pjwerneck

@pjwerneck pjwerneck commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a catalog of commonly used jax/flax functions categorized by risk, and an audit tool to check allow_functions against the catalog.

Changes

  • Add the catalogs for current jax 0.11 and flax 0.12 (linen).
  • Add the audit tool (WIP)

Testing

  • Unit tests

Asana task

https://app.asana.com/1/1185126988600652/project/1216249688888494/task/1216819877469865?focus=true

Base automatically changed from pjwerneck/fix-restrict-loose-ends to dev July 23, 2026 11:59
@pjwerneck
pjwerneck force-pushed the pjwerneck/restrict-allowed-audit branch from 7051dd4 to a23e10c Compare July 23, 2026 12:15
@pjwerneck pjwerneck changed the title Pjwerneck/restrict allowed audit feat: audit tool for allow_functions Jul 23, 2026
@pjwerneck
pjwerneck force-pushed the pjwerneck/restrict-allowed-audit branch 2 times, most recently from 95afe4c to 25b2a2a Compare July 23, 2026 19:30
@pjwerneck
pjwerneck force-pushed the pjwerneck/restrict-allowed-audit branch from 25b2a2a to 12d03f9 Compare July 23, 2026 19:33
@pjwerneck
pjwerneck requested a review from Copilot July 23, 2026 19:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an advisory “allow-list audit” capability to syft-restrict so reviewers can see whether allow_functions entries are considered safe/dual-use/unsafe (or deferred to “review”) based on an external, curated catalog, without changing the verifier’s pass/fail behavior.

Changes:

  • Introduces syft_restrict.auditor (audit_allow_functions, AuditReport, PathAudit) and wires the audit report into runner.RunResult.audit (plus catalog_dir parameter).
  • Adds a catalog linter CLI (syft-restrict-lint) and example catalogs for JAX/Flax plus cross-library _common patterns.
  • Adds unit tests covering audit classification, catalog version matching, linting behavior, and run() audit attachment semantics.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/syft-restrict/tests/test_run.py Adds tests asserting RunResult.audit is attached and remains advisory (doesn’t change ok).
packages/syft-restrict/tests/test_auditor.py New tests for audit verdicts, version-dir matching, and catalog linter --fix behavior.
packages/syft-restrict/src/syft_restrict/runner.py Attaches an advisory audit report to RunResult and adds catalog_dir plumbing.
packages/syft-restrict/src/syft_restrict/catalog_lint.py Adds a CLI linter to canonicalize/validate catalog.json formatting.
packages/syft-restrict/src/syft_restrict/auditor.py Implements catalog-based allow-list classification and report formatting.
packages/syft-restrict/src/syft_restrict/init.py Exposes audit API (audit_allow_functions, AuditReport, PathAudit) at the package top level.
packages/syft-restrict/README.md Documents the new auditor concept and usage guidance around globs vs tight allows.
packages/syft-restrict/pyproject.toml Registers syft-restrict-lint console script entrypoint.
packages/syft-restrict/examples/catalog/jax/0.11/catalog.json Adds example JAX 0.11 risk catalog (safe/dual-use/unsafe).
packages/syft-restrict/examples/catalog/flax/0.12/catalog.json Adds example Flax 0.12 (linen) risk catalog.
packages/syft-restrict/examples/catalog/_common/default/catalog.json Adds cross-library unsafe patterns (e.g., *.tofile, *.io_callback) and orbax blanket rule.
packages/syft-restrict/docs/blacklist.md Updates guidance about preferring tight allow_functions and risks of globs.
packages/syft-restrict/docs/audit.md New documentation for audit verdicts and catalog layout/workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +201 to +213
def _detect_versions(paths) -> dict[str, str]:
versions: dict[str, str] = {}
for path in paths:
root = path.split(".", 1)[0].lstrip("*")
if not root or root in versions:
continue
try:
mod = importlib.import_module(root)
except ImportError:
versions[root] = "not installed"
else:
versions[root] = getattr(mod, "__version__", "unknown")
return versions
Comment on lines +168 to +173
def _load_ruleset(root: Path, library: str, version_dir: str) -> dict:
"""Read ``<root>/<library>/<version_dir>/catalog.json``; empty dict if the file is absent."""
path = root / library / version_dir / "catalog.json"
if not path.is_file():
return {}
return json.loads(path.read_text())
Comment on lines +18 to +20
- **The auditor** checks the allow-list of library calls and operators against a
catalog of known safe/dual-use/unsafe paths, and warns on any uncatalogued
paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants