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 changing user password route for htpasswd #2183

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

onidoru
Copy link
Contributor

@onidoru onidoru commented Jan 25, 2024

What type of PR is this?
feature

Which issue does this PR fix:
It adds a feature of changing user password for htpasswd-file authentication.

What does this PR do / Why do we need it:

Issue: #702

Testing done on this change:
Unit testing.

Will this break upgrades or downgrades?
No.

Does this PR introduce any user-facing change?:
No.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@laurentiuNiculae laurentiuNiculae left a comment

Choose a reason for hiding this comment

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

lgtm

errors/errors.go Outdated Show resolved Hide resolved
pkg/api/controller.go Outdated Show resolved Hide resolved
pkg/api/controller.go Outdated Show resolved Hide resolved
pkg/api/routes.go Outdated Show resolved Hide resolved
pkg/api/routes.go Show resolved Hide resolved
pkg/api/htpasswd_test.go Outdated Show resolved Hide resolved
pkg/api/controller_test.go Outdated Show resolved Hide resolved
pkg/api/htpasswd_test.go Show resolved Hide resolved
pkg/api/htpasswd.go Outdated Show resolved Hide resolved
pkg/api/htpasswd.go Outdated Show resolved Hide resolved
pkg/api/htpasswd.go Outdated Show resolved Hide resolved
pkg/api/routes.go Outdated Show resolved Hide resolved

username := userAc.GetUsername()
if username == "" {
resp.WriteHeader(http.StatusNotFound)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is related to my previous comment: https://github.com/project-zot/zot/pull/2183/files#r1466598996

return fmt.Errorf("error occurred while replacing htpasswd file with new file: %w", err)
}

err = os.WriteFile(hc.filepath, output, constants.DefaultDirPerms)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should not be needed, right, or am I missing something?

you first write in tmpfile then you rename it to hc.filepath, that should be enough.

return fmt.Errorf("error occurred while encrypting new password: %w", err)
}

file, err := os.ReadFile(hc.filepath)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need a lock to block other users changing their passwords from reading/writing the file at the same time, and only one of the password changes ending up in the file.

@rchincha rchincha added this to the v2.1.0 milestone Feb 7, 2024
@@ -19,6 +19,7 @@ const (
LoginPath = AppNamespacePath + "/auth/login"
LogoutPath = AppNamespacePath + "/auth/logout"
APIKeyPath = AppNamespacePath + "/auth/apikey"
ChangePasswordPath = AppNamespacePath + "/auth/change_password"
Copy link
Contributor

Choose a reason for hiding this comment

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

"chpasswd"

@rchincha
Copy link
Contributor

rchincha commented Feb 7, 2024

Cases to take care of:

  1. Two competing API calls - set_admin_passwd=A, set_admin_passwd=B
  2. Competing calls between API and direct file modification

onidoru and others added 5 commits February 15, 2024 23:03
Signed-off-by: onidoru <onidoru@yahoo.com>
Signed-off-by: onidoru <onidoru@yahoo.com>
Signed-off-by: Nikita Kotikov <onidoru@yahoo.com>
Signed-off-by: onidoru <25552941+onidoru@users.noreply.github.com>
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.

None yet

5 participants