-
Notifications
You must be signed in to change notification settings - Fork 21
Support for in-place re-encryption, encryption, decryption #1257
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
Merged
mulkieran
merged 12 commits into
stratis-storage:master
from
mulkieran:issue-stratisd-3597
Apr 21, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8cfa6d7
Update introspection data
mulkieran 7a6b5d3
Set up clevis + keyring options for sharing
mulkieran 12d54ec
Add commands for encrypt, re-encrypt, and unencrypt
mulkieran 8fdd64f
Test parsing clevis options in encryption on
mulkieran 6d047a7
Add an --in-place option
mulkieran a590c2d
Half D-Bus timeout
mulkieran 9053613
Add a decorator for our long running operations
mulkieran aa46061
Display last time re-encrypted in pool detail view
mulkieran d70d14d
Add man page entries for the moved subcommands
mulkieran 3221491
man: Add entries for encryption on, off, and re-encrypt
mulkieran 7e12d43
man: Add entry for the "Last Time Reencrypted" field
mulkieran 1c9b873
Time out after ten seconds for long-running methods
mulkieran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| # Copyright 2025 Red Hat, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
| Miscellaneous whole pool encryption actions. | ||
| """ | ||
|
|
||
| # isort: STDLIB | ||
| import json | ||
| from argparse import Namespace | ||
|
|
||
| from .._constants import PoolId | ||
| from .._errors import ( | ||
| StratisCliEngineError, | ||
| StratisCliIncoherenceError, | ||
| StratisCliInPlaceNotSpecified, | ||
| StratisCliNoChangeError, | ||
| ) | ||
| from .._stratisd_constants import StratisdErrors | ||
| from ._connection import get_object | ||
| from ._constants import TOP_OBJECT | ||
| from ._utils import long_running_operation | ||
|
|
||
|
|
||
| class CryptActions: | ||
| """ | ||
| Whole pool encryption actions. | ||
| """ | ||
|
|
||
| @staticmethod | ||
| @long_running_operation(method_names=["EncryptPool"]) | ||
| def encrypt(namespace: Namespace): | ||
| """ | ||
| Encrypt a previously unencrypted pool. | ||
| """ | ||
|
|
||
| if not namespace.in_place: | ||
| raise StratisCliInPlaceNotSpecified() | ||
|
|
||
| # pylint: disable=import-outside-toplevel | ||
| from ._data import MOPool, ObjectManager, Pool, pools | ||
|
|
||
| pool_id = PoolId.from_parser_namespace(namespace) | ||
| assert pool_id is not None | ||
|
|
||
| proxy = get_object(TOP_OBJECT) | ||
|
|
||
| managed_objects = ObjectManager.Methods.GetManagedObjects(proxy, {}) | ||
|
|
||
| (pool_object_path, mopool) = next( | ||
| pools(props=pool_id.managed_objects_key()) | ||
| .require_unique_match(True) | ||
| .search(managed_objects) | ||
| ) | ||
|
|
||
| if bool(MOPool(mopool).Encrypted()): | ||
| raise StratisCliNoChangeError("encryption on", pool_id) | ||
|
|
||
| (changed, return_code, message) = Pool.Methods.EncryptPool( | ||
| get_object(pool_object_path), | ||
| { | ||
| "key_descs": ( | ||
| [] | ||
| if namespace.key_desc is None | ||
| else [((False, 0), namespace.key_desc)] | ||
| ), | ||
| "clevis_infos": ( | ||
| [] | ||
| if namespace.clevis is None | ||
| else [ | ||
| ( | ||
| (False, 0), | ||
| namespace.clevis.pin, | ||
| json.dumps(namespace.clevis.config), | ||
| ) | ||
| ] | ||
| ), | ||
| }, | ||
| timeout=10, | ||
| ) | ||
|
|
||
| if return_code != StratisdErrors.OK: | ||
| raise StratisCliEngineError(return_code, message) | ||
|
|
||
| if not changed: # pragma: no cover | ||
| raise StratisCliIncoherenceError( | ||
| f"Expected to change {pool_id} encryption status to " | ||
| "encrypted, but stratisd reports that it did not change " | ||
| "the encryption status" | ||
| ) | ||
|
|
||
| @staticmethod | ||
| @long_running_operation(method_names=["DecryptPool"]) | ||
| def unencrypt(namespace: Namespace): | ||
| """ | ||
| Unencrypt a previously encrypted pool. | ||
| """ | ||
| if not namespace.in_place: | ||
| raise StratisCliInPlaceNotSpecified() | ||
|
|
||
| # pylint: disable=import-outside-toplevel | ||
| from ._data import MOPool, ObjectManager, Pool, pools | ||
|
|
||
| pool_id = PoolId.from_parser_namespace(namespace) | ||
| assert pool_id is not None | ||
|
|
||
| proxy = get_object(TOP_OBJECT) | ||
|
|
||
| managed_objects = ObjectManager.Methods.GetManagedObjects(proxy, {}) | ||
|
|
||
| (pool_object_path, mopool) = next( | ||
| pools(props=pool_id.managed_objects_key()) | ||
| .require_unique_match(True) | ||
| .search(managed_objects) | ||
| ) | ||
|
|
||
| if not bool(MOPool(mopool).Encrypted()): | ||
| raise StratisCliNoChangeError("encryption off", pool_id) | ||
|
|
||
| (changed, return_code, message) = Pool.Methods.DecryptPool( | ||
| get_object(pool_object_path), | ||
| {}, | ||
| timeout=10, | ||
| ) | ||
|
|
||
| if return_code != StratisdErrors.OK: # pragma: no cover | ||
| raise StratisCliEngineError(return_code, message) | ||
|
|
||
| if not changed: # pragma: no cover | ||
| raise StratisCliIncoherenceError( | ||
| f"Expected to change {pool_id} encryption status to " | ||
| "unencrypted, but stratisd reports that it did not change " | ||
| "the pool's encryption status" | ||
| ) | ||
|
|
||
| @staticmethod | ||
| @long_running_operation(method_names=["ReencryptPool"]) | ||
| def reencrypt(namespace: Namespace): | ||
| """ | ||
| Reencrypt an already encrypted pool with a new key. | ||
| """ | ||
| if not namespace.in_place: | ||
| raise StratisCliInPlaceNotSpecified() | ||
|
|
||
| # pylint: disable=import-outside-toplevel | ||
| from ._data import ObjectManager, Pool, pools | ||
|
|
||
| pool_id = PoolId.from_parser_namespace(namespace) | ||
| assert pool_id is not None | ||
|
|
||
| proxy = get_object(TOP_OBJECT) | ||
|
|
||
| managed_objects = ObjectManager.Methods.GetManagedObjects(proxy, {}) | ||
|
|
||
| (pool_object_path, _) = next( | ||
| pools(props=pool_id.managed_objects_key()) | ||
| .require_unique_match(True) | ||
| .search(managed_objects) | ||
| ) | ||
|
|
||
| (changed, return_code, message) = Pool.Methods.ReencryptPool( | ||
| get_object(pool_object_path), | ||
| {}, | ||
| timeout=10, | ||
| ) | ||
|
|
||
| if return_code != StratisdErrors.OK: | ||
| raise StratisCliEngineError(return_code, message) | ||
|
|
||
| if not changed: # pragma: no cover | ||
| raise StratisCliIncoherenceError( | ||
| f"Expected to reencrypt {pool_id} with a new key but stratisd " | ||
| "reports that it did not perform the operation" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.