-
Notifications
You must be signed in to change notification settings - Fork 242
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
proxy: Update trimTrailingEOL function to handle carriage return (\r) #3799
Conversation
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.
Oh good catch!
I don't think this necessarily is caused by users changing the cert file, it could also be tools which would add /r/n
to the end of certificate files on Windows.
I'd give more details about what happens exactly. When the cert file ends with \r\n
, trimTrailingEOL
would only remove \n
and the file will end with \r
. Then this causes issues in
crc/pkg/crc/cluster/cluster.go
Lines 388 to 391 in 97705a0
` | |
// Replace the carriage return ("\n" or "\r\n") with literal `\n` string | |
re := regexp.MustCompile(`\r?\n`) | |
p := fmt.Sprintf(proxyCABundleTemplate, re.ReplaceAllString(proxy.ProxyCACert, `\n`), trustedCAName) |
\r\n
and \n
with \\n
but will not do anything with a single \r
.This in turn causes bug #3785
@cfergeau you mean to say crc/pkg/crc/cluster/cluster.go Lines 388 to 391 in 97705a0
\r case also and replace it \n because that is again going to fail. what we want there should be no new line after -----END CERTIFICATE----- otherwise user-ca-bundle.json is not applied correctly on the cluster so I think this should be handled by trimTrailingEOL itself?
|
I was only trying to describe the situation before your changes, imo it would be useful to have in the commit log. |
It will fix the proxy parse issue in case user update the cert on windows and add blank line at the end of certificate. Unit test is also added for same. When the cert file ends with \r\n, trimTrailingEOL would only remove \n and the file will end with \r. Then this causes issues in regexp which only replace `\r\n` => `\n` but doesn't perform any action for `\r` and eventualy turn up this bug. fixes: crc-org#3785
fb88809
to
e0619ed
Compare
Not sure what happened, but the code was initially correct in #1443, and when moving it to a helper function, \r was lost :-/ |
There's a second occurrence of the same code:
and the test code has
Let's make use of the recently added |
Looks like we are using `strings.TrimRight(<string>, "\n\r")` at multiple locations so better to move this helper to pkg/strings for better maintainance.
Added another commit to do that. |
@praveenkumar: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cfergeau The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
It will fix the proxy parse issue in case user update the cert on windows and add blank line at the end of certificate. Unit test is also added for same.
fixes: #3785