-
Notifications
You must be signed in to change notification settings - Fork 202
K8SPXC-1568: prevent having * prefix in proxyadmin password
#2124
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
pkg/controller/pxc/secrets.go
Outdated
| // generatePass generates a random password of length passwordLen. | ||
| // The optional rules parameter expects usernames and adjusts the | ||
| // password generation logic based on them. | ||
| func generatePass(rules ...string) ([]byte, error) { |
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.
isn't rules ...string a bit confusing if we just passing usernames?
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.
| return nil, errors.Wrap(err, "get rand int") | ||
| } | ||
| b[i] = passSymbols[randInt.Int64()] | ||
| } |
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.
Why we use passSymbols here? Should we use symbols instead?
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.
pkg/controller/pxc/secrets_test.go
Outdated
| t.Fatal(err) | ||
| } | ||
| if !strings.HasPrefix(string(p), "*") { | ||
| t.Fatal("expected '*' prefix when no rules are applied to the password") |
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.
Why dont we use assert and require for ensuring that we have the expected results?
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.
pkg/controller/pxc/secrets.go
Outdated
| // generatePass generates a random password of length passwordLen. | ||
| // The optional rules parameter expects usernames and adjusts the | ||
| // password generation logic based on them. | ||
| func generatePass(usernames ...string) ([]byte, error) { |
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.
Why usernames is not username? We are passing a single user.
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.
pkg/controller/pxc/secrets.go
Outdated
|
|
||
| for i := range passwordLen { | ||
| symbols := passSymbols | ||
| if slices.Contains(usernames, users.ProxyAdmin) { |
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.
We can determine if we are proxyadmin by running simply something like this, correct?
len(username) > 0 && username[0] == users.ProxyAdmin
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.
Also this can be pre calculated insteda of resolving it for every len(passwordLen) iteration
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.
pkg/controller/pxc/secrets.go
Outdated
| symbols = strings.ReplaceAll(symbols, "*", "") | ||
| } | ||
| symbols = strings.ReplaceAll(symbols, ":", "") | ||
| symbols = strings.ReplaceAll(symbols, ";", "") |
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 also think these can be precalculated in general
e.g.
firstCharSymbols = excludeChars(passSymbols, "*:;")
otherSymbols = excludeChars(passSymbols, ":;")
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.
commit: f48cc30 |
https://perconadev.atlassian.net/browse/K8SPXC-1568
DESCRIPTION
It's not possible to use a
proxyadminpassword, which starts with*char.This PR ensures the operator generates
proxyadminpassword that do not begin with*.CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
compare/*-oc.yml)?Config/Logging/Testability