Repository navigation
Enable user and password update #149
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // SPDX-FileCopyrightText: 2026 The bink Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package registry | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| registrypkg "github.com/bootc-dev/bink/internal/registry" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func newUpdatePasswordCmd() *cobra.Command { | ||
| var registryUser string | ||
| var registryPassword string | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "update-password", | ||
| Short: "Update the authenticated registry password", | ||
| Long: "Update the credentials for the running authenticated registry without restarting it", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := registrypkg.ValidateAuthCredentials(registryUser, registryPassword); err != nil { | ||
| return fmt.Errorf("invalid credentials: %w", err) | ||
| } | ||
|
|
||
| mgr, err := registrypkg.NewManager() | ||
| if err != nil { | ||
| return fmt.Errorf("creating registry manager: %w", err) | ||
| } | ||
|
|
||
| if err := mgr.UpdateAuthRegistryPassword(cmd.Context(), registryUser, registryPassword); err != nil { | ||
| return fmt.Errorf("updating auth registry password: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(®istryUser, "registry-user", "", "Username for the authenticated registry") | ||
| cmd.Flags().StringVar(®istryPassword, "registry-password", "", "Password for the authenticated registry") | ||
| _ = cmd.MarkFlagRequired("registry-user") | ||
| _ = cmd.MarkFlagRequired("registry-password") | ||
|
|
||
| return cmd | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // SPDX-FileCopyrightText: 2026 The bink Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package registry | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| func TestUpdatePasswordRequiresCredentials(t *testing.T) { | ||
| g := NewWithT(t) | ||
| cmd := newUpdatePasswordCmd() | ||
| cmd.SilenceErrors = true | ||
| cmd.SilenceUsage = true | ||
|
|
||
| g.Expect(cmd.Execute()).To(MatchError(ContainSubstring("required flag"))) | ||
| } | ||
|
|
||
| func TestUpdatePasswordFlagsDefaultToEmpty(t *testing.T) { | ||
| g := NewWithT(t) | ||
| cmd := newUpdatePasswordCmd() | ||
|
|
||
| username, err := cmd.Flags().GetString("registry-user") | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
| password, err := cmd.Flags().GetString("registry-password") | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
| g.Expect(username).To(BeEmpty()) | ||
| g.Expect(password).To(BeEmpty()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,7 +202,7 @@ func (m *Manager) RegistryInfo(ctx context.Context) (*RegistryStatus, error) { | |
|
|
||
| // EnsureAuthRegistry starts (or creates) the authenticated registry. Credentials are not | ||
| // stored anywhere inspectable, so they cannot be compared against an already-running | ||
| // container: to change them, stop the registry and start it again. | ||
| // container: to change them, use UpdateAuthRegistryPassword. | ||
| func (m *Manager) EnsureAuthRegistry(ctx context.Context, username, password string) error { | ||
| logrus.Info("Ensuring authenticated registry is running") | ||
| if err := ValidateAuthCredentials(username, password); err != nil { | ||
|
|
@@ -290,6 +290,44 @@ func (m *Manager) createAuthContainer(ctx context.Context, username, password st | |
| return nil | ||
| } | ||
|
|
||
| func (m *Manager) UpdateAuthRegistryPassword(ctx context.Context, username, password string) error { | ||
| if err := ValidateAuthCredentials(username, password); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| exists, err := m.podman.ContainerExists(ctx, config.AuthRegistryContainerName) | ||
| if err != nil { | ||
| return fmt.Errorf("checking auth registry container: %w", err) | ||
| } | ||
| if !exists { | ||
| return fmt.Errorf("auth registry container %q does not exist", config.AuthRegistryContainerName) | ||
| } | ||
|
|
||
| status, err := m.podman.ContainerStatus(ctx, config.AuthRegistryContainerName) | ||
| if err != nil { | ||
| return fmt.Errorf("checking auth registry status: %w", err) | ||
| } | ||
| if status != define.ContainerStateRunning.String() { | ||
| return fmt.Errorf("auth registry is not running (status: %s)", status) | ||
| } | ||
|
|
||
| htpasswdEntry, err := generateHtpasswd(username, password) | ||
| if err != nil { | ||
| return fmt.Errorf("generating htpasswd: %w", err) | ||
| } | ||
|
|
||
| escaped := strings.ReplaceAll(htpasswdEntry, "'", "'\\''") | ||
| _, err = m.podman.ContainerExec(ctx, config.AuthRegistryContainerName, []string{ | ||
| "/bin/sh", "-c", fmt.Sprintf("printf '%%s\\n' '%s' > /auth/htpasswd", escaped), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can use backticks in Sprintf which should also help with escaping quotes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when restart the container entrypoint re-executes this leading to file being overwritten with initial credentials |
||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("updating htpasswd in auth registry: %w", err) | ||
| } | ||
|
|
||
| logrus.Infof("Auth registry password updated for user %q", username) | ||
| return nil | ||
| } | ||
|
|
||
| func (m *Manager) StopAuthRegistry(ctx context.Context) error { | ||
| exists, err := m.podman.ContainerExists(ctx, config.AuthRegistryContainerName) | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will show the password in the terminal right? We should probably use a hidden field for passwords