Skip to content

Commit 97058e0

Browse files
committed
Log the client-id when VenafiCloudKeypair authentication is used
To help debugging authentication problems Signed-off-by: Richard Wall <[email protected]>
1 parent f644b84 commit 97058e0

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

@@ -370,29 +371,33 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
370371

371372
{
372373
var (
373-
mode AuthMode
374-
reason string
374+
mode AuthMode
375+
reason string
376+
keysAndValues []any
375377
)
376378
switch {
377379
case flags.VenafiCloudMode && flags.CredentialsPath != "":
378380
mode = VenafiCloudKeypair
379-
reason = fmt.Sprintf("Using the %s auth mode since --venafi-cloud and --credentials-path were specified.", mode)
381+
reason = "--venafi-cloud and --credentials-path were specified"
382+
keysAndValues = []any{"credentialsPath", flags.CredentialsPath}
380383
case flags.ClientID != "" && flags.PrivateKeyPath != "":
381384
mode = VenafiCloudKeypair
382-
reason = fmt.Sprintf("Using the %s auth mode since --client-id and --private-key-path were specified.", mode)
385+
reason = "--client-id and --private-key-path were specified"
386+
keysAndValues = []any{"clientID", flags.ClientID, "privateKeyPath", flags.PrivateKeyPath}
383387
case flags.ClientID != "":
384388
return CombinedConfig{}, nil, fmt.Errorf("if --client-id is specified, --private-key-path must also be specified")
385389
case flags.PrivateKeyPath != "":
386390
return CombinedConfig{}, nil, fmt.Errorf("--private-key-path is specified, --client-id must also be specified")
387391
case flags.VenConnName != "":
388392
mode = VenafiCloudVenafiConnection
389-
reason = fmt.Sprintf("Using the %s auth mode since --venafi-connection was specified.", mode)
393+
reason = "--venafi-connection was specified"
394+
keysAndValues = []any{"venConnName", flags.VenConnName}
390395
case flags.APIToken != "":
391396
mode = JetstackSecureAPIToken
392-
reason = fmt.Sprintf("Using the %s auth mode since --api-token was specified.", mode)
397+
reason = "--api-token was specified"
393398
case !flags.VenafiCloudMode && flags.CredentialsPath != "":
394399
mode = JetstackSecureOAuth
395-
reason = fmt.Sprintf("Using the %s auth mode since --credentials-file was specified without --venafi-cloud.", mode)
400+
reason = "--credentials-file was specified without --venafi-cloud"
396401
default:
397402
return CombinedConfig{}, nil, fmt.Errorf("no auth mode specified. You can use one of four auth modes:\n" +
398403
" - Use (--venafi-cloud with --credentials-file) or (--client-id with --private-key-path) to use the " + string(VenafiCloudKeypair) + " mode.\n" +
@@ -401,7 +406,8 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
401406
" - Use --api-token if you want to use the " + string(JetstackSecureAPIToken) + " mode.\n")
402407
}
403408
res.AuthMode = mode
404-
log.Info(reason)
409+
keysAndValues = append(keysAndValues, "mode", mode, "reason", reason)
410+
log.V(logs.Debug).Info("Authentication mode", keysAndValues...)
405411
}
406412

407413
// 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
@@ -98,7 +98,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
9898
withCmdLineFlags("--period", "99m", "--credentials-file", fakeCredsPath))
9999
require.NoError(t, err)
100100
assert.Equal(t, testutil.Undent(`
101-
INFO Using the Jetstack Secure OAuth auth mode since --credentials-file was specified without --venafi-cloud.
101+
INFO Authentication mode mode="Jetstack Secure OAuth" reason="--credentials-file was specified without --venafi-cloud"
102102
INFO Both the 'period' field and --period are set. Using the value provided with --period.
103103
`), gotLogs.String())
104104
assert.Equal(t, 99*time.Minute, got.Period)
@@ -588,7 +588,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
588588
)
589589
require.NoError(t, err)
590590
assert.Equal(t, testutil.Undent(`
591-
INFO Using the Venafi Cloud VenafiConnection auth mode since --venafi-connection was specified.
591+
INFO Authentication mode venConnName="venafi-components" mode="Venafi Cloud VenafiConnection" reason="--venafi-connection was specified"
592592
INFO ignoring the server field specified in the config file. In Venafi Cloud VenafiConnection mode, this field is not needed.
593593
INFO ignoring the venafi-cloud.upload_path field in the config file. In Venafi Cloud VenafiConnection mode, this field is not needed.
594594
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)