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(htpasswd): add autoreload for htpasswd #2933

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

Conversation

vooon
Copy link
Contributor

@vooon vooon commented Jan 31, 2025

What type of PR is this?

feature

Which issue does this PR fix:

Fix #2925

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

If an issue # is not available please add repro steps and logs showing the issue:

Testing done on this change:

Automation added to e2e:

Will this break upgrades or downgrades?

Does this PR introduce any user-facing change?:


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

@vooon
Copy link
Contributor Author

vooon commented Jan 31, 2025

Unsure, htpasswd change do not require full reload with server restarts. But putting the logic into existing watcher much easier.
And in my case the event is not very often.

@vooon
Copy link
Contributor Author

vooon commented Jan 31, 2025

Looks like it works, but not as fast as file updates.

@vooon vooon force-pushed the htpasswd-reload branch 6 times, most recently from 1f35ccb to e4605a5 Compare February 5, 2025 14:57
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 71.25749% with 48 lines in your changes missing coverage. Please review.

Project coverage is 90.94%. Comparing base (d0ad935) to head (dff945a).

Files with missing lines Patch % Lines
pkg/api/htpasswd.go 69.67% 30 Missing and 7 partials ⚠️
pkg/api/controller.go 45.00% 8 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2933      +/-   ##
==========================================
- Coverage   91.06%   90.94%   -0.12%     
==========================================
  Files         174      175       +1     
  Lines       32655    32787     +132     
==========================================
+ Hits        29736    29819      +83     
- Misses       2207     2246      +39     
- Partials      712      722      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vooon vooon marked this pull request as ready for review February 5, 2025 17:33
@rchincha
Copy link
Contributor

rchincha commented Feb 6, 2025

Ideally, we need the watching logic to move outside the server/controller logic, so it is just another config file we watch (along with zot config)

That could be second step. Let other folks take a look also.

andaaron
andaaron previously approved these changes Feb 6, 2025
@andaaron
Copy link
Contributor

andaaron commented Feb 7, 2025

Looks like it works, but not as fast as file updates.

What do you mean by file updates?

@vooon
Copy link
Contributor Author

vooon commented Feb 7, 2025

@andaaron i mean the delay observed after file write.

@andaaron
Copy link
Contributor

andaaron commented Feb 7, 2025

@andaaron i mean the delay observed after file write.

If a separate watcher is an improvement, I think we should go for it. It doesn't make sense to restart the whole server for a new user.

@vooon vooon force-pushed the htpasswd-reload branch 3 times, most recently from 743d50c to 8db17b2 Compare February 8, 2025 11:49
@vooon
Copy link
Contributor Author

vooon commented Feb 8, 2025

@andaaron i've added separate watcher. Need to test it, and also write some tests, but I'm more used to testify...

}

case err := <-ret.watcher.Errors:
ret.log.Panic().Err(err).Str("htpasswd-file", ret.filePath).Msg("fsnotfy error while watching config")
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't panic a bit harsh? Do we want to stop the server in case of an error watching the credentials file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, i copied that behaviour from config watcher. Unsure if i ever seen that error, so probably better to die, than left unpredictable state.

Copy link
Contributor

@andaaron andaaron Feb 8, 2025

Choose a reason for hiding this comment

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

A change in the config file not being applied is something impacting the entire service, while a change in htpasswd not being applied impacts just specific users who were added/removed/had the passwords changed.
I don't think we should stop the service in this specific case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But that's more like entire system error, than this file error. Or i'm wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well yes, but do we want to interrupt service for all users, or just the ones which don't have access anyway? Or would it help the admin with troubleshooting the issue if the entire service stops?

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.

[Feat]: Autoreload htpasswd on changes
3 participants