-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flags to encrypt persistent partition on install: * encrypt-persistent: flag to enable luks encryption on persistent partition. * enroll-passphrase: string to enroll as passphrase to unlock partition. * enroll-key-file: key-file to enroll as key to unlock partition. During install this will invoke cryptsetup to create the LUKS partition and during mount we use systemd-cryptsetup to attach the partition before mounting the contained filesystem. This also introduces some changes in the grub configuration, the encrypted_volumes variable can be set in grub_oem_env during install to configure which volumes are actually encrypted. Signed-off-by: Fredrik Lönnegren <[email protected]>
- Loading branch information
Showing
18 changed files
with
380 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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,76 @@ | ||
/* | ||
Copyright © 2022 - 2024 SUSE LLC | ||
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. | ||
*/ | ||
|
||
package partitioner | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/rancher/elemental-toolkit/v2/pkg/types" | ||
) | ||
|
||
func EncryptDevice(runner types.Runner, device, mappedName string, slots []types.KeySlot) error { | ||
logger := runner.GetLogger() | ||
|
||
if len(slots) == 0 { | ||
return fmt.Errorf("Needs at least 1 key-slot to encrypt %s", device) | ||
} | ||
|
||
firstSlot := slots[0] | ||
|
||
cmd := runner.InitCmd("cryptsetup", "luksFormat", "--key-slot", fmt.Sprintf("%d", firstSlot.Slot), device, "-") | ||
err := unlockCmd(cmd, firstSlot) | ||
if err != nil { | ||
logger.Errorf("Error generating unlock command for device '%s': %s", device, err.Error()) | ||
return err | ||
} | ||
|
||
stdout, err := runner.RunCmd(cmd) | ||
if err != nil { | ||
logger.Errorf("Error formatting device %s: %s", device, stdout) | ||
return err | ||
} | ||
|
||
cmd = runner.InitCmd("cryptsetup", "open", device, mappedName) | ||
|
||
if err = unlockCmd(cmd, firstSlot); err != nil { | ||
return err | ||
} | ||
|
||
stdout, err = runner.RunCmd(cmd) | ||
if err != nil { | ||
logger.Errorf("Error opening device %s: %s", device, stdout) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func unlockCmd(cmd *exec.Cmd, slot types.KeySlot) error { | ||
if slot.Passphrase != "" { | ||
cmd.Stdin = strings.NewReader(string(slot.Passphrase)) | ||
return nil | ||
} | ||
|
||
if slot.KeyFile != "" { | ||
cmd.Args = append(cmd.Args, "--key-file", slot.KeyFile) | ||
return nil | ||
} | ||
|
||
return errors.New("Unknown key slot authorization") | ||
} |
Oops, something went wrong.