Skip to content

Conversation

@oxtoacart
Copy link
Contributor

@oxtoacart oxtoacart commented Dec 6, 2025

The create-version operation Creates a specific version of a secret, sets its value and
immediately activates that version. It fails with HTTP status 412 (precondition failed) if this
version of the secret already has a value.

Updates tailscale/corp#34020

@oxtoacart oxtoacart requested a review from creachadair December 6, 2025 22:14
@oxtoacart oxtoacart force-pushed the percy/putifabsent branch 2 times, most recently from a133b51 to 8f07909 Compare December 6, 2025 22:38
@oxtoacart oxtoacart changed the title support set operation support create-version operation Dec 8, 2025
@oxtoacart oxtoacart requested a review from creachadair December 8, 2025 20:18
Copy link
Member

@creachadair creachadair left a comment

Choose a reason for hiding this comment

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

Mechanically this LGTM, though I would like to ask for a bit more text and test while we're here.

acl/acl.go Outdated
Comment on lines 30 to 32
// ActionCreateVersion ("create-version" in the API) denotes permission to
// create a specific version of a secret if and only if that version has no
// current value.
Copy link
Member

Choose a reason for hiding this comment

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

Optional simplification:

Suggested change
// ActionCreateVersion ("create-version" in the API) denotes permission to
// create a specific version of a secret if and only if that version has no
// current value.
// ActionCreateVersion ("create-version" in the API) denotes permission to
// create a specific version of a secret if and only if that version does
// not exist.

since we do not allow version values to change.

And this actually raises an interesting corner case I hadn't considered: Previously it was not possible to delete and replace a version (because any new version got a previously-unused version counter), but this allows that to happen.

I'm not sure if we care about that, but it makes me worry slightly: Does it matter if someone has a reliance interest on a value that may be now different, i.e., that the ID is no longer a reliable indicator of its content?

I wonder if we should consider making deleting a version leave a tombstone (remove the value, set a flag, perhaps), so that we cannot re-create the same version again later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if we should consider making deleting a version leave a tombstone

This is where my mind went after reading your previous sentence :)

Really great catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I implemented this. I considered using a sentinel value, but instead I track deletions in their own map. This way we don't have to try to discern between a sentinel value and a real value.

// UNIX timestamps. This simulates that.
year2099 := api.SecretVersion(time.Date(2099, 12, 31, 24, 60, 60, 0, time.UTC).Unix())

t.Run("create", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: The convention we used in the existing tests was MixedCase or MixedCase_withQualifier.

@oxtoacart oxtoacart force-pushed the percy/putifabsent branch 2 times, most recently from 60213be to 6d62412 Compare December 9, 2025 19:50
@oxtoacart oxtoacart requested a review from creachadair December 9, 2025 19:51
Copy link
Member

@creachadair creachadair left a comment

Choose a reason for hiding this comment

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

LGTM! I appreciate your patience talking through it all.

The `create-version` operation Creates a specific version of a secret, sets its value and
immediately activates that version. It fails with HTTP status 412 (precondition failed)
if this version of the secret was ever set, even if it has since been deleted..

Updates tailscale/corp#34020

Signed-off-by: Percy Wegmann <[email protected]>
@oxtoacart
Copy link
Contributor Author

LGTM! I appreciate your patience talking through it all.

Likewise!

@oxtoacart oxtoacart merged commit d603572 into main Dec 10, 2025
1 check passed
@oxtoacart oxtoacart deleted the percy/putifabsent branch December 10, 2025 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants