id: databricks-unity-catalog-grant-compliance-gate
namespace: company.team
description: |
Audit who holds high-risk Unity Catalog privileges on a securable object, alert Slack when a
principal outside the allow list holds one, and optionally revoke the violating privileges
with the Databricks CLI's own grants update command behind a dry_run gate, then re-probe to
verify the revoke actually worked.
inputs:
- id: securable_type
type: SELECT
displayName: Unity Catalog securable type
description: Type of the Unity Catalog object to audit. Maps to the Get and
Update tasks' securableType field.
values:
- "CATALOG"
- "SCHEMA"
- "TABLE"
defaults: "SCHEMA"
- id: full_name
type: STRING
displayName: Securable full name
description: Full name of the securable, catalog, catalog.schema, or
catalog.schema.table depending on securable_type.
defaults: "main.landing_zone"
- id: allowed_principals
type: JSON
displayName: Allow-listed principals
description: Users, groups or service principals permitted to hold a
high_risk_privileges privilege on this securable. Anyone else holding one
is a violation.
defaults: '["data-platform-admins"]'
- id: high_risk_privileges
type: JSON
displayName: High-risk privileges to audit
description: Privileges that only an allow-listed principal may hold on this
securable, for example ALL_PRIVILEGES or MODIFY.
defaults: '["ALL_PRIVILEGES", "MODIFY"]'
- id: auto_remediate
type: BOOL
displayName: Auto remediate
description: When true, together with dry_run false, revoke every violating
privilege found via the Databricks CLI's grants update command.
defaults: false
- id: dry_run
type: BOOL
displayName: Dry run
description: Must be false, together with auto_remediate true, for the revoke to
actually run.
defaults: true
tasks:
- id: probe_grants
type: io.kestra.plugin.databricks.cli.DatabricksCLI
description: Read-only. Runs the Databricks CLI's own grants get command and
writes its JSON response to internal storage for the audit step to read.
allowFailure: true
databricksHost: "{{ secret('DATABRICKS_HOST') }}"
databricksToken: "{{ secret('DATABRICKS_TOKEN') }}"
commands:
- databricks grants get {{ inputs.securable_type }} {{ inputs.full_name }}
--output json > grants.json
outputFiles:
- grants.json
- id: audit_grants
type: io.kestra.plugin.core.output.OutputValues
description: Flags every principal outside the allow list that holds a high-risk
privilege. Empty violations when the probe itself did not return. Field
names (privilege_assignments) match the Databricks Grants REST API
response verbatim, since the CLI's --output json passes the API response
straight through.
values:
violations: >-
{{ (outputs.probe_grants is not defined) ? '[]' : ({'assignments':
(fromJson(read(outputs.probe_grants.outputFiles['grants.json'])).privilege_assignments
?? []), 'allowed': inputs.allowed_principals, 'risky':
inputs.high_risk_privileges} | jq('.allowed as $a | .risky as $r |
[(.assignments // [])[] | . as $x | ($x.privileges // [] | map(select(.
as $p | $r | index($p) != null))) as $hit | select(($hit | length > 0)
and (($x.principal as $pr | $a | index($pr)) == null)) | {principal:
$x.principal, matched_privileges: $hit}]') | first | toJson) }}
- id: log_summary
type: io.kestra.plugin.core.log.Log
message: "Unity Catalog grant audit on {{ inputs.securable_type }} {{
inputs.full_name }}: {{ fromJson(outputs.audit_grants.values.violations) |
length }} violation(s)."
- id: route_compliance
type: io.kestra.plugin.core.flow.Switch
description: Branch A logs a compliant securable. Branch B alerts Slack when a
non-allow-listed principal holds a high-risk privilege, or when the probe
itself failed.
value: "{{ outputs.probe_grants is not defined ? 'PROBE_FAILED' :
(fromJson(outputs.audit_grants.values.violations) | length > 0 ?
'VIOLATION' : 'COMPLIANT') }}"
cases:
"PROBE_FAILED":
- id: alert_probe_failed
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {"text": "Unity Catalog grant probe for " ~ inputs.securable_type ~ " " ~ inputs.full_name ~ " did not return a result. Check DATABRICKS_HOST, DATABRICKS_TOKEN, and that the securable exists."} | toJson }}
"VIOLATION":
- id: alert_violation
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {"text": "Unity Catalog compliance VIOLATION on " ~ inputs.securable_type ~ " " ~ inputs.full_name ~ ". " ~ (fromJson(outputs.audit_grants.values.violations) | length) ~ " principal(s) outside the allow list hold a high-risk privilege: " ~ (fromJson(outputs.audit_grants.values.violations) | jq('map("\(.principal): \(.matched_privileges | join(\", \"))") | join("; ")') | first) ~ "." ~ (inputs.auto_remediate and not inputs.dry_run ? " Revoking now." : " No change applied (auto_remediate=" ~ inputs.auto_remediate ~ ", dry_run=" ~ inputs.dry_run ~ ").")} | toJson }}
- id: remediate_gate
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.auto_remediate and not inputs.dry_run }}"
then:
- id: revoke_violations
type: io.kestra.plugin.core.flow.Loop
concurrencyLimit: 1
values: "{{ outputs.audit_grants.values.violations }}"
tasks:
- id: revoke_grant
type: io.kestra.plugin.databricks.cli.DatabricksCLI
description: Calls the Databricks CLI's own grants update command with a Grants
REST API-shaped --json body
(changes[].principal/add/remove), revoking only the
privileges that caused this violation for this principal.
databricksHost: "{{ secret('DATABRICKS_HOST') }}"
databricksToken: "{{ secret('DATABRICKS_TOKEN') }}"
commands:
- |
databricks grants update {{ inputs.securable_type }} {{ inputs.full_name }} --output json --json '{{ {'changes': [{'principal': (item.value | jq('.principal') | first), 'remove': (item.value | jq('.matched_privileges') | first)}]} | toJson }}'
- id: reprobe_grants
type: io.kestra.plugin.databricks.cli.DatabricksCLI
description: Read-only re-check after the revoke, same command as probe_grants.
allowFailure: true
databricksHost: "{{ secret('DATABRICKS_HOST') }}"
databricksToken: "{{ secret('DATABRICKS_TOKEN') }}"
commands:
- databricks grants get {{ inputs.securable_type }} {{
inputs.full_name }} --output json > grants.json
outputFiles:
- grants.json
- id: reaudit_grants
type: io.kestra.plugin.core.output.OutputValues
values:
violations: >-
{{ (outputs.reprobe_grants is not defined) ? '[]' :
({'assignments':
(fromJson(read(outputs.reprobe_grants.outputFiles['grants.json'])).privilege_assignments
?? []), 'allowed': inputs.allowed_principals, 'risky':
inputs.high_risk_privileges} | jq('.allowed as $a | .risky as
$r | [(.assignments // [])[] | . as $x | ($x.privileges // []
| map(select(. as $p | $r | index($p) != null))) as $hit |
select(($hit | length > 0) and (($x.principal as $pr | $a |
index($pr)) == null)) | {principal: $x.principal,
matched_privileges: $hit}]') | first | toJson) }}
- id: verify_remediation
type: io.kestra.plugin.core.flow.If
description: Fails the flow when a revoke ran but a violation still remains, so
a broken revoke is never silently reported as fixed.
condition: "{{ fromJson(outputs.reaudit_grants.values.violations) | length > 0
}}"
then:
- id: remediation_failed
type: io.kestra.plugin.core.execution.Fail
errorMessage: "grants update ran, but a violation still remains on this
securable."
else:
- id: remediated
type: io.kestra.plugin.core.log.Log
message: "Revoked and verified. 0 violations remain on {{ inputs.securable_type
}} {{ inputs.full_name }}."
"COMPLIANT":
- id: log_compliant
type: io.kestra.plugin.core.log.Log
message: "No violations. Every principal holding a high-risk privilege on {{
inputs.securable_type }} {{ inputs.full_name }} is on the allow
list."
- id: log_audit_summary
type: io.kestra.plugin.core.log.Log
description: Final audit log confirming the gate ran, regardless of the branch
taken above.
message: "Unity Catalog grant compliance gate completed. securable={{
inputs.securable_type }} {{ inputs.full_name }} auto_remediate={{
inputs.auto_remediate }} dry_run={{ inputs.dry_run }}"
errors:
- id: alert_flow_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {"text": "Unity Catalog grant compliance gate flow failed (execution " ~ execution.id ~ "). Check the execution logs."} | toJson }}
triggers:
- id: schedule_every_6_hours
type: io.kestra.plugin.core.trigger.Schedule
description: Shipped disabled, and always in safe mode by default.
cron: "0 */6 * * *"
disabled: true
inputs:
securable_type: "SCHEMA"
full_name: "main.landing_zone"
allowed_principals: '["data-platform-admins"]'
high_risk_privileges: '["ALL_PRIVILEGES", "MODIFY"]'
auto_remediate: false
dry_run: true