mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-02-23 00:10:06 -05:00
adjusted code accordingly
This commit is contained in:
parent
6f2f5b58f0
commit
0718f14bc5
@ -10,7 +10,6 @@ import (
|
|||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
@ -28,8 +27,8 @@ import (
|
|||||||
func NewSSHCmd() *cobra.Command {
|
func NewSSHCmd() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "ssh",
|
Use: "ssh",
|
||||||
Short: "Prepare your cluster for emergency ssh access",
|
Short: "Generate a certificate for emergency ssh access",
|
||||||
Long: "Prepare your cluster for emergency ssh access and sign a given key pair for authorization.",
|
Long: "Generate a certificate for emergency ssh access to your ssh enabled constellation cluster.",
|
||||||
Args: cobra.ExactArgs(0),
|
Args: cobra.ExactArgs(0),
|
||||||
RunE: runSSH,
|
RunE: runSSH,
|
||||||
}
|
}
|
||||||
@ -54,18 +53,10 @@ func runSSH(cmd *cobra.Command, _ []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeCertificateForKey(cmd *cobra.Command, keyPath string, fh file.Handler, debugLogger debugLog) error {
|
func writeCertificateForKey(cmd *cobra.Command, keyPath string, fh file.Handler, debugLogger debugLog) error {
|
||||||
_, err := fh.Stat(constants.TerraformWorkingDir)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return fmt.Errorf("directory %q does not exist", constants.TerraformWorkingDir)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(miampf): Since other KMS aren't fully implemented yet, this commands assumes that the cKMS is used and derives the key accordingly.
|
// NOTE(miampf): Since other KMS aren't fully implemented yet, this commands assumes that the cKMS is used and derives the key accordingly.
|
||||||
var mastersecret uri.MasterSecret
|
var mastersecret uri.MasterSecret
|
||||||
if err = fh.ReadJSON(constants.MasterSecretFilename, &mastersecret); err != nil {
|
if err := fh.ReadJSON(constants.MasterSecretFilename, &mastersecret); err != nil {
|
||||||
return fmt.Errorf("reading master secret: %s", err)
|
return fmt.Errorf("reading master secret (does %q exist?): %s", constants.MasterSecretFilename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mastersecretURI := uri.MasterSecret{Key: mastersecret.Key, Salt: mastersecret.Salt}
|
mastersecretURI := uri.MasterSecret{Key: mastersecret.Key, Salt: mastersecret.Salt}
|
||||||
@ -113,10 +104,10 @@ func writeCertificateForKey(cmd *cobra.Command, keyPath string, fh file.Handler,
|
|||||||
}
|
}
|
||||||
|
|
||||||
debugLogger.Debug("Signed certificate", "certificate", string(ssh.MarshalAuthorizedKey(&certificate)))
|
debugLogger.Debug("Signed certificate", "certificate", string(ssh.MarshalAuthorizedKey(&certificate)))
|
||||||
if err := fh.Write(fmt.Sprintf("%s/ca_cert.pub", constants.TerraformWorkingDir), ssh.MarshalAuthorizedKey(&certificate), file.OptOverwrite); err != nil {
|
if err := fh.Write("constellation_cert.pub", ssh.MarshalAuthorizedKey(&certificate), file.OptOverwrite); err != nil {
|
||||||
return fmt.Errorf("writing certificate: %s", err)
|
return fmt.Errorf("writing certificate: %s", err)
|
||||||
}
|
}
|
||||||
cmd.Printf("You can now connect to a node using 'ssh -F %s/ssh_config -i <your private key> <node ip>' in your constellation workspace.\nYou can obtain the private node IP via the web UI of your CSP.\n", constants.TerraformWorkingDir)
|
cmd.Printf("You can now connect to a node using the \"constellation_cert.pub\" certificate.\nLook at the documentation for a how to guide:\n\n\thttps://https://docs.edgeless.systems/constellation/workflows/troubleshooting#emergency-ssh-access\n")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
@ -29,18 +28,6 @@ func TestSSH(t *testing.T) {
|
|||||||
"salt": "MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAK"
|
"salt": "MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAK"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
newFsWithDirectory := func() file.Handler {
|
|
||||||
require := require.New(t)
|
|
||||||
fh := file.NewHandler(afero.NewMemMapFs())
|
|
||||||
require.NoError(fh.MkdirAll(constants.TerraformWorkingDir))
|
|
||||||
return fh
|
|
||||||
}
|
|
||||||
newFsNoDirectory := func() file.Handler {
|
|
||||||
fh := file.NewHandler(afero.NewMemMapFs())
|
|
||||||
return fh
|
|
||||||
}
|
|
||||||
|
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
fh file.Handler
|
fh file.Handler
|
||||||
pubKey string
|
pubKey string
|
||||||
@ -48,38 +35,32 @@ func TestSSH(t *testing.T) {
|
|||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
"everything exists": {
|
"everything exists": {
|
||||||
fh: newFsWithDirectory(),
|
fh: file.NewHandler(afero.NewMemMapFs()),
|
||||||
pubKey: someSSHPubKey,
|
pubKey: someSSHPubKey,
|
||||||
masterSecret: someMasterSecret,
|
masterSecret: someMasterSecret,
|
||||||
},
|
},
|
||||||
"no public key": {
|
"no public key": {
|
||||||
fh: newFsWithDirectory(),
|
fh: file.NewHandler(afero.NewMemMapFs()),
|
||||||
masterSecret: someMasterSecret,
|
masterSecret: someMasterSecret,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"no master secret": {
|
"no master secret": {
|
||||||
fh: newFsWithDirectory(),
|
fh: file.NewHandler(afero.NewMemMapFs()),
|
||||||
pubKey: someSSHPubKey,
|
pubKey: someSSHPubKey,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"malformed public key": {
|
"malformed public key": {
|
||||||
fh: newFsWithDirectory(),
|
fh: file.NewHandler(afero.NewMemMapFs()),
|
||||||
pubKey: "asdf",
|
pubKey: "asdf",
|
||||||
masterSecret: someMasterSecret,
|
masterSecret: someMasterSecret,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"malformed master secret": {
|
"malformed master secret": {
|
||||||
fh: newFsWithDirectory(),
|
fh: file.NewHandler(afero.NewMemMapFs()),
|
||||||
masterSecret: "asdf",
|
masterSecret: "asdf",
|
||||||
pubKey: someSSHPubKey,
|
pubKey: someSSHPubKey,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"directory does not exist": {
|
|
||||||
fh: newFsNoDirectory(),
|
|
||||||
pubKey: someSSHPubKey,
|
|
||||||
masterSecret: someMasterSecret,
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, tc := range testCases {
|
for name, tc := range testCases {
|
||||||
@ -104,7 +85,7 @@ func TestSSH(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
cert, err := tc.fh.Read(fmt.Sprintf("%s/ca_cert.pub", constants.TerraformWorkingDir))
|
cert, err := tc.fh.Read("constellation_cert.pub")
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
_, _, _, _, err = ssh.ParseAuthorizedKey(cert)
|
_, _, _, _, err = ssh.ParseAuthorizedKey(cert)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
@ -296,19 +296,3 @@ data "azurerm_user_assigned_identity" "uaid" {
|
|||||||
name = local.uai_name
|
name = local.uai_name
|
||||||
resource_group_name = local.uai_resource_group
|
resource_group_name = local.uai_resource_group
|
||||||
}
|
}
|
||||||
|
|
||||||
# emergency ssh configuration files
|
|
||||||
resource "local_file" "ssh_config" {
|
|
||||||
filename = "./ssh_config"
|
|
||||||
file_permission = "0600"
|
|
||||||
content = <<EOF
|
|
||||||
Host ${azurerm_public_ip.loadbalancer_ip[0].fqdn}
|
|
||||||
ProxyJump none
|
|
||||||
|
|
||||||
Host *
|
|
||||||
PreferredAuthentications publickey
|
|
||||||
CertificateFile=constellation-terraform/ca_cert.pub
|
|
||||||
User root
|
|
||||||
ProxyJump ${azurerm_public_ip.loadbalancer_ip[0].fqdn}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user