feat(agent): Add command-line option to specify password (#12812)
This commit is contained in:
parent
df19061166
commit
7981260f22
|
|
@ -8,9 +8,10 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/config"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func processFilterOnlySecretStoreFlags(ctx *cli.Context) Filters {
|
func processFilterOnlySecretStoreFlags(ctx *cli.Context) Filters {
|
||||||
|
|
@ -78,6 +79,7 @@ To also reveal the actual secret, i.e. the value, you can pass the
|
||||||
config: cCtx.StringSlice("config"),
|
config: cCtx.StringSlice("config"),
|
||||||
configDir: cCtx.StringSlice("config-directory"),
|
configDir: cCtx.StringSlice("config-directory"),
|
||||||
plugindDir: cCtx.String("plugin-directory"),
|
plugindDir: cCtx.String("plugin-directory"),
|
||||||
|
password: cCtx.String("password"),
|
||||||
debug: cCtx.Bool("debug"),
|
debug: cCtx.Bool("debug"),
|
||||||
}
|
}
|
||||||
w := WindowFlags{}
|
w := WindowFlags{}
|
||||||
|
|
@ -155,6 +157,7 @@ with the ID 'mystore'.
|
||||||
config: cCtx.StringSlice("config"),
|
config: cCtx.StringSlice("config"),
|
||||||
configDir: cCtx.StringSlice("config-directory"),
|
configDir: cCtx.StringSlice("config-directory"),
|
||||||
plugindDir: cCtx.String("plugin-directory"),
|
plugindDir: cCtx.String("plugin-directory"),
|
||||||
|
password: cCtx.String("password"),
|
||||||
debug: cCtx.Bool("debug"),
|
debug: cCtx.Bool("debug"),
|
||||||
}
|
}
|
||||||
w := WindowFlags{}
|
w := WindowFlags{}
|
||||||
|
|
@ -218,6 +221,7 @@ you will be prompted to enter the value of the secret.
|
||||||
config: cCtx.StringSlice("config"),
|
config: cCtx.StringSlice("config"),
|
||||||
configDir: cCtx.StringSlice("config-directory"),
|
configDir: cCtx.StringSlice("config-directory"),
|
||||||
plugindDir: cCtx.String("plugin-directory"),
|
plugindDir: cCtx.String("plugin-directory"),
|
||||||
|
password: cCtx.String("password"),
|
||||||
debug: cCtx.Bool("debug"),
|
debug: cCtx.Bool("debug"),
|
||||||
}
|
}
|
||||||
w := WindowFlags{}
|
w := WindowFlags{}
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,7 @@ func runApp(args []string, outputBuffer io.Writer, pprof Server, c TelegrafConfi
|
||||||
watchConfig: cCtx.String("watch-config"),
|
watchConfig: cCtx.String("watch-config"),
|
||||||
pidFile: cCtx.String("pidfile"),
|
pidFile: cCtx.String("pidfile"),
|
||||||
plugindDir: cCtx.String("plugin-directory"),
|
plugindDir: cCtx.String("plugin-directory"),
|
||||||
|
password: cCtx.String("password"),
|
||||||
test: cCtx.Bool("test"),
|
test: cCtx.Bool("test"),
|
||||||
debug: cCtx.Bool("debug"),
|
debug: cCtx.Bool("debug"),
|
||||||
once: cCtx.Bool("once"),
|
once: cCtx.Bool("once"),
|
||||||
|
|
@ -281,6 +282,10 @@ func runApp(args []string, outputBuffer io.Writer, pprof Server, c TelegrafConfi
|
||||||
Name: "pidfile",
|
Name: "pidfile",
|
||||||
Usage: "file to write our pid to",
|
Usage: "file to write our pid to",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "password",
|
||||||
|
Usage: "password to unlock secret-stores",
|
||||||
|
},
|
||||||
//
|
//
|
||||||
// Bool flags
|
// Bool flags
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ type GlobalFlags struct {
|
||||||
watchConfig string
|
watchConfig string
|
||||||
pidFile string
|
pidFile string
|
||||||
plugindDir string
|
plugindDir string
|
||||||
|
password string
|
||||||
test bool
|
test bool
|
||||||
debug bool
|
debug bool
|
||||||
once bool
|
once bool
|
||||||
|
|
@ -81,6 +82,11 @@ func (t *Telegraf) Init(pprofErr <-chan error, f Filters, g GlobalFlags, w Windo
|
||||||
t.secretstoreFilters = f.secretstore
|
t.secretstoreFilters = f.secretstore
|
||||||
t.GlobalFlags = g
|
t.GlobalFlags = g
|
||||||
t.WindowFlags = w
|
t.WindowFlags = w
|
||||||
|
|
||||||
|
// Set global password
|
||||||
|
if g.password != "" {
|
||||||
|
config.Password = config.NewSecret([]byte(g.password))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Telegraf) ListSecretStores() ([]string, error) {
|
func (t *Telegraf) ListSecretStores() ([]string, error) {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,9 @@ var (
|
||||||
// fetchURLRe is a regex to determine whether the requested file should
|
// fetchURLRe is a regex to determine whether the requested file should
|
||||||
// be fetched from a remote or read from the filesystem.
|
// be fetched from a remote or read from the filesystem.
|
||||||
fetchURLRe = regexp.MustCompile(`^\w+://`)
|
fetchURLRe = regexp.MustCompile(`^\w+://`)
|
||||||
|
|
||||||
|
// Password specified via command-line
|
||||||
|
Password Secret
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config specifies the URL/user/password for the database that telegraf
|
// Config specifies the URL/user/password for the database that telegraf
|
||||||
|
|
|
||||||
|
|
@ -40,15 +40,21 @@ func (j *Jose) Init() error {
|
||||||
return errors.New("path missing")
|
return errors.New("path missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
passwd, err := j.Password.Get()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("getting password failed: %w", err)
|
|
||||||
}
|
|
||||||
defer config.ReleaseSecret(passwd)
|
|
||||||
|
|
||||||
// Create the prompt-function in case we need it
|
// Create the prompt-function in case we need it
|
||||||
promptFunc := keyring.TerminalPrompt
|
promptFunc := keyring.TerminalPrompt
|
||||||
if len(passwd) != 0 {
|
if !j.Password.Empty() {
|
||||||
|
passwd, err := j.Password.Get()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("getting password failed: %w", err)
|
||||||
|
}
|
||||||
|
defer config.ReleaseSecret(passwd)
|
||||||
|
promptFunc = keyring.FixedStringPrompt(string(passwd))
|
||||||
|
} else if !config.Password.Empty() {
|
||||||
|
passwd, err := config.Password.Get()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("getting global password failed: %w", err)
|
||||||
|
}
|
||||||
|
defer config.ReleaseSecret(passwd)
|
||||||
promptFunc = keyring.FixedStringPrompt(string(passwd))
|
promptFunc = keyring.FixedStringPrompt(string(passwd))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue