-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance HMAC auth plugin to support structured signature headers (Tailscale-style) #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: GrantBirki <[email protected]>
Co-authored-by: GrantBirki <[email protected]>
Co-authored-by: GrantBirki <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for structured signature headers (Tailscale-style) to the HMAC auth plugin, while preserving full backward compatibility.
- Introduces
parse_structured_header
and integrates structured header handling into the HMAC validation flow. - Extends default config and
build_config
to includeheader_format
,signature_key
, andtimestamp_key
. - Adds unit tests for parsing and validating structured headers.
- Updates documentation with new configuration options and Tailscale examples.
Reviewed Changes
Copilot reviewed 10 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
spec/unit/lib/hooks/plugins/auth/hmac_spec.rb | Added tests for parse_structured_header and structured-header validation |
lib/hooks/plugins/auth/hmac.rb | Implemented structured-header parsing and integrated in valid? |
docs/auth_plugins.md | Documented header_format , signature_key , timestamp_key and Tailscale example |
.bundle/config | Bundler path settings updated (CI-specific, should be reverted) |
Comments suppressed due to low confidence (2)
lib/hooks/plugins/auth/hmac.rb:38
- [nitpick] The inline example uses
type: HMAC
(uppercase) but elsewhere the plugin type is specified in lowercase (hmac
). For consistency, update this example totype: hmac
.
# type: HMAC
.bundle/config:3
- This file includes CI-specific Bundler paths that should not be committed. Revert or remove these changes to avoid breaking local development environments.
BUNDLE_PATH: "/home/runner/work/hooks/hooks/vendor/bundle"
…lt hmac auth plugin
- Introduced MAX_HEADER_VALUE_LENGTH and MAX_PAYLOAD_SIZE constants for validation. - Implemented header and payload size validation methods in Base class. - Updated HMAC and SharedSecret validators to utilize new validation methods. - Added tests for oversized headers and payloads to ensure compliance with limits.
The HMAC auth plugin now supports providers like Tailscale that use structured signature headers with comma-separated key-value pairs, while maintaining full backward compatibility with existing webhook providers.
Problem
The existing HMAC plugin supported various webhook providers (GitHub, GitLab, Shopify, Slack) but couldn't handle providers like Tailscale that use:
t=1663781880,v1=0123456789abcdef
{timestamp}.{body}
Solution
Added minimal, backward-compatible enhancements to support structured headers:
New Configuration Options
header_format: "structured"
- Enables parsing of comma-separated key-value pairssignature_key: "v1"
- Configurable key name for signature in structured headertimestamp_key: "t"
- Configurable key name for timestamp in structured headerpayload_template
to support dot-separated formatExample: Tailscale Configuration
How It Works
t=1663781880,v1=abc123...
→ Extract timestamp and signature{timestamp}.{body}
→1663781880.{"event":"test"}
Testing & Quality
Security
Backward Compatibility
All existing webhook configurations continue to work unchanged:
X-Hub-Signature-256: sha256=abc123...
X-Gitlab-Token: sha256=abc123...
X-Shopify-Hmac-Sha256: abc123...
X-Slack-Signature: v0=abc123...
Documentation
docs/auth_plugins.md
This enhancement makes the hooks framework significantly more versatile for webhook processing across different provider ecosystems without breaking any existing functionality.
Fixes #51.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.