diff --git a/README.md b/README.md index 0d1a9db3c3..7f06d6b0d3 100644 --- a/README.md +++ b/README.md @@ -34,17 +34,17 @@ Skywire can be statically built. For instructions check [the docs](docs/static-b ### Expose hypervisorUI -In order to expose the hypervisor UI, generate a config file with `--is-hypervisor` flag: +In order to expose the hypervisor UI, generate a config file with `--is-hypervisor` or `-i` flag: ```bash -$ skywire-cli visor gen-config --is-hypervisor +$ skywire-cli visor gen-config -i ``` Docker container will create config automatically for you, should you want to run it manually, you can do: ```bash $ docker run --rm -v :/opt/skywire \ - skycoin/skywire:test skywire-cli gen-config --is-hypervisor + skycoin/skywire:test skywire-cli gen-config -i ``` After starting up the visor, the UI will be exposed by default on `localhost:8000`. diff --git a/cmd/apps/skychat/chat.go b/cmd/apps/skychat/chat.go index 1ff04fb7ef..eb2836207c 100644 --- a/cmd/apps/skychat/chat.go +++ b/cmd/apps/skychat/chat.go @@ -4,17 +4,18 @@ skychat app for skywire visor package main import ( - "embed" "encoding/json" "flag" "fmt" - "io/fs" "net" "net/http" "os" "sync" "time" + "embed" + "io/fs" + "github.com/skycoin/dmsg/buildinfo" "github.com/skycoin/dmsg/cipher" diff --git a/cmd/skywire-cli/README.md b/cmd/skywire-cli/README.md index 9eae0666eb..dadbbce8d2 100644 --- a/cmd/skywire-cli/README.md +++ b/cmd/skywire-cli/README.md @@ -334,12 +334,15 @@ Usage: Flags: -h, --help help for gen-config --hypervisor-pks string public keys of hypervisors that should be added to this visor - --is-hypervisor whether to generate config to run this visor as a hypervisor. + -i, --is-hypervisor generate a hypervisor configuration. -o, --output string path of output config file. (default "skywire-config.json") - -p, --package use defaults for package-based installations - -r, --replace whether to allow rewrite of a file that already exists (this retains the keys). - --sk cipher.SecKey if unspecified, a random key pair will be generated. (default 0000000000000000000000000000000000000000000000000000000000000000) - -t, --testenv whether to use production or test deployment service. + -p, --package use defaults for package-based installations in /opt/skywire + -r, --replace rewrite existing config (retains keys). + --sk cipher.SecKey if unspecified, a random key pair will be generated. + (default 0000000000000000000000000000000000000000000000000000000000000000) + -s, --skybian use defaults paths found in skybian + writes config to /etc/skywire-config.json + -t, --testenv use test deployment service. Global Flags: --rpc string RPC server address (default "localhost:3435") @@ -438,18 +441,35 @@ $ skywire-cli visor gen-config } ``` -The default configuration is for a visor only. To generate a configuration which provides the hypervisor web interface, the --is-hypervisor flag can be passed. +The default configuration is for a visor only. To generate a configuration which provides the hypervisor web interface, the `-i` or `--is-hypervisor` flag should be specified. ``` -$ skywire-cli visor gen-config --is-hypervisor +$ skywire-cli visor gen-config -i +``` + +##### Example hypervisor configuration for skybian +``` +$ skywire-cli visor gen-config -irs +``` +##### Example visor configuration for skybian + +It is the typical arrangement to set a visor to use a remote hypervisor if a local instance is not started. + +Determine the hypervisor public key by running the following command on the machine running the hypervisor + +``` +$ skywire-cli visor pk +``` +substitute the hypervisor public key in the following command: +``` +$ skywire-cli visor gen-config --hypervisor-pks -rs ``` ##### Example hypervisor configuration for package based installation -This assumes the skywire installation is at /opt/skywire with binaries and apps in their own subdirectories. +This assumes the skywire installation is at `/opt/skywire` with binaries and apps in their own subdirectories. ``` -$ cd /opt/skywire -$ skywire-cli visor gen-config --is-hypervisor -pro skywire.json +$ skywire-cli visor gen-config -ip [2021-06-24T09:09:39-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="/opt/skywire/skywire.json" [2021-06-24T09:09:39-05:00] INFO [visor:config]: Flushing config to file. config_version="v1.0.0" filepath="/opt/skywire/skywire.json" [2021-06-24T09:09:39-05:00] INFO [skywire-cli]: Updated file '/opt/skywire/skywire.json' to: { @@ -561,10 +581,10 @@ The configuration is written (or rewritten) It is the typical arrangement to set a visor to use a remote hypervisor if a local instance is not started. -Determine the hypervisor public key by running the following command on the remote machine +Determine the hypervisor public key by running the following command on the machine running the hypervisor ``` -_pubkey=$(cat /opt/skywire/skywire.json | grep pk\") _pubkey=${_pubkey#*: } ; echo $_pubkey +$ skywire-cli visor pk ``` When running a visor with or without a hypervisor on the same machine, it's wise to keep the same keys for the other config file. @@ -572,13 +592,12 @@ When running a visor with or without a hypervisor on the same machine, it's wise Copy the `skywire.json` config file from the previous example to `skywire-visor.json`; then paste the public key from the above command output into the following command ``` -$ cd /opt/skywire -$ skywire-cli visor gen-config --hypervisor-pks -pro skywire-visor.json +$ skywire-cli visor gen-config --hypervisor-pks -pr ``` The configuration is written (or rewritten) -The configuration files may be specified in corresponding systemd service files or init / startup scripts to start either a visor or hypervisor instance +The configuration files should be specified in corresponding systemd service files or init / startup scripts to start either a visor or hypervisor instance starting the hypervisor intance ``` diff --git a/cmd/skywire-cli/commands/visor/gen-config.go b/cmd/skywire-cli/commands/visor/gen-config.go index 265f60eb68..7d847b23f0 100644 --- a/cmd/skywire-cli/commands/visor/gen-config.go +++ b/cmd/skywire-cli/commands/visor/gen-config.go @@ -26,17 +26,19 @@ var ( replace bool testEnv bool packageConfig bool + skybianConfig bool hypervisor bool hypervisorPKs string ) func init() { - genConfigCmd.Flags().Var(&sk, "sk", "if unspecified, a random key pair will be generated.") + genConfigCmd.Flags().Var(&sk, "sk", "if unspecified, a random key pair will be generated.\n") genConfigCmd.Flags().StringVarP(&output, "output", "o", "skywire-config.json", "path of output config file.") - genConfigCmd.Flags().BoolVarP(&replace, "replace", "r", false, "whether to allow rewrite of a file that already exists (this retains the keys).") - genConfigCmd.Flags().BoolVarP(&packageConfig, "package", "p", false, "use defaults for package-based installations") - genConfigCmd.Flags().BoolVarP(&testEnv, "testenv", "t", false, "whether to use production or test deployment service.") - genConfigCmd.Flags().BoolVar(&hypervisor, "is-hypervisor", false, "whether to generate config to run this visor as a hypervisor.") + genConfigCmd.Flags().BoolVarP(&replace, "replace", "r", false, "rewrite existing config (retains keys).") + genConfigCmd.Flags().BoolVarP(&packageConfig, "package", "p", false, "use defaults for package-based installations in /opt/skywire") + genConfigCmd.Flags().BoolVarP(&skybianConfig, "skybian", "s", false, "use defaults paths found in skybian\n writes config to /etc/skywire-config.json") + genConfigCmd.Flags().BoolVarP(&testEnv, "testenv", "t", false, "use test deployment service.") + genConfigCmd.Flags().BoolVarP(&hypervisor, "is-hypervisor", "i", false, "generate a hypervisor configuration.") genConfigCmd.Flags().StringVar(&hypervisorPKs, "hypervisor-pks", "", "public keys of hypervisors that should be added to this visor") } @@ -53,6 +55,23 @@ var genConfigCmd = &cobra.Command{ mLog := logging.NewMasterLogger() mLog.SetLevel(logrus.InfoLevel) + //Fail on -pst combination + if (packageConfig && skybianConfig) || (packageConfig && testEnv) || (skybianConfig && testEnv) { + logger.Fatal("Failed to create config: use of mutually exclusive flags") + } + + //set output for package and skybian configs + if packageConfig { + if hypervisor { + output = "/opt/skywire/skywire.json" + } else { + output = "/opt/skywire/skywire-visor.json" + } + } + if skybianConfig { + output = "/etc/skywire-config.json" + } + // Read in old config (if any) and obtain old secret key. // Otherwise, we generate a new random secret key. var sk cipher.SecKey @@ -65,9 +84,11 @@ var genConfigCmd = &cobra.Command{ // Determine config type to generate. var genConf func(log *logging.MasterLogger, confPath string, sk *cipher.SecKey, hypervisor bool) (*visorconfig.V1, error) - // to be improved later + // default paths for different installations if packageConfig { genConf = visorconfig.MakePackageConfig + } else if skybianConfig { + genConf = visorconfig.MakeSkybianConfig } else if testEnv { genConf = visorconfig.MakeTestConfig } else { @@ -89,7 +110,6 @@ var genConfigCmd = &cobra.Command{ } conf.Hypervisors = append(conf.Hypervisors, cipher.PubKey(keyParsed)) } - } // Save config to file. @@ -116,7 +136,7 @@ func readOldConfig(log *logging.MasterLogger, confPath string, replace bool) (*v } if !replace { - logger.Fatal("Config file already exists. Specify the 'replace,r' flag to replace this.") + logger.Fatal("Config file already exists. Specify the 'replace, r' flag to replace this.") } conf, err := visorconfig.Parse(log, confPath, raw) diff --git a/cmd/skywire-visor/README.md b/cmd/skywire-visor/README.md index 13f27cb90d..be4af355c9 100644 --- a/cmd/skywire-visor/README.md +++ b/cmd/skywire-visor/README.md @@ -94,16 +94,14 @@ The configuration file is generated in the following way for a visor with local hypervisor: ``` -$ cd /opt/skywire -$ skywire-cli visor gen-config --is-hypervisor -pro skywire.json +$ skywire-cli visor gen-config -ip ``` for visor with remote hypervisor; first copy the existing configuration file to keep the same keys. ``` -$ cd /opt/skywire -# cp skywire.json skywire-visor.json -# skywire-cli visor gen-config --hypervisor-pks -pro skywire-visor.json +# cp /opt/skywire/skywire.json /opt/skywire/skywire-visor.json +# skywire-cli visor gen-config --hypervisor-pks -p ``` These two configuration files can be referenced in systemd service files or init scripts to start skywire with either a local or remote hypervisor. diff --git a/pkg/skyenv/values.go b/pkg/skyenv/values.go index 2e59b647be..ccc9a2f350 100644 --- a/pkg/skyenv/values.go +++ b/pkg/skyenv/values.go @@ -103,13 +103,42 @@ const ( AppDiscUpdateInterval = time.Minute DefaultAppBinPath = DefaultSkywirePath + "/apps" DefaultLogLevel = "info" - PackageAppBinPath = PackageSkywirePath + "/apps" +) + +// Package defaults +const ( + PackageAppBinPath = PackageSkywirePath + "/apps" + PackageLocalPath = PackageSkywirePath + "/local" + PackageDmsgPtyWhiteList = PackageSkywirePath + "/dmsgpty/whitelist.json" + PackageDmsgPtyCLIAddr = PackageSkywirePath + "/dmsgpty/cli.sock" + PackageTpLogStore = PackageSkywirePath + "/transport_logs" + PackageDBPath = PackageSkywirePath + "/users.db" + PackageEnableTLS = false + PackageTLSKey = PackageSkywirePath + "/ssl/key.pem" + PackageTLSCert = PackageSkywirePath + "/ssl/cert.pem" +) + +// Default routing constants +const ( + DefaultTpLogStore = DefaultSkywirePath + "/transport_logs" +) + +// Skybian defaults +const ( + SkybianAppBinPath = "/usr/bin/apps" + SkybianDmsgPtyWhiteList = "/var/skywire-visor/dsmgpty/whitelist.json" + SkybianDmsgPtyCLIAddr = "/run/skywire-visor/dmsgpty/cli.sock" + SkybianLocalPath = "/var/skywire-visor/apps" + SkybianTpLogStore = "/var/skywire-visor/transports" + SkybianEnableTLS = false + SkybianDBPath = "/var/skywire-visor/users.db" + SkybianTLSKey = "/var/skywire-visor/ssl/key.pem" + SkybianTLSCert = "/var/skywire-visor/ssl/cert.pem" ) // Default local constants const ( DefaultLocalPath = DefaultSkywirePath + "/local" - PackageLocalPath = PackageSkywirePath + "/local" ) // Default hypervisor constants @@ -119,9 +148,6 @@ const ( DefaultEnableTLS = false DefaultTLSKey = DefaultSkywirePath + "/ssl/key.pem" DefaultTLSCert = DefaultSkywirePath + "/ssl/cert.pem" - PackageEnableTLS = true - PackageTLSKey = PackageSkywirePath + "/ssl/key.pem" - PackageTLSCert = PackageSkywirePath + "/ssl/cert.pem" ) // MustPK unmarshals string PK to cipher.PubKey. It panics if unmarshaling fails. diff --git a/pkg/visor/hypervisorconfig/config.go b/pkg/visor/hypervisorconfig/config.go index 637e815a89..1b165cc331 100644 --- a/pkg/visor/hypervisorconfig/config.go +++ b/pkg/visor/hypervisorconfig/config.go @@ -3,13 +3,14 @@ package hypervisorconfig import ( "encoding/hex" "encoding/json" - "io/fs" "log" "net/http" "os" "path/filepath" "time" + "io/fs" + "github.com/skycoin/dmsg/cipher" "github.com/skycoin/skywire/pkg/skyenv" diff --git a/pkg/visor/visorconfig/config.go b/pkg/visor/visorconfig/config.go index dbdb8ebe68..848216f31c 100644 --- a/pkg/visor/visorconfig/config.go +++ b/pkg/visor/visorconfig/config.go @@ -166,6 +166,32 @@ func MakePackageConfig(log *logging.MasterLogger, confPath string, sk *cipher.Se conf.Hypervisor.EnableTLS = skyenv.PackageEnableTLS conf.Hypervisor.TLSKeyFile = skyenv.PackageTLSKey conf.Hypervisor.TLSCertFile = skyenv.PackageTLSCert + conf.Hypervisor.DBPath = skyenv.PackageDBPath + } + return conf, nil +} + +// MakeSkybianConfig acts like MakeDefaultConfig but uses default paths, etc. as found in skybian / produced by skyimager +func MakeSkybianConfig(log *logging.MasterLogger, confPath string, sk *cipher.SecKey, hypervisor bool) (*V1, error) { + conf, err := MakeDefaultConfig(log, confPath, sk, hypervisor) + if err != nil { + return nil, err + } + + conf.Dmsgpty = &V1Dmsgpty{ + Port: skyenv.DmsgPtyPort, + CLINet: skyenv.DefaultDmsgPtyCLINet, + CLIAddr: skyenv.SkybianDmsgPtyCLIAddr, + } + conf.LocalPath = skyenv.SkybianLocalPath + conf.Launcher.BinPath = skyenv.SkybianAppBinPath + + if conf.Hypervisor != nil { + conf.Hypervisor.EnableAuth = skyenv.DefaultEnableAuth + conf.Hypervisor.EnableTLS = skyenv.SkybianEnableTLS + conf.Hypervisor.TLSKeyFile = skyenv.SkybianTLSKey + conf.Hypervisor.TLSCertFile = skyenv.SkybianTLSCert + conf.Hypervisor.DBPath = skyenv.SkybianDBPath } return conf, nil }