Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 650c3cf

Browse files
committed
fixup! feat: Add user configuration for all providers
Address review comments
1 parent 9f56b56 commit 650c3cf

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,10 @@ type User struct {
365365
// Name specifies the user name
366366
Name string `json:"name"`
367367

368-
// Passwd specifies a hashed password for the user
368+
// HashedPassword specifies a hashed password for the user.
369+
// An empty string is not marshalled, because it is not a valid value.
369370
// +optional
370-
Passwd *string `json:"passwd,omitempty"`
371+
HashedPassword string `json:"hashedPassword,omitempty"`
371372

372373
// SSHAuthorizedKeys specifies a list of ssh authorized keys for the user
373374
// +optional
@@ -387,7 +388,7 @@ func (User) VariableSchema() clusterv1.VariableSchema {
387388
Description: "The username",
388389
Type: "string",
389390
},
390-
"passwd": {
391+
"hashedPassword": {
391392
Description: "The hashed password for the user",
392393
Type: "string",
393394
},

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Copyright 2023 D2iQ, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters,verbs=watch;list;get
54
package users

pkg/handlers/generic/mutation/users/inject.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,23 @@ func (h *usersPatchHandler) Mutate(
119119
func generateBootstrapUser(userFromVariable v1alpha1.User) bootstrapv1.User {
120120
bootstrapUser := bootstrapv1.User{
121121
Name: userFromVariable.Name,
122-
Passwd: userFromVariable.Passwd,
122+
Passwd: ptr.To(userFromVariable.HashedPassword),
123123
SSHAuthorizedKeys: userFromVariable.SSHAuthorizedKeys,
124124
Sudo: userFromVariable.Sudo,
125125
}
126126

127127
// LockPassword is not part of our API, because we can derive its value
128128
// for the use cases our API supports.
129129
//
130-
// We do not support the edge cases where a password is defined, but
131-
// password authentication is disabled, or where no password is defined, but
132-
// password authentication is enabled.
130+
// We do not support these edge cases:
131+
// (a) Hashed password is defined, password authentication is not enabled.
132+
// (b) Hashed password is not defined, password authentication is enabled.
133133
//
134134
// We disable password authentication by default.
135-
bootstrapUser.LockPassword = ptr.To[bool](true)
136-
if userFromVariable.Passwd != nil {
137-
// We enable password authentication only if a password is defined.
138-
bootstrapUser.LockPassword = ptr.To[bool](true)
135+
bootstrapUser.LockPassword = ptr.To(true)
136+
if userFromVariable.HashedPassword != "" {
137+
// We enable password authentication only if a hashed password is defined.
138+
bootstrapUser.LockPassword = ptr.To(true)
139139
}
140140

141141
return bootstrapUser

pkg/handlers/generic/mutation/users/tests/generate_patches.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import (
1919

2020
var (
2121
testUser1 = v1alpha1.User{
22-
Name: "complete",
23-
Passwd: ptr.To[string]("password"),
22+
Name: "complete",
23+
HashedPassword: "password",
2424
SSHAuthorizedKeys: []string{
2525
"key1",
2626
"key2",
2727
},
28-
Sudo: ptr.To[string]("ALL=(ALL) NOPASSWD:ALL"),
28+
Sudo: ptr.To("ALL=(ALL) NOPASSWD:ALL"),
2929
}
3030
testUser2 = v1alpha1.User{
3131
Name: "onlyname",

pkg/handlers/generic/mutation/users/variables_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ func TestVariableValidation(t *testing.T) {
2626
Vals: v1alpha1.GenericClusterConfig{
2727
Users: []v1alpha1.User{
2828
{
29-
Name: "complete",
30-
Passwd: ptr.To[string]("password"),
29+
Name: "complete",
30+
HashedPassword: "password",
3131
SSHAuthorizedKeys: []string{
3232
"key1",
3333
"key2",
3434
},
35-
Sudo: ptr.To[string]("ALL=(ALL) NOPASSWD:ALL"),
35+
Sudo: ptr.To("ALL=(ALL) NOPASSWD:ALL"),
3636
},
3737
{
3838
Name: "onlyname",

0 commit comments

Comments
 (0)