-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix(#19314, #15700): allow ssh
/altssh
subdomains in repo URLs to match webhook payload
#21227
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Matthew Bennett <[email protected]>
🔴 Preview Environment stopped on BunnyshellSee: Environment Details | Pipeline Logs Available commands (reply to this comment):
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21227 +/- ##
=======================================
Coverage 55.22% 55.23%
=======================================
Files 337 337
Lines 57057 57061 +4
=======================================
+ Hits 31511 31515 +4
+ Misses 22850 22845 -5
- Partials 2696 2701 +5 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
… fix-19314 Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
util/webhook/webhook.go
Outdated
// 3. Required: hostname parsed from `webURL` | ||
// 4. Optional: `:` followed by port number | ||
// 5. Optional: `/` | ||
return getUrlRegex(apiURL, `(?i)^(https?://)?(%[1]s@)?%[2]s(:[0-9]+)?/?$`) |
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.
These regexes seem different from the previous ones.
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.
Correct, there are subtle differences.
The previous Application
webhook web URL regex was:
(http://|https://|%s@|ssh://(%s@)?)%s(:[0-9]+|)[:/]%s(\.git)?
Which broke down to:
http://
,https://
,username@
,ssh://
, orssh://username@
(whereusername
is the RFC 3986 pattern defined elsewhere in the file)- hostname from original URL, passed through
regexp.QuoteMeta()
:port
or nothing- colon or slash
- path from original URL, passed through
regexp.QuoteMeta()
(which might be empty) - optional
.git
extension
The previous ApplicationSet
webhook web URL regex was:
(http://|https://|\w+@|ssh://(\w+@)?)%s(:[0-9]+|)[:/]%s(\.git)?
Which differed from the Application
one in that:
- Any sequence of one or more word characters was allowed for username.
- The hostname and path values were not passed through
regexp.QuoteMeta()
.
In the new common web URL regex used by both webhooks:
- Protocol and username are separated and are both optional. (This fixes 2.9.0-RC1: Azure Devops git webhooks do not match with http[s] schemas #15700 to allow usernames with
https?
URLs.) - An optional
altssh
orssh
subdomain is allowed. (This fixes Webhooks not compatible with alternative SSH addressing schemes #19314 to allow for SSH-over-443 alternatives.) - Hostname and path are both passed through
regexp.QuoteMeta()
. (This doesn’t fix any reported issue that I’m aware of, but prevents edge cases of hostname/path values containing anything that would have otherwise been interpreted as regex syntax.)
The previous ApplicationSet
webhook API URL regex was:
(http://|https://|\w+@|ssh://(\w+@)?)%s(:[0-9]+|)[:/]
(Basically the same as the web URL regex, but no path or extension.)
The new API URL regex has the same benefits as listed above for the new web URL regex (except for the altssh
/ssh
subdomain allowance since these URLs will never have that).
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
Fixes #19314. Fixes #15700 (cc: @robinlieb). Possibly fixes #16854 (cc: @aki-ks).
util/webhook
’sgetWebUrlRegex
into separateGetWebUrlRegex
andGetApiUrlRegex
.GetWebUrlRegex
allows for optionalaltssh
orssh
subdomain. (Addresses Webhooks not compatible with alternative SSH addressing schemes #19314.)GetWebUrlRegex
andGetApiUrlRegex
both allow for username inhttps?
URLs. (Addresses 2.9.0-RC1: Azure Devops git webhooks do not match with http[s] schemas #15700.)util/webhook
andapplicationset/webhook
to use the two new methods for consistent matching between the two.Justification:
ssh
subdomain over443
: https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-portaltssh
subdomain over443
: https://about.gitlab.com/blog/2016/02/18/gitlab-dot-com-now-supports-an-alternate-git-plus-ssh-port/#how-to-use-the-alternate-ssh-connection-on-gitlab.comaltssh
subdomain over443
: https://confluence.atlassian.com/bbkb/port-22-is-blocked-on-local-network-1168865232.htmlHowever, when using these patterns, webhook payload URLs will not include the subdomain, which causes the current regex matching to fail.
Signed-off-by: Matthew Bennett [email protected]
Checklist:
I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.Does this PR require documentation updates?I've updated documentation as required by this PR.My new feature complies with the feature status guidelines.Optional. My organization is added to USERS.md.