Webhook icon
Schedule icon
Script icon
Process icon
Get icon
If icon
SlackIncomingWebhook icon
Set icon
Log icon
Pause icon

Audit S3 Object Lock Before Retention Drift Becomes Data Loss

Audit S3 bucket versioning, Object Lock defaults and noncurrent bytes with Kestra; approve versioning or stronger future retention safely.

Categories
CloudInfrastructure

A bucket can have versioning and still leave new objects without default WORM retention, or accumulate old versions without a lifecycle rule. This flow audits one S3-compatible bucket, counts all object versions up to a configured cap, and reports policy drift with noncurrent byte totals. It never deletes an object. A human can approve enabling versioning or strengthening the default retention of an already Object-Lock-enabled bucket.

How it works

  1. bucket_policy_webhook starts an audit after a policy change; daily_backstop is a disabled schedule for operators who want regular sweeps.
  2. validate_inputs rejects malformed bucket names, endpoint URLs and scan limits before a network call.
  3. audit_bucket reads bucket versioning, Object Lock defaults and lifecycle rules, then paginates ListObjectVersions. It reports current and noncurrent version counts, noncurrent bytes, old noncurrent bytes and delete markers. Exceeding max_versions fails rather than pretending a partial scan is complete.
  4. load_last_state and changed_policy compare a policy signature in Kestra KV. Slack receives one drift or recovery message per policy change, not one per poll.
  5. If offer_repair is true and one of two safe actions is available, wait_for_approval displays a multi-select. apply_approved_repair compares the live bucket-policy hash with the audited hash immediately before writing. It can enable versioning or raise the bucket's default Object Lock mode/duration for future versions; it cannot shorten a rule. verify_repair reads the bucket again before reporting the result.

Error handling

  • S3 reads use bounded SDK retries and a Kestra retry with backoff. Approval-gated writes have no automatic retry because a timeout may hide a successful write.
  • Missing configuration is distinguished from permission denied. Access failures, unreachable endpoints and scan-cap overflows fail the execution and alert Slack with the task and a safe cause category; exact errors stay in execution logs.
  • A changed policy during approval blocks the write. This is an optimistic recheck, not an atomic compare-and-swap against another writer between the last read and write.
  • Object Lock missing on an existing bucket and lifecycle expiry policy changes are left to a separately reviewed migration. Enabling versioning alone never claims the bucket is WORM-protected.

What this blueprint teaches about Kestra

Use a webhook plus a disabled schedule for event-driven and periodic auditing; store only a compact policy signature in KV to avoid repeat alerts; use Pause to bind a human choice to a snapshot; and re-read external state before and after an approved action. Python's S3 SDK handles paginated version listings and S3-compatible XML responses while Kestra provides orchestration, output and alerting.

Prerequisites

  • Kestra with the Python and Slack plugins and a worker with Python 3.12, network access to the S3 endpoint and permission to install the declared Python packages.
  • An S3-compatible service such as MinIO. The read role needs HeadBucket, GetBucketVersioning, GetBucketObjectLockConfiguration, GetLifecycleConfiguration and ListBucketVersions. The optional repair role also needs PutBucketVersioning or PutBucketObjectLockConfiguration.
  • A Slack incoming webhook. Configure the bucket_policy_webhook key before exposing it publicly.

Secrets

  • MINIO_ACCESS_KEY_ID: S3 access key ID.
  • MINIO_SECRET_KEY_ID: S3 secret access key.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL.

Inputs

  • endpoint and bucket select the target. The defaults point to the local MinIO quick start.
  • required_mode and min_retention_days define the minimum default retention for new versions. COMPLIANCE is stronger than GOVERNANCE.
  • max_noncurrent_days requires an enabled bucket-wide lifecycle rule with noncurrent expiry no later than that limit. It does not inspect prefix- or tag-scoped rules as bucket-wide coverage.
  • noncurrent_age_days classifies old noncurrent bytes; max_versions caps scan work and fails on overflow.
  • offer_repair defaults to false. Turn it on only when an operator is ready to review the approval form.

Outputs

  • audit contains findings, policy hash and version counts/bytes. post_repair contains the re-read result when an approved repair ran.
  • Noncurrent bytes are storage volume, not a bill estimate. Bucket default retention does not retroactively protect old versions; this flow does not inspect each version's retention or legal hold.

Quick start

  1. Start MinIO and create a disposable bucket with Object Lock enabled at creation. Set the three secrets and update endpoint and bucket.
  2. Run manually with offer_repair=false and inspect audit.findings, noncurrent_bytes and the policy hash. Call the webhook after a bucket policy change.
  3. Set offer_repair=true only to approve versioning or a stronger default retention. After approval, inspect post_repair; resolve missing Object Lock or lifecycle drift through the platform team's normal change process.
  4. Enable daily_backstop after validating the webhook and alert destination.

Plugins used

  • io.kestra.plugin.scripts.python.Script for S3 policy/version auditing and guarded repair.
  • io.kestra.plugin.slack.notifications.SlackIncomingWebhook for actionable drift, recovery, repair and failure messages.
  • Kestra core If, Pause, Webhook, Schedule and KV tasks.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.