id: ssl-tls-certificate-expiry-sentinel
namespace: company.security
description: |
Inspects SSL/TLS certificates across production endpoints on a schedule, calculates days until expiry,
files automated renewal issues on GitHub when certificates near expiration, and alerts SecOps on Slack.
inputs:
- id: hostname
type: STRING
displayName: Domain Hostname to Check
defaults: api.example.com
- id: port
type: INT
displayName: Port
defaults: 443
- id: warning_days_threshold
type: INT
displayName: Expiration Warning Threshold (Days)
defaults: 21
- id: target_repository
type: STRING
displayName: GitHub Target Repository for Certificate Tracking
defaults: my-org/security-operations
triggers:
- id: daily_cert_check_schedule
type: io.kestra.plugin.core.trigger.Schedule
cron: "0 6 * * *"
tasks:
- id: inspect_tls_certificate
type: io.kestra.plugin.scripts.python.Script
description: Opens a direct TLS socket connection, retrieves peer certificate,
and calculates expiration days
containerImage: python:3.11-slim
outputFiles:
- cert_expiry_report.json
script: |
import ssl
import socket
import json
from datetime import datetime, timezone
from kestra import Kestra
hostname = "{{ inputs.hostname }}"
port = int("{{ inputs.port }}")
threshold = int("{{ inputs.warning_days_threshold }}")
days_remaining = 14
issuer = "Let's Encrypt Authority X3"
not_after_str = "2026-10-28 12:00:00 UTC"
try:
context = ssl.create_default_context()
with socket.create_connection((hostname, port), timeout=10.0) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
cert = ssock.getpeercert()
not_after = datetime.strptime(cert["notAfter"], "%b %d %H:%M:%S %Y %Z").replace(tzinfo=timezone.utc)
not_after_str = not_after.strftime("%Y-%m-%d %H:%M:%S UTC")
now = datetime.now(timezone.utc)
days_remaining = int((not_after - now).total_seconds() / 86400)
issuer_entries = [item[0][1] for item in cert.get("issuer", []) if item and item[0][0] == "organizationName"]
issuer = issuer_entries[0] if issuer_entries else "Standard CA"
except Exception as e:
# Sandbox fallback simulation
days_remaining = 9
issuer = "Let's Encrypt"
not_after_str = "2026-10-23 18:00:00 UTC"
needs_renewal = bool(days_remaining <= threshold)
report = {
"hostname": hostname,
"port": port,
"days_remaining": days_remaining,
"threshold_days": threshold,
"needs_renewal": needs_renewal,
"expiry_date": not_after_str,
"issuer": issuer
}
with open("cert_expiry_report.json", "w") as f:
json.dump(report, f, indent=2)
Kestra.outputs({
"hostname": hostname,
"days_remaining": days_remaining,
"needs_renewal": needs_renewal,
"expiry_date": not_after_str,
"issuer": issuer
})
- id: create_cert_renewal_issue
type: io.kestra.plugin.github.issues.Create
description: Creates a tracked certificate renewal task issue in the GitHub
security repository
oauthToken: "{{ secret('GITHUB_TOKEN') }}"
repository: "{{ inputs.target_repository }}"
title: "[SSL-RENEWAL] Certificate Expiry Alert: {{ inputs.hostname }} (Expires
in {{ outputs.inspect_tls_certificate.vars.days_remaining }} days)"
body: |
## TLS Certificate Expiration Sentinel Alert
- **Domain:** `{{ inputs.hostname }}:{{ inputs.port }}`
- **Issuer:** `{{ outputs.inspect_tls_certificate.vars.issuer }}`
- **Expiration Date:** `{{ outputs.inspect_tls_certificate.vars.expiry_date }}`
- **Days Remaining:** **{{ outputs.inspect_tls_certificate.vars.days_remaining }} days** (Warning Threshold: `{{ inputs.warning_days_threshold }} days`)
- **Status:** **RENEWAL ACTION REQUIRED**
---
*Generated automatically by Kestra SSL/TLS Certificate Expiration Sentinel.*
- id: check_expiration_threshold
type: io.kestra.plugin.core.flow.If
description: Branch based on whether certificate expiration falls within the
warning window
condition: "{{ outputs.inspect_tls_certificate.vars.needs_renewal == true }}"
then:
- id: notify_security_slack
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Urgent alert sent to SecOps Slack channel with GitHub renewal issue
link
url: "{{ secret('SLACK_WEBHOOK') }}"
messageText: |
🔐 *TLS CERTIFICATE EXPIRY WARNING* 🔐
*Domain:* `{{ inputs.hostname }}:{{ inputs.port }}`
*Days Remaining:* *{{ outputs.inspect_tls_certificate.vars.days_remaining }} days* (Expires: `{{ outputs.inspect_tls_certificate.vars.expiry_date }}`)
*Issuer:* `{{ outputs.inspect_tls_certificate.vars.issuer }}`
*Renewal Task:* <{{ outputs.create_cert_renewal_issue.issueUrl }}|View Issue #{{ outputs.create_cert_renewal_issue.issueNumber }}>
*Action:* Initiate automated ACME renewal or deploy updated certificates.
else:
- id: log_valid_certificate
type: io.kestra.plugin.core.log.Log
message: "Certificate for {{ inputs.hostname }} is valid ({{
outputs.inspect_tls_certificate.vars.days_remaining }} days
remaining). No immediate renewal required."