-
Notifications
You must be signed in to change notification settings - Fork 72
Randomize Root Password #325
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a699c1a
Randomize root password or use provided secret.
db386d9
Only bootstrap new deployments.
546444b
Reworked bootstrap mechanics.
8a55037
Style.
d070459
Style.
81b1375
Empty string is auto.
4eeaeaf
Added documentation. Simplified code.
e91f28b
Merge remote-tracking branch 'origin' into feature/bootstrap-root-pwd
3ccf78e
Merge remote-tracking branch 'origin/master' into feature/bootstrap-r…
ea5e3ff
Added BootstrapSucceeded condition.
e58fb32
Changed default value for root password initialization to None.
e9f0469
Merge remote-tracking branch 'origin/master' into feature/bootstrap-r…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // | ||
| // DISCLAIMER | ||
| // | ||
| // Copyright 2018 ArangoDB GmbH, Cologne, Germany | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // Copyright holder is ArangoDB GmbH, Cologne, Germany | ||
| // | ||
|
|
||
| package v1alpha | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" | ||
| ) | ||
|
|
||
| const ( | ||
| // UserNameRoot root user name | ||
| UserNameRoot = "root" | ||
| ) | ||
|
|
||
| // PasswordSecretName contains user password secret name | ||
| type PasswordSecretName string | ||
|
|
||
| const ( | ||
| // PasswordSecretNameNone is magic value for no action | ||
| PasswordSecretNameNone PasswordSecretName = "None" | ||
| // PasswordSecretNameAuto is magic value for autogenerate name | ||
| PasswordSecretNameAuto PasswordSecretName = "Auto" | ||
| ) | ||
|
|
||
| // PasswordSecretNameList is a map from username to secretnames | ||
| type PasswordSecretNameList map[string]PasswordSecretName | ||
|
|
||
| // BootstrapSpec contains information for cluster bootstrapping | ||
| type BootstrapSpec struct { | ||
| // PasswordSecretNames contains a map of username to password-secret-name | ||
| PasswordSecretNames PasswordSecretNameList `json:"passwordSecretNames,omitempty"` | ||
| } | ||
|
|
||
| // IsNone returns true if p is None or p is empty | ||
| func (p PasswordSecretName) IsNone() bool { | ||
| return p == PasswordSecretNameNone || p == "" | ||
| } | ||
|
|
||
| // IsAuto returns true if p is Auto | ||
| func (p PasswordSecretName) IsAuto() bool { | ||
| return p == PasswordSecretNameAuto | ||
| } | ||
|
|
||
| // GetSecretName returns the secret name given by the specs. Or None if not set. | ||
maierlars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func (s PasswordSecretNameList) GetSecretName(user string) PasswordSecretName { | ||
| if s != nil { | ||
| if secretname, ok := s[user]; ok { | ||
| return secretname | ||
| } | ||
| } | ||
| return PasswordSecretNameNone | ||
| } | ||
|
|
||
| // getSecretNameForUserPassword returns the default secret name for the given user | ||
| func getSecretNameForUserPassword(deploymentname, username string) PasswordSecretName { | ||
| return PasswordSecretName(k8sutil.FixupResourceName(deploymentname + "-" + username + "-password")) | ||
| } | ||
|
|
||
| // Validate the specification. | ||
| func (b *BootstrapSpec) Validate() error { | ||
| for username, secretname := range b.PasswordSecretNames { | ||
| // Remove this restriction as soon as we can bootstrap databases | ||
| if username != UserNameRoot { | ||
| return fmt.Errorf("only username `root` allowed in passwordSecretNames") | ||
| } | ||
|
|
||
| if secretname.IsNone() { | ||
| if username != UserNameRoot { | ||
| return fmt.Errorf("magic value None not allowed for %s", username) | ||
| } | ||
| } else { | ||
| if err := k8sutil.ValidateResourceName(string(secretname)); err != nil { | ||
| return maskAny(err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // SetDefaults fills in default values when a field is not specified. | ||
| func (b *BootstrapSpec) SetDefaults(deploymentname string) { | ||
maierlars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if b.PasswordSecretNames == nil { | ||
| b.PasswordSecretNames = make(map[string]PasswordSecretName) | ||
| } | ||
|
|
||
| // If root is not set init with Auto | ||
| if _, ok := b.PasswordSecretNames[UserNameRoot]; !ok { | ||
| b.PasswordSecretNames[UserNameRoot] = PasswordSecretNameAuto | ||
| } | ||
|
|
||
| // Replace Auto with generated secret name | ||
| for user, secretname := range b.PasswordSecretNames { | ||
| if secretname.IsAuto() { | ||
| b.PasswordSecretNames[user] = getSecretNameForUserPassword(deploymentname, user) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // NewPasswordSecretNameListOrNil returns nil if input is nil, otherwise returns a clone of the given value. | ||
| func NewPasswordSecretNameListOrNil(list PasswordSecretNameList) PasswordSecretNameList { | ||
| if list == nil { | ||
| return nil | ||
| } | ||
| var newList = make(PasswordSecretNameList) | ||
| for k, v := range list { | ||
| newList[k] = v | ||
| } | ||
| return newList | ||
| } | ||
|
|
||
| // SetDefaultsFrom fills unspecified fields with a value from given source spec. | ||
| func (b *BootstrapSpec) SetDefaultsFrom(source BootstrapSpec) { | ||
| if b.PasswordSecretNames == nil { | ||
| b.PasswordSecretNames = NewPasswordSecretNameListOrNil(source.PasswordSecretNames) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.