Skip to content

Commit 8e6110a

Browse files
authored
Log the client-id when VenafiCloudKeypair authentication is used (#625)
To help debugging authentication problems Signed-off-by: Richard Wall <[email protected]>
1 parent 3e62412 commit 8e6110a

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pkg/agent/config.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/jetstack/preflight/pkg/datagatherer/k8s"
2222
"github.com/jetstack/preflight/pkg/datagatherer/local"
2323
"github.com/jetstack/preflight/pkg/kubeconfig"
24+
"github.com/jetstack/preflight/pkg/logs"
2425
"github.com/jetstack/preflight/pkg/version"
2526
)
2627

@@ -367,29 +368,33 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
367368

368369
{
369370
var (
370-
mode AuthMode
371-
reason string
371+
mode AuthMode
372+
reason string
373+
keysAndValues []any
372374
)
373375
switch {
374376
case flags.VenafiCloudMode && flags.CredentialsPath != "":
375377
mode = VenafiCloudKeypair
376-
reason = fmt.Sprintf("Using the %s auth mode since --venafi-cloud and --credentials-path were specified.", mode)
378+
reason = "--venafi-cloud and --credentials-path were specified"
379+
keysAndValues = []any{"credentialsPath", flags.CredentialsPath}
377380
case flags.ClientID != "" && flags.PrivateKeyPath != "":
378381
mode = VenafiCloudKeypair
379-
reason = fmt.Sprintf("Using the %s auth mode since --client-id and --private-key-path were specified.", mode)
382+
reason = "--client-id and --private-key-path were specified"
383+
keysAndValues = []any{"clientID", flags.ClientID, "privateKeyPath", flags.PrivateKeyPath}
380384
case flags.ClientID != "":
381385
return CombinedConfig{}, nil, fmt.Errorf("if --client-id is specified, --private-key-path must also be specified")
382386
case flags.PrivateKeyPath != "":
383387
return CombinedConfig{}, nil, fmt.Errorf("--private-key-path is specified, --client-id must also be specified")
384388
case flags.VenConnName != "":
385389
mode = VenafiCloudVenafiConnection
386-
reason = fmt.Sprintf("Using the %s auth mode since --venafi-connection was specified.", mode)
390+
reason = "--venafi-connection was specified"
391+
keysAndValues = []any{"venConnName", flags.VenConnName}
387392
case flags.APIToken != "":
388393
mode = JetstackSecureAPIToken
389-
reason = fmt.Sprintf("Using the %s auth mode since --api-token was specified.", mode)
394+
reason = "--api-token was specified"
390395
case !flags.VenafiCloudMode && flags.CredentialsPath != "":
391396
mode = JetstackSecureOAuth
392-
reason = fmt.Sprintf("Using the %s auth mode since --credentials-file was specified without --venafi-cloud.", mode)
397+
reason = "--credentials-file was specified without --venafi-cloud"
393398
default:
394399
return CombinedConfig{}, nil, fmt.Errorf("no auth mode specified. You can use one of four auth modes:\n" +
395400
" - Use (--venafi-cloud with --credentials-file) or (--client-id with --private-key-path) to use the " + string(VenafiCloudKeypair) + " mode.\n" +
@@ -398,7 +403,8 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
398403
" - Use --api-token if you want to use the " + string(JetstackSecureAPIToken) + " mode.\n")
399404
}
400405
res.AuthMode = mode
401-
log.Info(reason)
406+
keysAndValues = append(keysAndValues, "mode", mode, "reason", reason)
407+
log.V(logs.Debug).Info("Authentication mode", keysAndValues...)
402408
}
403409

404410
// Validation and defaulting of `server` and the deprecated `endpoint.path`.

pkg/agent/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
9595
withCmdLineFlags("--period", "99m", "--credentials-file", fakeCredsPath))
9696
require.NoError(t, err)
9797
assert.Equal(t, testutil.Undent(`
98-
INFO Using the Jetstack Secure OAuth auth mode since --credentials-file was specified without --venafi-cloud.
98+
INFO Authentication mode mode="Jetstack Secure OAuth" reason="--credentials-file was specified without --venafi-cloud"
9999
INFO Both the 'period' field and --period are set. Using the value provided with --period.
100100
`), gotLogs.String())
101101
assert.Equal(t, 99*time.Minute, got.Period)
@@ -592,7 +592,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
592592
)
593593
require.NoError(t, err)
594594
assert.Equal(t, testutil.Undent(`
595-
INFO Using the Venafi Cloud VenafiConnection auth mode since --venafi-connection was specified.
595+
INFO Authentication mode venConnName="venafi-components" mode="Venafi Cloud VenafiConnection" reason="--venafi-connection was specified"
596596
INFO ignoring the server field specified in the config file. In Venafi Cloud VenafiConnection mode, this field is not needed.
597597
INFO ignoring the venafi-cloud.upload_path field in the config file. In Venafi Cloud VenafiConnection mode, this field is not needed.
598598
INFO ignoring the venafi-cloud.uploader_id field in the config file. This field is not needed in Venafi Cloud VenafiConnection mode.

0 commit comments

Comments
 (0)