Skip to content
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

Improvements to secret injector #13282

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/util/urlpattern/urlpattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var InvalidPatternError = errors.New("invalid pattern")

var urlPatternRegex = regexp.MustCompile(`^` +
`(?:(\*|git|http|https|ssh)://)` +
`(\*|(?:\*\.)?[^/*]+)` +
`(\*|(?:\*\.)?[^@/*]+)` +
`(/.*)` +
`$`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we should be disallowing this for all users of the utility, since technically urls containing @ can be valid, even though you want to disallow it in your particular usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're disallowing @ in the host part of the /pattern/, not in the URL matched. A pattern of http://example.com/* would still match the URL http://user:password@example.com/ (although I'll add a test case for this). I want to disable @ in the pattern because I don't think it makes any sense for us to match user:password@ in the URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test cases added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't think we'd have a case where we want to ensure a user name is being supplied in the url, as for an ssh url?

we might not need it today, i'm not convinced we wouldn't want it in the future, but i guess i'm ok with adding this restriction for now.


Expand Down
10 changes: 7 additions & 3 deletions pkg/util/urlpattern/urlpattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestMatchPattern(t *testing.T) {
expectedScheme: `^(git|http|https|ssh)$`,
expectedHost: `^.*$`,
expectedPath: `^/.*$`,
expectedMatch: []string{`https://github.com/`},
expectedMatch: []string{`https://github.com/`, `https://user:password@github.com/`, `ssh://git@github.com/`},
expectedNotMatch: []string{`ftp://github.com/`},
},
{
Expand Down Expand Up @@ -80,15 +80,15 @@ func TestMatchPattern(t *testing.T) {
expectedScheme: `^https$`,
expectedHost: `^github\.com$`,
expectedPath: `^/.*$`,
expectedMatch: []string{`https://github.com/`},
expectedMatch: []string{`https://github.com/`, `https://user:password@github.com/`},
expectedNotMatch: []string{`https://test.github.com/`},
},
{
pattern: `https://*.git.luolix.top/*`,
expectedScheme: `^https$`,
expectedHost: `^(?:.*\.)?github\.com$`,
expectedPath: `^/.*$`,
expectedMatch: []string{`https://github.com/`, `https://test.github.com/`},
expectedMatch: []string{`https://github.com/`, `https://user:password@github.com/`, `https://test.github.com/`},
},
{
pattern: `https://\.+?()|[]{}^$/*`,
Expand All @@ -108,6 +108,10 @@ func TestMatchPattern(t *testing.T) {
pattern: `https://git*hub.com/*`,
expectedErr: true,
},
{
pattern: `*://git@github.com/*`,
expectedErr: true,
},
{
pattern: `https://github.com/`,
expectedScheme: `^https$`,
Expand Down