-
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): allow ssh/altssh subdomains in repo URLs to match webhook payload #19315
fix(#19314): allow ssh/altssh subdomains in repo URLs to match webhook payload #19315
Conversation
Signed-off-by: Matthew Bennett <[email protected]>
❗ Preview Environment delete from Bunnyshell failedSee: Environment Details | Pipeline Logs Available commands (reply to this comment):
|
❌ Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19315 +/- ##
==========================================
- Coverage 55.95% 55.90% -0.05%
==========================================
Files 322 323 +1
Lines 44546 44530 -16
==========================================
- Hits 24924 24895 -29
- Misses 17055 17075 +20
+ Partials 2567 2560 -7 ☔ View full report in Codecov by Sentry. |
…sh-subdomain Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
…sh-subdomain Signed-off-by: Matthew Bennett <[email protected]>
…sh-subdomain Signed-off-by: Matthew Bennett <[email protected]>
applicationset/webhook/webhook.go
Outdated
// https://www.rfc-editor.org/rfc/rfc3986#section-3.2.1 | ||
// https://github.com/shadow-maint/shadow/blob/master/libmisc/chkname.c#L36 | ||
const usernameRegex = `[a-zA-Z0-9_\.][a-zA-Z0-9_\.-]{0,30}[a-zA-Z0-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.
Copied directly from https://github.com/argoproj/argo-cd/blob/7746506/util/webhook/webhook.go#L41-L43.
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.
Should we instead move this to a common util package?
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.
I had the same thought but wasn’t sure if I should dig in that much. (Wasn’t sure if the 2 webhooks were being allowed to diverge intentionally for some reason.) There’s another new feature in the Application
webhook (maxPayloadSizeMB
) that isn’t here either that I wanted to pull in.
I’ll see what I can do about reusing as much as possible between the 2 webhooks.
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.
I have a similar PR open where the thing with the util package is already done (#16292). Maybe this can be used as an inspiration to these two PRs can be combined somehow.
applicationset/webhook/webhook.go
Outdated
regexEscapedHostname := regexp.QuoteMeta(urlObj.Hostname()) | ||
regexEscapedPath := regexp.QuoteMeta(urlObj.EscapedPath()[1:]) | ||
regexpStr := fmt.Sprintf(`(?i)^(http://|https://|%s@|ssh://(%s@)?((alt)?ssh\.)?)%s(:[0-9]+|)[:/]%s(\.git)?$`, | ||
usernameRegex, usernameRegex, regexEscapedHostname, regexEscapedPath) |
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.
QuoteMeta
and Sprintf
formatting copied from https://github.com/argoproj/argo-cd/blob/7746506/util/webhook/webhook.go#L348-L351.
…sh-subdomain Signed-off-by: Matthew Bennett <[email protected]>
applicationset/webhook/webhook.go
Outdated
// https://www.rfc-editor.org/rfc/rfc3986#section-3.2.1 | ||
// https://github.com/shadow-maint/shadow/blob/master/libmisc/chkname.c#L36 | ||
const usernameRegex = `[a-zA-Z0-9_\.][a-zA-Z0-9_\.-]{0,30}[a-zA-Z0-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.
Should we instead move this to a common util package?
applicationset/webhook/webhook.go
Outdated
regexEscapedHostname := regexp.QuoteMeta(urlObj.Hostname()) | ||
regexEscapedPath := regexp.QuoteMeta(urlObj.EscapedPath()[1:]) | ||
regexpStr := fmt.Sprintf(`(?i)^(http://|https://|%s@|ssh://(%s@)?((alt)?ssh\.)?)%s(:[0-9]+|)[:/]%s(\.git)?$`, | ||
usernameRegex, usernameRegex, regexEscapedHostname, regexEscapedPath) |
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.
Ditto with this, if it's identical to the appset webhook handling logic, can we just move it to a shared location?
…sh-subdomain Signed-off-by: Matthew Bennett <[email protected]>
…sh-subdomain Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
…sh-subdomain 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]>
…sh-subdomain 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
func GetApiUrlRegex(originalUrl string) (*regexp.Regexp, error) { | ||
return getUrlRegex(originalUrl, `(?i)^https?://%[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.
The original regex used for this (here) allowed for SSH URLs which, AFAIK, aren’t valid for an API URL. If I’m mistaken on that, I can easily expand this to account for that. (There were no tests for this regex before. I added basic positive and negative cases in new Test_GetApiUrlRegex
.)
The common webhook handling code (HTTP- and provider-related bits and the queue logic) has been split from the use case-specific webhook payload handling (to make the former reusable across instances of the latter):
|
Signed-off-by: Matthew Bennett <[email protected]>
Signed-off-by: Matthew Bennett <[email protected]>
func GetWebUrlRegex(originalUrl string) (*regexp.Regexp, error) { | ||
return getUrlRegex(originalUrl, `(?i)^((https?|ssh)://)?(%[1]s@)?((alt)?ssh\.)?%[2]s(:[0-9]+)?[:/]%[3]s$`) |
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.
@robinlieb As far as I can tell, this regex covers the changes you introduced in #16292.
The updated regex matches the following sequence of parts:
- optional: protocol (
http
,https
, orssh
) followed by://
- optional: username followed by
@
- previously, the regex did not allow for usernames in
http
,https
, or protocol-less URLs.
- previously, the regex did not allow for usernames in
- optional:
ssh
oraltssh
subdomain- this is the tiny change I originally set out to introduce 😅
- required: hostname parsed from original URL
- optional:
:
followed by port number - required:
:
or/
- required: path parsed from original URL followed by optional
.git
Feel free to suggest any additional test cases in webhook_test.go
and I’ll incorporate them and make sure the regex works against them.
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]>
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]>
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]>
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]>
Closing in favor of much smaller #21227. |
ℹ️ Edit: There was a request to make things reusable between the Application and ApplicationSet webhooks. See #19315 (comment) for notes on those refactors. Original PR description follows.
Fixes #19314.
Application
andApplicationSet
webhooks to allow an optionalssh
oraltssh
subdomain to exist in the resource’s repo URL that doesn’t appear in the webhook payload’s repo URL.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.htmlApplicationSet
webhook regular expression logic to matchApplication
’s:usernameRegex
instead of just\w+
.regexp.QuoteMeta
on hostname and path.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.