Schedule icon
AwsCLI icon
If icon
SlackIncomingWebhook icon
Pause icon
Log icon

AWS ECR Lifecycle Policy Governance Sentinel and Remediation Gate

Audit all Amazon ECR repositories for missing lifecycle policies, alert Slack on governance gaps, and enforce baseline retention policies behind human approval.

Categories
CloudInfrastructure

Amazon Elastic Container Registry (ECR) repositories store container images and layer blobs in Amazon S3. When a repository lacks an ECR lifecycle policy, orphaned untagged image digests, build artifacts, and stale release tags accumulate indefinitely, creating uncontrolled cloud storage costs and compliance gaps.

This sentinel periodically audits every ECR repository in your AWS region using io.kestra.plugin.aws.cli.AwsCLI, identifies repositories that have no lifecycle policy attached, posts an actionable alert to Slack, and gates automated baseline policy enforcement behind a human-in-the-loop operator approval.

How it works

  1. Fleet Discovery and Policy Audit: The scan_ecr_lifecycle_policies task executes AWS CLI commands to list all ECR repositories via aws ecr describe-repositories and tests each repository for an active policy via aws ecr get-lifecycle-policy. Only repositories returning LifecyclePolicyNotFoundException are counted as missing policies, ensuring API permission errors are not falsely reported as compliance gaps.
  2. Governance Gap Classification: Repositories lacking lifecycle policies are cataloged and counted. If has_compliance_gaps is true, the workflow transitions to alerting and remediation.
  3. Slack Team Notification: SecOps and DevOps engineers receive immediate Slack notifications listing all unmanaged repository names with context on the storage risk.
  4. Human-in-the-Loop Approval: When auto_enforce is enabled, the flow halts at approval_gate (io.kestra.plugin.core.flow.Pause) with a 30-minute safety window (pauseDuration: PT30M, behavior: CANCEL), allowing engineers to inspect the candidate list before any changes are written. Operators must explicitly approve by setting proceed: true (defaults to false), gating baseline policy enforcement, verification, and summary alerts behind evaluate_remediation_approval.
  5. Baseline Policy Enforcement: Upon sign-off, enforce_baseline_lifecycle_policy applies a standardized rule set via aws ecr put-lifecycle-policy:
    • Prunes untagged images older than untagged_retention_days (default: 14 days).
    • Retains the most recent max_image_count images (default: 100 images).
  6. Fleet Verification: The verify_fleet_compliance task re-queries the modified repositories to confirm active policy attachment using the same LifecyclePolicyNotFoundException filter, tracks confirmed, unverified, and error counts, and posts a verification summary to Slack.

What you get

  • Account-wide visibility into unmanaged ECR repositories without deploying third-party agent daemons.
  • Automated Slack alerts highlighting non-compliant container repositories before monthly storage invoices spike.
  • Safe human-in-the-loop remediation preventing unintentional image expiration.
  • Full execution lineage, task logs, and compliance audit trail in Kestra.

Who it's for

  • Platform and Cloud Engineering teams maintaining container registries across development and production clusters.
  • FinOps teams tracking and reclaiming wasted cloud storage expenses.
  • DevSecOps engineers enforcing repository governance standards across AWS organizations.

Why orchestrate this with Kestra

Building this logic in ad-hoc shell scripts or cron jobs leaves no audit trail, requires hardcoded credentials, and lacks approval gates. AWS Config or Lambda alternatives require managing SNS topics, IAM event buses, and custom function runtimes. Kestra consolidates discovery, decision trees, Slack alerting, and human approval into a declarative, self-documenting workflow with namespace secrets and complete execution logs.

Prerequisites

  • An AWS IAM user or role with permissions to read and update ECR repositories:
    • ecr:DescribeRepositories
    • ecr:GetLifecyclePolicy
    • ecr:PutLifecyclePolicy (only required when auto_enforce is true)
  • A Slack Incoming Webhook URL.

Secrets

  • AWS_ACCESS_KEY_ID: AWS IAM access key ID.
  • AWS_SECRET_ACCESS_KEY: AWS IAM secret access key.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for notifications.

Quick start

  1. Configure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Run the workflow manually in audit-only mode (auto_enforce: false) to view current compliance status across your ECR repositories.
  3. To enable automated remediation, set auto_enforce: true and approve the pause prompt when prompted.
  4. Enable the scheduled_compliance_audit trigger to run daily checks automatically.

How to extend

  • Multi-Region Fleet Scan: Wrap the flow in a Loop task iterating over an array of AWS regions.
  • Tag-Specific Exclusion: Customize the baseline lifecycle policy JSON to retain images with release tags like v* or prod-* indefinitely.
  • Ticket Creation: Replace or augment the Slack notification task with io.kestra.plugin.jira.issues.Create or io.kestra.plugin.github.issues.Create to track compliance tickets in your team's backlog.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.