From f78dfae6950c9e44e14ec234a77f35d8086b1fd5 Mon Sep 17 00:00:00 2001 From: Alistair Hey Date: Wed, 25 Dec 2019 20:46:30 +0000 Subject: [PATCH] Add a password STDIN option to registry login I had not added the --password-stdin option to registry-login command, it has now been added so users dont leave stuff in history Signed-off-by: Alistair Hey --- README.md | 8 ++++++-- cmd/registry_login.go | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1a34721..f9ddd3b 100644 --- a/README.md +++ b/README.md @@ -214,11 +214,15 @@ After the installation has completed in a later step, you will need to create DN ofc-bootstrap has a command to generate the registry auth file in the correct format. -If you are using Dockerhub you only need to supply your `--username` and `--password`. +If you are using Dockerhub you only need to supply your `--username` and `--password-stdin` (or `--password`, but this leaves the password in history). ```sh -ofc-bootstrap registry-login --username --password + +ofc-bootstrap registry-login --username --password-stdin +(the enter your password and hit return) ``` +You could also have you password in a file, or environment variable and echo/cat this instead of entering interactively + If you are using a different registry (that is not ECR) then also provide a `--server` as well. diff --git a/cmd/registry_login.go b/cmd/registry_login.go index 85ddab5..e289755 100644 --- a/cmd/registry_login.go +++ b/cmd/registry_login.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" ) func init() { @@ -16,8 +17,9 @@ func init() { registryLoginCommand.Flags().String("server", "https://index.docker.io/v1/", "The server URL, it is defaulted to the docker registry") registryLoginCommand.Flags().String("username", "", "The Registry Username") registryLoginCommand.Flags().String("password", "", "The registry password") + registryLoginCommand.Flags().BoolP("password-stdin", "s", false, "Reads the gateway password from stdin") - registryLoginCommand.Flags().Bool("ecr", false, "If we are using ECR we need a different set of flags, so if this is set, we need to set --username and --password-stdin") + registryLoginCommand.Flags().Bool("ecr", false, "If we are using ECR we need a different set of flags, so if this is set, we need to set --username and --password") registryLoginCommand.Flags().String("account-id", "", "Your AWS Account id") registryLoginCommand.Flags().String("region", "", "Your AWS region") } @@ -36,11 +38,20 @@ func generateRegistryAuthFile(command *cobra.Command, _ []string) error { username, _ := command.Flags().GetString("username") password, _ := command.Flags().GetString("password") server, _ := command.Flags().GetString("server") + passStdIn, _ := command.Flags().GetBool("password-stdin") if ecrEnabled { return generateECRFile(accountID, region) } else { - return generateFile(username, password, server) + if passStdIn { + passwordStdin, err := ioutil.ReadAll(os.Stdin) + if err != nil { + return err + } + return generateFile(username, strings.TrimSpace(string(passwordStdin)), server) + } else { + return generateFile(username, password, server) + } } }