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

[JUJU-3333] Users removal triggers the removal of model access #15324

Conversation

juanmanuel-tirado
Copy link
Contributor

@juanmanuel-tirado juanmanuel-tirado commented Mar 22, 2023

After enabling user names to be reused (#15266 ) it has been observed that for those recreated users that where previously granted with access permissions to other models, these permissions are automatically recreated. This is a misbehaviour that is corrected in this PR by removing all the permissions a user is granted when the user is removed from the controller. This makes possible to have a clear list of permissions when a user is recreated avoiding this unexpected behaviour.

Checklist

If an item is not applicable, use ~strikethrough~.

- [ ] Code style: imports ordered, good names, simple structure, etc
- [ ] Comments saying why design decisions were made

  • Go unit tests, with comments saying what you're testing
    - [ ] Integration tests, with comments saying what you're testing
    - [ ] doc.go added or updated in changed packages

QA steps

Try to replicate an scenario for a recreated user who was granted some permissions.

juju add-user mrx
User "mrx" added
Please send this command to mrx:
    juju register MHsTA21yeDBFDC5bZmQ0MjpjZmExOmFkZjc6NjI3NDoyMTY6M2VmZjpmZTE1OjZiYzldOjE3MDcwExMxMC4yMjAuMTguMjIyOjE3MDcwBCC9TIZM91FQZPJ2bjnICsB4rcyUlcpmPXrxgpQpxJx5NRMJbG9jYWx0ZXN0EwAA

"mrx" has not been granted access to any models. You can use "juju grant" to grant access.

Grant user access

juju add-model test
juju grant mrx admin test
juju users test
Name    Display name  Access  Last connection
admin*  admin         admin   36 minutes ago
mrx                   admin   never connected

Destroy the user and recreate

juju remove-user mrx --yes
users test
Name    Display name  Access  Last connection
admin*  admin         admin   37 minutes ago

juju add-user mrx
User "mrx" added
Please send this command to mrx:
    juju register MHsTA21yeDBFDC5bZmQ0MjpjZmExOmFkZjc6NjI3NDoyMTY6M2VmZjpmZTE1OjZiYzldOjE3MDcwExMxMC4yMjAuMTguMjIyOjE3MDcwBCC9TIZM91FQZPJ2bjnICsB4rcyUlcpmPXrxgpQpxJx5NRMJbG9jYWx0ZXN0EwAA

"mrx" has not been granted access to any models. You can use "juju grant" to grant access.

Now if you check the users for model test, no permissions are set

users test
Name    Display name  Access  Last connection
admin*  admin         admin   37 minutes ago

… the user is registered in that controller.
Copy link
Member

@nvinuesa nvinuesa left a comment

Choose a reason for hiding this comment

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

LGTM, only a minor comment. QA passes

state/user.go Outdated Show resolved Hide resolved
@juanmanuel-tirado juanmanuel-tirado merged commit 27dbafb into juju:2.9 Mar 28, 2023
@@ -215,6 +212,28 @@ func (st *State) RemoveUser(tag names.UserTag) error {
return nil
}

// remove the access to all the models and the current controller
// first query all the models for this user
modelsSummary, err := st.ModelSummariesForUser(tag, true)
Copy link
Member

Choose a reason for hiding this comment

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

This is not how you would iterate across all the model users.


for _, summary := range modelsSummary {
// remove all the access permissions
removeModelOps := removeModelUserOps(summary.UUID, tag)
Copy link
Member

Choose a reason for hiding this comment

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

removeModelUserOps can't be run like this. You'll need to manually write the ops for this, as the removeModelUserOps are meant to be run from the state opened for a specific model, so you'll need to handle model prefixed ids manually. See ensureModelUUID and modelStateCollection and GetCollection.

}

// remove the user from the user controllers
if err := st.removeControllerUser(tag); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

You should actually be getting this user from state first to check it still exists.

@@ -235,13 +254,14 @@ func (st *State) RemoveUser(tag names.UserTag) error {
return nil, errors.Trace(err)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

You should be building all of those ops and txns above into this buildTxn function so they can be done together.

hpidcock added a commit that referenced this pull request Mar 29, 2023
@hpidcock
Copy link
Member

hpidcock commented Mar 29, 2023

Please address my comment in this one here #15279

jujubot added a commit that referenced this pull request Mar 31, 2023
…_user_access

#15395

This PR ports the fix for the broken user access reported in #15351 and #15324 

## Checklist

*If an item is not applicable, use `~strikethrough~`.*

- [ ] Code style: imports ordered, good names, simple structure, etc
- [ ] Comments saying why design decisions were made
- [ ] Go unit tests, with comments saying what you're testing
- [ ] [Integration tests](https://github.com/juju/juju/tree/develop/tests), with comments saying what you're testing
- [ ] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages

## QA steps

Refer to #15324 for QA steps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants