diff --git a/etcdctl/ctlv3/command/global.go b/etcdctl/ctlv3/command/global.go index 93b62068af68..05268b0d75b5 100644 --- a/etcdctl/ctlv3/command/global.go +++ b/etcdctl/ctlv3/command/global.go @@ -56,6 +56,7 @@ type GlobalFlags struct { User string Password string + Token string Debug bool } @@ -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 { diff --git a/etcdctl/ctlv3/ctl.go b/etcdctl/ctlv3/ctl.go index 4f9c31055c0e..fcb3b538538e 100644 --- a/etcdctl/ctlv3/ctl.go +++ b/etcdctl/ctlv3/ctl.go @@ -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")