Script icon
Process icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

GitHub Personal Access Token Expiration Sentinel

Audits GitHub organization personal access tokens to detect upcoming expirations and prevent CI/CD automation pipeline disruptions.

Categories
CloudInfrastructure

Enterprise organizations rely on GitHub Personal Access Tokens (PATs) and fine-grained access keys for automation, CI/CD runners, and developer workflows. When tokens expire unexpectedly, production build pipelines fail, deployment gates freeze, and access to internal package registries is revoked. This sentinel scans organization personal access tokens via the GitHub REST API, flags tokens nearing their expiration window, and notifies Security and DevOps teams on Slack to ensure uninterrupted automation.

How it works

  1. Scheduled triggering: Executes daily at 08:00 UTC using a cron schedule trigger (0 8 * * *) or triggers on-demand via manual execution.
  2. API enumeration: Queries the GitHub REST API (/orgs/{org}/personal-access-tokens) using organization administrator credentials.
  3. Expiration window analysis: Compares token expiration timestamps (expires_at) against current UTC time and flags tokens within expiration_warning_days.
  4. Condition evaluation: An io.kestra.plugin.core.flow.If task evaluates whether expiring_tokens_count exceeds max_expiring_token_threshold.
  5. Slack notification: Dispatches an alert via SlackIncomingWebhook listing owner usernames, token names, and remaining days.
  6. Audit trail logging and return: Emits operational execution logs and returns a structured compliance manifest for auditing.

Architecture diagram

flowchart TD
  A[daily_token_audit Schedule Trigger] --> B[scan_github_tokens Python Script]
  B --> C[check_expiring_tokens Flowable If]
  C -- Expiring Tokens Found --> D[notify_slack_security Webhook]
  C -- All Tokens Valid --> E[log_token_audit_status Log]
  D --> E
  E --> F[export_token_manifest Return]

Use cases

  • CI/CD pipeline continuity: Prevent critical deployment pipelines and release automations from failing due to expired deploy keys or PATs.
  • Security and credential hygiene: Identify abandoned tokens and enforce strict rotation schedules in compliance with SOC2 access controls.
  • Multi-organization governance: Provide security teams visibility into active automation credentials across enterprise GitHub organizations.

Inputs

Name Type Default Description
github_org_name STRING enterprise-engineering Name of the GitHub Enterprise or organization to audit for personal access tokens.
expiration_warning_days INT 14 Number of days before token expiration to flag tokens for proactive renewal.
alert_on_expiring_tokens BOOL true Whether to dispatch alerts when expiring or expired tokens are detected.
max_expiring_token_threshold INT 0 Maximum allowable count of expiring tokens before triggering an incident notification.

Expected outputs

  • {{ outputs.scan_github_tokens.vars.total_tokens_audited }}: Total number of organization tokens evaluated.
  • {{ outputs.scan_github_tokens.vars.expiring_tokens_count }}: Number of tokens nearing expiration or already expired.
  • {{ outputs.scan_github_tokens.vars.expiring_tokens_details }}: Serialized JSON list containing token names, owners, and expiration dates.
  • {{ outputs.export_token_manifest.value }}: Structured dictionary containing the complete organization token audit manifest.

Prerequisites

  • Outbound HTTPS network access from Kestra execution workers to api.github.com.
  • GitHub Personal Access Token or GitHub App with organization administration permissions (read:org, admin:org).
  • Configured Slack Incoming Webhook endpoint for security team notifications.

Secrets

  • GITHUB_ADMIN_TOKEN: GitHub personal access token with organization administrator permissions.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL used for dispatching alert messages.

Quick start

  1. Define GITHUB_ADMIN_TOKEN and SLACK_WEBHOOK_URL in your Kestra Secret storage.
  2. Deploy this flow under the company.security namespace.
  3. Configure github_org_name to match your GitHub organization.
  4. Run a manual execution to inspect organization tokens and confirm alert delivery.

Common pitfalls and troubleshooting

  • API rate limits: Ensure the admin token is an authenticated GitHub token to take advantage of the 5,000 requests-per-hour rate limit.
  • Fine-grained vs classic PATs: Modern GitHub organizations manage fine-grained personal access tokens through the programmatic management API, which requires appropriate organization owner permissions.
  • Single Sign-On (SSO) authorization: If SAML SSO is enforced in the organization, ensure the personal access token has been explicitly authorized for the organization.

How to extend

  • Automated owner notification: Send direct Slack or email messages to individual token owners rather than a general security channel.
  • Automated token revocation: Add a task that calls the GitHub API to revoke tokens that have been expired for more than 30 days.
  • Jira ticket generation: Automatically create renewal tickets in Jira for tokens tied to mission-critical infrastructure.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.