Skip to content

Commit

Permalink
etcdclt: support passing JWT auth token
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Crute <[email protected]>
  • Loading branch information
mcrute committed Nov 23, 2023
1 parent 828b555 commit d398cf0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion etcdctl/ctlv3/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type GlobalFlags struct {

User string
Password string
Token string

Debug bool
}
Expand Down Expand Up @@ -270,13 +271,22 @@ func authCfgFromCmd(cmd *cobra.Command) *clientv3.AuthConfig {
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
}
tokenFlag, err := cmd.Flags().GetString("auth-token")
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
}

if userFlag == "" {
if userFlag == "" && tokenFlag == "" {
return nil
}

var cfg clientv3.AuthConfig

if tokenFlag != "" {
cfg.Token = tokenFlag
return &cfg
}

if passwordFlag == "" {
splitted := strings.SplitN(userFlag, ":", 2)
if len(splitted) < 2 {
Expand Down
1 change: 1 addition & 0 deletions etcdctl/ctlv3/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.KeyFile, "key", "", "identify secure client using this TLS key file")
rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.TrustedCAFile, "cacert", "", "verify certificates of TLS-enabled secure servers using this CA bundle")
rootCmd.PersistentFlags().StringVar(&globalFlags.User, "user", "", "username[:password] for authentication (prompt if password is not supplied)")
rootCmd.PersistentFlags().StringVar(&globalFlags.Token, "auth-token", "", "JWT token used for authentication (if this option is used, --user and --password should not be set)")
rootCmd.PersistentFlags().StringVar(&globalFlags.Password, "password", "", "password for authentication (if this option is used, --user option shouldn't include password)")
rootCmd.PersistentFlags().StringVarP(&globalFlags.TLS.ServerName, "discovery-srv", "d", "", "domain name to query for SRV records describing cluster endpoints")
rootCmd.PersistentFlags().StringVarP(&globalFlags.DNSClusterServiceName, "discovery-srv-name", "", "", "service name to query when using DNS discovery")
Expand Down

0 comments on commit d398cf0

Please sign in to comment.