Skip to content

Commit f28e6c8

Browse files
committed
initializer/cobra: rework (cobra) docs
1 parent d93f711 commit f28e6c8

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

initializer/mount.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
encryptionPassphrasePrefix = "/dev/shm/disk-key"
2929
)
3030

31+
// luksVolume struct holds the representative attributes related to a LUKS encrypted volume.
3132
type luksVolume struct {
3233
devicePath string
3334
mappingName string
@@ -41,13 +42,27 @@ func must(err error) {
4142
}
4243
}
4344

44-
// NewSetupEncryptedMountCmd creates a Cobra subcommand of the initializer to set up specified encrypted volumes.
45+
// NewSetupEncryptedMountCmd creates a Cobra subcommand of the initializer to set up the specified encrypted LUKS volume.
4546
func NewSetupEncryptedMountCmd() *cobra.Command {
4647
cmd := &cobra.Command{
4748
Use: "setupEncryptedMount -d [device-path] -m [mount-point]",
48-
Short: "",
49-
Long: "",
50-
RunE: setupEncryptedMount,
49+
Short: "setupEncryptedMount on block device at [device-path] with decrypted mapper device at [mount-point]",
50+
Long: `Set up an LUKS encrypted VolumeMount on the provided VolumeDevice
51+
located at the specified [device-path] and mount the decrypted mapper
52+
device to the provided [mount-point].
53+
54+
In certain deployments, we require a persistent volume claim configured
55+
as block storage to be encrypted by the initializer binary.
56+
Therefore we expose the defined PVC as a block VolumeDevice to our
57+
initializer container. This allows the initializer to setup the
58+
encryption on the block device located at [device-path] using cryptsetup,
59+
the encryption passphrase is derived from the UUID of the LUKS formatted
60+
block device and the current workload secret.
61+
62+
The mapped decrypted block device can then be shared with other containers
63+
on the pod by setting up a shared VolumeMount on the specified [mount-point],
64+
where the mapper device will be mounted to.`,
65+
RunE: setupEncryptedMount,
5166
}
5267
cmd.Flags().StringP("device-path", "d", "/dev/csi0", "path to the volume device to be encrypted")
5368
cmd.Flags().StringP("mount-point", "m", "/state", "mount point of decrypted mapper device")
@@ -90,7 +105,6 @@ func setupEncryptedMount(cmd *cobra.Command, _ []string) error {
90105
}
91106
ctx := cmd.Context()
92107
if !isLuks(ctx, logger, luksVolume.devicePath) {
93-
// TODO(jmxnzo) might just use stdin instead for the initial passphrase generation
94108
if err := createInitPassphrase(tmpPassphrase); err != nil {
95109
return err
96110
}
@@ -228,7 +242,6 @@ func createEncryptionPassphrase(ctx context.Context, luksVolume *luksVolume, wor
228242
if err != nil {
229243
return fmt.Errorf("reading workload secret: %w", err)
230244
}
231-
print(string(workloadSecretBytes))
232245
// Using UUID of the LUKS device ensures to not derive the same encryption key for multiple devices,
233246
// still allowing reconstruction when UUID of device is known.
234247
err = os.WriteFile(luksVolume.encryptionPassphrase, []byte(blk.UUID+string(workloadSecretBytes)), 0o644)

0 commit comments

Comments
 (0)