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

Consistently use constant-time comparison of password hashes instead of bare password strings #7455

Merged
merged 1 commit into from
May 9, 2023

Conversation

brandond
Copy link
Member

@brandond brandond commented May 8, 2023

Proposed Changes

Consistently use constant-time comparison of password hashes

As per golang/go#47001 even subtle.ConstantTimeCompare should never be used with variable-length inputs, as it will return 0 if the lengths do not match. Switch to consistently using constant-time comparisons of hashes for password checks to avoid any possible side-channel leaks that could be combined with other vectors to discover password lengths.

The passwordfile misuse of subtle.ConstantTimeCompare comes from upstream Kubernetes:
https://github.com/kubernetes/kubernetes/blob/release-1.18/staging/src/k8s.io/apiserver/plugin/pkg/authenticator/password/passwordfile/passwordfile.go

Types of Changes

bugfix

Verification

Normal CI and release testing (no visible user impact)

Testing

Linked Issues

User-Facing Change


Further Comments

@brandond brandond requested a review from a team as a code owner May 8, 2023 22:16
As per golang/go#47001 even subtle.ConstantTimeCompare should never be used with variable-length inputs, as it will return 0 if the lengths do not match. Switch to consistently using constant-time comparisons of hashes for password checks to avoid any possible side-channel leaks that could be combined with other vectors to discover password lengths.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
@@ -60,14 +60,6 @@ func Read(file string) (*Passwd, error) {
return result, nil
}

func (p *Passwd) Check(name, pass string) (matches bool, exists bool) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: this function was not used anywhere in the codebase.

@codecov
Copy link

codecov bot commented May 8, 2023

Codecov Report

Patch coverage: 50.00% and project coverage change: +28.04 🎉

Comparison is base (b32bf49) 19.48% compared to head (840ddeb) 47.53%.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #7455       +/-   ##
===========================================
+ Coverage   19.48%   47.53%   +28.04%     
===========================================
  Files          81      139       +58     
  Lines        5497    14254     +8757     
===========================================
+ Hits         1071     6775     +5704     
- Misses       4204     6403     +2199     
- Partials      222     1076      +854     
Flag Coverage Δ
inttests 44.88% <35.71%> (?)
unittests 19.88% <66.66%> (+0.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/passwd/passwd.go 68.86% <ø> (+11.17%) ⬆️
pkg/server/router.go 48.71% <20.00%> (ø)
pkg/authenticator/passwordfile/passwordfile.go 74.46% <57.14%> (-6.18%) ⬇️
pkg/nodepassword/nodepassword.go 77.14% <100.00%> (+4.06%) ⬆️

... and 135 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

4 participants