Skip to content

Commit 6b888bd

Browse files
committed
feat : Add config option to set developer password for cluster (crc-org#2539)
Add option to set developer password for the user. ``` $ crc config set developer-password mypassword $ crc start [...] INFO Adding crc-admin and crc-developer contexts to kubeconfig... Started the OpenShift cluster. The server is accessible via web console at: https://console-openshift-console.apps-crc.testing Log in as developer: Username: developer Password: mypassword ``` Signed-off-by: Rohan Kumar <[email protected]>
1 parent 8a1cef2 commit 6b888bd

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

cmd/crc/cmd/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func runStart(ctx context.Context) (*types.StartResult, error) {
7575
NameServer: config.Get(crcConfig.NameServer).AsString(),
7676
PullSecret: cluster.NewInteractivePullSecretLoader(config),
7777
KubeAdminPassword: config.Get(crcConfig.KubeAdminPassword).AsString(),
78+
DeveloperPassword: config.Get(crcConfig.DeveloperPassword).AsString(),
7879
Preset: crcConfig.GetPreset(config),
7980
IngressHTTPPort: config.Get(crcConfig.IngressHTTPPort).AsUInt(),
8081
IngressHTTPSPort: config.Get(crcConfig.IngressHTTPSPort).AsUInt(),

pkg/crc/api/handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func getStartConfig(cfg crcConfig.Storage, args client.StartConfig) types.StartC
127127
NameServer: cfg.Get(crcConfig.NameServer).AsString(),
128128
PullSecret: cluster.NewNonInteractivePullSecretLoader(cfg, args.PullSecretFile),
129129
KubeAdminPassword: cfg.Get(crcConfig.KubeAdminPassword).AsString(),
130+
DeveloperPassword: cfg.Get(crcConfig.DeveloperPassword).AsString(),
130131
IngressHTTPPort: cfg.Get(crcConfig.IngressHTTPPort).AsUInt(),
131132
IngressHTTPSPort: cfg.Get(crcConfig.IngressHTTPSPort).AsUInt(),
132133
Preset: crcConfig.GetPreset(cfg),

pkg/crc/cluster/kubeadmin_password.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ func GenerateUserPassword(passwordFile string, user string) error {
2727
return os.WriteFile(passwordFile, []byte(kubeAdminPassword), 0600)
2828
}
2929

30-
// UpdateKubeAdminUserPassword updates the htpasswd secret
31-
func UpdateKubeAdminUserPassword(ctx context.Context, ocConfig oc.Config, newPassword string) error {
32-
if newPassword != "" {
30+
// UpdateUserPassword updates the htpasswd secret
31+
func UpdateUserPassword(ctx context.Context, ocConfig oc.Config, newKubeAdminPassword string, newDeveloperPassword string) error {
32+
if newKubeAdminPassword != "" {
3333
logging.Infof("Overriding password for kubeadmin user")
34-
if err := os.WriteFile(constants.GetKubeAdminPasswordPath(), []byte(strings.TrimSpace(newPassword)), 0600); err != nil {
34+
if err := os.WriteFile(constants.GetKubeAdminPasswordPath(), []byte(strings.TrimSpace(newKubeAdminPassword)), 0600); err != nil {
35+
return err
36+
}
37+
}
38+
if newDeveloperPassword != "" {
39+
logging.Infof("Overriding password for developer user")
40+
if err := os.WriteFile(constants.GetDeveloperPasswordPath(), []byte(strings.TrimSpace(newDeveloperPassword)), 0600); err != nil {
3541
return err
3642
}
3743
}
@@ -65,7 +71,7 @@ func UpdateKubeAdminUserPassword(ctx context.Context, ocConfig oc.Config, newPas
6571
return nil
6672
}
6773

68-
logging.Infof("Changing the password for the kubeadmin user")
74+
logging.Infof("Changing the password for the users")
6975
expected, err := getHtpasswd(credentials, externals)
7076
if err != nil {
7177
return err
@@ -75,7 +81,7 @@ func UpdateKubeAdminUserPassword(ctx context.Context, ocConfig oc.Config, newPas
7581
"-n", "openshift-config", "--type", "merge"}
7682
_, stderr, err = ocConfig.RunOcCommandPrivate(cmdArgs...)
7783
if err != nil {
78-
return fmt.Errorf("Failed to update kubeadmin password %v: %s", err, stderr)
84+
return fmt.Errorf("failed to update user passwords %v: %s", err, stderr)
7985
}
8086
return nil
8187
}

pkg/crc/config/settings.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
ConsentTelemetry = "consent-telemetry"
3030
EnableClusterMonitoring = "enable-cluster-monitoring"
3131
KubeAdminPassword = "kubeadmin-password"
32+
DeveloperPassword = "developer-password"
3233
Preset = "preset"
3334
EnableSharedDirs = "enable-shared-dirs"
3435
SharedDirPassword = "shared-dir-password" // #nosec G101
@@ -134,6 +135,8 @@ func RegisterSettings(cfg *Config) {
134135

135136
cfg.AddSetting(KubeAdminPassword, "", validateString, SuccessfullyApplied,
136137
"User defined kubeadmin password")
138+
cfg.AddSetting(DeveloperPassword, "", validateString, SuccessfullyApplied,
139+
"User defined developer password")
137140
cfg.AddSetting(IngressHTTPPort, constants.OpenShiftIngressHTTPPort, validatePort, RequiresHTTPPortChangeWarning,
138141
fmt.Sprintf("HTTP port to use for OpenShift ingress/routes on the host (1024-65535, default: %d)", constants.OpenShiftIngressHTTPPort))
139142
cfg.AddSetting(IngressHTTPSPort, constants.OpenShiftIngressHTTPSPort, validatePort, RequiresHTTPSPortChangeWarning,

pkg/crc/machine/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
575575
return nil, errors.Wrap(err, "Failed to update pull secret on the disk")
576576
}
577577

578-
if err := cluster.UpdateKubeAdminUserPassword(ctx, ocConfig, startConfig.KubeAdminPassword); err != nil {
578+
if err := cluster.UpdateUserPassword(ctx, ocConfig, startConfig.KubeAdminPassword, startConfig.DeveloperPassword); err != nil {
579579
return nil, errors.Wrap(err, "Failed to update kubeadmin user password")
580580
}
581581

pkg/crc/machine/types/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type StartConfig struct {
2626
// User defined kubeadmin password
2727
KubeAdminPassword string
2828

29+
// User defined developer password
30+
DeveloperPassword string
31+
2932
// Preset
3033
Preset crcpreset.Preset
3134

0 commit comments

Comments
 (0)