Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skybian defaults from skywire-cli visor gen-config -s #852

Merged
merged 12 commits into from
Aug 24, 2021
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <YOUR_CONFIG_DIR>:/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`.
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps/skychat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
49 changes: 34 additions & 15 deletions cmd/skywire-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 <hypervisor-public-key> -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: {
Expand Down Expand Up @@ -561,24 +581,23 @@ 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.

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 <hypervisor-public-key> -pro skywire-visor.json
$ skywire-cli visor gen-config --hypervisor-pks <hypervisor-public-key> -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
```
Expand Down
36 changes: 28 additions & 8 deletions cmd/skywire-cli/commands/visor/gen-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
0pcom marked this conversation as resolved.
Show resolved Hide resolved
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")
}

Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -89,7 +110,6 @@ var genConfigCmd = &cobra.Command{
}
conf.Hypervisors = append(conf.Hypervisors, cipher.PubKey(keyParsed))
}

}

// Save config to file.
Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions cmd/skywire-visor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <remote-hypervisor-public-key> -pro skywire-visor.json
# cp /opt/skywire/skywire.json /opt/skywire/skywire-visor.json
# skywire-cli visor gen-config --hypervisor-pks <remote-hypervisor-public-key> -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.
Expand Down
36 changes: 31 additions & 5 deletions pkg/skyenv/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion pkg/visor/hypervisorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions pkg/visor/visorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down