2023-08-03 07:54:48 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
Overrides contains helm values that are dynamically injected into the helm charts.
|
|
|
|
*/
|
|
|
|
package helm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
2023-09-25 10:19:43 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/state"
|
2023-08-03 07:54:48 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/azureshared"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/gcpshared"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/openstack"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/config"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
2023-08-07 09:24:46 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/uri"
|
2023-08-03 07:54:48 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// TODO(malt3): switch over to DNS name on AWS and Azure
|
|
|
|
// soon as every apiserver certificate of every control-plane node
|
|
|
|
// has the dns endpoint in its SAN list.
|
|
|
|
// extraCiliumValues extends the given values map by some values depending on user input.
|
|
|
|
// This extra step of separating the application of user input is necessary since service upgrades should
|
|
|
|
// reuse user input from the init step. However, we can't rely on reuse-values, because
|
|
|
|
// during upgrades we all values need to be set locally as they might have changed.
|
|
|
|
// Also, the charts are not rendered correctly without all of these values.
|
2023-09-25 10:19:43 -04:00
|
|
|
func extraCiliumValues(provider cloudprovider.Provider, conformanceMode bool, output state.Infrastructure) map[string]any {
|
2023-08-03 07:54:48 -04:00
|
|
|
extraVals := map[string]any{}
|
|
|
|
if conformanceMode {
|
|
|
|
extraVals["kubeProxyReplacementHealthzBindAddr"] = ""
|
|
|
|
extraVals["kubeProxyReplacement"] = "partial"
|
|
|
|
extraVals["sessionAffinity"] = true
|
|
|
|
extraVals["cni"] = map[string]any{
|
|
|
|
"chainingMode": "portmap",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-23 09:59:19 -04:00
|
|
|
strictMode := map[string]any{}
|
|
|
|
if provider != cloudprovider.QEMU {
|
|
|
|
strictMode = map[string]any{
|
|
|
|
"nodeCIDRList": []string{output.IPCidrNode},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-17 09:46:15 -04:00
|
|
|
extraVals["k8sServiceHost"] = output.InClusterEndpoint
|
2023-08-03 07:54:48 -04:00
|
|
|
extraVals["k8sServicePort"] = constants.KubernetesPort
|
|
|
|
if provider == cloudprovider.GCP {
|
|
|
|
extraVals["ipv4NativeRoutingCIDR"] = output.GCP.IPCidrPod
|
2023-10-23 09:59:19 -04:00
|
|
|
strictMode["podCIDRList"] = []string{output.GCP.IPCidrPod}
|
|
|
|
}
|
|
|
|
extraVals["encryption"] = map[string]any{
|
|
|
|
"strictMode": strictMode,
|
2023-08-03 07:54:48 -04:00
|
|
|
}
|
|
|
|
return extraVals
|
|
|
|
}
|
|
|
|
|
|
|
|
// extraConstellationServicesValues extends the given values map by some values depending on user input.
|
|
|
|
// Values set inside this function are only applied during init, not during upgrade.
|
2023-08-07 09:24:46 -04:00
|
|
|
func extraConstellationServicesValues(
|
2023-10-09 07:04:29 -04:00
|
|
|
cfg *config.Config, masterSecret uri.MasterSecret, serviceAccURI string, output state.Infrastructure,
|
2023-08-03 07:54:48 -04:00
|
|
|
) (map[string]any, error) {
|
|
|
|
extraVals := map[string]any{}
|
|
|
|
extraVals["join-service"] = map[string]any{
|
|
|
|
"attestationVariant": cfg.GetAttestationConfig().GetVariant().String(),
|
|
|
|
}
|
|
|
|
extraVals["verification-service"] = map[string]any{
|
|
|
|
"attestationVariant": cfg.GetAttestationConfig().GetVariant().String(),
|
|
|
|
}
|
2023-11-15 06:38:01 -05:00
|
|
|
extraVals["konnectivity"] = map[string]any{
|
|
|
|
"loadBalancerIP": output.ClusterEndpoint,
|
|
|
|
}
|
2023-08-03 07:54:48 -04:00
|
|
|
|
|
|
|
extraVals["key-service"] = map[string]any{
|
2023-08-07 09:24:46 -04:00
|
|
|
"masterSecret": base64.StdEncoding.EncodeToString(masterSecret.Key),
|
|
|
|
"salt": base64.StdEncoding.EncodeToString(masterSecret.Salt),
|
2023-08-03 07:54:48 -04:00
|
|
|
}
|
|
|
|
switch cfg.GetProvider() {
|
|
|
|
case cloudprovider.OpenStack:
|
|
|
|
extraVals["openstack"] = map[string]any{
|
|
|
|
"deployYawolLoadBalancer": cfg.DeployYawolLoadBalancer(),
|
|
|
|
}
|
|
|
|
if cfg.DeployYawolLoadBalancer() {
|
|
|
|
extraVals["yawol-controller"] = map[string]any{
|
|
|
|
"yawolOSSecretName": "yawolkey",
|
|
|
|
// has to be larger than ~30s to account for slow OpenStack API calls.
|
|
|
|
"openstackTimeout": "1m",
|
|
|
|
"yawolFloatingID": cfg.Provider.OpenStack.FloatingIPPoolID,
|
|
|
|
"yawolFlavorID": cfg.Provider.OpenStack.YawolFlavorID,
|
|
|
|
"yawolImageID": cfg.Provider.OpenStack.YawolImageID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case cloudprovider.GCP:
|
|
|
|
serviceAccountKey, err := gcpshared.ServiceAccountKeyFromURI(serviceAccURI)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("getting service account key: %w", err)
|
|
|
|
}
|
|
|
|
rawKey, err := json.Marshal(serviceAccountKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshaling service account key: %w", err)
|
|
|
|
}
|
|
|
|
if output.GCP == nil {
|
|
|
|
return nil, fmt.Errorf("no GCP output from Terraform")
|
|
|
|
}
|
|
|
|
extraVals["ccm"] = map[string]any{
|
|
|
|
"GCP": map[string]any{
|
|
|
|
"projectID": output.GCP.ProjectID,
|
2023-10-09 07:04:29 -04:00
|
|
|
"uid": output.UID,
|
2023-08-03 07:54:48 -04:00
|
|
|
"secretData": string(rawKey),
|
|
|
|
"subnetworkPodCIDR": output.GCP.IPCidrPod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case cloudprovider.Azure:
|
|
|
|
if output.Azure == nil {
|
|
|
|
return nil, fmt.Errorf("no Azure output from Terraform")
|
|
|
|
}
|
|
|
|
ccmConfig, err := getCCMConfig(*output.Azure, serviceAccURI)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("getting Azure CCM config: %w", err)
|
|
|
|
}
|
|
|
|
extraVals["ccm"] = map[string]any{
|
|
|
|
"Azure": map[string]any{
|
|
|
|
"azureConfig": string(ccmConfig),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return extraVals, nil
|
|
|
|
}
|
|
|
|
|
2023-08-24 10:40:47 -04:00
|
|
|
// cloudConfig is used to marshal the cloud config for the Kubernetes Cloud Controller Manager on Azure.
|
|
|
|
type cloudConfig struct {
|
|
|
|
Cloud string `json:"cloud,omitempty"`
|
|
|
|
TenantID string `json:"tenantId,omitempty"`
|
|
|
|
SubscriptionID string `json:"subscriptionId,omitempty"`
|
|
|
|
ResourceGroup string `json:"resourceGroup,omitempty"`
|
|
|
|
Location string `json:"location,omitempty"`
|
|
|
|
SubnetName string `json:"subnetName,omitempty"`
|
|
|
|
SecurityGroupName string `json:"securityGroupName,omitempty"`
|
|
|
|
SecurityGroupResourceGroup string `json:"securityGroupResourceGroup,omitempty"`
|
|
|
|
LoadBalancerName string `json:"loadBalancerName,omitempty"`
|
|
|
|
LoadBalancerSku string `json:"loadBalancerSku,omitempty"`
|
|
|
|
VNetName string `json:"vnetName,omitempty"`
|
|
|
|
VNetResourceGroup string `json:"vnetResourceGroup,omitempty"`
|
|
|
|
CloudProviderBackoff bool `json:"cloudProviderBackoff,omitempty"`
|
|
|
|
UseInstanceMetadata bool `json:"useInstanceMetadata,omitempty"`
|
|
|
|
VMType string `json:"vmType,omitempty"`
|
|
|
|
UseManagedIdentityExtension bool `json:"useManagedIdentityExtension,omitempty"`
|
|
|
|
UserAssignedIdentityID string `json:"userAssignedIdentityID,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-08-03 07:54:48 -04:00
|
|
|
// getCCMConfig returns the configuration needed for the Kubernetes Cloud Controller Manager on Azure.
|
2023-09-25 10:19:43 -04:00
|
|
|
func getCCMConfig(azureState state.Azure, serviceAccURI string) ([]byte, error) {
|
2023-08-03 07:54:48 -04:00
|
|
|
creds, err := azureshared.ApplicationCredentialsFromURI(serviceAccURI)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("getting service account key: %w", err)
|
|
|
|
}
|
|
|
|
useManagedIdentityExtension := creds.PreferredAuthMethod == azureshared.AuthMethodUserAssignedIdentity
|
|
|
|
config := cloudConfig{
|
|
|
|
Cloud: "AzurePublicCloud",
|
|
|
|
TenantID: creds.TenantID,
|
2023-09-25 10:19:43 -04:00
|
|
|
SubscriptionID: azureState.SubscriptionID,
|
|
|
|
ResourceGroup: azureState.ResourceGroup,
|
2023-08-03 07:54:48 -04:00
|
|
|
LoadBalancerSku: "standard",
|
2023-09-25 10:19:43 -04:00
|
|
|
SecurityGroupName: azureState.NetworkSecurityGroupName,
|
|
|
|
LoadBalancerName: azureState.LoadBalancerName,
|
2023-08-03 07:54:48 -04:00
|
|
|
UseInstanceMetadata: true,
|
|
|
|
VMType: "vmss",
|
|
|
|
Location: creds.Location,
|
|
|
|
UseManagedIdentityExtension: useManagedIdentityExtension,
|
2023-09-25 10:19:43 -04:00
|
|
|
UserAssignedIdentityID: azureState.UserAssignedIdentity,
|
2023-08-03 07:54:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
// extraOperatorValues returns the values for the constellation-operator chart.
|
|
|
|
func extraOperatorValues(uid string) map[string]any {
|
|
|
|
return map[string]any{
|
|
|
|
"constellation-operator": map[string]any{
|
|
|
|
"constellationUID": uid,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// extraCSIValues returns the values for the csi chart.
|
|
|
|
func extraCSIValues(provider cloudprovider.Provider, serviceAccURI string) (map[string]any, error) {
|
|
|
|
var csiVals map[string]any
|
|
|
|
if provider == cloudprovider.OpenStack {
|
|
|
|
creds, err := openstack.AccountKeyFromURI(serviceAccURI)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cinderIni := creds.CloudINI().CinderCSIConfiguration()
|
|
|
|
csiVals = map[string]any{
|
|
|
|
"cinder-config": map[string]any{
|
|
|
|
"secretData": cinderIni,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return csiVals, nil
|
|
|
|
}
|