2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-04-11 08:25:19 -04:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
2023-09-25 04:23:35 -04:00
|
|
|
"context"
|
2022-04-11 08:25:19 -04:00
|
|
|
"io/fs"
|
|
|
|
"os"
|
2022-09-08 08:45:27 -04:00
|
|
|
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
2022-04-11 08:25:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Mounter is an interface for mount and unmount operations.
|
|
|
|
type Mounter interface {
|
|
|
|
Mount(source string, target string, fstype string, flags uintptr, data string) error
|
|
|
|
Unmount(target string, flags int) error
|
|
|
|
MkdirAll(path string, perm fs.FileMode) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeviceMapper is an interface for device mapping operations.
|
|
|
|
type DeviceMapper interface {
|
2023-07-17 07:55:31 -04:00
|
|
|
DiskUUID() (string, error)
|
2022-04-11 08:25:19 -04:00
|
|
|
FormatDisk(passphrase string) error
|
|
|
|
MapDisk(target string, passphrase string) error
|
2022-08-15 08:50:03 -04:00
|
|
|
UnmapDisk(target string) error
|
2022-04-11 08:25:19 -04:00
|
|
|
}
|
|
|
|
|
2022-08-15 08:50:03 -04:00
|
|
|
// ConfigurationGenerator is an interface for generating systemd-cryptsetup@.service unit files.
|
|
|
|
type ConfigurationGenerator interface {
|
|
|
|
Generate(volumeName, encryptedDevice, keyFile, options string) error
|
|
|
|
}
|
|
|
|
|
2022-09-08 08:45:27 -04:00
|
|
|
// MetadataAPI is an interface for accessing cloud metadata.
|
|
|
|
type MetadataAPI interface {
|
|
|
|
metadata.InstanceSelfer
|
|
|
|
metadata.InstanceLister
|
2023-09-25 04:23:35 -04:00
|
|
|
GetLoadBalancerEndpoint(ctx context.Context) (host, port string, err error)
|
2022-09-08 08:45:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// RecoveryDoer is an interface to perform key recovery operations.
|
|
|
|
// Calls to Do may be blocking, and if successful return a passphrase and measurementSecret.
|
|
|
|
type RecoveryDoer interface {
|
|
|
|
Do(uuid, endpoint string) (passphrase, measurementSecret []byte, err error)
|
|
|
|
}
|
|
|
|
|
2022-04-11 08:25:19 -04:00
|
|
|
// DiskMounter uses the syscall package to mount disks.
|
|
|
|
type DiskMounter struct{}
|
|
|
|
|
|
|
|
// MkdirAll uses os.MkdirAll to create the directory.
|
|
|
|
func (m DiskMounter) MkdirAll(path string, perm fs.FileMode) error {
|
|
|
|
return os.MkdirAll(path, perm)
|
|
|
|
}
|