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

apiserver identity : use SHA256 hash in lease names #113649

Merged

Conversation

andrewsykim
Copy link
Member

Signed-off-by: Andrew Sy Kim andrewsy@google.com

What type of PR is this?

/kind feature

What this PR does / why we need it:

Following up on #113307 (comment) and updating the apiserver identity lease to use a SHA256 hash in the lease name.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/feature Categorizes issue or PR as related to a new feature. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 5, 2022
@k8s-ci-robot k8s-ci-robot added area/apiserver area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 5, 2022
@dims
Copy link
Member

dims commented Nov 5, 2022

@andrewsykim looks like the verify is barfing on gofmt. can you please do that?

h.Write([]byte(hostname))
id = "kube-apiserver-" + fmt.Sprint(h.Sum32())
hash := sha256.Sum256([]byte(hostname))
id = "kube-apiserver-" + hex.EncodeToString(hash[:])
Copy link
Member

Choose a reason for hiding this comment

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

This will be 64 characters long, I'd suggest maybe hash[:16] to get it down to 32 characters. Or use encoding/base32 or 64 (but might need to remove forbidden characters). I thought we had a base58 encoding package in use but I can't seem to find it if so.

Copy link
Member

Choose a reason for hiding this comment

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

I still do not understand why we feel the need to truncate here. Are we expecting people to interact with these values somehow? That being said normally I use base32:

"kube-apiserver-" + strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:]))

which gives you something like kube-apiserver-ftze3os7wcrq4jxihmvmlopctynrmhs4d6tuexttaqzwfe4ltasa (67 characters total, 52 for the hash.

Copy link
Member

Choose a reason for hiding this comment

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

It's mostly just nicer to deal with shorter strings. Your solution works for me. You could call base32.NewEncoding() instead of using ToLower every time, that would make it more obvious that it's not obscuring the difference between upper and lowercase letters.

Copy link
Member Author

Choose a reason for hiding this comment

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

sgtm, will update shortly

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to use base32 encoding and only the first 16 bytes of the hash. I ended up leaving the strings.ToLower in there to avoid creating two copies of the encoder string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually inclined to stick with hex encoding with hash[:16]. It's only a few more characters but it's just more consistent with everything else that uses hex encoding in our codebase.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we use hex in object names?

Copy link
Member

Choose a reason for hiding this comment

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

base 16 is just extremely not dense.

Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
@lavalamp
Copy link
Member

lavalamp commented Nov 7, 2022

I might add a comment to the effect that the ToLower isn't a problem because there's no mixed case. But not urgent.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 7, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewsykim, lavalamp

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 7, 2022
@k8s-ci-robot k8s-ci-robot merged commit 3d5725d into kubernetes:master Nov 7, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Nov 7, 2022
@fedebongio
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Nov 8, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants