Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

GCP Secret Manager Version Lifecycle Staleness Auditor

Audits GCP Secret Manager secret versions to detect unrotated credentials exceeding age policies, delivering security compliance reports via Slack.

Categories
CloudInfrastructure

Enterprise security compliance frameworks such as SOC 2 Type II, ISO 27001, and PCI-DSS mandate strict cryptographic lifecycle controls, requiring organizations to rotate database credentials, third-party API tokens, and encryption keys on a recurring 90-day cadence. Google Cloud Secret Manager offers secure storage for sensitive configuration payloads, versioning every update. However, without proactive monitoring, development teams frequently provision production API secrets and leave them in active use for years without rotation. When external security audits occur or employee offboarding takes place, stale credentials create serious vulnerability windows and audit non-compliance findings. This sentinel audits all secrets within a target Google Cloud project on a weekly schedule, identifies enabled versions older than the configured threshold (e.g., 90 days), and delivers actionable compliance manifests to SecOps teams on Slack.

How it works

  1. Scheduled triggering: Executes weekly every Monday at 09:00 UTC via automated cron trigger (0 9 * * 1) or runs on-demand via manual execution.
  2. Secret enumeration: Queries the Google Cloud Secret Manager API (ListSecrets) across the specified project namespace.
  3. Version state inspection: Interrogates ListSecretVersions for each discovered secret, isolating versions in the ENABLED state.
  4. Age threshold comparison: Calculates the elapsed duration since create_time and flags versions older than max_version_age_days.
  5. Conditional alerting: An io.kestra.plugin.core.flow.If flowable checks if stale secrets exist and dispatches a Slack notification to #secops-compliance-alerts.
  6. Manifest export: Emits a structured JSON audit payload detailing secret identifiers, active version numbers, and creation timestamps for compliance tracking.

Architecture diagram

flowchart TD
  A[weekly_secret_rotation_audit Schedule Trigger] --> B[scan_secret_versions Python Script]
  B --> C[check_staleness_violations Flowable If]
  C -- Stale Versions Found --> D[notify_slack_stale_secrets Webhook]
  C -- Secrets Compliant --> E[log_compliance_state Log]
  D --> E
  E --> F[export_secret_manifest Return]

What you get

  • Continuous verification of credential rotation policies without manual spreadsheet tracking.
  • Automated detection of forgotten database passwords, legacy API keys, and long-lived service account tokens.
  • Contextual Slack alerts detailing affected secret names, current version numbers, and exact ages in days.
  • Structured JSON audit records ready for SOC 2 and ISO 27001 auditor evidence packs.

Who it's for

  • Security Operations (SecOps) and Cloud Security Architects enforcing cryptographic hygiene.
  • Compliance Officers gathering automated evidence for SOC 2, HIPAA, and PCI-DSS audits.
  • DevOps and Platform Engineers maintaining microservice configuration and database credentials.

Why orchestrate this with Kestra

Secret rotation compliance requires periodic scanning across hundreds of cloud credentials, cross-referencing creation timestamps, and routing alerts to relevant teams. Kestra provides scheduled orchestration with container isolation, secure service account credential handling, and native Slack integration. Orchestrating this sentinel in Kestra bridges the gap between static cloud secrets and active security compliance governance.

Use cases

  • SOC 2 90-Day Rotation Guardrail: Automatically identify database connection strings and third-party API tokens exceeding the 90-day rotation requirement.
  • Post-Incident Credential Review: Sweep Secret Manager following security incidents to ensure all sensitive tokens have been refreshed.
  • Orphaned Secret Version Cleanup: Flag secrets whose latest versions have not been updated in over 180 days to identify abandoned microservice configs.

Inputs

Name Type Default Description
gcp_project_id STRING company-prod-security Google Cloud project identifier containing the Secret Manager secrets to audit.
max_version_age_days INT 90 Maximum allowable age in days for an enabled secret version before flagging rotation staleness.
alert_on_stale_secrets BOOL true Whether to dispatch automated Slack alerts when stale unrotated secret versions are identified.

Expected outputs

  • {{ outputs.scan_secret_versions.vars.project_id }}: Identifier of the evaluated Google Cloud project.
  • {{ outputs.scan_secret_versions.vars.total_secrets }}: Total count of secrets audited in the project.
  • {{ outputs.scan_secret_versions.vars.stale_count }}: Number of secrets with enabled versions exceeding the age threshold.
  • {{ outputs.export_secret_manifest.value }}: Structured dictionary containing the consolidated secret rotation compliance manifest.

Prerequisites

  • Outbound HTTPS network access from Kestra execution workers to Google Cloud Secret Manager API endpoints.
  • A GCP Service Account JSON key configured with roles/secretmanager.viewer permissions (payload access is not required).
  • A Slack Incoming Webhook URL configured in Kestra secrets.

Secrets

  • GCP_SERVICE_ACCOUNT_KEY: Service account credentials JSON with permissions to inspect Secret Manager metadata.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL used to dispatch security compliance alerts.

Quick start

  1. Register GCP_SERVICE_ACCOUNT_KEY and SLACK_WEBHOOK_URL in your Kestra secret storage.
  2. Import this blueprint into your Kestra instance under the company.cloud namespace.
  3. Configure gcp_project_id with your GCP project ID.
  4. Run a manual execution to test Secret Manager metadata discovery and confirm the output manifest format.

Common pitfalls and troubleshooting

  • Payload Access Not Needed: The sentinel inspects only metadata (create_time, state); granting roles/secretmanager.secretAccessor is unnecessary and violates least privilege.
  • Disabled vs Enabled Versions: Older disabled or destroyed versions are ignored; only actively enabled versions are evaluated for rotation compliance.
  • Service Account Permissions: Ensure the service account has secretmanager.secrets.list and secretmanager.versions.list permissions.

How to extend

  • Automated Secret Rotation Trigger: Dispatch a downstream webhook or Cloud Pub/Sub message to trigger automated key rotation Cloud Functions.
  • Jira Compliance Ticket Creation: Automatically generate a Jira security remediation task when a secret exceeds 120 days unrotated.
  • Multi-Project Organization Scan: Wrap the evaluation in an io.kestra.plugin.core.flow.ForEach loop to audit all projects in the GCP organization.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.