K8SPXC-1568: prevent having * prefix in proxyadmin password#2124
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.
isn't rules ...string a bit confusing if we just passing usernames?
| return nil, errors.Wrap(err, "get rand int") | ||
| } | ||
| b[i] = passSymbols[randInt.Int64()] | ||
| } |
There was a problem hiding this comment.
Why we use passSymbols here? Should we use symbols instead?
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.
Why dont we use assert and require for ensuring that we have the expected results?
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.
Why usernames is not username? We are passing a single user.
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.
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.
Also this can be pre calculated insteda of resolving it for every len(passwordLen) iteration
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.
I also think these can be precalculated in general
e.g.
firstCharSymbols = excludeChars(passSymbols, "*:;")
otherSymbols = excludeChars(passSymbols, ":;")
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