-
Notifications
You must be signed in to change notification settings - Fork 272
kms: Add unsupported config for vault kms plugin log level #2290
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
Open
kevinrizza
wants to merge
1
commit into
openshift:master
Choose a base branch
from
kevinrizza:unsupported-log-level-vault-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
pkg/operator/encryption/kms/pluginlifecycle/unsupported_config.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package pluginlifecycle | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "k8s.io/klog/v2" | ||
|
|
||
| kyaml "k8s.io/apimachinery/pkg/util/yaml" | ||
| ) | ||
|
|
||
| type unsupportedKMSConfig struct { | ||
| Encryption struct { | ||
| KMS struct { | ||
| Vault struct { | ||
| LogLevel string `json:"logLevel"` | ||
| } `json:"vault"` | ||
| } `json:"kms"` | ||
| } `json:"encryption"` | ||
| } | ||
|
|
||
| func parseUnsupportedKMSConfig(raw []byte) (unsupportedKMSConfig, error) { | ||
| if len(raw) == 0 { | ||
| return unsupportedKMSConfig{}, nil | ||
| } | ||
|
|
||
| jsonRaw, err := kyaml.ToJSON(raw) | ||
| if err != nil { | ||
| klog.Warning(err) | ||
| return unsupportedKMSConfig{}, err | ||
| } | ||
|
|
||
| config := unsupportedKMSConfig{} | ||
| if err := json.Unmarshal(jsonRaw, &config); err != nil { | ||
| return unsupportedKMSConfig{}, nil | ||
| } | ||
|
|
||
| return config, nil | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
pkg/operator/encryption/kms/pluginlifecycle/unsupported_config_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package pluginlifecycle | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestParseUnsupportedKMSConfig(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| raw []byte | ||
| expectedLogLevel string | ||
| expectError bool | ||
| }{ | ||
| { | ||
| name: "nil input returns empty config", | ||
| raw: nil, | ||
| expectedLogLevel: "", | ||
| }, | ||
| { | ||
| name: "empty input returns empty config", | ||
| raw: []byte{}, | ||
| expectedLogLevel: "", | ||
| }, | ||
| { | ||
| name: "JSON with log level", | ||
| raw: []byte(`{"encryption":{"kms":{"vault":{"logLevel":"debug-extended"}}}}`), | ||
| expectedLogLevel: "debug-extended", | ||
| }, | ||
| { | ||
| name: "YAML with log level", | ||
| raw: []byte("encryption:\n kms:\n vault:\n logLevel: trace\n"), | ||
| expectedLogLevel: "trace", | ||
| }, | ||
| { | ||
| name: "unrelated fields are ignored", | ||
| raw: []byte(`{"encryption":{"reason":"test"}}`), | ||
| expectedLogLevel: "", | ||
| }, | ||
| { | ||
| name: "malformed JSON is handled gracefully", | ||
| raw: []byte(`{not json`), | ||
| expectedLogLevel: "", | ||
| }, | ||
| { | ||
| name: "unparsable input returns error", | ||
| raw: []byte{0x00, 0x01, 0x02}, | ||
| expectError: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| config, err := parseUnsupportedKMSConfig(tt.raw) | ||
| if tt.expectError { | ||
| require.Error(t, err) | ||
| return | ||
| } | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.expectedLogLevel, config.Encryption.KMS.Vault.LogLevel) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log JSON unmarshaling errors before swallowing them.
Line 34 silently ignores JSON unmarshaling errors and returns an empty config with no error. While the test shows this lenient behavior is intentional, the error should be logged (like the YAML conversion error at line 28) so users know when their unsupported config is malformed and being ignored.
As per coding guidelines, Go code should never ignore error returns. Even when errors are intentionally not propagated, they should be logged for observability.
📋 Proposed fix to add logging
config := unsupportedKMSConfig{} if err := json.Unmarshal(jsonRaw, &config); err != nil { + klog.V(4).Infof("failed to unmarshal unsupported KMS config, ignoring: %v", err) return unsupportedKMSConfig{}, nil }🤖 Prompt for AI Agents
Source: Coding guidelines