Skip to content

Commit

Permalink
treewide: coordapi -> userapi
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Meyer <[email protected]>
  • Loading branch information
katexochen committed Feb 26, 2024
1 parent 170c6b0 commit 51ed5ed
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 285 deletions.
10 changes: 5 additions & 5 deletions cli/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (

"github.com/edgelesssys/nunki/internal/atls"
"github.com/edgelesssys/nunki/internal/attestation/snp"
"github.com/edgelesssys/nunki/internal/coordapi"
"github.com/edgelesssys/nunki/internal/fsstore"
"github.com/edgelesssys/nunki/internal/grpc/dialer"
"github.com/edgelesssys/nunki/internal/manifest"
"github.com/edgelesssys/nunki/internal/spinner"
"github.com/edgelesssys/nunki/internal/userapi"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -112,8 +112,8 @@ func runSet(cmd *cobra.Command, args []string) error {
}
defer conn.Close()

client := coordapi.NewCoordAPIClient(conn)
req := &coordapi.SetManifestRequest{
client := userapi.NewUserAPIClient(conn)
req := &userapi.SetManifestRequest{
Manifest: manifestBytes,
Policies: policyMapToBytesList(policies),
}
Expand Down Expand Up @@ -227,8 +227,8 @@ func loadWorkloadOwnerKey(path string, manifst manifest.Manifest, log *slog.Logg
}

func setLoop(
ctx context.Context, client coordapi.CoordAPIClient, out io.Writer, req *coordapi.SetManifestRequest,
) (resp *coordapi.SetManifestResponse, retErr error) {
ctx context.Context, client userapi.UserAPIClient, out io.Writer, req *userapi.SetManifestRequest,
) (resp *userapi.SetManifestResponse, retErr error) {
spinner := spinner.New(" Waiting for coordinator ", 500*time.Millisecond, out)
spinner.Start()
defer func() {
Expand Down
6 changes: 3 additions & 3 deletions cli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

"github.com/edgelesssys/nunki/internal/atls"
"github.com/edgelesssys/nunki/internal/attestation/snp"
"github.com/edgelesssys/nunki/internal/coordapi"
"github.com/edgelesssys/nunki/internal/fsstore"
"github.com/edgelesssys/nunki/internal/grpc/dialer"
"github.com/edgelesssys/nunki/internal/manifest"
"github.com/edgelesssys/nunki/internal/userapi"
"github.com/google/go-sev-guest/abi"
"github.com/google/go-sev-guest/kds"
"github.com/google/go-sev-guest/validate"
Expand Down Expand Up @@ -78,8 +78,8 @@ func runVerify(cmd *cobra.Command, _ []string) error {
defer conn.Close()

log.Debug("Getting manifest")
client := coordapi.NewCoordAPIClient(conn)
resp, err := client.GetManifests(cmd.Context(), &coordapi.GetManifestsRequest{})
client := userapi.NewUserAPIClient(conn)
resp, err := client.GetManifests(cmd.Context(), &userapi.GetManifestsRequest{})
if err != nil {
return fmt.Errorf("failed to get manifest: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions coordinator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"

"github.com/edgelesssys/nunki/internal/ca"
"github.com/edgelesssys/nunki/internal/coordapi"
"github.com/edgelesssys/nunki/internal/logger"
"github.com/edgelesssys/nunki/internal/meshapi"
"github.com/edgelesssys/nunki/internal/userapi"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -38,14 +38,14 @@ func run() (retErr error) {
}

meshAuth := newMeshAuthority(caInstance, logger)
coordS := newCoordAPIServer(meshAuth, caInstance, logger)
userAPI := newUserAPIServer(meshAuth, caInstance, logger)
meshAPI := newMeshAPIServer(meshAuth, caInstance, logger)

eg := errgroup.Group{}

eg.Go(func() error {
logger.Info("Coordinator API listening")
if err := coordS.Serve(net.JoinHostPort("0.0.0.0", coordapi.Port)); err != nil {
logger.Info("Coordinator user API listening")
if err := userAPI.Serve(net.JoinHostPort("0.0.0.0", userapi.Port)); err != nil {
return fmt.Errorf("serving Coordinator API: %w", err)
}
return nil
Expand Down
30 changes: 15 additions & 15 deletions coordinator/coordapi.go → coordinator/userapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (

"github.com/edgelesssys/nunki/internal/appendable"
"github.com/edgelesssys/nunki/internal/attestation/snp"
"github.com/edgelesssys/nunki/internal/coordapi"
"github.com/edgelesssys/nunki/internal/grpc/atlscredentials"
"github.com/edgelesssys/nunki/internal/logger"
"github.com/edgelesssys/nunki/internal/manifest"
"github.com/edgelesssys/nunki/internal/memstore"
"github.com/edgelesssys/nunki/internal/userapi"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
Expand All @@ -28,45 +28,45 @@ import (
"google.golang.org/grpc/status"
)

type coordAPIServer struct {
type userAPIServer struct {
grpc *grpc.Server
policyTextStore store[manifest.HexString, manifest.Policy]
manifSetGetter manifestSetGetter
caChainGetter certChainGetter
logger *slog.Logger
mux sync.RWMutex

coordapi.UnimplementedCoordAPIServer
userapi.UnimplementedUserAPIServer
}

func newCoordAPIServer(mSGetter manifestSetGetter, caGetter certChainGetter, log *slog.Logger) *coordAPIServer {
func newUserAPIServer(mSGetter manifestSetGetter, caGetter certChainGetter, log *slog.Logger) *userAPIServer {
issuer := snp.NewIssuer(logger.NewNamed(log, "snp-issuer"))
credentials := atlscredentials.New(issuer, nil)
grpcServer := grpc.NewServer(
grpc.Creds(credentials),
grpc.KeepaliveParams(keepalive.ServerParameters{Time: 15 * time.Second}),
)
s := &coordAPIServer{
s := &userAPIServer{
grpc: grpcServer,
policyTextStore: memstore.New[manifest.HexString, manifest.Policy](),
manifSetGetter: mSGetter,
caChainGetter: caGetter,
logger: log.WithGroup("coordapi"),
logger: log.WithGroup("userapi"),
}
coordapi.RegisterCoordAPIServer(s.grpc, s)
userapi.RegisterUserAPIServer(s.grpc, s)
return s
}

func (s *coordAPIServer) Serve(endpoint string) error {
func (s *userAPIServer) Serve(endpoint string) error {
lis, err := net.Listen("tcp", endpoint)
if err != nil {
return fmt.Errorf("failed to listen: %w", err)
}
return s.grpc.Serve(lis)
}

func (s *coordAPIServer) SetManifest(ctx context.Context, req *coordapi.SetManifestRequest,
) (*coordapi.SetManifestResponse, error) {
func (s *userAPIServer) SetManifest(ctx context.Context, req *userapi.SetManifestRequest,
) (*userapi.SetManifestResponse, error) {
s.logger.Info("SetManifest called")
s.mux.Lock()
defer s.mux.Unlock()
Expand Down Expand Up @@ -100,7 +100,7 @@ func (s *coordAPIServer) SetManifest(ctx context.Context, req *coordapi.SetManif
return nil, status.Errorf(codes.Internal, "setting manifest: %v", err)
}

resp := &coordapi.SetManifestResponse{
resp := &userapi.SetManifestResponse{
CACert: s.caChainGetter.GetRootCACert(),
IntermCert: s.caChainGetter.GetIntermCert(),
}
Expand All @@ -109,8 +109,8 @@ func (s *coordAPIServer) SetManifest(ctx context.Context, req *coordapi.SetManif
return resp, nil
}

func (s *coordAPIServer) GetManifests(_ context.Context, _ *coordapi.GetManifestsRequest,
) (*coordapi.GetManifestsResponse, error) {
func (s *userAPIServer) GetManifests(_ context.Context, _ *userapi.GetManifestsRequest,
) (*userapi.GetManifestsResponse, error) {
s.logger.Info("GetManifest called")
s.mux.RLock()
defer s.mux.RUnlock()
Expand All @@ -130,7 +130,7 @@ func (s *coordAPIServer) GetManifests(_ context.Context, _ *coordapi.GetManifest
return nil, status.Error(codes.Internal, "no policies found in store")
}

resp := &coordapi.GetManifestsResponse{
resp := &userapi.GetManifestsResponse{
Manifests: manifestBytes,
Policies: policySliceToBytesSlice(policies),
CACert: s.caChainGetter.GetRootCACert(),
Expand All @@ -141,7 +141,7 @@ func (s *coordAPIServer) GetManifests(_ context.Context, _ *coordapi.GetManifest
return resp, nil
}

func (s *coordAPIServer) validatePeer(ctx context.Context) error {
func (s *userAPIServer) validatePeer(ctx context.Context) error {
latest, err := s.manifSetGetter.LatestManifest()
if err != nil && errors.Is(err, appendable.ErrIsEmpty) {
// in the initial state, no peer validation is required
Expand Down
40 changes: 20 additions & 20 deletions coordinator/coordapi_test.go → coordinator/userapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"testing"

"github.com/edgelesssys/nunki/internal/appendable"
"github.com/edgelesssys/nunki/internal/coordapi"
"github.com/edgelesssys/nunki/internal/manifest"
"github.com/edgelesssys/nunki/internal/memstore"
"github.com/edgelesssys/nunki/internal/userapi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -46,19 +46,19 @@ func TestManifestSet(t *testing.T) {
require.NoError(t, err)

testCases := map[string]struct {
req *coordapi.SetManifestRequest
req *userapi.SetManifestRequest
mSGetter *stubManifestSetGetter
caGetter *stubCertChainGetter
workloadOwnerKey *ecdsa.PrivateKey
wantErr bool
}{
"empty request": {
req: &coordapi.SetManifestRequest{},
req: &userapi.SetManifestRequest{},
mSGetter: &stubManifestSetGetter{},
wantErr: true,
},
"manifest without policies": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = nil
}),
Expand All @@ -67,7 +67,7 @@ func TestManifestSet(t *testing.T) {
wantErr: true,
},
"request without policies": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("a"): {"a1", "a2"},
Expand All @@ -79,7 +79,7 @@ func TestManifestSet(t *testing.T) {
wantErr: true,
},
"policy not in manifest": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"): {"a1", "a2"},
Expand All @@ -95,7 +95,7 @@ func TestManifestSet(t *testing.T) {
wantErr: true,
},
"valid manifest": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"): {"a1", "a2"},
Expand All @@ -111,7 +111,7 @@ func TestManifestSet(t *testing.T) {
caGetter: &stubCertChainGetter{},
},
"valid manifest but error when setting it": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"): {"a1", "a2"},
Expand All @@ -128,7 +128,7 @@ func TestManifestSet(t *testing.T) {
wantErr: true,
},
"workload owner key match": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"): {"a1", "a2"},
Expand All @@ -147,7 +147,7 @@ func TestManifestSet(t *testing.T) {
workloadOwnerKey: trustedKey,
},
"workload owner key mismatch": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"): {"a1", "a2"},
Expand All @@ -167,7 +167,7 @@ func TestManifestSet(t *testing.T) {
wantErr: true,
},
"workload owner key missing": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"): {"a1", "a2"},
Expand All @@ -186,7 +186,7 @@ func TestManifestSet(t *testing.T) {
wantErr: true,
},
"manifest not updatable": {
req: &coordapi.SetManifestRequest{
req: &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"): {"a1", "a2"},
Expand All @@ -212,7 +212,7 @@ func TestManifestSet(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

coordinator := coordAPIServer{
coordinator := userAPIServer{
manifSetGetter: tc.mSGetter,
caChainGetter: tc.caGetter,
policyTextStore: memstore.New[manifest.HexString, manifest.Policy](),
Expand Down Expand Up @@ -278,15 +278,15 @@ func TestGetManifests(t *testing.T) {
policyStore.Set(k, v)
}

coordinator := coordAPIServer{
coordinator := userAPIServer{
manifSetGetter: tc.mSGetter,
caChainGetter: tc.caGetter,
policyTextStore: policyStore,
logger: slog.Default(),
}

ctx := context.Background()
resp, err := coordinator.GetManifests(ctx, &coordapi.GetManifestsRequest{})
resp, err := coordinator.GetManifests(ctx, &userapi.GetManifestsRequest{})

if tc.wantErr {
assert.Error(err)
Expand All @@ -300,9 +300,9 @@ func TestGetManifests(t *testing.T) {
}
}

// TestCoordAPIConcurrent tests potential synchronization problems between the different
// TestUserAPIConcurrent tests potential synchronization problems between the different
// gRPCs of the server.
func TestCoordAPIConcurrent(t *testing.T) {
func TestUserAPIConcurrent(t *testing.T) {
newBaseManifest := func() manifest.Manifest {
return manifest.Default()
}
Expand All @@ -316,13 +316,13 @@ func TestCoordAPIConcurrent(t *testing.T) {
return b
}

coordinator := coordAPIServer{
coordinator := userAPIServer{
manifSetGetter: &stubManifestSetGetter{},
caChainGetter: &stubCertChainGetter{},
policyTextStore: memstore.New[manifest.HexString, manifest.Policy](),
logger: slog.Default(),
}
setReq := &coordapi.SetManifestRequest{
setReq := &userapi.SetManifestRequest{
Manifest: newManifestBytes(func(m *manifest.Manifest) {
m.Policies = map[manifest.HexString][]string{
manifest.HexString("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"): {"a1", "a2"},
Expand All @@ -344,7 +344,7 @@ func TestCoordAPIConcurrent(t *testing.T) {
}
get := func() {
defer wg.Done()
_, _ = coordinator.GetManifests(ctx, &coordapi.GetManifestsRequest{})
_, _ = coordinator.GetManifests(ctx, &userapi.GetManifestsRequest{})
}

wg.Add(12)
Expand Down
2 changes: 1 addition & 1 deletion deployments/emojivoto/coordinator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
- name: meshapi
port: 7777
protocol: TCP
- name: coordapi
- name: userapi
port: 1313
protocol: TCP
selector:
Expand Down
2 changes: 1 addition & 1 deletion deployments/openssl/coordinator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
- name: meshapi
port: 7777
protocol: TCP
- name: coordapi
- name: userapi
port: 1313
protocol: TCP
selector:
Expand Down
2 changes: 1 addition & 1 deletion deployments/simple/coordinator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
- name: meshapi
port: 7777
protocol: TCP
- name: coordapi
- name: userapi
port: 1313
protocol: TCP
selector:
Expand Down
Loading

0 comments on commit 51ed5ed

Please sign in to comment.