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

Introduce ability to update HashAlgo #14751

Closed
wants to merge 15 commits into from
Closed

Conversation

boppy
Copy link

@boppy boppy commented Feb 19, 2021

After discussions on discord, I implemented the ability to set the Hashing Algo more freely. Including any param for any of the available HashAlgos. This is my first ever PR to gitea (or any go project), so please patient with me ;)

In particular:

Update Hashing Generation and Storage

The password hash now also includes the parameters that have been used to create the hash. This is needed, because the params a volatile now.

Add Defaults in settings

Those follow the current set of settings.

Add Flag to Update Password on next use in settings

If this setting is set, gitea will update the user password to match current settings the next time a password validation takes place (and succeeds, for sure)

Create Crypto-Fallbacks in structs

Created a struct where the fallback config for any of the available hash algos is saved. This is needed in order to verify passwords that are not stored using the newly inserted logic


Some questions are still needing discussion (beside the question if my approach even matches coding standards used):

  1. Should I provide error handling here?

  2. Should (how?) I provide any swagger related contents here - I just copied the sources and kept the swagger comment.

  3. Should each and every of the aspects be integrated into the config file? I did not add any by now, but prepared it

Regarding (3) I would totally opt in for making every aspect configurable. It could be [security.password] or just passwords.

- Add Defaults in settings
- Add Flag to Update Password on next use in settings
- Create Crypto-Fallbacks in structs
- Update Hashing Generation
- Introduce hashing module with 4 submodules, one for each hashing algo
- Migrate User table:
  - Update Password format
  - Remove HashAlgo field
- Remove all usages of passwdHashAlgo field
- Update config file
- Update all usages of password verification
- Update the detection of password resetting need
- Set defaults if hashing conf is n/a in config file
- Update user fixture to mirror changes
- Append user in fixture with not-default password setting
- Update test for the changes above
# Conflicts:
#	models/migrations/migrations.go
#	models/migrations/v172.go
#	models/user.go
lunny
lunny previously requested changes Feb 21, 2021
models/fixtures/user.yml Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 21, 2021
- Fix CR by @lunny
- Revert migration to User table
- Revert remove all usages of passwdHashAlgo field
- Update relevant parts for password setting to write passwdHashAlgo
Copy link
Contributor

@zeripath zeripath left a comment

Choose a reason for hiding this comment

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

I think we need to do the configuration slightly differently but we're getting there!

models/user.go Outdated Show resolved Hide resolved
modules/auth/db/hash.go Outdated Show resolved Hide resolved
modules/auth/db/hash_argon2.go Outdated Show resolved Hide resolved
modules/setting/setting.go Outdated Show resolved Hide resolved
@lunny
Copy link
Member

lunny commented Mar 4, 2021

Documentation changes could be added on this PR.

@boppy
Copy link
Author

boppy commented Mar 4, 2021

Thanks to both of you for the inputs. Will continue implementing this weekend.

models/user_test.go Outdated Show resolved Hide resolved
Add password_hash options to
  - config-cheat-sheet
  - /admin/config
  - default ini
Add passing of error if hashing fails
@boppy boppy changed the title [WIP] Introduce ability to update HashAlgo Introduce ability to update HashAlgo Mar 6, 2021
@boppy boppy marked this pull request as ready for review March 6, 2021 18:07
@boppy boppy requested a review from lunny March 14, 2021 12:40
modules/auth/hash/hash.go Outdated Show resolved Hide resolved
@lunny lunny added the type/enhancement An improvement of existing functionality label Mar 20, 2021
@lunny lunny added this to the 1.15.0 milestone Mar 20, 2021
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 21, 2021
@6543
Copy link
Member

6543 commented Jun 30, 2021

@boppy please resolve conflicts

@boppy
Copy link
Author

boppy commented Jul 1, 2021

Will do it this weekend.

# Conflicts:
#	custom/conf/app.example.ini
#	models/fixtures/user.yml
#	routers/install/install.go
#	routers/web/user/setting/account.go
custom/conf/app.example.ini Outdated Show resolved Hide resolved
@6543
Copy link
Member

6543 commented Jul 4, 2021

@boppy routers/install/install.go:6:1: Imports are sorted wrong

boppy and others added 2 commits July 5, 2021 21:19
* Make all hash related parameters optional
* Set fallback parameters for each algo
* Note in ini that all params (per algo) have to be defined in order to be used
* Comment out ini entries
* Reorder imports in install.go
@zeripath zeripath modified the milestones: 1.15.0, 1.16.0 Jul 13, 2021
@lafriks
Copy link
Member

lafriks commented Aug 18, 2021

please resolve conflicts

@lunny lunny dismissed their stale review November 14, 2021 14:08

The review request resolved.

@lunny lunny modified the milestones: 1.16.0, 1.17.0 Nov 15, 2021
@stale
Copy link

stale bot commented May 2, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions.

@stale stale bot added the issue/stale label May 2, 2022
@lunny lunny modified the milestones: 1.17.0, 1.18.0 Jun 3, 2022
@stale stale bot removed the issue/stale label Jun 3, 2022
@lunny lunny modified the milestones: 1.18.0, 1.19.0 Oct 19, 2022
@lunny lunny removed this from the 1.19.0 milestone Feb 1, 2023
zeripath added a commit to zeripath/gitea that referenced this pull request Feb 16, 2023
This PR refactors and improves the password hashing code within gitea
and makes it possible for server administrators to set the password
hashing parameters

In addition it takes the opportunity to adjust the settings for `pbkdf2`
in order to make the hashing a little stronger.

The majority of this work was inspired by PR go-gitea#14751 and I would like to
thank @boppy for their work on this.

Thanks to @Gusted for the suggestion to adjust the `pbkdf2` hashing
parameters.

Close go-gitea#14751

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit to zeripath/gitea that referenced this pull request Feb 16, 2023
…ea#22942)

Backport go-gitea#22942

This PR refactors and improves the password hashing code within gitea
and makes it possible for server administrators to set the password
hashing parameters

In addition it takes the opportunity to adjust the settings for `pbkdf2`
in order to make the hashing a little stronger.

The majority of this work was inspired by PR go-gitea#14751 and I would like to
thank @boppy for their work on this.

Thanks to @Gusted for the suggestion to adjust the `pbkdf2` hashing
parameters.

Close go-gitea#14751

Signed-off-by: Andrew Thornton <art27@cantab.net>
@lunny lunny closed this in #22942 Feb 19, 2023
lunny added a commit that referenced this pull request Feb 19, 2023
This PR refactors and improves the password hashing code within gitea
and makes it possible for server administrators to set the password
hashing parameters

In addition it takes the opportunity to adjust the settings for `pbkdf2`
in order to make the hashing a little stronger.

The majority of this work was inspired by PR #14751 and I would like to
thank @boppy for their work on this.

Thanks to @Gusted for the suggestion to adjust the `pbkdf2` hashing
parameters.

Close #14751

---------

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
lunny added a commit that referenced this pull request Feb 19, 2023
#22943)

Backport #22942

This PR refactors and improves the password hashing code within gitea
and makes it possible for server administrators to set the password
hashing parameters

In addition it takes the opportunity to adjust the settings for `pbkdf2`
in order to make the hashing a little stronger.

The majority of this work was inspired by PR #14751 and I would like to
thank @boppy for their work on this.

Thanks to @Gusted for the suggestion to adjust the `pbkdf2` hashing
parameters.

Close #14751

---------

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants