Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VC-36032] Log the client-id when VenafiCloudKeypair authentication is used #625

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions pkg/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/jetstack/preflight/pkg/datagatherer/k8s"
"github.com/jetstack/preflight/pkg/datagatherer/local"
"github.com/jetstack/preflight/pkg/kubeconfig"
"github.com/jetstack/preflight/pkg/logs"
"github.com/jetstack/preflight/pkg/version"
)

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

{
var (
mode AuthMode
reason string
mode AuthMode
reason string
keysAndValues []any
)
switch {
case flags.VenafiCloudMode && flags.CredentialsPath != "":
mode = VenafiCloudKeypair
reason = fmt.Sprintf("Using the %s auth mode since --venafi-cloud and --credentials-path were specified.", mode)
reason = "--venafi-cloud and --credentials-path were specified"
keysAndValues = []any{"credentialsPath", flags.CredentialsPath}
case flags.ClientID != "" && flags.PrivateKeyPath != "":
mode = VenafiCloudKeypair
reason = fmt.Sprintf("Using the %s auth mode since --client-id and --private-key-path were specified.", mode)
reason = "--client-id and --private-key-path were specified"
keysAndValues = []any{"clientID", flags.ClientID, "privateKeyPath", flags.PrivateKeyPath}
case flags.ClientID != "":
return CombinedConfig{}, nil, fmt.Errorf("if --client-id is specified, --private-key-path must also be specified")
case flags.PrivateKeyPath != "":
return CombinedConfig{}, nil, fmt.Errorf("--private-key-path is specified, --client-id must also be specified")
case flags.VenConnName != "":
mode = VenafiCloudVenafiConnection
reason = fmt.Sprintf("Using the %s auth mode since --venafi-connection was specified.", mode)
reason = "--venafi-connection was specified"
keysAndValues = []any{"venConnName", flags.VenConnName}
case flags.APIToken != "":
mode = JetstackSecureAPIToken
reason = fmt.Sprintf("Using the %s auth mode since --api-token was specified.", mode)
reason = "--api-token was specified"
case !flags.VenafiCloudMode && flags.CredentialsPath != "":
mode = JetstackSecureOAuth
reason = fmt.Sprintf("Using the %s auth mode since --credentials-file was specified without --venafi-cloud.", mode)
reason = "--credentials-file was specified without --venafi-cloud"
default:
return CombinedConfig{}, nil, fmt.Errorf("no auth mode specified. You can use one of four auth modes:\n" +
" - Use (--venafi-cloud with --credentials-file) or (--client-id with --private-key-path) to use the " + string(VenafiCloudKeypair) + " mode.\n" +
Expand All @@ -401,7 +406,8 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
" - Use --api-token if you want to use the " + string(JetstackSecureAPIToken) + " mode.\n")
}
res.AuthMode = mode
log.Info(reason)
keysAndValues = append(keysAndValues, "mode", mode, "reason", reason)
log.V(logs.Debug).Info("Authentication mode", keysAndValues...)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to a Debug log, so it will not be shown by default. Why? Because I thought it might be desirable to keep the logs as quiet as possible by default, while allowing these details to be logged in the case of problems.

I'm also not sure if the client-id is sensitive information...is there any risk in logging it?

Copy link
Member

@maelvls maelvls Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client ID is just like a username I think. The difference being that it isn't a personal information (this GRPD course I had the other day made me start worrying about these things 😁). So I'd say that there is no problem displaying the client ID.

}

// Validation and defaulting of `server` and the deprecated `endpoint.path`.
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
withCmdLineFlags("--period", "99m", "--credentials-file", fakeCredsPath))
require.NoError(t, err)
assert.Equal(t, testutil.Undent(`
INFO Using the Jetstack Secure OAuth auth mode since --credentials-file was specified without --venafi-cloud.
INFO Authentication mode mode="Jetstack Secure OAuth" reason="--credentials-file was specified without --venafi-cloud"
INFO Both the 'period' field and --period are set. Using the value provided with --period.
`), gotLogs.String())
assert.Equal(t, 99*time.Minute, got.Period)
Expand Down Expand Up @@ -588,7 +588,7 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
)
require.NoError(t, err)
assert.Equal(t, testutil.Undent(`
INFO Using the Venafi Cloud VenafiConnection auth mode since --venafi-connection was specified.
INFO Authentication mode venConnName="venafi-components" mode="Venafi Cloud VenafiConnection" reason="--venafi-connection was specified"
INFO ignoring the server field specified in the config file. In Venafi Cloud VenafiConnection mode, this field is not needed.
INFO ignoring the venafi-cloud.upload_path field in the config file. In Venafi Cloud VenafiConnection mode, this field is not needed.
INFO ignoring the venafi-cloud.uploader_id field in the config file. This field is not needed in Venafi Cloud VenafiConnection mode.
Expand Down