Minor things
This commit is contained in:
parent
8f62831b9d
commit
41d8cb42c9
5 changed files with 47 additions and 12 deletions
|
|
@ -63,5 +63,5 @@ func init() {
|
||||||
defaultDataDir = filepath.Join(homeDir, homeDirName)
|
defaultDataDir = filepath.Join(homeDir, homeDirName)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVar(&dataDirFlag, "data-dir", defaultDataDir, "Specifies the data directory (folder) to use. The VM images will be stored here.")
|
rootCmd.PersistentFlags().StringVarP(&dataDirFlag, "data-dir", "d", defaultDataDir, "Specifies the data directory (folder) to use. VM images and related work files will be stored here.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
cmd/run.go
36
cmd/run.go
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
var runCmd = &cobra.Command{
|
var runCmd = &cobra.Command{
|
||||||
Use: "run",
|
Use: "run",
|
||||||
Short: "Start a VM and expose a file share.",
|
Short: "Start a VM and expose an FTP file share.",
|
||||||
Args: cobra.ExactArgs(3),
|
Args: cobra.ExactArgs(3),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
vmMountDevName := args[1]
|
vmMountDevName := args[1]
|
||||||
|
|
@ -28,8 +28,24 @@ var runCmd = &cobra.Command{
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ftpListenIP := net.ParseIP(ftpListenAddrFlag)
|
||||||
|
if ftpListenIP == nil {
|
||||||
|
slog.Error("Invalid FTP listen address specified", "value", ftpListenAddrFlag)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
ftpExtIP := net.ParseIP(ftpExtIPFlag)
|
||||||
|
if ftpExtIP == nil {
|
||||||
|
slog.Error("Invalid FTP external IP specified", "value", ftpExtIPFlag)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ftpListenAddrFlag != defaultFTPListenAddr && ftpExtIPFlag == defaultFTPListenAddr {
|
||||||
|
slog.Warn("No external FTP IP address via --ftp-extip was configured. This is a requirement in almost all scenarios if you want to connect remotely.")
|
||||||
|
}
|
||||||
|
|
||||||
ports := []vm.PortForwardingRule{{
|
ports := []vm.PortForwardingRule{{
|
||||||
HostIP: net.ParseIP("127.0.0.1"), // TODO: Make this changeable.
|
HostIP: ftpListenIP,
|
||||||
HostPort: networkSharePort,
|
HostPort: networkSharePort,
|
||||||
VMPort: 21,
|
VMPort: 21,
|
||||||
}}
|
}}
|
||||||
|
|
@ -37,7 +53,7 @@ var runCmd = &cobra.Command{
|
||||||
for i := uint16(0); i < ftpPassivePortCount; i++ {
|
for i := uint16(0); i < ftpPassivePortCount; i++ {
|
||||||
p := networkSharePort + 1 + i
|
p := networkSharePort + 1 + i
|
||||||
ports = append(ports, vm.PortForwardingRule{
|
ports = append(ports, vm.PortForwardingRule{
|
||||||
HostIP: net.ParseIP("127.0.0.1"), // TODO: Make this changeable.
|
HostIP: ftpListenIP,
|
||||||
HostPort: p,
|
HostPort: p,
|
||||||
VMPort: p,
|
VMPort: p,
|
||||||
})
|
})
|
||||||
|
|
@ -61,7 +77,7 @@ var runCmd = &cobra.Command{
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
err = fm.StartFTP(sharePWD, networkSharePort+1, ftpPassivePortCount)
|
err = fm.StartFTP(sharePWD, networkSharePort+1, ftpPassivePortCount, ftpExtIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to start FTP server", "error", err.Error())
|
slog.Error("Failed to start FTP server", "error", err.Error())
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -69,9 +85,9 @@ var runCmd = &cobra.Command{
|
||||||
|
|
||||||
slog.Info("Started the network share successfully", "type", "ftp")
|
slog.Info("Started the network share successfully", "type", "ftp")
|
||||||
|
|
||||||
shareURI := "ftp://linsk:" + sharePWD + "@localhost:" + fmt.Sprint(networkSharePort)
|
shareURI := "ftp://linsk:" + sharePWD + "@" + ftpExtIP.String() + ":" + fmt.Sprint(networkSharePort)
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "================\n[Network File Share Config]\nThe network file share was started. Please use the credentials below to connect to the file server.\n\nType: FTP\nServer Address: ftp://localhost:%v\nUsername: linsk\nPassword: %v\n\nShare URI: %v\n================\n", networkSharePort, sharePWD, shareURI)
|
fmt.Fprintf(os.Stderr, "================\n[Network File Share Config]\nThe network file share was started. Please use the credentials below to connect to the file server.\n\nType: FTP\nServer Address: ftp://%v:%v\nUsername: linsk\nPassword: %v\n\nShare URI: %v\n================\n", ftpExtIP.String(), networkSharePort, sharePWD, shareURI)
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -80,7 +96,13 @@ var runCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var luksFlag bool
|
var luksFlag bool
|
||||||
|
var ftpListenAddrFlag string
|
||||||
|
var ftpExtIPFlag string
|
||||||
|
|
||||||
|
const defaultFTPListenAddr = "127.0.0.1"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runCmd.Flags().BoolVarP(&luksFlag, "luks", "l", false, "Use cryptsetup to open a LUKS volume (password will be prompted)")
|
runCmd.Flags().BoolVarP(&luksFlag, "luks", "l", false, "Use cryptsetup to open a LUKS volume (password will be prompted).")
|
||||||
|
runCmd.Flags().StringVar(&ftpListenAddrFlag, "ftp-listen", defaultFTPListenAddr, "Specifies the address to bind the FTP ports to. NOTE: Changing bind address is not enough to connect remotely. You should also specify --ftp-extip.")
|
||||||
|
runCmd.Flags().StringVar(&ftpExtIPFlag, "ftp-extip", defaultFTPListenAddr, "Specifies the external IP the FTP server should advertise.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ func runAlpineSetupCmd(sc *ssh.Client, pkgs []string) error {
|
||||||
cmd += " && mount /dev/vda3 /mnt && chroot /mnt apk add " + strings.Join(pkgsQuoted, " ")
|
cmd += " && mount /dev/vda3 /mnt && chroot /mnt apk add " + strings.Join(pkgsQuoted, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd += `&& chroot /mnt ash -c 'echo "PasswordAuthentication no" >> /etc/ssh/sshd_config && addgroup -g 1000 linsk && adduser -D -h /mnt -G linsk linsk -u 1000'`
|
cmd += `&& chroot /mnt ash -c 'echo "PasswordAuthentication no" >> /etc/ssh/sshd_config && addgroup -g 1000 linsk && adduser -D -h /mnt -G linsk linsk -u 1000 && touch /etc/network/interfaces'`
|
||||||
|
|
||||||
err = sess.Run(cmd)
|
err = sess.Run(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,19 @@ func (s *Storage) BuildVMImageWithInterruptHandler(showBuilderVMDisplay bool, ov
|
||||||
return errors.Wrap(err, "create new img build context")
|
return errors.Wrap(err, "create new img build context")
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.Wrap(buildCtx.BuildWithInterruptHandler(), "build")
|
err = buildCtx.BuildWithInterruptHandler()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "do build")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Remove(baseImagePath)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("Failed to remove base image", "error", err.Error(), "path", baseImagePath)
|
||||||
|
} else {
|
||||||
|
s.logger.Info("Removed base image", "path", baseImagePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) CheckVMImageExists() (string, error) {
|
func (s *Storage) CheckVMImageExists() (string, error) {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -195,7 +196,7 @@ func (fm *FileManager) Mount(devName string, mo MountOptions) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fm *FileManager) StartFTP(pwd string, passivePortStart uint16, passivePortCount uint16) error {
|
func (fm *FileManager) StartFTP(pwd string, passivePortStart uint16, passivePortCount uint16, extIP net.IP) error {
|
||||||
// This timeout is for the SCP client exclusively.
|
// This timeout is for the SCP client exclusively.
|
||||||
scpCtx, scpCtxCancel := context.WithTimeout(fm.vm.ctx, time.Second*5)
|
scpCtx, scpCtxCancel := context.WithTimeout(fm.vm.ctx, time.Second*5)
|
||||||
defer scpCtxCancel()
|
defer scpCtxCancel()
|
||||||
|
|
@ -217,7 +218,7 @@ listen=YES
|
||||||
seccomp_sandbox=NO
|
seccomp_sandbox=NO
|
||||||
pasv_min_port=` + fmt.Sprint(passivePortStart) + `
|
pasv_min_port=` + fmt.Sprint(passivePortStart) + `
|
||||||
pasv_max_port=` + fmt.Sprint(passivePortStart+passivePortCount) + `
|
pasv_max_port=` + fmt.Sprint(passivePortStart+passivePortCount) + `
|
||||||
pasv_address=127.0.0.1
|
pasv_address=` + extIP.String() + `
|
||||||
`
|
`
|
||||||
|
|
||||||
err = scpClient.CopyFile(scpCtx, strings.NewReader(ftpdCfg), "/etc/vsftpd/vsftpd.conf", "0400")
|
err = scpClient.CopyFile(scpCtx, strings.NewReader(ftpdCfg), "/etc/vsftpd/vsftpd.conf", "0400")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue