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

Respect DefaultUserIsRestricted system default when creating new user #19310

Merged
merged 15 commits into from
Apr 29, 2022

Conversation

jpraet
Copy link
Member

@jpraet jpraet commented Apr 2, 2022

The DefaultUserIsRestricted system configuration options is not always enforced when creating a new user.

This PR configures the system defaults in user_model.CreateUser, and also enhances the CreateUserOverwriteOptions to allow overwriting the system defaults when needed.

Note that the RegisterEmailConfirm and RegisterManualConfirm are also not enforced in most places.
Normalization of these settings has been taken out of the scope of this PR.

@jpraet
Copy link
Member Author

jpraet commented Apr 2, 2022

There are a lot of places where IsActive is currently set to true instead of
!(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm).
I'm not sure which of these need to remain true by design?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 2, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 2, 2022

Codecov Report

Merging #19310 (a8dc6ec) into main (d242511) will decrease coverage by 0.11%.
The diff coverage is 41.66%.

❗ Current head a8dc6ec differs from pull request most recent head ee95d3e. Consider uploading reports for the commit ee95d3e to get more accurate results

@@            Coverage Diff             @@
##             main   #19310      +/-   ##
==========================================
- Coverage   47.51%   47.39%   -0.12%     
==========================================
  Files         944      949       +5     
  Lines      131549   132139     +590     
==========================================
+ Hits        62500    62623     +123     
- Misses      61541    61974     +433     
- Partials     7508     7542      +34     
Impacted Files Coverage Δ
cmd/admin.go 0.00% <0.00%> (ø)
cmd/serv.go 2.33% <0.00%> (-0.06%) ⬇️
models/action.go 48.61% <0.00%> (ø)
models/error.go 36.46% <ø> (-0.03%) ⬇️
models/issue_label.go 68.02% <0.00%> (ø)
models/issue_lock.go 0.00% <0.00%> (ø)
models/issue_project.go 31.70% <0.00%> (ø)
models/pull.go 55.81% <0.00%> (ø)
models/statistic.go 0.00% <0.00%> (ø)
models/unittest/testdb.go 15.50% <0.00%> (-0.13%) ⬇️
... and 121 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72479bf...ee95d3e. Read the comment docs.

cmd/admin.go Show resolved Hide resolved
routers/api/v1/admin/user.go Show resolved Hide resolved
routers/web/admin/users.go Show resolved Hide resolved
routers/web/auth/oauth.go Show resolved Hide resolved
services/auth/reverseproxy.go Show resolved Hide resolved
services/auth/source/ldap/source_sync.go Show resolved Hide resolved
@jpraet jpraet changed the title [WIP] Respect restricted and account confirmation system defaults when creating new user Respect restricted and account confirmation system defaults when creating new user Apr 4, 2022
@jpraet jpraet marked this pull request as ready for review April 4, 2022 17:19
@jpraet jpraet added the topic/security Something leaks user information or is otherwise vulnerable. Should be fixed! label Apr 5, 2022
@jpraet
Copy link
Member Author

jpraet commented Apr 9, 2022

Could anyone advise on where setting.Service.RegisterEmailConfirm and/or setting.Service.RegisterManualConfirm can be bypassed and where they cannot?

@lunny
Copy link
Member

lunny commented Apr 10, 2022

Could anyone advise on where setting.Service.RegisterEmailConfirm and/or setting.Service.RegisterManualConfirm can be bypassed and where they cannot?

I think gitea command line could ignore these options. Otherwise they should be obey.

@lafriks
Copy link
Member

lafriks commented Apr 10, 2022

I don't really think external authentication sources should obey to these rules also, probably they could have option to them to added then to activate user or not but currently I don't think that's a good idea to have to activate them

@jpraet
Copy link
Member Author

jpraet commented Apr 10, 2022

My initial reason for this PR was that DefaultUserIsRestricted is currently not taken into account in multiple places where new user accounts are created.

When discussing this on discord @zeripath mentioned "you might wanna check isManualConfirm too - appears I may have missed some", so I broadened the scope to also look into RegisterEmailConfirm and RegisterManualConfirm as well.

But it looks like there's no consensus as to where these settings should apply?

@jpraet
Copy link
Member Author

jpraet commented Apr 26, 2022

Should I maybe leave the RegisterEmailConfirm and RegisterManualConfirm settings AS-IS, and only address DefaultUserIsRestricted in this PR?

@lunny
Copy link
Member

lunny commented Apr 26, 2022

Should I maybe leave the RegisterEmailConfirm and RegisterManualConfirm settings AS-IS, and only address DefaultUserIsRestricted in this PR?

I'm OK for that.

IsAdmin: c.Bool("admin"),
MustChangePassword: changePassword,
Theme: setting.UI.DefaultTheme,
Copy link
Member

Choose a reason for hiding this comment

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

Why default theme is removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Already applied by default in CreateUser:

u.Theme = setting.UI.DefaultTheme

@jpraet jpraet changed the title Respect restricted and account confirmation system defaults when creating new user Respect DefaultUserIsRestricted system default when creating new user Apr 26, 2022
@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 Apr 29, 2022
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 29, 2022
@techknowlogick techknowlogick merged commit 5aebc4f into go-gitea:main Apr 29, 2022
@techknowlogick techknowlogick added this to the 1.17.0 milestone Apr 29, 2022
@techknowlogick techknowlogick added backport/v1.16 backport/done All backports for this PR have been created labels Apr 29, 2022
Gusted pushed a commit to Gusted/gitea that referenced this pull request Apr 30, 2022
…go-gitea#19310)

* Apply DefaultUserIsRestricted in CreateUser

* Enforce system defaults in CreateUser

Allow for overwrites with CreateUserOverwriteOptions

* Fix compilation errors

* Add "restricted" option to create user command

* Add "restricted" option to create user admin api

* Respect default setting.Service.RegisterEmailConfirm and setting.Service.RegisterManualConfirm where needed

* Revert "Respect default setting.Service.RegisterEmailConfirm and setting.Service.RegisterManualConfirm where needed"

This reverts commit ee95d3e.
zjjhot added a commit to zjjhot/gitea that referenced this pull request May 1, 2022
* giteaofficial/main:
  Avoid MoreThanOne Error (go-gitea#19557)
  [skip ci] Updated licenses and gitignores
  Simplify loops to copy (go-gitea#19569)
  Use middleware to open gitRepo (go-gitea#19559)
  Added X-Mailer header to outgoing emails (go-gitea#19562)
  fix go-gitea#19545 (go-gitea#19563)
  [skip ci] Updated translations via Crowdin
  Respect DefaultUserIsRestricted system default when creating new user (go-gitea#19310)
  Mute link in diff header (go-gitea#19556)
  Add API to query collaborators permission for a repository (go-gitea#18761)
  Permalink files In PR diff (go-gitea#19534)
  Fix Pull Request comment filename word breaks (go-gitea#19535)
  Don't error when branch's commit doesn't exist (go-gitea#19547)
AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this pull request Aug 24, 2022
…go-gitea#19310)

* Apply DefaultUserIsRestricted in CreateUser

* Enforce system defaults in CreateUser

Allow for overwrites with CreateUserOverwriteOptions

* Fix compilation errors

* Add "restricted" option to create user command

* Add "restricted" option to create user admin api

* Respect default setting.Service.RegisterEmailConfirm and setting.Service.RegisterManualConfirm where needed

* Revert "Respect default setting.Service.RegisterEmailConfirm and setting.Service.RegisterManualConfirm where needed"

This reverts commit ee95d3e.
@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
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/security Something leaks user information or is otherwise vulnerable. Should be fixed!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants