Skip to content

Latest commit

 

History

History
242 lines (187 loc) · 8.14 KB

README.md

File metadata and controls

242 lines (187 loc) · 8.14 KB

Examples

These files let you try lfpolicy without AWS credentials:

  • desired.json: a desired Lake Formation LF-Tag and grant policy.
  • desired.yaml: the same desired policy in YAML.
  • policy-exceptions.json: a narrow example of exception-controlled risky access with reason, ticket, owner, approver, and expiry metadata.
  • policy.py: a Python-native permission group policy that can generate desired state.
  • policy-from-import.py: a migration example that keeps an imported desired state reference beside the equivalent Python policy model.
  • policy-bundles.py: a Python-native policy using generic permission bundles such as reader(), producer(), steward(), data_location_access(), and admin().
  • permission-requests.py: a Python-native policy that models approved access requests as data and compiles them to ordinary desired state.
  • current-snapshot.json: a deliberately incomplete current-state snapshot.
  • access-requests.json and access-current-snapshot.json: batch access diagnosis inputs for service adapter tests.
  • artifacts/: checked-in report fixtures for audit, plan, review bundles, explain, and explain-batch evidence.
  • github-actions/lakeformation-drift.yml: a copyable GitHub Actions workflow for scheduled or manually dispatched drift checks against live AWS state. It expects policy.py and generated policy/desired.json in the policy repository.
  • github-actions/lakeformation-code-scanning.yml: a copyable GitHub Actions workflow that checks generated desired state and uploads lint and audit SARIF reports to GitHub Code Scanning.
  • pre-commit/pre-commit-config.yaml: a copyable local pre-commit hook that regenerates and checks a desired-state policy before commit.

YAML examples require installing lfpolicy[yaml]; JSON examples work with the base package.

The snapshot is missing two desired LF-Tag values, one table tag assignment, and one LF-Tag policy grant. That makes it useful for seeing audit findings and conservative plans.

The artifacts/ directory contains pre-generated examples of the JSON and Markdown evidence a pull request or scheduled governance job would attach:

  • artifacts/lfpolicy-audit.json
  • artifacts/lfpolicy-plan.json
  • artifacts/lfpolicy-explain.json
  • artifacts/lfpolicy-explain-batch.json
  • artifacts/review-bundle/
  • artifacts/review-cases/
  • artifacts/explain-batch-cases/

If you installed lfpolicy from PyPI and do not have this repository checked out, generate the same kind of local demo files with:

lfpolicy sample --output-dir lfpolicy-demo

Check the Policy

lfpolicy check \
  --desired examples/desired.json \
  --current-snapshot examples/current-snapshot.json

This command only reads local files. It validates the desired policy and current snapshot, then catches undefined LF-Tag keys and values in resource tag assignments and LF-Tag policy expressions.

Generate From Python

Use policy.py when you want permission groups to be the source of truth:

lfpolicy generate examples/policy.py --output-file /tmp/lfpolicy-desired.json --force
lfpolicy check --desired /tmp/lfpolicy-desired.json --fail-on-findings

The example assigns LF-Tags to neutral databases, tables, and a sensitive column. It uses user-defined groups such as dataconsumer, dataengineer, operations, and catalog_admin, while the package supplies the safer reader(), editor(), producer(), table_creator(), database_creator(), steward(), data_location_access(), and admin() templates.

To see the newer generic bundle names:

lfpolicy generate examples/policy-bundles.py --output-file /tmp/lfpolicy-bundles.json --force
lfpolicy check --desired /tmp/lfpolicy-bundles.json --fail-on-findings

To see how a reviewed import scaffold can become policy.py:

lfpolicy generate examples/policy-from-import.py --output-file /tmp/lfpolicy-migrated.json --force
lfpolicy check --desired /tmp/lfpolicy-migrated.json --fail-on-findings

To see access requests represented as policy data, without adding an approval UI to lfpolicy core:

lfpolicy generate examples/permission-requests.py --output-file /tmp/lfpolicy-requests.json --force
lfpolicy check --desired /tmp/lfpolicy-requests.json --fail-on-findings

The request records include ticket, requester, owner, approver, review date, target table, requested permissions, and evidence path metadata. After generating desired state, use ../docs/permission-request-bundles.md for the review workflow: write request-specific explain and plan artifacts, approve exact plan-local change IDs, and pass those IDs to the consuming service that owns AWS write execution.

Review Exceptions

Use policy-exceptions.json to see how intentional risky grants are scoped without globally weakening lint rules:

lfpolicy lint --desired examples/policy-exceptions.json

The example suppresses ALL and named database grant lint findings only for the matching principal, resource, permissions, and non-expired exception rules.

Summarize the Policy

lfpolicy summary \
  --desired examples/desired.json \
  --current-snapshot examples/current-snapshot.json

This produces a compact inventory of LF-Tag keys, resource kinds, grant principals, grant resource kinds, and permissions for reviewers.

Audit Drift

lfpolicy audit \
  --desired examples/desired.json \
  --current-snapshot examples/current-snapshot.json

Expected summary:

Findings: 3 total, 3 error(s), 0 warning(s).

To use the audit in CI and save evidence for review:

lfpolicy audit \
  --desired examples/desired.json \
  --current-snapshot examples/current-snapshot.json \
  --output json \
  --output-file artifacts/lfpolicy-audit.json \
  --fail-on-findings

The command writes artifacts/lfpolicy-audit.json before exiting with status 1.

Use --fail-on-severity error when warnings should be reported but should not fail the job:

lfpolicy audit \
  --desired examples/desired.json \
  --current-snapshot examples/current-snapshot.json \
  --fail-on-findings \
  --fail-on-severity error

Plan Safe Changes

lfpolicy plan \
  --desired examples/desired.json \
  --current-snapshot examples/current-snapshot.json

Expected summary:

Plan: 3 change(s), 3 safe, 0 destructive.

To save a Markdown plan for pull request review:

lfpolicy plan \
  --desired examples/desired.json \
  --current-snapshot examples/current-snapshot.json \
  --output markdown \
  --output-file artifacts/lfpolicy-plan.md

By default, the plan is additive only. It will add missing LF-Tag values, resource tag assignments, and permissions, but it will not revoke permissions or remove tag values unless a matching --allow-* flag is supplied.

Try YAML

Install the YAML extra, then run the same plan against the YAML desired policy:

python -m pip install "lfpolicy[yaml]"
lfpolicy plan \
  --desired examples/desired.yaml \
  --current-snapshot examples/current-snapshot.json

Copy a GitHub Actions Workflow

Use github-actions/lakeformation-drift.yml as a starting point when your policy repository already uses GitHub OIDC to assume an AWS role. Replace the example role ARN, region, and policy paths before enabling the workflow.

Use github-actions/lakeformation-code-scanning.yml when your repository can upload SARIF to GitHub Code Scanning. It uploads separate lfpolicy-lint and lfpolicy-audit categories before enforcing the check and drift gates.

For the evidence model behind these workflows, see ../docs/ci-evidence-workflows.md.

Copy a Pre-Commit Hook

Use pre-commit/pre-commit-config.yaml as a starting point when developers should regenerate and check desired-state policy before committing. Copy it to .pre-commit-config.yaml, update the policy paths, and install the hook in an environment where lfpolicy is available:

python -m pip install lfpolicy pre-commit
pre-commit install
pre-commit run --all-files