Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: remove Linux dependencies #1036

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion coordinator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/edgelesssys/contrast/coordinator/history"
"github.com/edgelesssys/contrast/coordinator/internal/authority"
"github.com/edgelesssys/contrast/internal/atls"
"github.com/edgelesssys/contrast/internal/atls/issuer"
"github.com/edgelesssys/contrast/internal/grpc/atlscredentials"
"github.com/edgelesssys/contrast/internal/logger"
"github.com/edgelesssys/contrast/internal/meshapi"
Expand Down Expand Up @@ -154,7 +155,7 @@ func newServerMetrics(reg *prometheus.Registry) *grpcprometheus.ServerMetrics {
}

func newGRPCServer(serverMetrics *grpcprometheus.ServerMetrics, log *slog.Logger) (*grpc.Server, error) {
issuer, err := atls.PlatformIssuer(log)
issuer, err := issuer.New(log)
if err != nil {
return nil, fmt.Errorf("creating issuer: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"github.com/edgelesssys/contrast/internal/atls"
"github.com/edgelesssys/contrast/internal/atls/issuer"
"github.com/edgelesssys/contrast/internal/grpc/dialer"
"github.com/edgelesssys/contrast/internal/logger"
"github.com/edgelesssys/contrast/internal/meshapi"
Expand Down Expand Up @@ -55,7 +56,7 @@ func run() (retErr error) {
return fmt.Errorf("generating key: %w", err)
}

issuer, err := atls.PlatformIssuer(log)
issuer, err := issuer.New(log)
if err != nil {
return fmt.Errorf("creating issuer: %w", err)
}
Expand Down
17 changes: 10 additions & 7 deletions internal/atls/issuer.go → internal/atls/issuer/issuer_linux.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
// Copyright 2024 Edgeless Systems GmbH
// SPDX-License-Identifier: AGPL-3.0-only

package atls
//go:build linux

package issuer

import (
"fmt"
"log/slog"

"github.com/edgelesssys/contrast/internal/attestation/snp"
"github.com/edgelesssys/contrast/internal/attestation/tdx"
"github.com/edgelesssys/contrast/internal/atls"
snpissuer "github.com/edgelesssys/contrast/internal/attestation/snp/issuer"
tdxissuer "github.com/edgelesssys/contrast/internal/attestation/tdx/issuer"
"github.com/edgelesssys/contrast/internal/logger"
"github.com/klauspost/cpuid/v2"
)

// PlatformIssuer creates an attestation issuer for the current platform.
func PlatformIssuer(log *slog.Logger) (Issuer, error) {
// New creates an attestation issuer for the current platform.
func New(log *slog.Logger) (atls.Issuer, error) {
cpuid.Detect()
switch {
case cpuid.CPU.Supports(cpuid.SEV_SNP):
return snp.NewIssuer(
return snpissuer.New(
logger.NewWithAttrs(logger.NewNamed(log, "issuer"), map[string]string{"tee-type": "snp"}),
), nil
case cpuid.CPU.Supports(cpuid.TDX_GUEST):
return tdx.NewIssuer(
return tdxissuer.New(
logger.NewWithAttrs(logger.NewNamed(log, "issuer"), map[string]string{"tee-type": "tdx"}),
), nil
default:
Expand Down
17 changes: 17 additions & 0 deletions internal/atls/issuer/issuer_universal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024 Edgeless Systems GmbH
// SPDX-License-Identifier: AGPL-3.0-only

//go:build !linux

package issuer

import (
"log/slog"

"github.com/edgelesssys/contrast/internal/atls"
)

// New creates an attestation issuer for the current platform.
func New(_ *slog.Logger) (atls.Issuer, error) {
panic("issuing is only supported on Linux")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright 2024 Edgeless Systems GmbH
// SPDX-License-Identifier: AGPL-3.0-only

package snp
//go:build linux

// package issuer provides functions to create an aTLS issuer.
package issuer

import (
"context"
Expand All @@ -27,8 +30,8 @@ type Issuer struct {
logger *slog.Logger
}

// NewIssuer returns a new Issuer.
func NewIssuer(log *slog.Logger) *Issuer {
// New returns a new Issuer.
func New(log *slog.Logger) *Issuer {
return &Issuer{
thimGetter: NewTHIMGetter(http.DefaultClient),
logger: log,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Edgeless Systems GmbH
// SPDX-License-Identifier: AGPL-3.0-only

package snp
package issuer

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Edgeless Systems GmbH
// SPDX-License-Identifier: AGPL-3.0-only

package tdx
package issuer

import (
"context"
Expand All @@ -23,8 +23,8 @@ type Issuer struct {
logger *slog.Logger
}

// NewIssuer returns a new Issuer.
func NewIssuer(log *slog.Logger) *Issuer {
// New returns a new Issuer.
func New(log *slog.Logger) *Issuer {
return &Issuer{
logger: log,
}
Expand Down