Skip to content

github: support multiple webhook secrets#2378

Open
ubiratansoares wants to merge 2 commits intomasterfrom
u/gh-webhooks-secrets
Open

github: support multiple webhook secrets#2378
ubiratansoares wants to merge 2 commits intomasterfrom
u/gh-webhooks-secrets

Conversation

@ubiratansoares
Copy link
Copy Markdown

Added this support to beter manage github webhook updates minimizing the impact.

Kept the envvar name for the sake of simplicity.

@ubiratansoares ubiratansoares self-assigned this Apr 16, 2026
Comment thread src/github/webhook.rs Outdated
@marcoieni marcoieni self-assigned this Apr 16, 2026
@marcoieni
Copy link
Copy Markdown
Member

marcoieni commented Apr 16, 2026

AI suggestion:

Trim each secret and reject empty entries to guard against trailing commas and accidental whitespace:

for secret in gh_webhook_secrets.split(',') {
    let secret = secret.trim();
    if secret.is_empty() {
        // or also consider failing to avoid misconfigurations
        continue;
    }
    let mut mac = Hmac::<Sha256>::new_from_slice(secret.as_bytes())
        .expect("GITHUB_WEBHOOK_SECRET contains an invalid key");
    mac.update(payload);
    if mac.verify_slice(&signature).is_ok() {
        return Ok(());
    }
}


  This restores the fail-loud behavior for truly invalid keys while cleanly skipping empty segments from trailing commas.

But maybe it's better to do these validations at startup instead of doing them on a per request basis to avoid impacting performance

@marcoieni
Copy link
Copy Markdown
Member

This is also another nice AI suggestion:

Consider logging a warning at startup (not per-request) if more than one secret is configured, so operators have visibility that rotation mode is active.

@ubiratansoares ubiratansoares force-pushed the u/gh-webhooks-secrets branch from 56c90c6 to 6512f5d Compare April 16, 2026 11:36
@ubiratansoares ubiratansoares marked this pull request as ready for review April 17, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants