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

feat: add secretManager version alias #3282

Merged

Conversation

yuwenma
Copy link
Collaborator

@yuwenma yuwenma commented Dec 3, 2024

Change description

Fixes #

Tests you have done

  • Run make ready-pr to ensure this PR is ready for review.
  • Perform necessary E2E testing for changed resources.

@yuwenma yuwenma changed the title chore: improve secretmanager on edge case handling feat: add secretManager version alias Dec 3, 2024
@yuwenma yuwenma force-pushed the sm-version-alias branch 2 times, most recently from bec47e4 to e21f5bc Compare December 3, 2024 07:29
pkg/controller/direct/secretmanager/secret_controller.go Outdated Show resolved Hide resolved
return nil
}
out := &krm.SecretManagerSecretObservedState{}
out.VersionAliases = MapStringInt64_ToMapStringString(mapCtx, in.VersionAliases)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: might be worth adding this to the autogenerator. Though there is something to be said for "flagging" this by refusing to generate it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking of the same thing. But this use here is not typical enough and IMO more like a unclear SecretManager API decision. I'd prefer adding it later if we encounter another case.

pkg/controller/direct/secretmanager/secret_mapping.go Outdated Show resolved Hide resolved
@@ -96,8 +103,7 @@ func SecretManagerSecretSpec_ToProto(mapCtx *direct.MapContext, in *krm.SecretMa
}
// MISSING: Etag
out.Rotation = Rotation_ToProto(mapCtx, in.Rotation)
// MISSING: VersionAliases
// out.VersionAliases = in.VersionAliases
out.VersionAliases = MapStringString_ToMapStringInt64(mapCtx, in.VersionAliases)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh ... we should test with really big values (bigger than max json values)

We have had bugs in the past where int64 values went through json numbers and were rounder. IIRC it is numbers bigger than 10^53. It doesn't always happen, but some methods do "reparse" the values and truncate them.

This is status, and it doesn't really matter, except that we might have to make the KRM type map[string]string (which would be a shame, because map[string]int64 can work)

Copy link
Collaborator Author

@yuwenma yuwenma Dec 5, 2024

Choose a reason for hiding this comment

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

Very interesting case! I can do a follow up PR to improve this. This is less likely to happen for SecretManager because the int64 is used as a version count starting from 1.

@@ -79,6 +79,43 @@ X-Xss-Protection: 0

---

GET https://secretmanager.googleapis.com/v1/projects/${projectId}/secrets/secretmanagersecret-${uniqueId}?alt=json
Copy link
Collaborator

Choose a reason for hiding this comment

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

The extra get is because we're now exporting? If so 👍

observedState: {}
observedState:
versionAliases:
string: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well now I'm confused!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

status.versionAliases is a new field I added in this PR. otherwise, it is very unclear whether the versionAliases succeeds or not.
The spec.versionAliases are already there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I was confused by github's presentation of the diff. map[string]string makes sense. It would be nice if it was map[string]int64 in KRM and proto, but it may encounter some bugs with big values.

return ""
switch gvk.Kind {
case "SecretManagerSecretVersion":
// Skip run export.Execute because the SecretVersion servicemappings has a broken marker
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we only export if using direct? Or just move to direct export everywhere?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess in practice it's not very useful to export the SecretManagerSecretVersion, and potentially risky (exposing secret material)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree. And agree. I hit an error around the scenario, and explored on what happened in the code. Lots of improvements are needed for Export.

@@ -203,7 +204,14 @@ func (a *Adapter) Create(ctx context.Context, op *directbase.CreateOperation) er
external := a.id.String()
status.ExternalRef = &external
status.Name = created.Name
return op.UpdateStatus(ctx, status, nil)
if err = op.UpdateStatus(ctx, status, nil); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if err = op.UpdateStatus(ctx, status, nil); err != nil {
if err := op.UpdateStatus(ctx, status, nil); err != nil {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let me fix that in follow up PRs. have some other comments and nits want to resolve as well.

observedState: {}
observedState:
versionAliases:
string: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I was confused by github's presentation of the diff. map[string]string makes sense. It would be nice if it was map[string]int64 in KRM and proto, but it may encounter some bugs with big values.

@justinsb
Copy link
Collaborator

justinsb commented Dec 5, 2024

LGTM, will hold so you can decide when you want to merge

/approve
/lgtm
/hold

Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb

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

The pull request process is described here

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

@yuwenma
Copy link
Collaborator Author

yuwenma commented Dec 5, 2024

/hold cancel

@google-oss-prow google-oss-prow bot merged commit 2c92427 into GoogleCloudPlatform:master Dec 5, 2024
18 checks passed
@yuwenma yuwenma added this to the 1.126 milestone Dec 11, 2024
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