Skip to content

fix(users): preserve user type in role revocations - #2239

Open
feiiiiii5 wants to merge 2 commits into
weaviate:mainfrom
feiiiiii5:codex/revoke-user-role-type
Open

feiiiiii5 wants to merge 2 commits into
weaviate:mainfrom
feiiiiii5:codex/revoke-user-role-type

Conversation

@feiiiiii5

Copy link
Copy Markdown

The typed users.db.revoke_roles() and users.oidc.revoke_roles() APIs construct a userType discriminator, but _revoke_roles_from_user posts a new roles-only dictionary. Send the already constructed payload, matching the assignment path.

The regression uses real synchronous/asynchronous clients and pytest_httpserver to inspect request JSON. It covers DB/OIDC users, role strings/lists, and the deprecated untyped entry points.

Validation on Python 3.12.8:

  • Native regression on unchanged 7266681a: 8 failures / 4 passing compatibility controls; fixed: 12 passed. Independently repeated.
  • .venv/bin/python -m pytest -q test mock_tests --tb=short: 647 passed, 1 skipped (the existing unimplemented collection-model test).
  • Ruff 0.14.7 format/check, Flake8 with the project plugins, Pyright 1.1.399 on both changed files, and diff checks pass.

Dependencies follow the existing development/test requirements; no dependency or configuration changes. The full suite required the repository's original PNG fixture, included before the passing run. Live Weaviate and other Python/platform versions were not run; these regressions verify the client's actual HTTP payload.

@orca-security-eu orca-security-eu Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@weaviate-git-bot

Copy link
Copy Markdown

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Forum?

@feiiiiii5

Copy link
Copy Markdown
Author

I agree to the Contributor License Agreement.

Comment thread mock_tests/test_users.py Outdated
@@ -0,0 +1,91 @@
from typing import Any, Dict, List, Union

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

these mock tests can be replaced with a simple extension of an integration test:

integration/test_rbac.py::test_get_assigned_users_db already creates a db user and a role and assigns it. OIDC is enabled on the RBAC container, so the test can extend straight from there:

  +        client.users.db.delete(user_id=names)
           client.users.db.create(user_id=names)
   ...
           assert assigned_users[0].user_type == UserTypes.DB_DYNAMIC

  +        # an OIDC user with the same id keeps the role when the db user's is revoked
  +        client.users.oidc.assign_roles(user_id=names, role_names=names)
  +        client.users.db.revoke_roles(user_id=names, role_names=names)
  +        assigned_users = client.roles.get_user_assignments(names)
  +        assert len(assigned_users) == 1
  +        assert assigned_users[0].user_type == UserTypes.OIDC

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done: removed the mock test and extended test_get_assigned_users_db with the OIDC assignment and db revoke sequence you suggested. CI is the first live run.

@feiiiiii5

Copy link
Copy Markdown
Author

Done. Dropped the mock file and extended integration/test_rbac.py::test_get_assigned_users_db the way you outlined:

  • delete/recreate the db user, assign the db role, and assert DB_DYNAMIC;
  • assign the same role to an OIDC user with the same id;
  • revoke the db user's roles;
  • assert exactly one assignment remains, with user_type == OIDC.

On main, the revoke request omits userType, so the db revoke also removes the OIDC assignment and the last assertion fails; with the fix the userType: db keeps them separate. I did not run the integration suite locally because there is no RBAC-enabled Weaviate server here. CI is the first live run.

This branch has not been deployed

No deployments
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.

3 participants