mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-02-08 19:08:40 -05:00
openstack: use metadata client where possible
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
0d24b3ee29
commit
ebf7dd8842
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
||||||
gcpcloud "github.com/edgelesssys/constellation/v2/internal/cloud/gcp"
|
gcpcloud "github.com/edgelesssys/constellation/v2/internal/cloud/gcp"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
||||||
|
"github.com/edgelesssys/constellation/v2/internal/cloud/openstack"
|
||||||
qemucloud "github.com/edgelesssys/constellation/v2/internal/cloud/qemu"
|
qemucloud "github.com/edgelesssys/constellation/v2/internal/cloud/qemu"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/grpc/dialer"
|
"github.com/edgelesssys/constellation/v2/internal/grpc/dialer"
|
||||||
@ -64,7 +65,7 @@ func main() {
|
|||||||
var err error
|
var err error
|
||||||
var diskPath string
|
var diskPath string
|
||||||
var issuer atls.Issuer
|
var issuer atls.Issuer
|
||||||
var metadataAPI setup.MetadataAPI
|
var metadataClient setup.MetadataAPI
|
||||||
switch cloudprovider.FromString(*csp) {
|
switch cloudprovider.FromString(*csp) {
|
||||||
case cloudprovider.AWS:
|
case cloudprovider.AWS:
|
||||||
// on AWS Nitro platform, disks are attached over NVMe
|
// on AWS Nitro platform, disks are attached over NVMe
|
||||||
@ -74,9 +75,9 @@ func main() {
|
|||||||
_ = exportPCRs()
|
_ = exportPCRs()
|
||||||
log.With(zap.Error(err)).Fatalf("Unable to resolve Azure state disk path")
|
log.With(zap.Error(err)).Fatalf("Unable to resolve Azure state disk path")
|
||||||
}
|
}
|
||||||
metadataAPI, err = awscloud.New(context.Background())
|
metadataClient, err = awscloud.New(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.With(zap.Error(err)).Fatalf("Failed to set up AWS metadata API")
|
log.With(zap.Error(err)).Fatalf("Failed to set up AWS metadata client")
|
||||||
}
|
}
|
||||||
|
|
||||||
issuer = aws.NewIssuer(log)
|
issuer = aws.NewIssuer(log)
|
||||||
@ -87,9 +88,9 @@ func main() {
|
|||||||
_ = exportPCRs()
|
_ = exportPCRs()
|
||||||
log.With(zap.Error(err)).Fatalf("Unable to resolve Azure state disk path")
|
log.With(zap.Error(err)).Fatalf("Unable to resolve Azure state disk path")
|
||||||
}
|
}
|
||||||
metadataAPI, err = azurecloud.New(context.Background())
|
metadataClient, err = azurecloud.New(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.With(zap.Error).Fatalf("Failed to set up Azure metadata API")
|
log.With(zap.Error).Fatalf("Failed to set up Azure metadata client")
|
||||||
}
|
}
|
||||||
|
|
||||||
issuer = azure.NewIssuer(log)
|
issuer = azure.NewIssuer(log)
|
||||||
@ -103,26 +104,25 @@ func main() {
|
|||||||
issuer = gcp.NewIssuer(log)
|
issuer = gcp.NewIssuer(log)
|
||||||
gcpMeta, err := gcpcloud.New(context.Background())
|
gcpMeta, err := gcpcloud.New(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.With(zap.Error).Fatalf("Failed to create GCP client")
|
log.With(zap.Error).Fatalf("Failed to create GCP metadata client")
|
||||||
}
|
}
|
||||||
defer gcpMeta.Close()
|
defer gcpMeta.Close()
|
||||||
metadataAPI = gcpMeta
|
metadataClient = gcpMeta
|
||||||
|
|
||||||
case cloudprovider.OpenStack:
|
case cloudprovider.OpenStack:
|
||||||
diskPath = openstackStateDiskPath
|
diskPath = openstackStateDiskPath
|
||||||
// TODO(malt3): implement OpenStack metadata API and quote issuer
|
metadataClient, err = openstack.New(context.Background())
|
||||||
// issuer = ...
|
if err != nil {
|
||||||
// metadataAPI = ...
|
log.With(zap.Error).Fatalf("Failed to create OpenStack metadata client")
|
||||||
|
}
|
||||||
// TODO(katexochen): Remove the following
|
// TODO(malt3): implement OpenStack quote issuer
|
||||||
issuer = qemu.NewIssuer(log)
|
issuer = qemu.NewIssuer(log)
|
||||||
metadataAPI = qemucloud.New()
|
|
||||||
_ = exportPCRs()
|
_ = exportPCRs()
|
||||||
|
|
||||||
case cloudprovider.QEMU:
|
case cloudprovider.QEMU:
|
||||||
diskPath = qemuStateDiskPath
|
diskPath = qemuStateDiskPath
|
||||||
issuer = qemu.NewIssuer(log)
|
issuer = qemu.NewIssuer(log)
|
||||||
metadataAPI = qemucloud.New()
|
metadataClient = qemucloud.New()
|
||||||
_ = exportPCRs()
|
_ = exportPCRs()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -154,14 +154,14 @@ func main() {
|
|||||||
if mapper.IsLUKSDevice() {
|
if mapper.IsLUKSDevice() {
|
||||||
// set up rejoin client
|
// set up rejoin client
|
||||||
var self metadata.InstanceMetadata
|
var self metadata.InstanceMetadata
|
||||||
self, err = metadataAPI.Self(context.Background())
|
self, err = metadataClient.Self(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.With(zap.Error(err)).Fatalf("Failed to get self metadata")
|
log.With(zap.Error(err)).Fatalf("Failed to get self metadata")
|
||||||
}
|
}
|
||||||
rejoinClient := rejoinclient.New(
|
rejoinClient := rejoinclient.New(
|
||||||
dialer.New(issuer, nil, &net.Dialer{}),
|
dialer.New(issuer, nil, &net.Dialer{}),
|
||||||
self,
|
self,
|
||||||
metadataAPI,
|
metadataClient,
|
||||||
log.Named("rejoinClient"),
|
log.Named("rejoinClient"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
||||||
gcpcloud "github.com/edgelesssys/constellation/v2/internal/cloud/gcp"
|
gcpcloud "github.com/edgelesssys/constellation/v2/internal/cloud/gcp"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
||||||
|
"github.com/edgelesssys/constellation/v2/internal/cloud/openstack"
|
||||||
qemucloud "github.com/edgelesssys/constellation/v2/internal/cloud/qemu"
|
qemucloud "github.com/edgelesssys/constellation/v2/internal/cloud/qemu"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||||
@ -115,17 +116,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getVPCIP(ctx context.Context, provider string) (string, error) {
|
func getVPCIP(ctx context.Context, provider string) (string, error) {
|
||||||
var metadata metadataAPI
|
var metadataClient metadataAPI
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch cloudprovider.FromString(provider) {
|
switch cloudprovider.FromString(provider) {
|
||||||
case cloudprovider.AWS:
|
case cloudprovider.AWS:
|
||||||
metadata, err = awscloud.New(ctx)
|
metadataClient, err = awscloud.New(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
case cloudprovider.Azure:
|
case cloudprovider.Azure:
|
||||||
metadata, err = azurecloud.New(ctx)
|
metadataClient, err = azurecloud.New(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -135,14 +136,19 @@ func getVPCIP(ctx context.Context, provider string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer gcpMeta.Close()
|
defer gcpMeta.Close()
|
||||||
metadata = gcpMeta
|
metadataClient = gcpMeta
|
||||||
|
case cloudprovider.OpenStack:
|
||||||
|
metadataClient, err = openstack.New(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
case cloudprovider.QEMU:
|
case cloudprovider.QEMU:
|
||||||
metadata = qemucloud.New()
|
metadataClient = qemucloud.New()
|
||||||
default:
|
default:
|
||||||
return "", errors.New("unsupported cloud provider")
|
return "", errors.New("unsupported cloud provider")
|
||||||
}
|
}
|
||||||
|
|
||||||
self, err := metadata.Self(ctx)
|
self, err := metadataClient.Self(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user