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

Fix rawAcl database scope #1514

Merged
merged 5 commits into from
Nov 17, 2023
Merged

Fix rawAcl database scope #1514

merged 5 commits into from
Nov 17, 2023

Conversation

haakonvt
Copy link
Contributor

@haakonvt haakonvt commented Nov 17, 2023

Description

[7.2.1] - 2023-11-17

Fixed

  • The new compare methods for capabilities in major version 7, IAMAPI.verify_capabilities and IAMAPI.compare_capabilities now works correctly for rawAcl with database scope ("all tables").

Removed

  • Capability scopes no longer have the is_within method, and capabilities no longer have has_capability. Use the more general IAMAPI.compare_capabilities instead.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

@haakonvt haakonvt requested review from a team as code owners November 17, 2023 00:46
Copy link

codecov bot commented Nov 17, 2023

Codecov Report

Merging #1514 (5e269af) into master (b855dc2) will increase coverage by 0.18%.
The diff coverage is 93.75%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1514      +/-   ##
==========================================
+ Coverage   91.56%   91.75%   +0.18%     
==========================================
  Files         120      120              
  Lines       15611    15582      -29     
==========================================
+ Hits        14294    14297       +3     
+ Misses       1317     1285      -32     
Files Coverage Δ
cognite/client/_api/iam.py 87.96% <100.00%> (+2.96%) ⬆️
cognite/client/_version.py 100.00% <100.00%> (ø)
cognite/client/data_classes/capabilities.py 96.93% <66.66%> (+2.90%) ⬆️

... and 2 files with indirect coverage changes

@haakonvt haakonvt force-pushed the fix-raw-acl-db-scope branch from 290adbf to 5e269af Compare November 17, 2023 01:00
@@ -100,8 +99,10 @@ def compare_capabilities(
project (str | None): If a ProjectCapability or ProjectCapabilityList is passed, we need to know which CDF project
to pull capabilities from (existing might be from several). If project is not passed, and ProjectCapabilityList
is used, it will be inferred from the CogniteClient used to call retrieve it via token/inspect.
ignore_allscope_meaning (bool): Option on how to treat allScopes. When True, this function will return
e.g. an Acl scoped to a dataset even if the user have the same Acl scoped to all. Defaults to False.
ignore_allscope_meaning (bool): Option on how to treat scopes that encompass other scopes, like allScope. When True,
Copy link
Collaborator

Choose a reason for hiding this comment

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

When would you want this set to True?

Copy link
Contributor

Choose a reason for hiding this comment

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

That is the most logical to me. You have access to all data sets when you have all, which would be the most common use case.

Copy link
Contributor Author

@haakonvt haakonvt Nov 17, 2023

Choose a reason for hiding this comment

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

If you want two groups of capabilities to be equal, and they differ in scopes "not all" - but you still have some all-scopes here and there, then this option will tell you exactly what those differences are. For Peter's bootstrap CLI (and maybe others...) it means the manual work of removing any possible all-scopes or raw-database-scopes before comparing is not needed.

@@ -98,9 +98,6 @@ def as_tuples(self) -> set[tuple]:
# Basic implementation for all simple Scopes (e.g. all or currentuser)
return {(self._scope_name,)}

def is_within(self, other: Self) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Surprised that these slipped through the reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually kept it as a "simple 1:1 check", but decided now with the raw-database changes to not duplicate the error-prone scope logic.

Copy link
Contributor

@doctrino doctrino left a comment

Choose a reason for hiding this comment

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

Brutal edge case. A bit surprised that we forgot to remove is_within before the v7 release.

Comment on lines +364 to +365
[RawAcl(actions=[RawAcl.Action.Read], scope=TableScope({"db1": []}))],
[RawAcl(actions=[RawAcl.Action.Read], scope=TableScope({"db1": {"tables": []}}))],
Copy link
Contributor

Choose a reason for hiding this comment

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

These are confusing, but if I understand it correctly, it means all in db1? Both of them are equal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This means access is granted to all current and all future tables in the database "db1":
TableScope({"db1": []})

I don't like the syntax one bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, that's how the API does it, and hence we shouldn't add our own DataBaseScope imo

@haakonvt haakonvt merged commit e6328f2 into master Nov 17, 2023
7 checks passed
@haakonvt haakonvt deleted the fix-raw-acl-db-scope branch November 17, 2023 15:02
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