mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-27 07:47:02 -05:00
Add VPNIP to nodestate
Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
parent
f2b3fc328b
commit
f827e479b1
@ -225,13 +225,14 @@ func (c *Core) Initialize() (nodeActivated bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PersistNodeState persists node state to disk.
|
// PersistNodeState persists node state to disk.
|
||||||
func (c *Core) PersistNodeState(role role.Role, ownerID []byte, clusterID []byte) error {
|
func (c *Core) PersistNodeState(role role.Role, vpnIP string, ownerID []byte, clusterID []byte) error {
|
||||||
vpnPrivKey, err := c.vpn.GetPrivateKey()
|
vpnPrivKey, err := c.vpn.GetPrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to retrieve VPN private key: %w", err)
|
return fmt.Errorf("failed to retrieve VPN private key: %w", err)
|
||||||
}
|
}
|
||||||
nodeState := nodestate.NodeState{
|
nodeState := nodestate.NodeState{
|
||||||
Role: role,
|
Role: role,
|
||||||
|
VPNIP: vpnIP,
|
||||||
VPNPrivKey: vpnPrivKey,
|
VPNPrivKey: vpnPrivKey,
|
||||||
OwnerID: ownerID,
|
OwnerID: ownerID,
|
||||||
ClusterID: clusterID,
|
ClusterID: clusterID,
|
||||||
|
@ -268,7 +268,7 @@ func TestPersistNodeState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
core, err := NewCore(tc.vpn, nil, nil, nil, nil, nil, nil, zaptest.NewLogger(t), nil, nil, fileHandler)
|
core, err := NewCore(tc.vpn, nil, nil, nil, nil, nil, nil, zaptest.NewLogger(t), nil, nil, fileHandler)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
err = core.PersistNodeState(role.Coordinator, []byte("owner-id"), []byte("cluster-id"))
|
err = core.PersistNodeState(role.Coordinator, "192.0.2.1", []byte("owner-id"), []byte("cluster-id"))
|
||||||
if tc.wantErr {
|
if tc.wantErr {
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
return
|
return
|
||||||
@ -278,6 +278,7 @@ func TestPersistNodeState(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(nodestate.NodeState{
|
assert.Equal(nodestate.NodeState{
|
||||||
Role: role.Coordinator,
|
Role: role.Coordinator,
|
||||||
|
VPNIP: "192.0.2.1",
|
||||||
VPNPrivKey: []byte("private-key"),
|
VPNPrivKey: []byte("private-key"),
|
||||||
OwnerID: []byte("owner-id"),
|
OwnerID: []byte("owner-id"),
|
||||||
ClusterID: []byte("cluster-id"),
|
ClusterID: []byte("cluster-id"),
|
||||||
|
@ -13,6 +13,7 @@ const nodeStatePath = "/run/state/constellation/node_state.json"
|
|||||||
// Can be persisted to disk and reloaded later.
|
// Can be persisted to disk and reloaded later.
|
||||||
type NodeState struct {
|
type NodeState struct {
|
||||||
Role role.Role
|
Role role.Role
|
||||||
|
VPNIP string
|
||||||
VPNPrivKey []byte
|
VPNPrivKey []byte
|
||||||
OwnerID []byte
|
OwnerID []byte
|
||||||
ClusterID []byte
|
ClusterID []byte
|
||||||
|
@ -18,9 +18,10 @@ func TestFromFile(t *testing.T) {
|
|||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
"nodestate exists": {
|
"nodestate exists": {
|
||||||
fileContents: `{ "Role": "Coordinator", "VPNPrivKey": "dGVzdA==", "OwnerID": "T3duZXJJRA==", "ClusterID": "Q2x1c3RlcklE" }`,
|
fileContents: `{ "Role": "Coordinator", "VPNIP": "192.0.2.1", "VPNPrivKey": "dGVzdA==", "OwnerID": "T3duZXJJRA==", "ClusterID": "Q2x1c3RlcklE" }`,
|
||||||
wantState: &NodeState{
|
wantState: &NodeState{
|
||||||
Role: role.Coordinator,
|
Role: role.Coordinator,
|
||||||
|
VPNIP: "192.0.2.1",
|
||||||
VPNPrivKey: []byte("test"),
|
VPNPrivKey: []byte("test"),
|
||||||
OwnerID: []byte("OwnerID"),
|
OwnerID: []byte("OwnerID"),
|
||||||
ClusterID: []byte("ClusterID"),
|
ClusterID: []byte("ClusterID"),
|
||||||
@ -63,12 +64,14 @@ func TestToFile(t *testing.T) {
|
|||||||
"writing works": {
|
"writing works": {
|
||||||
state: &NodeState{
|
state: &NodeState{
|
||||||
Role: role.Coordinator,
|
Role: role.Coordinator,
|
||||||
|
VPNIP: "192.0.2.1",
|
||||||
VPNPrivKey: []byte("test"),
|
VPNPrivKey: []byte("test"),
|
||||||
OwnerID: []byte("OwnerID"),
|
OwnerID: []byte("OwnerID"),
|
||||||
ClusterID: []byte("ClusterID"),
|
ClusterID: []byte("ClusterID"),
|
||||||
},
|
},
|
||||||
wantFile: `{
|
wantFile: `{
|
||||||
"Role": "Coordinator",
|
"Role": "Coordinator",
|
||||||
|
"VPNIP": "192.0.2.1",
|
||||||
"VPNPrivKey": "dGVzdA==",
|
"VPNPrivKey": "dGVzdA==",
|
||||||
"OwnerID": "T3duZXJJRA==",
|
"OwnerID": "T3duZXJJRA==",
|
||||||
"ClusterID": "Q2x1c3RlcklE"
|
"ClusterID": "Q2x1c3RlcklE"
|
||||||
|
@ -113,7 +113,7 @@ func (a *API) ActivateAsCoordinator(in *pubproto.ActivateAsCoordinatorRequest, s
|
|||||||
return status.Errorf(codes.Internal, "node initialization: %v", err)
|
return status.Errorf(codes.Internal, "node initialization: %v", err)
|
||||||
}
|
}
|
||||||
// persist node state on disk
|
// persist node state on disk
|
||||||
if err := a.core.PersistNodeState(role.Coordinator, ownerID, clusterID); err != nil {
|
if err := a.core.PersistNodeState(role.Coordinator, coordPeer.VPNIP, ownerID, clusterID); err != nil {
|
||||||
return status.Errorf(codes.Internal, "persist node state: %v", err)
|
return status.Errorf(codes.Internal, "persist node state: %v", err)
|
||||||
}
|
}
|
||||||
diskUUID, err := a.core.GetDiskUUID()
|
diskUUID, err := a.core.GetDiskUUID()
|
||||||
|
@ -19,7 +19,7 @@ type Core interface {
|
|||||||
GetNextCoordinatorIP() (string, error)
|
GetNextCoordinatorIP() (string, error)
|
||||||
SwitchToPersistentStore() error
|
SwitchToPersistentStore() error
|
||||||
GetIDs(masterSecret []byte) (ownerID []byte, clusterID []byte, err error)
|
GetIDs(masterSecret []byte) (ownerID []byte, clusterID []byte, err error)
|
||||||
PersistNodeState(role role.Role, ownerID []byte, clusterID []byte) error
|
PersistNodeState(role role.Role, vpnIP string, ownerID []byte, clusterID []byte) error
|
||||||
SetUpKMS(ctx context.Context, storageURI, kmsURI, kekID string, useExisting bool) error
|
SetUpKMS(ctx context.Context, storageURI, kmsURI, kekID string, useExisting bool) error
|
||||||
GetKMSInfo() (kms.KMSInformation, error)
|
GetKMSInfo() (kms.KMSInformation, error)
|
||||||
GetDataKey(ctx context.Context, keyID string, length int) ([]byte, error)
|
GetDataKey(ctx context.Context, keyID string, length int) ([]byte, error)
|
||||||
|
@ -129,7 +129,7 @@ func (c *fakeCore) JoinCluster(args *kubeadm.BootstrapTokenDiscovery, _ string,
|
|||||||
return c.joinClusterErr
|
return c.joinClusterErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeCore) PersistNodeState(role role.Role, ownerID []byte, clusterID []byte) error {
|
func (c *fakeCore) PersistNodeState(role role.Role, vpnIP string, ownerID []byte, clusterID []byte) error {
|
||||||
c.persistNodeStateRoles = append(c.persistNodeStateRoles, role)
|
c.persistNodeStateRoles = append(c.persistNodeStateRoles, role)
|
||||||
return c.persistNodeStateErr
|
return c.persistNodeStateErr
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ func (a *API) ActivateAsAdditionalCoordinator(ctx context.Context, in *pubproto.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// persist node state on disk
|
// persist node state on disk
|
||||||
if err := a.core.PersistNodeState(role.Coordinator, in.OwnerId, in.ClusterId); err != nil {
|
if err := a.core.PersistNodeState(role.Coordinator, in.AssignedVpnIp, in.OwnerId, in.ClusterId); err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "persist node state: %v", err)
|
return nil, status.Errorf(codes.Internal, "persist node state: %v", err)
|
||||||
}
|
}
|
||||||
diskUUID, err := a.core.GetDiskUUID()
|
diskUUID, err := a.core.GetDiskUUID()
|
||||||
|
@ -106,7 +106,7 @@ func (a *API) ActivateAsNode(stream pubproto.API_ActivateAsNodeServer) (reterr e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// persist node state on disk
|
// persist node state on disk
|
||||||
if err := a.core.PersistNodeState(role.Node, in.OwnerId, in.ClusterId); err != nil {
|
if err := a.core.PersistNodeState(role.Node, in.NodeVpnIp, in.OwnerId, in.ClusterId); err != nil {
|
||||||
return status.Errorf(codes.Internal, "persist node state: %v", err)
|
return status.Errorf(codes.Internal, "persist node state: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user