Skip to content

Commit

Permalink
Consider all encryption keys
Browse files Browse the repository at this point in the history
* It might happen that a user wants to reuse an LV but forgets to set
  create=false in the volume group.
  • Loading branch information
imobachgs committed Mar 14, 2018
1 parent 9489c52 commit 6d7ee39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/lib/autoinstall/activate_callbacks.rb
Expand Up @@ -61,12 +61,16 @@ def luks(uuid, attempt)

# Retrieves crypt keys for reused devices from the profile
#
# All encryption keys are considered, no matter if they are associated to
# a device that should be reused or not. The reason is that it might happen that a user
# wants to reuse a logical volume but forgets setting 'create' to 'false' for the
# volume group.
#
# @return [Array<String>] List of crypt keys
def crypt_keys_from_profile
profile = Yast::Profile.current.fetch("partitioning", [])
devices = profile.map { |d| d.fetch("partitions", []) }.flatten
crypted_devices = devices.select { |d| d["create"] == false && d.key?("crypt_key") }
keys = crypted_devices.map { |p| p["crypt_key"] }
keys = devices.map { |p| p["crypt_key"] }
keys.compact.uniq.sort
end
end
Expand Down
3 changes: 1 addition & 2 deletions test/lib/activate_callbacks_test.rb
Expand Up @@ -64,11 +64,10 @@
{ "partitioning" => [ { "device" => "/dev/sda", "partitions" => partitions } ] }
end

let(:partitions) { [root, home, srv, opt] }
let(:partitions) { [root, home, srv] }
let(:root) { { "mount" => "/", "crypt_key" => "abcdef", "create" => false } }
let(:home) { { "mount" => "/home", "crypt_key" => "abcdef", "create" => false } }
let(:srv) { { "mount" => "/home", "crypt_key" => "123456", "create" => false } }
let(:opt) { { "mount" => "/opt", "crypt_key" => "not-reused" } }

before do
allow(Yast::Profile).to receive(:current).and_return(profile)
Expand Down

0 comments on commit 6d7ee39

Please sign in to comment.