2022-09-05 03:06:08 -04:00
/ *
Copyright ( c ) Edgeless Systems GmbH
SPDX - License - Identifier : AGPL - 3.0 - only
* /
2022-05-16 12:54:25 -04:00
// This binary can be build from siderolabs/talos projects. Located at:
// https://github.com/siderolabs/talos/tree/master/hack/docgen
2022-08-05 09:30:23 -04:00
//
//go:generate docgen ./config.go ./config_doc.go Configuration
2023-01-19 09:57:50 -05:00
/ *
Definitions for Constellation ' s user config file .
The config file is used by the CLI to create and manage a Constellation cluster .
All config relevant definitions , parsing and validation functions should go here .
* /
2022-03-22 11:03:15 -04:00
package config
import (
2023-06-05 09:46:55 -04:00
"context"
2022-05-13 05:56:43 -04:00
"errors"
2022-03-22 11:03:15 -04:00
"fmt"
2022-05-13 05:56:43 -04:00
"io/fs"
2022-11-15 09:40:49 -05:00
"os"
2023-03-29 08:04:37 -04:00
"reflect"
2022-11-22 12:47:08 -05:00
"strings"
2022-03-22 11:03:15 -04:00
2023-04-05 10:49:03 -04:00
"github.com/go-playground/locales/en"
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
en_translations "github.com/go-playground/validator/v10/translations/en"
2023-06-14 11:50:57 -04:00
"gopkg.in/yaml.v3"
2023-04-05 10:49:03 -04:00
2023-06-07 10:16:32 -04:00
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi"
2023-06-19 10:51:39 -04:00
"github.com/edgelesssys/constellation/v2/internal/api/versionsapi"
2023-01-18 10:49:55 -05:00
"github.com/edgelesssys/constellation/v2/internal/attestation/idkeydigest"
2022-11-15 09:40:49 -05:00
"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
2023-06-09 09:41:02 -04:00
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
2022-09-21 07:47:57 -04:00
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
2023-04-03 12:09:03 -04:00
"github.com/edgelesssys/constellation/v2/internal/config/imageversion"
2022-11-15 09:40:49 -05:00
"github.com/edgelesssys/constellation/v2/internal/constants"
2024-01-24 09:10:15 -05:00
"github.com/edgelesssys/constellation/v2/internal/encoding"
2022-09-21 07:47:57 -04:00
"github.com/edgelesssys/constellation/v2/internal/file"
2023-07-25 08:20:25 -04:00
"github.com/edgelesssys/constellation/v2/internal/semver"
2022-09-21 07:47:57 -04:00
"github.com/edgelesssys/constellation/v2/internal/versions"
2022-03-22 11:03:15 -04:00
)
2022-05-18 12:10:57 -04:00
const (
2023-08-02 04:23:15 -04:00
// Version4 is the fourth version number for Constellation config file.
Version4 = "v4"
2023-02-17 03:05:42 -05:00
defaultName = "constell"
2023-06-30 10:46:05 -04:00
appRegistrationErrStr = "Azure app registrations are not supported since v2.9. Migrate to using a user assigned managed identity by following the migration guide: https://docs.edgeless.systems/constellation/reference/migration.\nPlease remove it from your config and from the Kubernetes secret in your running cluster. Ensure that the UAMI has all required permissions."
2022-05-18 12:10:57 -04:00
)
2022-05-16 12:54:25 -04:00
// Config defines configuration used by CLI.
type Config struct {
2022-05-18 12:10:57 -04:00
// description: |
// Schema version of this configuration file.
2023-08-02 04:23:15 -04:00
Version string ` yaml:"version" validate:"eq=v4" `
2022-05-16 12:54:25 -04:00
// description: |
2023-02-10 07:27:22 -05:00
// Machine image version used to create Constellation nodes.
2023-07-25 08:20:25 -04:00
Image string ` yaml:"image" validate:"required,image_compatibility" `
2022-11-22 12:47:08 -05:00
// description: |
2023-02-10 07:27:22 -05:00
// Name of the cluster.
2023-03-31 13:19:10 -04:00
Name string ` yaml:"name" validate:"valid_name,required" `
2023-02-10 07:27:22 -05:00
// description: |
2023-01-31 06:12:19 -05:00
// Kubernetes version to be installed into the cluster.
2023-09-19 07:50:00 -04:00
KubernetesVersion versions . ValidK8sVersion ` yaml:"kubernetesVersion" validate:"required,supported_k8s_version" `
2022-09-11 10:09:05 -04:00
// description: |
2023-03-31 13:19:10 -04:00
// Microservice version to be installed into the cluster. Defaults to the version of the CLI.
2023-07-25 08:20:25 -04:00
MicroserviceVersion semver . Semver ` yaml:"microserviceVersion" validate:"required" `
2023-01-31 06:12:19 -05:00
// description: |
2023-07-05 10:44:57 -04:00
// DON'T USE IN PRODUCTION: enable debug mode and use debug images.
2022-09-05 10:53:37 -04:00
DebugCluster * bool ` yaml:"debugCluster" validate:"required" `
2022-05-16 12:54:25 -04:00
// description: |
2023-07-21 10:43:51 -04:00
// Optional custom endpoint (DNS name) for the Constellation API server.
// This can be used to point a custom dns name at the Constellation API server
// and is added to the Subject Alternative Name (SAN) field of the TLS certificate used by the API server.
// A fallback to DNS name is always available.
CustomEndpoint string ` yaml:"customEndpoint" validate:"omitempty,hostname_rfc1123" `
2023-08-02 10:01:10 -04:00
// description: |
2023-10-17 09:46:15 -04:00
// Flag to enable/disable the internal load balancer. If enabled, the Constellation is only accessible from within the VPC.
InternalLoadBalancer bool ` yaml:"internalLoadBalancer" validate:"omitempty" `
// description: |
2023-12-01 08:39:05 -05:00
// The Kubernetes Service CIDR to be used for the cluster. This value will only be used during the first initialization of the Constellation.
ServiceCIDR string ` yaml:"serviceCIDR" validate:"omitempty,cidrv4" `
// description: |
2024-04-19 05:07:57 -04:00
// Additional tags that are applied to created resources.
Tags cloudprovider . Tags ` yaml:"tags" validate:"omitempty" `
// description: |
2023-08-02 10:01:10 -04:00
// Supported cloud providers and their specific configurations.
Provider ProviderConfig ` yaml:"provider" validate:"dive" `
// description: |
2023-08-02 04:23:15 -04:00
// Node groups to be created in the cluster.
NodeGroups map [ string ] NodeGroup ` yaml:"nodeGroups" validate:"required,dive" `
// description: |
2023-08-02 10:01:10 -04:00
// Configuration for attestation validation. This configuration provides sensible defaults for the Constellation version it was created for.\nSee the docs for an overview on attestation: https://docs.edgeless.systems/constellation/architecture/attestation
Attestation AttestationConfig ` yaml:"attestation" validate:"dive" `
2022-05-17 04:52:37 -04:00
}
2022-05-16 12:54:25 -04:00
// ProviderConfig are cloud-provider specific configuration values used by the CLI.
// Fields should remain pointer-types so custom specific configs can nil them
// if not required.
type ProviderConfig struct {
2022-10-21 06:24:18 -04:00
// description: |
// Configuration for AWS as provider.
AWS * AWSConfig ` yaml:"aws,omitempty" validate:"omitempty,dive" `
2022-05-16 12:54:25 -04:00
// description: |
// Configuration for Azure as provider.
2022-05-24 05:57:48 -04:00
Azure * AzureConfig ` yaml:"azure,omitempty" validate:"omitempty,dive" `
2022-05-16 12:54:25 -04:00
// description: |
// Configuration for Google Cloud as provider.
2022-05-24 05:57:48 -04:00
GCP * GCPConfig ` yaml:"gcp,omitempty" validate:"omitempty,dive" `
2022-05-16 12:54:25 -04:00
// description: |
2023-02-27 12:19:52 -05:00
// Configuration for OpenStack as provider.
OpenStack * OpenStackConfig ` yaml:"openstack,omitempty" validate:"omitempty,dive" `
// description: |
2022-05-16 12:54:25 -04:00
// Configuration for QEMU as provider.
2022-05-24 05:57:48 -04:00
QEMU * QEMUConfig ` yaml:"qemu,omitempty" validate:"omitempty,dive" `
2022-05-16 12:54:25 -04:00
}
2022-10-21 06:24:18 -04:00
// AWSConfig are AWS specific configuration values used by the CLI.
type AWSConfig struct {
// description: |
// AWS data center region. See: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions
2023-07-04 07:55:52 -04:00
Region string ` yaml:"region" validate:"required,aws_region" `
2022-10-21 06:24:18 -04:00
// description: |
// AWS data center zone name in defined region. See: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-availability-zones
2023-07-04 07:55:52 -04:00
Zone string ` yaml:"zone" validate:"required,aws_zone" `
2022-10-21 06:24:18 -04:00
// description: |
2023-07-05 10:44:57 -04:00
// Name of the IAM profile to use for the control-plane nodes.
2022-10-21 06:24:18 -04:00
IAMProfileControlPlane string ` yaml:"iamProfileControlPlane" validate:"required" `
// description: |
// Name of the IAM profile to use for the worker nodes.
IAMProfileWorkerNodes string ` yaml:"iamProfileWorkerNodes" validate:"required" `
2023-06-30 02:46:32 -04:00
// description: |
// Deploy Persistent Disk CSI driver with on-node encryption. For details see: https://docs.edgeless.systems/constellation/architecture/encrypted-storage
2023-09-08 15:15:02 -04:00
DeployCSIDriver * bool ` yaml:"deployCSIDriver" validate:"required" `
2024-02-06 06:13:59 -05:00
// description: |
// Use the specified AWS Marketplace image offering.
UseMarketplaceImage * bool ` yaml:"useMarketplaceImage" validate:"omitempty" `
2022-10-21 06:24:18 -04:00
}
2022-05-16 12:54:25 -04:00
// AzureConfig are Azure specific configuration values used by the CLI.
type AzureConfig struct {
// description: |
// Subscription ID of the used Azure account. See: https://docs.microsoft.com/en-us/azure/azure-portal/get-subscription-tenant-id#find-your-azure-subscription
2022-05-23 09:01:39 -04:00
SubscriptionID string ` yaml:"subscription" validate:"uuid" `
2022-05-16 12:54:25 -04:00
// description: |
// Tenant ID of the used Azure account. See: https://docs.microsoft.com/en-us/azure/azure-portal/get-subscription-tenant-id#find-your-azure-ad-tenant
2022-05-23 09:01:39 -04:00
TenantID string ` yaml:"tenant" validate:"uuid" `
2022-05-16 12:54:25 -04:00
// description: |
// Azure datacenter region to be used. See: https://docs.microsoft.com/en-us/azure/availability-zones/az-overview#azure-regions-with-availability-zones
2022-05-23 09:01:39 -04:00
Location string ` yaml:"location" validate:"required" `
2022-05-16 12:54:25 -04:00
// description: |
2022-09-11 10:09:05 -04:00
// Resource group for the cluster's resources. Must already exist.
2022-08-25 09:12:08 -04:00
ResourceGroup string ` yaml:"resourceGroup" validate:"required" `
// description: |
2022-09-02 11:11:06 -04:00
// Authorize spawned VMs to access Azure API.
UserAssignedIdentity string ` yaml:"userAssignedIdentity" validate:"required" `
// description: |
2022-11-18 04:05:02 -05:00
// Deploy Azure Disk CSI driver with on-node encryption. For details see: https://docs.edgeless.systems/constellation/architecture/encrypted-storage
DeployCSIDriver * bool ` yaml:"deployCSIDriver" validate:"required" `
2022-08-29 08:18:05 -04:00
// description: |
2022-11-18 04:05:02 -05:00
// Enable secure boot for VMs. If enabled, the OS image has to include a virtual machine guest state (VMGS) blob.
SecureBoot * bool ` yaml:"secureBoot" validate:"required" `
2023-12-08 08:40:31 -05:00
// description: |
// Use the specified Azure Marketplace image offering.
UseMarketplaceImage * bool ` yaml:"useMarketplaceImage" validate:"omitempty" `
2022-05-16 12:54:25 -04:00
}
// GCPConfig are GCP specific configuration values used by the CLI.
type GCPConfig struct {
// description: |
// GCP project. See: https://support.google.com/googleapi/answer/7014113?hl=en
2022-05-23 09:01:39 -04:00
Project string ` yaml:"project" validate:"required" `
2022-05-16 12:54:25 -04:00
// description: |
// GCP datacenter region. See: https://cloud.google.com/compute/docs/regions-zones#available
2022-05-23 09:01:39 -04:00
Region string ` yaml:"region" validate:"required" `
2022-05-16 12:54:25 -04:00
// description: |
// GCP datacenter zone. See: https://cloud.google.com/compute/docs/regions-zones#available
2022-05-23 09:01:39 -04:00
Zone string ` yaml:"zone" validate:"required" `
2022-05-16 12:54:25 -04:00
// description: |
2022-09-11 10:09:05 -04:00
// Path of service account key file. For required service account roles, see https://docs.edgeless.systems/constellation/getting-started/install#authorization
ServiceAccountKeyPath string ` yaml:"serviceAccountKeyPath" validate:"required" `
// description: |
2022-11-18 04:05:02 -05:00
// Deploy Persistent Disk CSI driver with on-node encryption. For details see: https://docs.edgeless.systems/constellation/architecture/encrypted-storage
DeployCSIDriver * bool ` yaml:"deployCSIDriver" validate:"required" `
2024-01-08 09:51:39 -05:00
// description: |
// Use the specified GCP Marketplace image offering.
UseMarketplaceImage * bool ` yaml:"useMarketplaceImage" validate:"omitempty" `
2022-05-16 12:54:25 -04:00
}
2023-02-27 12:19:52 -05:00
// OpenStackConfig holds config information for OpenStack based Constellation deployments.
type OpenStackConfig struct {
// description: |
// OpenStack cloud name to select from "clouds.yaml". Only required if config file for OpenStack is used. Fallback authentication uses environment variables. For details see: https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html.
Cloud string ` yaml:"cloud" `
// description: |
2024-03-11 09:20:19 -04:00
// Path to OpenStack "clouds.yaml" file. Only required if automatic detection fails.
CloudsYAMLPath string ` yaml:"cloudsYAMLPath" `
// description: |
2023-02-27 12:19:52 -05:00
// Availability zone to place the VMs in. For details see: https://docs.openstack.org/nova/latest/admin/availability-zones.html
AvailabilityZone string ` yaml:"availabilityZone" validate:"required" `
// description: |
// Floating IP pool to use for the VMs. For details see: https://docs.openstack.org/ocata/user-guide/cli-manage-ip-addresses.html
FloatingIPPoolID string ` yaml:"floatingIPPoolID" validate:"required" `
// description: |
2024-02-22 11:39:34 -05:00
// STACKITProjectID is the ID of the STACKIT project where a user resides.
// Only used if cloud is "stackit".
STACKITProjectID string ` yaml:"stackitProjectID" `
// description: |
2023-03-17 04:34:25 -04:00
// RegionName is the name of the region to use inside the cluster.
RegionName string ` yaml:"regionName" validate:"required" `
// description: |
2023-05-02 03:35:52 -04:00
// Deploy Yawol loadbalancer. For details see: https://github.com/stackitcloud/yawol
DeployYawolLoadBalancer * bool ` yaml:"deployYawolLoadBalancer" validate:"required" `
// description: |
// OpenStack OS image used by the yawollet. For details see: https://github.com/stackitcloud/yawol
YawolImageID string ` yaml:"yawolImageID" `
// description: |
// OpenStack flavor id used for yawollets. For details see: https://github.com/stackitcloud/yawol
YawolFlavorID string ` yaml:"yawolFlavorID" `
2023-05-08 13:44:06 -04:00
// description: |
// Deploy Cinder CSI driver with on-node encryption. For details see: https://docs.edgeless.systems/constellation/architecture/encrypted-storage
DeployCSIDriver * bool ` yaml:"deployCSIDriver" validate:"required" `
2023-02-27 12:19:52 -05:00
}
2022-11-09 09:57:54 -05:00
// QEMUConfig holds config information for QEMU based Constellation deployments.
2022-05-16 12:54:25 -04:00
type QEMUConfig struct {
2022-09-26 09:52:31 -04:00
// description: |
// Format of the image to use for the VMs. Should be either qcow2 or raw.
ImageFormat string ` yaml:"imageFormat" validate:"oneof=qcow2 raw" `
// description: |
// vCPU count for the VMs.
VCPUs int ` yaml:"vcpus" validate:"required" `
// description: |
// Amount of memory per instance (MiB).
Memory int ` yaml:"memory" validate:"required" `
// description: |
// Container image to use for the QEMU metadata server.
MetadataAPIImage string ` yaml:"metadataAPIServer" validate:"required" `
2022-05-16 12:54:25 -04:00
// description: |
2022-10-05 03:11:30 -04:00
// Libvirt connection URI. Leave empty to start a libvirt instance in Docker.
LibvirtURI string ` yaml:"libvirtSocket" `
// description: |
// Container image to use for launching a containerized libvirt daemon. Only relevant if `libvirtSocket = ""`.
LibvirtContainerImage string ` yaml:"libvirtContainerImage" `
// description: |
2022-10-19 07:10:15 -04:00
// NVRAM template to be used for secure boot. Can be sentinel value "production", "testing" or a path to a custom NVRAM template
NVRAM string ` yaml:"nvram" validate:"required" `
// description: |
// Path to the OVMF firmware. Leave empty for auto selection.
Firmware string ` yaml:"firmware" `
2023-05-03 05:11:53 -04:00
}
// AttestationConfig configuration values used for attestation.
// Fields should remain pointer-types so custom specific configs can nil them
// if not required.
type AttestationConfig struct {
2023-06-09 09:41:02 -04:00
// description: |
2023-11-28 06:44:31 -05:00
// AWS SEV-SNP attestation.
2023-06-09 09:41:02 -04:00
AWSSEVSNP * AWSSEVSNP ` yaml:"awsSEVSNP,omitempty" validate:"omitempty,dive" `
2022-10-21 10:08:52 -04:00
// description: |
2023-05-03 05:11:53 -04:00
// AWS Nitro TPM attestation.
AWSNitroTPM * AWSNitroTPM ` yaml:"awsNitroTPM,omitempty" validate:"omitempty,dive" `
// description: |
2023-06-01 06:33:06 -04:00
// Azure SEV-SNP attestation.\nFor details see: https://docs.edgeless.systems/constellation/architecture/attestation#cvm-verification
2023-05-03 05:11:53 -04:00
AzureSEVSNP * AzureSEVSNP ` yaml:"azureSEVSNP,omitempty" validate:"omitempty,dive" `
// description: |
2024-01-24 09:10:15 -05:00
// Azure TDX attestation.
AzureTDX * AzureTDX ` yaml:"azureTDX,omitempty" validate:"omitempty,dive" `
// description: |
2023-05-03 05:11:53 -04:00
// Azure TPM attestation (Trusted Launch).
AzureTrustedLaunch * AzureTrustedLaunch ` yaml:"azureTrustedLaunch,omitempty" validate:"omitempty,dive" `
// description: |
// GCP SEV-ES attestation.
GCPSEVES * GCPSEVES ` yaml:"gcpSEVES,omitempty" validate:"omitempty,dive" `
// description: |
2024-04-16 12:13:47 -04:00
// GCP SEV-SNP attestation.
GCPSEVSNP * GCPSEVSNP ` yaml:"gcpSEVSNP,omitempty" validate:"omitempty,dive" `
// description: |
2023-05-04 04:51:28 -04:00
// QEMU tdx attestation.
QEMUTDX * QEMUTDX ` yaml:"qemuTDX,omitempty" validate:"omitempty,dive" `
// description: |
2023-05-03 05:11:53 -04:00
// QEMU vTPM attestation.
QEMUVTPM * QEMUVTPM ` yaml:"qemuVTPM,omitempty" validate:"omitempty,dive" `
2022-03-22 11:03:15 -04:00
}
2023-08-02 04:23:15 -04:00
// NodeGroup defines a group of nodes with the same role and configuration.
// Cloud providers use scaling groups to manage nodes of a group.
type NodeGroup struct {
// description: |
// Role of the nodes in this group. Valid values are "control-plane" and "worker".
Role string ` yaml:"role" validate:"required,oneof=control-plane worker" `
// description: |
// Availability zone to place the VMs in.
Zone string ` yaml:"zone" validate:"valid_zone" `
// description: |
// VM instance type to use for the nodes.
InstanceType string ` yaml:"instanceType" validate:"instance_type" `
// description: |
// Size (in GB) of a node's disk to store the non-volatile state.
StateDiskSizeGB int ` yaml:"stateDiskSizeGB" validate:"min=0" `
// description: |
// Type of a node's state disk. The type influences boot time and I/O performance.
StateDiskType string ` yaml:"stateDiskType" validate:"disk_type" `
// description: |
// Number of nodes to be initially created.
InitialCount int ` yaml:"initialCount" validate:"min=0" `
}
2022-03-22 11:03:15 -04:00
// Default returns a struct with the default config.
2023-06-28 04:28:48 -04:00
// IMPORTANT: Ensure that any state mutation is followed by a call to Validate() to ensure that the config is always in a valid state. Avoid usage outside of tests.
2022-03-22 11:03:15 -04:00
func Default ( ) * Config {
return & Config {
2023-08-02 04:23:15 -04:00
Version : Version4 ,
2023-01-31 06:12:19 -05:00
Image : defaultImage ,
2023-02-17 03:05:42 -05:00
Name : defaultName ,
2023-07-25 08:20:25 -04:00
MicroserviceVersion : constants . BinaryVersion ( ) ,
2023-09-19 07:50:00 -04:00
KubernetesVersion : versions . Default ,
2023-02-28 12:44:21 -05:00
DebugCluster : toPtr ( false ) ,
2023-12-01 08:39:05 -05:00
ServiceCIDR : "10.96.0.0/12" ,
2024-04-19 05:07:57 -04:00
Tags : cloudprovider . Tags { } ,
2022-05-16 12:54:25 -04:00
Provider : ProviderConfig {
2022-10-21 06:24:18 -04:00
AWS : & AWSConfig {
Region : "" ,
IAMProfileControlPlane : "" ,
IAMProfileWorkerNodes : "" ,
2023-06-30 02:46:32 -04:00
DeployCSIDriver : toPtr ( true ) ,
2024-02-06 06:13:59 -05:00
UseMarketplaceImage : toPtr ( false ) ,
2022-10-21 06:24:18 -04:00
} ,
2022-03-22 11:03:15 -04:00
Azure : & AzureConfig {
2022-08-08 05:04:17 -04:00
SubscriptionID : "" ,
TenantID : "" ,
Location : "" ,
UserAssignedIdentity : "" ,
2022-08-25 09:12:08 -04:00
ResourceGroup : "" ,
2023-02-28 12:44:21 -05:00
DeployCSIDriver : toPtr ( true ) ,
SecureBoot : toPtr ( false ) ,
2023-12-11 02:15:47 -05:00
UseMarketplaceImage : toPtr ( false ) ,
2022-03-22 11:03:15 -04:00
} ,
GCP : & GCPConfig {
2022-08-23 11:49:55 -04:00
Project : "" ,
Region : "" ,
Zone : "" ,
2022-11-18 04:05:02 -05:00
ServiceAccountKeyPath : "" ,
2023-02-28 12:44:21 -05:00
DeployCSIDriver : toPtr ( true ) ,
2024-01-08 09:51:39 -05:00
UseMarketplaceImage : toPtr ( false ) ,
2022-03-22 11:03:15 -04:00
} ,
2023-02-27 12:19:52 -05:00
OpenStack : & OpenStackConfig {
2023-05-02 03:35:52 -04:00
DeployYawolLoadBalancer : toPtr ( true ) ,
2023-05-08 13:44:06 -04:00
DeployCSIDriver : toPtr ( true ) ,
2023-02-27 12:19:52 -05:00
} ,
2022-05-02 04:54:54 -04:00
QEMU : & QEMUConfig {
2022-11-08 12:32:59 -05:00
ImageFormat : "raw" ,
2022-10-05 03:11:30 -04:00
VCPUs : 2 ,
Memory : 2048 ,
2023-04-03 12:09:03 -04:00
MetadataAPIImage : imageversion . QEMUMetadata ( ) ,
2022-10-05 03:11:30 -04:00
LibvirtURI : "" ,
2023-04-03 12:09:03 -04:00
LibvirtContainerImage : imageversion . Libvirt ( ) ,
2022-11-18 04:05:02 -05:00
NVRAM : "production" ,
2022-05-02 04:54:54 -04:00
} ,
2022-03-22 11:03:15 -04:00
} ,
2023-08-02 04:23:15 -04:00
NodeGroups : map [ string ] NodeGroup {
constants . DefaultControlPlaneGroupName : {
Role : "control-plane" ,
Zone : "" ,
InstanceType : "" ,
StateDiskSizeGB : 30 ,
StateDiskType : "" ,
InitialCount : 3 ,
} ,
constants . DefaultWorkerGroupName : {
Role : "worker" ,
Zone : "" ,
InstanceType : "" ,
StateDiskSizeGB : 30 ,
StateDiskType : "" ,
InitialCount : 1 ,
} ,
} ,
2023-05-04 04:51:28 -04:00
// TODO(malt3): remove default attestation config as soon as one-to-one mapping is no longer possible.
// Some problematic pairings:
// OpenStack uses qemu-vtpm as attestation variant
// QEMU uses qemu-vtpm as attestation variant
// AWS uses aws-nitro-tpm as attestation variant
// AWS will have aws-sev-snp as attestation variant
2023-05-03 05:11:53 -04:00
Attestation : AttestationConfig {
2023-11-06 08:22:44 -05:00
AWSSEVSNP : DefaultForAWSSEVSNP ( ) ,
2023-05-04 04:51:28 -04:00
AWSNitroTPM : & AWSNitroTPM { Measurements : measurements . DefaultsFor ( cloudprovider . AWS , variant . AWSNitroTPM { } ) } ,
2023-05-03 05:11:53 -04:00
AzureSEVSNP : DefaultForAzureSEVSNP ( ) ,
2024-01-24 09:10:15 -05:00
AzureTDX : DefaultForAzureTDX ( ) ,
2023-05-04 04:51:28 -04:00
AzureTrustedLaunch : & AzureTrustedLaunch { Measurements : measurements . DefaultsFor ( cloudprovider . Azure , variant . AzureTrustedLaunch { } ) } ,
GCPSEVES : & GCPSEVES { Measurements : measurements . DefaultsFor ( cloudprovider . GCP , variant . GCPSEVES { } ) } ,
2024-04-16 12:13:47 -04:00
GCPSEVSNP : DefaultForGCPSEVSNP ( ) ,
2023-05-04 04:51:28 -04:00
QEMUVTPM : & QEMUVTPM { Measurements : measurements . DefaultsFor ( cloudprovider . QEMU , variant . QEMUVTPM { } ) } ,
2023-05-03 05:11:53 -04:00
} ,
2022-03-22 11:03:15 -04:00
}
}
2023-06-28 04:28:48 -04:00
// MiniDefault returns a default config for a mini cluster.
func MiniDefault ( ) ( * Config , error ) {
config := Default ( )
config . Name = constants . MiniConstellationUID
config . RemoveProviderAndAttestationExcept ( cloudprovider . QEMU )
2023-08-02 04:23:15 -04:00
for groupName , group := range config . NodeGroups {
group . StateDiskSizeGB = 8
group . InitialCount = 1
config . NodeGroups [ groupName ] = group
}
2023-06-28 04:28:48 -04:00
// only release images (e.g. v2.7.0) use the production NVRAM
if ! config . IsReleaseImage ( ) {
config . Provider . QEMU . NVRAM = "testing"
}
return config , config . Validate ( false )
}
2023-01-31 06:12:19 -05:00
// fromFile returns config file with `name` read from `fileHandler` by parsing
2022-11-15 09:40:49 -05:00
// it as YAML. You should prefer config.New to read env vars and validate
// config in a consistent manner.
2023-01-31 06:12:19 -05:00
func fromFile ( fileHandler file . Handler , name string ) ( * Config , error ) {
2022-11-15 09:40:49 -05:00
var conf Config
if err := fileHandler . ReadYAMLStrict ( name , & conf ) ; err != nil {
if errors . Is ( err , fs . ErrNotExist ) {
return nil , fmt . Errorf ( "unable to find %s - use `constellation config generate` to generate it first" , name )
}
2023-06-14 11:50:57 -04:00
if isAppClientIDError ( err ) {
2023-06-30 10:46:05 -04:00
return nil , & UnsupportedAppRegistrationError { }
2023-06-14 11:50:57 -04:00
}
2022-11-15 09:40:49 -05:00
return nil , fmt . Errorf ( "could not load config from file %s: %w" , name , err )
2022-09-07 05:53:44 -04:00
}
2022-11-15 09:40:49 -05:00
return & conf , nil
2022-09-07 05:53:44 -04:00
}
2023-06-14 11:50:57 -04:00
func isAppClientIDError ( err error ) bool {
var yamlErr * yaml . TypeError
if errors . As ( err , & yamlErr ) {
for _ , e := range yamlErr . Errors {
if strings . Contains ( e , "appClientID" ) {
return true
}
}
}
return false
}
// UnsupportedAppRegistrationError is returned when the config contains configuration related to now unsupported app registrations.
type UnsupportedAppRegistrationError struct { }
2023-06-30 10:46:05 -04:00
func ( e * UnsupportedAppRegistrationError ) Error ( ) string {
return appRegistrationErrStr
2023-06-14 11:50:57 -04:00
}
2022-11-15 09:40:49 -05:00
// New creates a new config by:
// 1. Reading config file via provided fileHandler from file with name.
2023-05-25 12:43:44 -04:00
// 2. For "latest" version values of the attestation variants fetch the version numbers.
// 3. Read secrets from environment variables.
// 4. Validate config. If `--force` is set the version validation will be disabled and any version combination is allowed.
2023-06-09 06:48:12 -04:00
func New ( fileHandler file . Handler , name string , fetcher attestationconfigapi . Fetcher , force bool ) ( * Config , error ) {
2022-11-15 09:40:49 -05:00
// Read config file
2023-01-31 06:12:19 -05:00
c , err := fromFile ( fileHandler , name )
2022-11-15 09:40:49 -05:00
if err != nil {
2022-08-31 11:35:33 -04:00
return nil , err
}
2023-06-01 07:55:46 -04:00
2023-06-09 06:48:12 -04:00
if azure := c . Attestation . AzureSEVSNP ; azure != nil {
2023-09-25 05:53:02 -04:00
if err := azure . FetchAndSetLatestVersionNumbers ( context . Background ( ) , fetcher ) ; err != nil {
2023-06-09 06:48:12 -04:00
return c , err
}
}
2022-08-31 11:35:33 -04:00
2023-11-08 07:54:18 -05:00
if aws := c . Attestation . AWSSEVSNP ; aws != nil {
if err := aws . FetchAndSetLatestVersionNumbers ( context . Background ( ) , fetcher ) ; err != nil {
return c , err
}
}
2024-04-16 12:13:47 -04:00
if gcp := c . Attestation . GCPSEVSNP ; gcp != nil {
if err := gcp . FetchAndSetLatestVersionNumbers ( context . Background ( ) , fetcher ) ; err != nil {
return c , err
}
}
2022-11-15 09:40:49 -05:00
// Read secrets from env-vars.
clientSecretValue := os . Getenv ( constants . EnvVarAzureClientSecretValue )
if clientSecretValue != "" && c . Provider . Azure != nil {
2023-06-30 10:46:05 -04:00
fmt . Fprintf ( os . Stderr , "WARNING: the environment variable %s is no longer used %s" , constants . EnvVarAzureClientSecretValue , appRegistrationErrStr )
2022-05-23 09:01:39 -04:00
}
2023-01-31 05:45:31 -05:00
return c , c . Validate ( force )
2022-09-07 05:53:44 -04:00
}
2022-05-23 09:01:39 -04:00
// HasProvider checks whether the config contains the provider.
func ( c * Config ) HasProvider ( provider cloudprovider . Provider ) bool {
switch provider {
2022-10-21 06:24:18 -04:00
case cloudprovider . AWS :
return c . Provider . AWS != nil
2022-05-23 09:01:39 -04:00
case cloudprovider . Azure :
return c . Provider . Azure != nil
case cloudprovider . GCP :
return c . Provider . GCP != nil
2023-04-05 10:49:03 -04:00
case cloudprovider . OpenStack :
return c . Provider . OpenStack != nil
2022-05-23 09:01:39 -04:00
case cloudprovider . QEMU :
return c . Provider . QEMU != nil
}
return false
}
2022-11-09 09:57:54 -05:00
// UpdateMeasurements overwrites measurements in config with the provided ones.
2023-05-03 05:11:53 -04:00
func ( c * Config ) UpdateMeasurements ( newMeasurements measurements . M ) {
2023-06-09 09:41:02 -04:00
if c . Attestation . AWSSEVSNP != nil {
c . Attestation . AWSSEVSNP . Measurements . CopyFrom ( newMeasurements )
}
2023-05-03 05:11:53 -04:00
if c . Attestation . AWSNitroTPM != nil {
c . Attestation . AWSNitroTPM . Measurements . CopyFrom ( newMeasurements )
2022-10-21 06:24:18 -04:00
}
2023-05-03 05:11:53 -04:00
if c . Attestation . AzureSEVSNP != nil {
c . Attestation . AzureSEVSNP . Measurements . CopyFrom ( newMeasurements )
2022-08-01 03:37:05 -04:00
}
2024-01-24 09:10:15 -05:00
if c . Attestation . AzureTDX != nil {
c . Attestation . AzureTDX . Measurements . CopyFrom ( newMeasurements )
}
2023-05-03 05:11:53 -04:00
if c . Attestation . AzureTrustedLaunch != nil {
c . Attestation . AzureTrustedLaunch . Measurements . CopyFrom ( newMeasurements )
2022-08-01 03:37:05 -04:00
}
2023-05-03 05:11:53 -04:00
if c . Attestation . GCPSEVES != nil {
c . Attestation . GCPSEVES . Measurements . CopyFrom ( newMeasurements )
2023-04-05 10:49:03 -04:00
}
2024-04-16 12:13:47 -04:00
if c . Attestation . GCPSEVSNP != nil {
c . Attestation . GCPSEVSNP . Measurements . CopyFrom ( newMeasurements )
}
2023-05-03 05:11:53 -04:00
if c . Attestation . QEMUVTPM != nil {
c . Attestation . QEMUVTPM . Measurements . CopyFrom ( newMeasurements )
2022-08-01 03:37:05 -04:00
}
}
2023-05-17 10:53:56 -04:00
// RemoveProviderAndAttestationExcept calls RemoveProviderExcept and sets the default attestations for the provider (only used for convenience in tests).
func ( c * Config ) RemoveProviderAndAttestationExcept ( provider cloudprovider . Provider ) {
c . RemoveProviderExcept ( provider )
c . SetAttestation ( variant . GetDefaultAttestation ( provider ) )
2024-01-25 10:22:14 -05:00
c . SetCSPNodeGroupDefaults ( provider )
2023-05-17 10:53:56 -04:00
}
2022-05-18 05:39:14 -04:00
// RemoveProviderExcept removes all provider specific configurations, i.e.,
// sets them to nil, except the one specified.
// If an unknown provider is passed, the same configuration is returned.
func ( c * Config ) RemoveProviderExcept ( provider cloudprovider . Provider ) {
currentProviderConfigs := c . Provider
c . Provider = ProviderConfig { }
2023-05-03 05:11:53 -04:00
2022-05-18 05:39:14 -04:00
switch provider {
2022-10-21 06:24:18 -04:00
case cloudprovider . AWS :
c . Provider . AWS = currentProviderConfigs . AWS
2022-05-18 05:39:14 -04:00
case cloudprovider . Azure :
c . Provider . Azure = currentProviderConfigs . Azure
case cloudprovider . GCP :
c . Provider . GCP = currentProviderConfigs . GCP
2023-02-27 12:19:52 -05:00
case cloudprovider . OpenStack :
c . Provider . OpenStack = currentProviderConfigs . OpenStack
2022-05-18 05:39:14 -04:00
case cloudprovider . QEMU :
c . Provider . QEMU = currentProviderConfigs . QEMU
default :
c . Provider = currentProviderConfigs
2023-05-17 10:53:56 -04:00
}
}
// SetAttestation sets the attestation config for the given attestation variant and removes all other attestation configs.
func ( c * Config ) SetAttestation ( attestation variant . Variant ) {
2023-08-02 04:23:15 -04:00
currentAttestationConfigs := c . Attestation
2023-05-17 10:53:56 -04:00
c . Attestation = AttestationConfig { }
switch attestation . ( type ) {
2023-06-09 09:41:02 -04:00
case variant . AWSSEVSNP :
2023-08-02 04:23:15 -04:00
c . Attestation = AttestationConfig { AWSSEVSNP : currentAttestationConfigs . AWSSEVSNP }
2023-05-17 10:53:56 -04:00
case variant . AWSNitroTPM :
2023-08-02 04:23:15 -04:00
c . Attestation = AttestationConfig { AWSNitroTPM : currentAttestationConfigs . AWSNitroTPM }
2024-01-24 09:10:15 -05:00
case variant . AzureSEVSNP :
c . Attestation = AttestationConfig { AzureSEVSNP : currentAttestationConfigs . AzureSEVSNP }
case variant . AzureTDX :
c . Attestation = AttestationConfig { AzureTDX : currentAttestationConfigs . AzureTDX }
2023-05-17 10:53:56 -04:00
case variant . AzureTrustedLaunch :
2023-08-02 04:23:15 -04:00
c . Attestation = AttestationConfig { AzureTrustedLaunch : currentAttestationConfigs . AzureTrustedLaunch }
2023-05-17 10:53:56 -04:00
case variant . GCPSEVES :
2023-08-02 04:23:15 -04:00
c . Attestation = AttestationConfig { GCPSEVES : currentAttestationConfigs . GCPSEVES }
2024-04-16 12:13:47 -04:00
case variant . GCPSEVSNP :
c . Attestation = AttestationConfig { GCPSEVSNP : currentAttestationConfigs . GCPSEVSNP }
2023-05-17 10:53:56 -04:00
case variant . QEMUVTPM :
2023-08-02 04:23:15 -04:00
c . Attestation = AttestationConfig { QEMUVTPM : currentAttestationConfigs . QEMUVTPM }
2022-05-18 05:39:14 -04:00
}
}
2022-11-15 09:40:49 -05:00
// IsDebugCluster checks whether the cluster is configured as a debug cluster.
func ( c * Config ) IsDebugCluster ( ) bool {
if c . DebugCluster != nil && * c . DebugCluster {
return true
}
return false
}
2022-11-22 12:47:08 -05:00
// IsReleaseImage checks whether image name looks like a release image.
func ( c * Config ) IsReleaseImage ( ) bool {
return strings . HasPrefix ( c . Image , "v" )
2022-08-16 09:53:54 -04:00
}
2023-06-19 10:51:39 -04:00
// IsNamedLikeDebugImage checks whether image name looks like a debug image.
func ( c * Config ) IsNamedLikeDebugImage ( ) bool {
v , err := versionsapi . NewVersionFromShortPath ( c . Image , versionsapi . VersionKindImage )
if err != nil {
return false
}
2023-08-01 10:48:13 -04:00
return v . Stream ( ) == "debug"
2023-06-19 10:51:39 -04:00
}
2022-08-31 05:59:07 -04:00
// GetProvider returns the configured cloud provider.
func ( c * Config ) GetProvider ( ) cloudprovider . Provider {
2022-10-21 06:24:18 -04:00
if c . Provider . AWS != nil {
return cloudprovider . AWS
}
2022-08-31 05:59:07 -04:00
if c . Provider . Azure != nil {
return cloudprovider . Azure
}
if c . Provider . GCP != nil {
return cloudprovider . GCP
}
2023-02-27 12:19:52 -05:00
if c . Provider . OpenStack != nil {
return cloudprovider . OpenStack
}
2022-08-31 05:59:07 -04:00
if c . Provider . QEMU != nil {
return cloudprovider . QEMU
}
return cloudprovider . Unknown
}
2023-05-03 05:11:53 -04:00
// GetAttestationConfig returns the configured attestation config.
func ( c * Config ) GetAttestationConfig ( ) AttestationCfg {
2023-06-09 09:41:02 -04:00
if c . Attestation . AWSSEVSNP != nil {
2024-01-10 07:32:13 -05:00
return c . Attestation . AWSSEVSNP . getToMarshallLatestWithResolvedVersions ( )
2023-06-09 09:41:02 -04:00
}
2023-05-03 05:11:53 -04:00
if c . Attestation . AWSNitroTPM != nil {
return c . Attestation . AWSNitroTPM
2023-02-20 04:32:33 -05:00
}
2023-05-03 05:11:53 -04:00
if c . Attestation . AzureSEVSNP != nil {
2024-01-10 07:32:13 -05:00
return c . Attestation . AzureSEVSNP . getToMarshallLatestWithResolvedVersions ( )
2023-02-20 04:32:33 -05:00
}
2024-01-24 09:10:15 -05:00
if c . Attestation . AzureTDX != nil {
return c . Attestation . AzureTDX . getToMarshallLatestWithResolvedVersions ( )
}
2023-05-03 05:11:53 -04:00
if c . Attestation . AzureTrustedLaunch != nil {
return c . Attestation . AzureTrustedLaunch
2023-02-20 04:32:33 -05:00
}
2023-05-03 05:11:53 -04:00
if c . Attestation . GCPSEVES != nil {
return c . Attestation . GCPSEVES
2023-04-05 10:49:03 -04:00
}
2024-04-16 12:13:47 -04:00
if c . Attestation . GCPSEVSNP != nil {
return c . Attestation . GCPSEVSNP
}
2023-05-03 05:11:53 -04:00
if c . Attestation . QEMUVTPM != nil {
return c . Attestation . QEMUVTPM
2023-02-20 04:32:33 -05:00
}
2023-05-03 05:11:53 -04:00
return & DummyCfg { }
2023-02-20 04:32:33 -05:00
}
2023-05-23 03:17:27 -04:00
// GetRegion returns the configured region.
func ( c * Config ) GetRegion ( ) string {
switch c . GetProvider ( ) {
case cloudprovider . AWS :
return c . Provider . AWS . Region
case cloudprovider . Azure :
return c . Provider . Azure . Location
case cloudprovider . GCP :
return c . Provider . GCP . Region
case cloudprovider . OpenStack :
return c . Provider . OpenStack . RegionName
case cloudprovider . QEMU :
return ""
}
return ""
}
2023-07-04 07:55:52 -04:00
// GetZone returns the configured zone or location for providers without zone support (Azure).
func ( c * Config ) GetZone ( ) string {
switch c . GetProvider ( ) {
case cloudprovider . AWS :
return c . Provider . AWS . Zone
case cloudprovider . Azure :
return c . Provider . Azure . Location
case cloudprovider . GCP :
return c . Provider . GCP . Zone
}
return ""
}
2023-05-03 05:11:53 -04:00
// UpdateMAAURL updates the MAA URL in the config.
func ( c * Config ) UpdateMAAURL ( maaURL string ) {
if c . Attestation . AzureSEVSNP != nil {
c . Attestation . AzureSEVSNP . FirmwareSignerConfig . MAAURL = maaURL
2023-03-21 07:46:49 -04:00
}
2023-01-18 10:49:55 -05:00
}
2022-11-18 04:05:02 -05:00
// DeployCSIDriver returns whether the CSI driver should be deployed for a given cloud provider.
func ( c * Config ) DeployCSIDriver ( ) bool {
return c . Provider . Azure != nil && c . Provider . Azure . DeployCSIDriver != nil && * c . Provider . Azure . DeployCSIDriver ||
2023-06-30 02:46:32 -04:00
c . Provider . AWS != nil && c . Provider . AWS . DeployCSIDriver != nil && * c . Provider . AWS . DeployCSIDriver ||
2023-05-08 13:44:06 -04:00
c . Provider . GCP != nil && c . Provider . GCP . DeployCSIDriver != nil && * c . Provider . GCP . DeployCSIDriver ||
c . Provider . OpenStack != nil && c . Provider . OpenStack . DeployCSIDriver != nil && * c . Provider . OpenStack . DeployCSIDriver
2022-11-18 04:05:02 -05:00
}
2023-05-02 03:35:52 -04:00
// DeployYawolLoadBalancer returns whether the Yawol load balancer should be deployed.
func ( c * Config ) DeployYawolLoadBalancer ( ) bool {
return c . Provider . OpenStack != nil && c . Provider . OpenStack . DeployYawolLoadBalancer != nil && * c . Provider . OpenStack . DeployYawolLoadBalancer
}
2023-12-08 08:40:31 -05:00
// UseMarketplaceImage returns whether a marketplace image should be used.
func ( c * Config ) UseMarketplaceImage ( ) bool {
2024-01-08 09:51:39 -05:00
return ( c . Provider . Azure != nil && c . Provider . Azure . UseMarketplaceImage != nil && * c . Provider . Azure . UseMarketplaceImage ) ||
2024-02-06 06:13:59 -05:00
( c . Provider . GCP != nil && c . Provider . GCP . UseMarketplaceImage != nil && * c . Provider . GCP . UseMarketplaceImage ) ||
2024-03-01 11:06:02 -05:00
( c . Provider . AWS != nil && c . Provider . AWS . UseMarketplaceImage != nil && * c . Provider . AWS . UseMarketplaceImage ) ||
( c . Provider . OpenStack != nil && c . Provider . OpenStack . Cloud == "stackit" )
2023-12-08 08:40:31 -05:00
}
2022-11-15 09:40:49 -05:00
// Validate checks the config values and returns validation errors.
2023-01-31 05:45:31 -05:00
func ( c * Config ) Validate ( force bool ) error {
2022-11-15 09:40:49 -05:00
trans := ut . New ( en . New ( ) ) . GetFallback ( )
validate := validator . New ( )
if err := en_translations . RegisterDefaultTranslations ( validate , trans ) ; err != nil {
return err
2022-03-22 11:03:15 -04:00
}
2022-08-12 09:59:45 -04:00
2023-03-29 08:04:37 -04:00
// Register name function to return yaml name tag
// This makes sure methods like fl.FieldName() return the yaml name tag instead of the struct field name
// e.g. struct{DataType string `yaml:"foo,omitempty"`} will return `foo` instead of `DataType` when calling fl.FieldName()
validate . RegisterTagNameFunc ( func ( fld reflect . StructField ) string {
name , _ , _ := strings . Cut ( fld . Tag . Get ( "yaml" ) , "," )
if name == "-" {
return ""
}
return name
} )
2022-11-15 09:40:49 -05:00
// Register AWS, Azure & GCP InstanceType validation error types
2023-08-02 04:23:15 -04:00
if err := validate . RegisterTranslation ( "instance_type" , trans , c . registerTranslateInstanceTypeError , c . translateInstanceTypeError ) ; err != nil {
2022-11-15 09:40:49 -05:00
return err
2022-10-21 06:24:18 -04:00
}
2022-11-15 09:40:49 -05:00
// Register Provider validation error types
if err := validate . RegisterTranslation ( "no_provider" , trans , registerNoProviderError , translateNoProviderError ) ; err != nil {
return err
2022-10-21 06:24:18 -04:00
}
2022-11-15 09:40:49 -05:00
if err := validate . RegisterTranslation ( "more_than_one_provider" , trans , registerMoreThanOneProviderError , c . translateMoreThanOneProviderError ) ; err != nil {
return err
2022-10-21 06:24:18 -04:00
}
2022-11-24 04:57:58 -05:00
if err := validate . RegisterTranslation ( "no_placeholders" , trans , registerContainsPlaceholderError , translateContainsPlaceholderError ) ; err != nil {
return err
}
2023-01-23 05:21:06 -05:00
if err := validate . RegisterTranslation ( "supported_k8s_version" , trans , registerInvalidK8sVersionError , translateInvalidK8sVersionError ) ; err != nil {
return err
}
2023-07-25 08:20:25 -04:00
if err := validate . RegisterTranslation ( "image_compatibility" , trans , registerImageCompatibilityError , translateImageCompatibilityError ) ; err != nil {
2023-01-31 05:45:31 -05:00
return err
}
2023-03-14 06:46:27 -04:00
2023-11-03 05:09:43 -04:00
if err := validate . RegisterTranslation ( "valid_name" , trans , c . registerValidateNameError , c . translateValidateNameError ) ; err != nil {
2023-02-10 07:27:22 -05:00
return err
}
if err := validate . RegisterValidation ( "valid_name" , c . validateName ) ; err != nil {
return err
}
2023-01-31 05:45:31 -05:00
2022-11-24 04:57:58 -05:00
if err := validate . RegisterValidation ( "no_placeholders" , validateNoPlaceholder ) ; err != nil {
return err
}
2022-11-15 09:40:49 -05:00
// register custom validator with label supported_k8s_version to validate version based on available versionConfigs.
2023-02-20 04:50:55 -05:00
if err := validate . RegisterValidation ( "supported_k8s_version" , c . validateK8sVersion ) ; err != nil {
2022-11-15 09:40:49 -05:00
return err
}
2022-10-21 06:24:18 -04:00
2023-01-31 05:45:31 -05:00
versionCompatibilityValidator := validateVersionCompatibility
if force {
versionCompatibilityValidator = returnsTrue
}
2023-07-25 08:20:25 -04:00
if err := validate . RegisterValidation ( "image_compatibility" , versionCompatibilityValidator ) ; err != nil {
2023-01-31 05:45:31 -05:00
return err
}
2023-08-02 04:23:15 -04:00
if err := validate . RegisterValidation ( "disk_type" , c . validateStateDiskTypeField ) ; err != nil {
2022-11-15 09:40:49 -05:00
return err
2022-10-21 06:24:18 -04:00
}
2023-08-02 04:23:15 -04:00
if err := validate . RegisterTranslation ( "disk_type" , trans , registerTranslateDiskTypeError , c . translateDiskTypeError ) ; err != nil {
2022-11-15 09:40:49 -05:00
return err
}
2022-10-21 06:24:18 -04:00
2023-08-02 04:23:15 -04:00
if err := validate . RegisterValidation ( "instance_type" , c . validateInstanceType ) ; err != nil {
2022-11-15 09:40:49 -05:00
return err
2022-10-21 06:24:18 -04:00
}
2023-03-29 08:04:37 -04:00
if err := validate . RegisterValidation ( "deprecated" , warnDeprecated ) ; err != nil {
return err
}
2022-11-15 09:40:49 -05:00
// Register provider validation
validate . RegisterStructValidation ( validateProvider , ProviderConfig { } )
2023-08-02 04:23:15 -04:00
// Register NodeGroup validation error types
if err := validate . RegisterTranslation ( "no_default_control_plane_group" , trans , registerNoDefaultControlPlaneGroupError , translateNoDefaultControlPlaneGroupError ) ; err != nil {
return err
}
if err := validate . RegisterTranslation ( "no_default_worker_group" , trans , registerNoDefaultWorkerGroupError , translateNoDefaultWorkerGroupError ) ; err != nil {
return err
}
if err := validate . RegisterTranslation ( "control_plane_group_initial_count" , trans , registerControlPlaneGroupInitialCountError , translateControlPlaneGroupInitialCountError ) ; err != nil {
return err
}
if err := validate . RegisterTranslation ( "control_plane_group_role_mismatch" , trans , registerControlPlaneGroupRoleMismatchError , translateControlPlaneGroupRoleMismatchError ) ; err != nil {
return err
}
if err := validate . RegisterTranslation ( "worker_group_role_mismatch" , trans , registerWorkerGroupRoleMismatchError , translateWorkerGroupRoleMismatchError ) ; err != nil {
return err
}
// Register NodeGroup validation
validate . RegisterStructValidation ( validateNodeGroups , Config { } )
2023-05-03 05:11:53 -04:00
// Register Attestation validation error types
if err := validate . RegisterTranslation ( "no_attestation" , trans , registerNoAttestationError , translateNoAttestationError ) ; err != nil {
return err
}
if err := validate . RegisterTranslation ( "more_than_one_attestation" , trans , registerMoreThanOneAttestationError , c . translateMoreThanOneAttestationError ) ; err != nil {
return err
}
2023-08-02 04:23:15 -04:00
if err := validate . RegisterValidation ( "valid_zone" , c . validateNodeGroupZoneField ) ; err != nil {
return err
}
2023-07-04 07:55:52 -04:00
if err := validate . RegisterValidation ( "aws_region" , validateAWSRegionField ) ; err != nil {
return err
}
if err := validate . RegisterValidation ( "aws_zone" , validateAWSZoneField ) ; err != nil {
return err
}
2023-08-02 04:23:15 -04:00
if err := validate . RegisterTranslation ( "valid_zone" , trans , registerValidZoneError , c . translateValidZoneError ) ; err != nil {
return err
}
2023-07-04 07:55:52 -04:00
if err := validate . RegisterTranslation ( "aws_region" , trans , registerAWSRegionError , translateAWSRegionError ) ; err != nil {
return err
}
if err := validate . RegisterTranslation ( "aws_zone" , trans , registerAWSZoneError , translateAWSZoneError ) ; err != nil {
return err
}
2023-06-09 09:41:02 -04:00
validate . RegisterStructValidation ( validateMeasurement , measurements . Measurement { } )
2023-05-03 05:11:53 -04:00
validate . RegisterStructValidation ( validateAttestation , AttestationConfig { } )
2023-07-25 08:20:25 -04:00
if ! force {
// Validating MicroserviceVersion separately is required since it is a custom type.
// The validation pkg we use does not allow accessing the field name during struct validation.
// Because of this we can't print the offending field name in the error message, resulting in
// suboptimal UX. Adding the field name to the struct validation of Semver would make it
// impossible to use Semver for other fields.
2023-12-22 04:24:13 -05:00
if err := ValidateMicroserviceVersion ( constants . BinaryVersion ( ) , c . MicroserviceVersion ) ; err != nil {
2023-07-25 08:20:25 -04:00
msg := "microserviceVersion: " + msgFromCompatibilityError ( err , constants . BinaryVersion ( ) . String ( ) , c . MicroserviceVersion . String ( ) )
return & ValidationError { validationErrMsgs : [ ] string { msg } }
}
}
2023-10-17 09:46:15 -04:00
if c . InternalLoadBalancer {
if c . GetProvider ( ) != cloudprovider . AWS && c . GetProvider ( ) != cloudprovider . GCP {
return & ValidationError { validationErrMsgs : [ ] string { "internalLoadBalancer is only supported for AWS and GCP" } }
}
}
2022-11-15 09:40:49 -05:00
err := validate . Struct ( c )
if err == nil {
return nil
2022-10-21 06:24:18 -04:00
}
2023-02-07 09:19:59 -05:00
var validationErrs validator . ValidationErrors
if ! errors . As ( err , & validationErrs ) {
2022-11-15 09:40:49 -05:00
return err
}
2022-10-21 06:24:18 -04:00
2023-02-07 06:56:25 -05:00
var validationErrMsgs [ ] string
2023-02-07 09:19:59 -05:00
for _ , e := range validationErrs {
2023-02-07 06:56:25 -05:00
validationErrMsgs = append ( validationErrMsgs , e . Translate ( trans ) )
2022-09-05 10:53:37 -04:00
}
2023-02-07 06:56:25 -05:00
return & ValidationError { validationErrMsgs : validationErrMsgs }
2022-09-05 10:53:37 -04:00
}
2023-02-28 12:44:21 -05:00
2023-05-30 03:02:50 -04:00
// WithOpenStackProviderDefaults fills the default values for the specific OpenStack provider.
// If the provider is not supported or not an OpenStack provider, the config is returned unchanged.
2024-03-01 11:45:12 -05:00
func ( c * Config ) WithOpenStackProviderDefaults ( csp cloudprovider . Provider , openStackProvider string ) * Config {
if csp != cloudprovider . OpenStack {
return c
}
c . Attestation . QEMUVTPM = & QEMUVTPM { Measurements : measurements . DefaultsFor ( cloudprovider . OpenStack , variant . QEMUVTPM { } ) }
2023-05-30 03:02:50 -04:00
switch openStackProvider {
case "stackit" :
c . Provider . OpenStack . Cloud = "stackit"
c . Provider . OpenStack . FloatingIPPoolID = "970ace5c-458f-484a-a660-0903bcfd91ad"
c . Provider . OpenStack . RegionName = "RegionOne"
c . Provider . OpenStack . DeployYawolLoadBalancer = toPtr ( true )
2024-02-12 09:25:56 -05:00
c . Provider . OpenStack . YawolImageID = "bcd6c13e-75d1-4c3f-bf0f-8f83580cc1be"
2023-05-30 03:02:50 -04:00
c . Provider . OpenStack . YawolFlavorID = "3b11b27e-6c73-470d-b595-1d85b95a8cdf"
c . Provider . OpenStack . DeployCSIDriver = toPtr ( true )
2023-08-02 04:23:15 -04:00
for groupName , group := range c . NodeGroups {
2024-02-28 07:29:28 -05:00
group . InstanceType = "m1a.4cd"
2023-08-02 04:23:15 -04:00
group . StateDiskType = "storage_premium_perf6"
c . NodeGroups [ groupName ] = group
}
2023-05-30 03:02:50 -04:00
return c
}
return c
}
2024-01-24 09:10:15 -05:00
// SetCSPNodeGroupDefaults sets the default values for the node groups based on the configured CSP.
func ( c * Config ) SetCSPNodeGroupDefaults ( csp cloudprovider . Provider ) {
2023-08-02 04:23:15 -04:00
var instanceType , stateDiskType , zone string
switch csp {
case cloudprovider . AWS :
instanceType = "m6a.xlarge"
stateDiskType = "gp3"
zone = c . Provider . AWS . Zone
case cloudprovider . Azure :
2024-01-24 09:10:15 -05:00
// Check attestation variant, and use different default instance type if we have TDX
if c . GetAttestationConfig ( ) . GetVariant ( ) . Equal ( variant . AzureTDX { } ) {
instanceType = "Standard_DC4es_v5"
} else {
instanceType = "Standard_DC4as_v5"
}
2023-08-02 04:23:15 -04:00
stateDiskType = "Premium_LRS"
case cloudprovider . GCP :
instanceType = "n2d-standard-4"
stateDiskType = "pd-ssd"
zone = c . Provider . GCP . Zone
case cloudprovider . QEMU , cloudprovider . OpenStack :
2024-01-24 09:10:15 -05:00
// empty. There are no defaults for this CSP
2023-08-02 04:23:15 -04:00
}
for groupName , group := range c . NodeGroups {
if len ( group . InstanceType ) == 0 && len ( instanceType ) != 0 {
group . InstanceType = instanceType
}
if len ( group . StateDiskType ) == 0 && len ( stateDiskType ) != 0 {
group . StateDiskType = stateDiskType
}
if len ( group . Zone ) == 0 && len ( zone ) != 0 {
group . Zone = zone
}
c . NodeGroups [ groupName ] = group
}
}
2023-04-06 11:00:56 -04:00
// SNPFirmwareSignerConfig is the configuration for validating the firmware signer.
type SNPFirmwareSignerConfig struct {
// description: |
// List of accepted values for the firmware signing key digest.\nValues are enforced according to the 'enforcementPolicy'\n - 'equal' : Error if the reported signing key digest does not match any of the values in 'acceptedKeyDigests'\n - 'maaFallback' : Use 'equal' checking for validation, but fallback to using Microsoft Azure Attestation (MAA) for validation if the reported digest does not match any of the values in 'acceptedKeyDigests'. See the Azure docs for more details: https://learn.microsoft.com/en-us/azure/attestation/overview#amd-sev-snp-attestation\n - 'warnOnly' : Same as 'equal', but only prints a warning instead of returning an error if no match is found
AcceptedKeyDigests idkeydigest . List ` json:"acceptedKeyDigests" yaml:"acceptedKeyDigests" `
// description: |
// Key digest enforcement policy. One of {'equal', 'maaFallback', 'warnOnly'}
EnforcementPolicy idkeydigest . Enforcement ` json:"enforcementPolicy" yaml:"enforcementPolicy" validate:"required" `
// description: |
// URL of the Microsoft Azure Attestation (MAA) instance to use for fallback validation. Only used if 'enforcementPolicy' is set to 'maaFallback'.
MAAURL string ` json:"maaURL,omitempty" yaml:"maaURL,omitempty" validate:"len=0" `
}
2023-05-03 05:11:53 -04:00
// EqualTo returns true if the config is equal to the given config.
func ( c SNPFirmwareSignerConfig ) EqualTo ( other SNPFirmwareSignerConfig ) bool {
return c . AcceptedKeyDigests . EqualTo ( other . AcceptedKeyDigests ) && c . EnforcementPolicy == other . EnforcementPolicy && c . MAAURL == other . MAAURL
}
2023-04-06 11:00:56 -04:00
// GCPSEVES is the configuration for GCP SEV-ES attestation.
type GCPSEVES struct {
// description: |
// Expected TPM measurements.
2023-05-03 05:11:53 -04:00
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
2023-04-06 11:00:56 -04:00
}
2024-04-16 12:13:47 -04:00
// GCPSEVSNP is the configuration for GCP SEV-SNP attestation.
type GCPSEVSNP struct {
// description: |
// Expected TPM measurements.
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
// description: |
// Lowest acceptable bootloader version.
BootloaderVersion AttestationVersion ` json:"bootloaderVersion" yaml:"bootloaderVersion" `
// description: |
// Lowest acceptable TEE version.
TEEVersion AttestationVersion ` json:"teeVersion" yaml:"teeVersion" `
// description: |
// Lowest acceptable SEV-SNP version.
SNPVersion AttestationVersion ` json:"snpVersion" yaml:"snpVersion" `
// description: |
// Lowest acceptable microcode version.
MicrocodeVersion AttestationVersion ` json:"microcodeVersion" yaml:"microcodeVersion" `
// description: |
// AMD Root Key certificate used to verify the SEV-SNP certificate chain.
AMDRootKey Certificate ` json:"amdRootKey" yaml:"amdRootKey" `
// description: |
// AMD Signing Key certificate used to verify the SEV-SNP VCEK / VLEK certificate.
AMDSigningKey Certificate ` json:"amdSigningKey,omitempty" yaml:"amdSigningKey,omitempty" `
2023-05-03 05:11:53 -04:00
}
2023-06-05 09:46:55 -04:00
// QEMUVTPM is the configuration for QEMU vTPM attestation.
type QEMUVTPM struct {
// description: |
// Expected TPM measurements.
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
}
// GetVariant returns qemu-vtpm as the variant.
func ( QEMUVTPM ) GetVariant ( ) variant . Variant {
return variant . QEMUVTPM { }
}
// GetMeasurements returns the measurements used for attestation.
func ( c QEMUVTPM ) GetMeasurements ( ) measurements . M {
return c . Measurements
}
// SetMeasurements updates a config's measurements using the given measurements.
func ( c * QEMUVTPM ) SetMeasurements ( m measurements . M ) {
c . Measurements = m
}
// EqualTo returns true if the config is equal to the given config.
func ( c QEMUVTPM ) EqualTo ( other AttestationCfg ) ( bool , error ) {
otherCfg , ok := other . ( * QEMUVTPM )
if ! ok {
return false , fmt . Errorf ( "cannot compare %T with %T" , c , other )
}
return c . Measurements . EqualTo ( otherCfg . Measurements ) , nil
}
// QEMUTDX is the configuration for QEMU TDX attestation.
type QEMUTDX struct {
// description: |
// Expected TDX measurements.
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
}
// GetVariant returns qemu-tdx as the variant.
func ( QEMUTDX ) GetVariant ( ) variant . Variant {
return variant . QEMUTDX { }
}
// GetMeasurements returns the measurements used for attestation.
func ( c QEMUTDX ) GetMeasurements ( ) measurements . M {
return c . Measurements
}
// SetMeasurements updates a config's measurements using the given measurements.
func ( c * QEMUTDX ) SetMeasurements ( m measurements . M ) {
c . Measurements = m
}
// EqualTo returns true if the config is equal to the given config.
func ( c QEMUTDX ) EqualTo ( other AttestationCfg ) ( bool , error ) {
otherCfg , ok := other . ( * QEMUTDX )
if ! ok {
return false , fmt . Errorf ( "cannot compare %T with %T" , c , other )
}
return c . Measurements . EqualTo ( otherCfg . Measurements ) , nil
}
2023-11-06 08:22:44 -05:00
// AWSSEVSNP is the configuration for AWS SEV-SNP attestation.
type AWSSEVSNP struct {
// description: |
// Expected TPM measurements.
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
// description: |
// Lowest acceptable bootloader version.
BootloaderVersion AttestationVersion ` json:"bootloaderVersion" yaml:"bootloaderVersion" `
// description: |
// Lowest acceptable TEE version.
TEEVersion AttestationVersion ` json:"teeVersion" yaml:"teeVersion" `
// description: |
// Lowest acceptable SEV-SNP version.
SNPVersion AttestationVersion ` json:"snpVersion" yaml:"snpVersion" `
// description: |
// Lowest acceptable microcode version.
MicrocodeVersion AttestationVersion ` json:"microcodeVersion" yaml:"microcodeVersion" `
// description: |
// AMD Root Key certificate used to verify the SEV-SNP certificate chain.
AMDRootKey Certificate ` json:"amdRootKey" yaml:"amdRootKey" `
// description: |
// AMD Signing Key certificate used to verify the SEV-SNP VCEK / VLEK certificate.
2023-11-07 06:17:08 -05:00
AMDSigningKey Certificate ` json:"amdSigningKey,omitempty" yaml:"amdSigningKey,omitempty" `
2023-11-06 08:22:44 -05:00
}
// AWSNitroTPM is the configuration for AWS Nitro TPM attestation.
type AWSNitroTPM struct {
// description: |
// Expected TPM measurements.
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
}
2023-06-05 09:46:55 -04:00
// AzureSEVSNP is the configuration for Azure SEV-SNP attestation.
type AzureSEVSNP struct {
// description: |
// Expected TPM measurements.
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
// description: |
// Lowest acceptable bootloader version.
BootloaderVersion AttestationVersion ` json:"bootloaderVersion" yaml:"bootloaderVersion" `
// description: |
// Lowest acceptable TEE version.
TEEVersion AttestationVersion ` json:"teeVersion" yaml:"teeVersion" `
// description: |
// Lowest acceptable SEV-SNP version.
SNPVersion AttestationVersion ` json:"snpVersion" yaml:"snpVersion" `
// description: |
// Lowest acceptable microcode version.
MicrocodeVersion AttestationVersion ` json:"microcodeVersion" yaml:"microcodeVersion" `
// description: |
// Configuration for validating the firmware signature.
FirmwareSignerConfig SNPFirmwareSignerConfig ` json:"firmwareSignerConfig" yaml:"firmwareSignerConfig" `
// description: |
// AMD Root Key certificate used to verify the SEV-SNP certificate chain.
AMDRootKey Certificate ` json:"amdRootKey" yaml:"amdRootKey" `
2023-09-29 08:29:50 -04:00
// description: |
// AMD Signing Key certificate used to verify the SEV-SNP VCEK / VLEK certificate.
AMDSigningKey Certificate ` json:"amdSigningKey,omitempty" yaml:"amdSigningKey,omitempty" validate:"len=0" `
2023-06-05 09:46:55 -04:00
}
// AzureTrustedLaunch is the configuration for Azure Trusted Launch attestation.
type AzureTrustedLaunch struct {
// description: |
// Expected TPM measurements.
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
}
2024-01-10 07:32:13 -05:00
2024-01-24 09:10:15 -05:00
// AzureTDX is the configuration for Azure TDX attestation.
type AzureTDX struct {
// description: |
// Expected TPM measurements.
Measurements measurements . M ` json:"measurements" yaml:"measurements" validate:"required,no_placeholders" `
// description: |
// Minimum required QE security version number (SVN).
QESVN uint16 ` json:"qeSVN" yaml:"qeSVN" `
// description: |
// Minimum required PCE security version number (SVN).
PCESVN uint16 ` json:"pceSVN" yaml:"pceSVN" `
// description: |
// Component-wise minimum required 16 byte hex-encoded TEE_TCB security version number (SVN).
TEETCBSVN encoding . HexBytes ` json:"teeTCBSVN" yaml:"teeTCBSVN" `
// description: |
// Expected 16 byte hex-encoded QE_VENDOR_ID field.
QEVendorID encoding . HexBytes ` json:"qeVendorID" yaml:"qeVendorID" `
// description: |
// Expected 48 byte hex-encoded MR_SEAM value.
2024-04-22 08:07:24 -04:00
MRSeam encoding . HexBytes ` json:"mrSeam,omitempty" yaml:"mrSeam,omitempty" `
2024-01-24 09:10:15 -05:00
// description: |
// Expected 8 byte hex-encoded XFAM field.
XFAM encoding . HexBytes ` json:"xfam" yaml:"xfam" `
// description: |
// Intel Root Key certificate used to verify the TDX certificate chain.
IntelRootKey Certificate ` json:"intelRootKey" yaml:"intelRootKey" `
}
func toPtr [ T any ] ( v T ) * T {
return & v
}
// svnResolveMarshaller is used to marshall "latest" security version numbers with resolved versions.
type svnResolveMarshaller interface {
2024-01-10 07:32:13 -05:00
// getToMarshallLatestWithResolvedVersions brings the attestation config into a state where marshalling uses the numerical version numbers for "latest" versions.
getToMarshallLatestWithResolvedVersions ( ) AttestationCfg
}