Skip to content

chore: cleanup legacy secret to use pattern more similar to refs#5856

Merged
google-oss-prow[bot] merged 1 commit into
GoogleCloudPlatform:masterfrom
justinsb:secretkeyref_deprecated_cleanup
Dec 22, 2025
Merged

chore: cleanup legacy secret to use pattern more similar to refs#5856
google-oss-prow[bot] merged 1 commit into
GoogleCloudPlatform:masterfrom
justinsb:secretkeyref_deprecated_cleanup

Conversation

@justinsb

@justinsb justinsb commented Dec 19, 2025

Copy link
Copy Markdown
Collaborator
  • chore: cleanup legacy secret to use pattern more similar to refs

@justinsb justinsb force-pushed the secretkeyref_deprecated_cleanup branch from ba48c47 to 97433ee Compare December 22, 2025 17:17
@justinsb justinsb marked this pull request as ready for review December 22, 2025 18:30
@justinsb

Copy link
Copy Markdown
Collaborator Author

/assign @cheftako

func (r *Legacy) ReadSecretValue(ctx context.Context, fieldPath string, namespace string, reader client.Reader) (*string, error) {
value := r.Value
valueFrom := r.ValueFrom
if value != nil && valueFrom != nil {

@cheftako cheftako Dec 22, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not thread safe with NormalizeSecret (if we care)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

NormalizeSecret is not thread-safe because it mutates in-place. We normally do that on a mutable copy of the object that we have mapped from unstructured. I wish go had const :-)

if err != nil {
return nil, err
}
value := string(secretValue)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a reason we leaving the Legacy with valueFrom set and value not? Seems like this may cause us to repeatedly look up the secret value.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So the refs pattern would probably use NormalizeSecret and not have ReadSecretValue. Even NormalizeSecret normally operates on a copy, so we are going to look up the secret repeatedly (i.e. once per Reconcile).

WDYT about marking ReadSecretValue as deprecated? There's some risk that we write back to the object if we call NormalizeSecret, but if we were to do that accidentally we should catch it in our tests, and we don't do it on any other references so ....

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1. I think we should probably have some sort of checks in mocks and controllers which errors out if we ever attempt to update any KRM secret.value field. Also we should probably try to avoid ever adding a new secret.value field. "it is much more convenient for users to be able to specify the secret inline." Its nice for demos. I think however its enough of an anti-pattern that we should look to avoid it going forward.

@cheftako cheftako Dec 22, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

once per Reconcile

I'm fine with once per reconcile. That should mean once per 10 minutes (normally). I was more worried that over time that once becomes twice, thrice, etc


// Resolve sensitive field 'spec.initialUser.password' when it is set.
if err := direct.ResolveSensitiveField(ctx, obj.Spec.InitialUser.Password, "spec.initialUser.password", obj.Namespace, a.reader); err != nil {
if err := obj.Spec.InitialUser.Password.NormalizeSecret(ctx, "spec.initialUser.password", obj.Namespace, a.reader); err != nil {

@cheftako cheftako Dec 22, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I realize its to late to remove 'initialUser.password.value' but do we have any checks to prevent this mistake from being repeated on other resources? Also should we update the description to indicate that users should use 'initialUser.password.valueFrom' instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We can add a check in our API checks (go test -v ./tests/apichecks/...) and we can deprecate the whole type LegacyValueFromSecretKeyRef (and friends).

But it is much more convenient for users to be able to specify the secret inline. But maybe we should make the less secure things not super-easy :-)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

/* Reference to a value with the given key in the given Secret in the resource's namespace. */
// +optional
SecretKeyRef *deprecatedrefs.SecretKeyRef `json:"secretKeyRef,omitempty"`
SecretKeyRef *LegacyValueFromSecretKeyRef `json:"secretKeyRef,omitempty"`

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was the big thing, I wanted to stop using the generated client as that's just too circular.

@cheftako

Copy link
Copy Markdown
Collaborator

/lgtm
/approve

@google-oss-prow google-oss-prow Bot added the lgtm label Dec 22, 2025
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheftako

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow Bot merged commit dd8d8e2 into GoogleCloudPlatform:master Dec 22, 2025
112 checks passed
@cheftako cheftako added this to the 1.142 milestone Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants