-
Notifications
You must be signed in to change notification settings - Fork 1
fix: don't restore revoked access from the gpg-id files #15
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,16 +180,26 @@ def _check_auth_file(self, filename: str) -> Path: | |
| return config_file | ||
|
|
||
| def _load_gpg_id_files(self) -> None: | ||
| """Load the data of the gpg-id files that is not already in the access store.""" | ||
| """Import the gpg-id files that are not yet in the access store. | ||
|
|
||
| Merging the keys of an already imported gpg-id file would undo any | ||
| revocation done on the access store, so they are only warned about. | ||
| """ | ||
| for gpg_id in self.store_dir.rglob(".gpg-id"): | ||
| access = self.gpg_id_access_key(gpg_id) | ||
| try: | ||
| existent_keys = self.access_keys(access) | ||
| for key in gpg_id.read_text().splitlines(): | ||
| if key not in existent_keys: | ||
| self.access[access].append(key) | ||
| except KeyError: | ||
| self.access[access] = gpg_id.read_text().splitlines() | ||
| keys = gpg_id.read_text().splitlines() | ||
|
|
||
| if access not in self.access: | ||
| self.access[access] = keys | ||
| continue | ||
|
|
||
| unknown = [key for key in keys if key not in self.access_keys(access)] | ||
| if unknown: | ||
| log.warning( | ||
| f"{gpg_id} contains keys that are not in the access store, " | ||
| f"they will be removed on the next reencryption: " | ||
| f"{', '.join(unknown)}" | ||
| ) | ||
|
|
||
| def save(self) -> None: | ||
| """Save the contents of the authentication store.""" | ||
|
|
@@ -466,6 +476,10 @@ def _revoke_access(self, identifier: Identifier, access: List[str]) -> List[str] | |
| # We may pass here when we remove the access of a user to a group, | ||
| # therefore the access to the directory doesn't change as it's | ||
| # binded to the group | ||
| if isinstance(revoke, User): | ||
| # An access entry can also be the key or the email of the user. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's why we use so we shouldn't need this block |
||
| return [entry for entry in access if not revoke.match(entry)] | ||
|
|
||
| with suppress(ValueError): | ||
| access.remove(revoke.name) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
| from ...factories import GroupFactory, UserFactory | ||
|
|
||
| if TYPE_CHECKING: | ||
| from _pytest.logging import LogCaptureFixture | ||
|
|
||
| from pass_collaborate.model.auth import AuthStore | ||
| from pass_collaborate.model.key import GPGKey | ||
|
|
||
|
|
@@ -175,16 +177,18 @@ def test_user_can_have_accents_on_name() -> None: | |
| assert user == result | ||
|
|
||
|
|
||
| def test_auth_loads_gpg_id_even_if_entry_exists( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this behaviour, why would you want to remove it? |
||
| auth: "AuthStore", admin: "User" | ||
| def test_auth_doesnt_load_gpg_id_if_entry_exists( | ||
| auth: "AuthStore", admin: "User", caplog: "LogCaptureFixture" | ||
| ) -> None: | ||
| """ | ||
| Given: an auth store with a key in the access property | ||
| Then: The missing keys are loaded | ||
| Given: an auth store with an already imported gpg-id file | ||
| When: the gpg-id file has keys that the access store doesn't have | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the test you made below doesn't reflect this case |
||
| Then: The keys are not loaded, so a revocation is not undone, but warned about | ||
| """ | ||
| auth.access[".gpg-id"] = [] | ||
| auth.save() | ||
|
|
||
| auth.reload() # act | ||
|
|
||
| assert auth.access[".gpg-id"] == [admin.key] | ||
| assert auth.access[".gpg-id"] == [] | ||
| assert admin.key in caplog.records[0].message | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no they wouldn't as the revocation takes care of this