mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-06 14:30:18 -04:00
peer: save PublicIP instead of publicEndpoint / add multi-coord gRPCs
This commit is contained in:
parent
55a1aa783f
commit
f0e35a43d4
31 changed files with 1216 additions and 666 deletions
|
@ -162,7 +162,7 @@ func activate(ctx context.Context, cmd *cobra.Command, client protoClient, input
|
|||
return activationResult{}, err
|
||||
}
|
||||
|
||||
respCl, err := client.Activate(ctx, input.pubKey, input.masterSecret, ipsToEndpoints(input.nodePrivIPs, *config.CoordinatorPort), input.autoscalingNodeGroups, input.cloudServiceAccountURI)
|
||||
respCl, err := client.Activate(ctx, input.pubKey, input.masterSecret, input.nodePrivIPs, input.autoscalingNodeGroups, input.cloudServiceAccountURI)
|
||||
if err != nil {
|
||||
return activationResult{}, err
|
||||
}
|
||||
|
|
|
@ -77,17 +77,17 @@ func (c *Client) Close() error {
|
|||
}
|
||||
|
||||
// Activate activates the Constellation coordinator via a grpc call.
|
||||
// The handed endpoints must be the private endpoints of running AWS or GCP instances,
|
||||
// The handed IP addresses must be the private IP addresses of running AWS or GCP instances,
|
||||
// and the userPublicKey is the VPN key of the users WireGuard interface.
|
||||
func (c *Client) Activate(ctx context.Context, userPublicKey, masterSecret []byte, endpoints, autoscalingNodeGroups []string, cloudServiceAccountURI string) (ActivationResponseClient, error) {
|
||||
func (c *Client) Activate(ctx context.Context, userPublicKey, masterSecret []byte, ips, autoscalingNodeGroups []string, cloudServiceAccountURI string) (ActivationResponseClient, error) {
|
||||
if c.avpn == nil {
|
||||
return nil, errors.New("client is not connected")
|
||||
}
|
||||
if len(userPublicKey) == 0 {
|
||||
return nil, errors.New("parameter userPublicKey is empty")
|
||||
}
|
||||
if len(endpoints) == 0 {
|
||||
return nil, errors.New("parameter endpoints is empty")
|
||||
if len(ips) == 0 {
|
||||
return nil, errors.New("parameter ips is empty")
|
||||
}
|
||||
|
||||
pubKey, err := wgtypes.ParseKey(string(userPublicKey))
|
||||
|
@ -97,7 +97,7 @@ func (c *Client) Activate(ctx context.Context, userPublicKey, masterSecret []byt
|
|||
|
||||
avpnRequest := &pubproto.ActivateAsCoordinatorRequest{
|
||||
AdminVpnPubKey: pubKey[:],
|
||||
NodePublicEndpoints: endpoints,
|
||||
NodePublicIps: ips,
|
||||
AutoscalingNodeGroups: autoscalingNodeGroups,
|
||||
MasterSecret: masterSecret,
|
||||
KmsUri: kms.ClusterKMSURI,
|
||||
|
|
|
@ -72,42 +72,42 @@ func TestActivate(t *testing.T) {
|
|||
testCases := map[string]struct {
|
||||
avpn *stubAVPNClient
|
||||
userPublicKey string
|
||||
endpoints []string
|
||||
ips []string
|
||||
errExpected bool
|
||||
}{
|
||||
"normal activation": {
|
||||
avpn: &stubAVPNClient{},
|
||||
userPublicKey: testKey,
|
||||
endpoints: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: false,
|
||||
},
|
||||
"client without avpn": {
|
||||
userPublicKey: testKey,
|
||||
endpoints: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: true,
|
||||
},
|
||||
"empty public key parameter": {
|
||||
avpn: &stubAVPNClient{},
|
||||
userPublicKey: "",
|
||||
endpoints: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: true,
|
||||
},
|
||||
"invalid public key parameter": {
|
||||
avpn: &stubAVPNClient{},
|
||||
userPublicKey: "invalid Key",
|
||||
endpoints: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: true,
|
||||
},
|
||||
"empty ips parameter": {
|
||||
avpn: &stubAVPNClient{},
|
||||
userPublicKey: testKey,
|
||||
endpoints: []string{},
|
||||
ips: []string{},
|
||||
errExpected: true,
|
||||
},
|
||||
"fail ActivateAsCoordinator": {
|
||||
avpn: &stubAVPNClient{activateAsCoordinatorErr: someErr},
|
||||
userPublicKey: testKey,
|
||||
endpoints: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||
errExpected: true,
|
||||
},
|
||||
}
|
||||
|
@ -120,13 +120,13 @@ func TestActivate(t *testing.T) {
|
|||
if tc.avpn != nil {
|
||||
client.avpn = tc.avpn
|
||||
}
|
||||
_, err := client.Activate(context.Background(), []byte(tc.userPublicKey), []byte("Constellation"), tc.endpoints, nil, "serviceaccount://test")
|
||||
_, err := client.Activate(context.Background(), []byte(tc.userPublicKey), []byte("Constellation"), tc.ips, nil, "serviceaccount://test")
|
||||
if tc.errExpected {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
assert.Equal("32bytesWireGuardKeyForTheTesting", string(tc.avpn.activateAsCoordinatorReqKey))
|
||||
assert.Equal(tc.endpoints, tc.avpn.activateAsCoordinatorReqEndpoints)
|
||||
assert.Equal(tc.ips, tc.avpn.activateAsCoordinatorReqIPs)
|
||||
assert.Equal("Constellation", string(tc.avpn.activateAsCoordinatorMasterSecret))
|
||||
assert.Equal("serviceaccount://test", tc.avpn.activateCloudServiceAccountURI)
|
||||
}
|
||||
|
@ -135,13 +135,13 @@ func TestActivate(t *testing.T) {
|
|||
}
|
||||
|
||||
type stubAVPNClient struct {
|
||||
activateAsCoordinatorErr error
|
||||
activateAdditionalNodesErr error
|
||||
activateAsCoordinatorReqKey []byte
|
||||
activateAsCoordinatorReqEndpoints []string
|
||||
activateAsCoordinatorMasterSecret []byte
|
||||
activateAdditionalNodesReqEndpoints []string
|
||||
activateCloudServiceAccountURI string
|
||||
activateAsCoordinatorErr error
|
||||
activateAdditionalNodesErr error
|
||||
activateAsCoordinatorReqKey []byte
|
||||
activateAsCoordinatorReqIPs []string
|
||||
activateAsCoordinatorMasterSecret []byte
|
||||
activateAdditionalNodesReqIPs []string
|
||||
activateCloudServiceAccountURI string
|
||||
pubproto.APIClient
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ func (s *stubAVPNClient) ActivateAsCoordinator(ctx context.Context, in *pubproto
|
|||
opts ...grpc.CallOption,
|
||||
) (pubproto.API_ActivateAsCoordinatorClient, error) {
|
||||
s.activateAsCoordinatorReqKey = in.AdminVpnPubKey
|
||||
s.activateAsCoordinatorReqEndpoints = in.NodePublicEndpoints
|
||||
s.activateAsCoordinatorReqIPs = in.NodePublicIps
|
||||
s.activateAsCoordinatorMasterSecret = in.MasterSecret
|
||||
s.activateCloudServiceAccountURI = in.CloudServiceAccountUri
|
||||
return dummyAVPNActivateAsCoordinatorClient{}, s.activateAsCoordinatorErr
|
||||
|
@ -158,6 +158,6 @@ func (s *stubAVPNClient) ActivateAsCoordinator(ctx context.Context, in *pubproto
|
|||
func (s *stubAVPNClient) ActivateAdditionalNodes(ctx context.Context, in *pubproto.ActivateAdditionalNodesRequest,
|
||||
opts ...grpc.CallOption,
|
||||
) (pubproto.API_ActivateAdditionalNodesClient, error) {
|
||||
s.activateAdditionalNodesReqEndpoints = in.NodePublicEndpoints
|
||||
s.activateAdditionalNodesReqIPs = in.NodePublicIps
|
||||
return dummyAVPNActivateAdditionalNodesClient{}, s.activateAdditionalNodesErr
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue