Schedule icon
Query icon
Script icon
If icon
Switch icon
Loop icon
Log icon
SlackIncomingWebhook icon

SurrealDB Access Grant Expiry Sentinel

Audit SurrealDB ACCESS methods for refresh grants that never expire, alert on breach, and record flagged methods for review.

Categories
DataInfrastructure

SurrealDB's own documentation calls out DURATION FOR GRANT NONE by name: a refresh token grant configured this way never expires. That is a deliberate, named capability, not a bug - but left in place on an ACCESS method nobody is actively reviewing, it is exactly the kind of standing risk a compliance program or security review will flag sooner or later. This blueprint runs INFO FOR DB, SurrealDB's own system-introspection statement, finds any ACCESS method configured this way, alerts Slack on breach, and can write an audit-trail record naming the flagged method for review - never altering the ACCESS method's own definition.

How it works

  1. periodic_grant_check (io.kestra.plugin.core.trigger.Schedule) runs every 6 hours, always forcing auto_remediate: "false" and dry_run: "true" through its own inputs: override regardless of this flow's defaults. Shipped disabled so you can validate a manual run first.
  2. audit_access_grants (io.kestra.plugin.surrealdb.Query) runs INFO FOR DB; with fetchType: STORE, returning a uri to the stored result - SurrealDB's own accesses map, keyed by access method name, each value being the re-serialized DEFINE ACCESS statement text.
  3. evaluate_access_risk (io.kestra.plugin.scripts.python.Script) reads that stored result and collects every access method whose definition text contains FOR GRANT NONE, emitting unbounded_count and unbounded_accesses through Kestra.outputs.
  4. evaluate_access_gate (io.kestra.plugin.core.flow.If) flags a breach whenever unbounded_count > max_unbounded_grants.
    • then (breach): route_remediation (io.kestra.plugin.core.flow.Switch on auto_remediate) either considers remediation ("true", gated again by dry_run through check_dry_run) or only logs that remediation is disabled ("false"). When both gates allow it, record_flagged_access (io.kestra.plugin.core.flow.Loop) runs create_audit_record (io.kestra.plugin.surrealdb.Query, a plain CREATE) for each flagged access method, writing a security_audit_log record. alert_access_risk always fires to Slack regardless of which path ran.
    • else (compliant): log_access_healthy records a clean check.
  5. log_audit_complete always runs last, printing the headline numbers regardless of which branch fired.
  6. The errors block alerts Slack separately if the flow itself fails - an unreachable instance or insufficient privileges must not read as "no breach".

What you get

  • A concrete, named list of ACCESS methods configured to never expire their refresh grants, not a generic "review your auth config" reminder.
  • Remediation that only ever adds a security_audit_log record; the flagged ACCESS method's own DURATION settings are never changed by this flow.
  • Two independent gates (auto_remediate, dry_run) between "risk detected" and "audit record actually written".
  • A final status log every run, risk or not, so the execution history doubles as an access-grant posture history for the database.

Who it's for

  • Platform and security teams running SurrealDB who need a standing check on authentication configuration, not a one-time schema review.
  • Teams using SurrealDB's RECORD or BEARER access methods for application auth who want unlimited refresh grants caught automatically.
  • Anyone evaluating the SurrealDB plugin who wants a worked example of INFO FOR DB beyond basic CREATE/SELECT usage.

Why orchestrate this with Kestra

INFO FOR DB is a one-shot introspection query with no memory of the last check, no threshold logic, and no notification path. Kestra supplies the schedule, the risk classification as a first-class branch, two independent authorization gates before anything is written, and an execution history that shows exactly when an unbounded grant first appeared and whether it was flagged for review.

Prerequisites

  • A reachable SurrealDB instance and a user with rights to run INFO FOR DB and, if remediation runs, CREATE records.
  • A Slack incoming webhook for alerts.

Local testing: docker run -d --name surrealdb-grant-sentinel -p 8001:8000 surrealdb/surrealdb:latest start --user root --pass root docker network connect YOUR_KESTRA_NETWORK surrealdb-grant-sentinel (only needed if the Kestra Worker runs in a separate Docker network than this container; set surrealdb_host to surrealdb-grant-sentinel from inside that network, or localhost with port 8001 from the host, matching this plugin's connection properties).

Secrets

  • SURREALDB_PASSWORD: password for surrealdb_username, matching this plugin's own documented pattern (see surreal-db.yaml).
  • SLACK_WEBHOOK: Slack incoming webhook used by alert_access_risk and the errors block.
  • In Kestra OSS (no Enterprise secrets backend), secrets are supplied as environment variables prefixed SECRET_, base64-encoded, and read back in flows with {{ secret('NAME') }} - for example SECRET_SLACK_WEBHOOK=$(echo -n 'https://hooks.slack.com/...' | base64). This keeps credentials out of the flow YAML but, per Kestra's own documentation, offers no encryption at rest or access control beyond the host environment; use the Enterprise secrets backend for stronger guarantees.

Inputs

  • surrealdb_host (STRING, default localhost): SurrealDB connection host.
  • surrealdb_namespace (STRING, default test): SurrealDB namespace (distinct from the Kestra flow namespace).
  • surrealdb_database (STRING, default test): database audited by INFO FOR DB.
  • surrealdb_username (STRING, default root): account used to run the audit and, if enabled, the remediation.
  • max_unbounded_grants (INT, default 0): breach threshold; 0 means any unbounded-grant access method at all breaches.
  • auto_remediate (SELECT: "false", "true"; default "false"): must be "true" for the audit record to even be considered.
  • dry_run (SELECT: "true", "false"; default "true"): must be explicitly "false", together with auto_remediate: "true", for the record to actually be written.

Outputs

  • outputs.audit_access_grants.uri: the raw stored INFO FOR DB result for every run.
  • outputs.evaluate_access_risk.vars.unbounded_count / .unbounded_accesses: the computed risk result for every run.

Quick start

  1. Start SurrealDB locally with the command above and define at least one access method with DURATION FOR GRANT NONE to produce a realistic breach (see SurrealDB's own DEFINE ACCESS documentation for the full statement syntax).
  2. Add the SURREALDB_PASSWORD and SLACK_WEBHOOK secrets.
  3. Run the flow manually with the defaults (auto_remediate: "false") and confirm alert_access_risk fires naming the expected access method, and that log_remediation_disabled logs without writing anything.
  4. Run once with auto_remediate: "true" and dry_run: "true" and confirm log_dry_run_remediation describes the audit record without writing it.
  5. Run once with auto_remediate: "true" and dry_run: "false" and confirm with SELECT * FROM security_audit_log; that the record now exists.
  6. Enable periodic_grant_check once you trust the check; it always runs in the safe auto_remediate: "false" / dry_run: "true" mode regardless of what you leave the flow's own defaults set to.

How to extend

  • Also run INFO FOR ROOT; to catch root-level access methods, not just database-level ones audited here.
  • Loop over several surrealdb_database values with io.kestra.plugin.core.flow.Loop to sweep multiple databases in one run.
  • Route the remediation branch through a Pause approval task instead of (or alongside) the static auto_remediate input, for a human-reviewed record on production databases.
  • If your SurrealDB version's ALTER ACCESS confirms support for modifying DURATION, extend create_audit_record into an actual remediation step that bounds the grant duration - this blueprint deliberately only records the risk for review, since that capability was not confirmed from available documentation.

Pitfalls

  • The exact JSON shape of this task's STORE output was not confirmed against a live instance. SurrealDB's query protocol typically wraps each statement's result in a per-statement envelope; evaluate_access_risk's script defensively handles both a bare result object and a list-of-statement-results, but this has not been exercised against a running SurrealDB server in this environment.
  • DURATION FOR GRANT NONE is valid, documented syntax - but DURATION FOR TOKEN NONE is explicitly rejected by SurrealDB on record-access methods. Verified from SurrealDB's own documentation: "Record-access authentication tokens are issued to end users and may be passed to third parties, so they must expire. As a result, DURATION FOR TOKEN NONE is rejected." This blueprint only checks FOR GRANT, the one case SurrealDB's docs confirm can legitimately be set to never expire.
  • This blueprint does not run ALTER ACCESS. Whether ALTER ACCESS supports modifying DURATION was not confirmed from available documentation; remediation here is limited to an additive audit-trail CREATE, never a change to the flagged access method itself.
  • auto_remediate and dry_run are independent gates, not a single boolean. Both must be "true"/"false" respectively for the audit-record Loop to run; setting only one leaves the other still blocking.
  • Switch case keys "true"/"false" are quoted strings. auto_remediate renders as the literal string "true" or "false"; unquoted true:/false: YAML map keys would parse as booleans instead and would not match.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.