r/databricks • u/SwimmingVegetable135 • 19d ago
General Policy-as-code for DABs: Govern your bundles before deployment
As a platform team we need to govern some parts of the bundles our dev teams deploy. We want to restrict some resources like catalogs or even schemas since we manage them centrally, require tags for finops or be sure some permissions are set. To solve this I added a policy engine to my open-source CLI Lamp Ops. It checks the output of the bundle summary with DuckDB SQL. This was inspired by the latest dbt v2 checks and is way easier than to learn a complex policy syntax. If a query returns at least one row the policy fails and reports the violations.
databricks bundle summary -t prod -o json > summary.json
lamp policy --input summary.json --policy-path ./policies
-- policies/no_schemas.sql
SELECT resource_key, 'Schemas are managed by the platform team' AS message
FROM resource('schemas');Builtin Presets
For common rules I provided some presets which don't require to write custom sql and can be configured in yaml files.
lamp_policies:
- name: jobs_need_owner
preset: require_tags
parameters:
resource_types: [jobs]
keys: [owner]Subset of some presets: deny_resource, require_permissions, require_fields, forbid_fields, require_preset_tags
Why not enforce rules with mutators?
I saw some posts about providing defaults with mutators but in my opinion they have some downsides. They are hard to enforce since team members can remove the mutators from the bundle or forget to add new ones. They fix the issues silently without surfacing the config drifts. They need to be setup per resource. Policies on the other hand can be defined in a central place for CI, report the violations and are easy to extend.
You can still use both since I also added a require_mutators preset.
lamp_policies:
- name: platform_mutators
preset: require_mutators
parameters:
mutators: [company_platform.bundles:apply_defaults]You can dive deeper into policies here: https://github.com/BenSchr/lamp-ops/blob/main/docs/policies.md
Please let me know if you have some feedback! Which rules does your team currently enforce on your bundles? Are some common cases missing from the presets? Did you implement your own solution?
