diff --git a/cmd/crc/cmd/start.go b/cmd/crc/cmd/start.go index e33d1fba2b..c8e9779e20 100644 --- a/cmd/crc/cmd/start.go +++ b/cmd/crc/cmd/start.go @@ -75,6 +75,7 @@ func runStart(ctx context.Context) (*types.StartResult, error) { NameServer: config.Get(crcConfig.NameServer).AsString(), PullSecret: cluster.NewInteractivePullSecretLoader(config), KubeAdminPassword: config.Get(crcConfig.KubeAdminPassword).AsString(), + DeveloperPassword: config.Get(crcConfig.DeveloperPassword).AsString(), Preset: crcConfig.GetPreset(config), IngressHTTPPort: config.Get(crcConfig.IngressHTTPPort).AsUInt(), IngressHTTPSPort: config.Get(crcConfig.IngressHTTPSPort).AsUInt(), diff --git a/pkg/crc/api/handlers.go b/pkg/crc/api/handlers.go index 82221f6620..870abf0621 100644 --- a/pkg/crc/api/handlers.go +++ b/pkg/crc/api/handlers.go @@ -127,6 +127,7 @@ func getStartConfig(cfg crcConfig.Storage, args client.StartConfig) types.StartC NameServer: cfg.Get(crcConfig.NameServer).AsString(), PullSecret: cluster.NewNonInteractivePullSecretLoader(cfg, args.PullSecretFile), KubeAdminPassword: cfg.Get(crcConfig.KubeAdminPassword).AsString(), + DeveloperPassword: cfg.Get(crcConfig.DeveloperPassword).AsString(), IngressHTTPPort: cfg.Get(crcConfig.IngressHTTPPort).AsUInt(), IngressHTTPSPort: cfg.Get(crcConfig.IngressHTTPSPort).AsUInt(), Preset: crcConfig.GetPreset(cfg), diff --git a/pkg/crc/cluster/kubeadmin_password.go b/pkg/crc/cluster/kubeadmin_password.go index c5d413d298..301810329e 100644 --- a/pkg/crc/cluster/kubeadmin_password.go +++ b/pkg/crc/cluster/kubeadmin_password.go @@ -27,11 +27,17 @@ func GenerateUserPassword(passwordFile string, user string) error { return os.WriteFile(passwordFile, []byte(kubeAdminPassword), 0600) } -// UpdateKubeAdminUserPassword updates the htpasswd secret -func UpdateKubeAdminUserPassword(ctx context.Context, ocConfig oc.Config, newPassword string) error { - if newPassword != "" { +// UpdateUserPassword updates the htpasswd secret +func UpdateUserPassword(ctx context.Context, ocConfig oc.Config, newKubeAdminPassword string, newDeveloperPassword string) error { + if newKubeAdminPassword != "" { logging.Infof("Overriding password for kubeadmin user") - if err := os.WriteFile(constants.GetKubeAdminPasswordPath(), []byte(strings.TrimSpace(newPassword)), 0600); err != nil { + if err := os.WriteFile(constants.GetKubeAdminPasswordPath(), []byte(strings.TrimSpace(newKubeAdminPassword)), 0600); err != nil { + return err + } + } + if newDeveloperPassword != "" { + logging.Infof("Overriding password for developer user") + if err := os.WriteFile(constants.GetDeveloperPasswordPath(), []byte(strings.TrimSpace(newDeveloperPassword)), 0600); err != nil { return err } } @@ -65,7 +71,7 @@ func UpdateKubeAdminUserPassword(ctx context.Context, ocConfig oc.Config, newPas return nil } - logging.Infof("Changing the password for the kubeadmin user") + logging.Infof("Changing the password for the users") expected, err := getHtpasswd(credentials, externals) if err != nil { return err @@ -75,7 +81,7 @@ func UpdateKubeAdminUserPassword(ctx context.Context, ocConfig oc.Config, newPas "-n", "openshift-config", "--type", "merge"} _, stderr, err = ocConfig.RunOcCommandPrivate(cmdArgs...) if err != nil { - return fmt.Errorf("Failed to update kubeadmin password %v: %s", err, stderr) + return fmt.Errorf("failed to update user passwords %v: %s", err, stderr) } return nil } diff --git a/pkg/crc/config/settings.go b/pkg/crc/config/settings.go index d4236d6a5c..e3044f6c30 100644 --- a/pkg/crc/config/settings.go +++ b/pkg/crc/config/settings.go @@ -29,6 +29,7 @@ const ( ConsentTelemetry = "consent-telemetry" EnableClusterMonitoring = "enable-cluster-monitoring" KubeAdminPassword = "kubeadmin-password" + DeveloperPassword = "developer-password" Preset = "preset" EnableSharedDirs = "enable-shared-dirs" SharedDirPassword = "shared-dir-password" // #nosec G101 @@ -134,6 +135,8 @@ func RegisterSettings(cfg *Config) { cfg.AddSetting(KubeAdminPassword, "", validateString, SuccessfullyApplied, "User defined kubeadmin password") + cfg.AddSetting(DeveloperPassword, "", validateString, SuccessfullyApplied, + "User defined developer password") cfg.AddSetting(IngressHTTPPort, constants.OpenShiftIngressHTTPPort, validatePort, RequiresHTTPPortChangeWarning, fmt.Sprintf("HTTP port to use for OpenShift ingress/routes on the host (1024-65535, default: %d)", constants.OpenShiftIngressHTTPPort)) cfg.AddSetting(IngressHTTPSPort, constants.OpenShiftIngressHTTPSPort, validatePort, RequiresHTTPSPortChangeWarning, diff --git a/pkg/crc/machine/start.go b/pkg/crc/machine/start.go index b87e13b6ca..97cf482417 100644 --- a/pkg/crc/machine/start.go +++ b/pkg/crc/machine/start.go @@ -575,7 +575,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig) return nil, errors.Wrap(err, "Failed to update pull secret on the disk") } - if err := cluster.UpdateKubeAdminUserPassword(ctx, ocConfig, startConfig.KubeAdminPassword); err != nil { + if err := cluster.UpdateUserPassword(ctx, ocConfig, startConfig.KubeAdminPassword, startConfig.DeveloperPassword); err != nil { return nil, errors.Wrap(err, "Failed to update kubeadmin user password") } diff --git a/pkg/crc/machine/types/types.go b/pkg/crc/machine/types/types.go index ef810a7218..1e8c1e48ea 100644 --- a/pkg/crc/machine/types/types.go +++ b/pkg/crc/machine/types/types.go @@ -26,6 +26,9 @@ type StartConfig struct { // User defined kubeadmin password KubeAdminPassword string + // User defined developer password + DeveloperPassword string + // Preset Preset crcpreset.Preset