Skip to content

Commit

Permalink
Add ability to map devices into containers when permitted for spawnpo…
Browse files Browse the repository at this point in the history
…int daemon (closes #30)
  • Loading branch information
jhkolb committed Oct 14, 2017
1 parent c534058 commit 83ae6af
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ Currently, the valid parameters are:
interface. Note that this represents a major security risk. Don't enable this
unless you are very confident that you need it.

A typical Spawnpoint configuration file might look as follows. Note that the
`localRouter` parameter is omitted, and thus it takes on the default value.
* `allowDeviceMappings` (optional): If enabled, this allows devices on a
Spawnpoint host (e.g. `/dev/tty1`) to be mapped into containers running on
that host. This allows containers to access these devices. Note that this
represents a security risk. Don't enable this feature unless you understand
the consequences and are confident that you need it.

A typical Spawnpoint configuration file might look as follows.
```yaml
entity: ~/bosswave/spawnpointTest.key
path: scratch.ns/spawnpoint/alpha
Expand Down
12 changes: 6 additions & 6 deletions installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Currently, the script only supports 64-bit Ubuntu Linux installations that use
when run on other platforms.

Additionally, the installer currently does not configure the metadata that is
advertised by the spawnpoint. To do this, you must edit `/etc/spawnd/metadat.yml`
advertised by the spawnpoint. To do this, you must edit `/etc/spawnd/metadata.yml`
manually.

This script will then take the following steps:
Expand Down Expand Up @@ -40,8 +40,8 @@ This script will then take the following steps:
7. Start up the new `spawnd` service, after enabling it to start on boot as
well.

### What about host networking?
In general, allowing containers to use the host network is discouraged unless
you know what you are doing. Therefore, it is disabled by the installer by
default, but the installer will not change your old settings when performing
an update.
### What about host networking and mapping devices?
In general, allowing containers to use the host network or to directly access
host devices is discouraged unless you know what you are doing. Therefore, it is
disabled by the installer by default, but the installer will not change your old
settings when performing an update.
1 change: 1 addition & 0 deletions installer/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ if [ ! -e /etc/spawnd/config.yml ]; then
localRouter: 172.17.0.1:28589
containerRouter: 172.17.0.1:28589
allowHostNet: false
allowDeviceMappings: false
EOF

entity=''
Expand Down
2 changes: 1 addition & 1 deletion spawnctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/urfave/cli"
)

const versionNum = `0.3.7`
const versionNum = `0.3.8`

type prevDeployment struct {
URI string
Expand Down
17 changes: 9 additions & 8 deletions spawnd/daemonconfig.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package main

type DaemonConfig struct {
Entity string `yaml:"entity"`
Alias string `yaml:"alias"`
Path string `yaml:"path"`
LocalRouter string `yaml:"localRouter"`
ContainerRouter string `yaml:"containerRouter"`
MemAlloc string `yaml:"memAlloc"`
CPUShares uint64 `yaml:"cpuShares"`
AllowHostNet bool `yaml:"allowHostNet"`
Entity string `yaml:"entity"`
Alias string `yaml:"alias"`
Path string `yaml:"path"`
LocalRouter string `yaml:"localRouter"`
ContainerRouter string `yaml:"containerRouter"`
MemAlloc string `yaml:"memAlloc"`
CPUShares uint64 `yaml:"cpuShares"`
AllowHostNet bool `yaml:"allowHostNet"`
AllowDeviceMappings bool `yaml:"allowDeviceMappings"`
}
7 changes: 4 additions & 3 deletions spawnd/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ func RestartContainer(alias string, cfg *Manifest, bwRouter string, rebuildImg b
var containerDevices []docker.Device
if len(cfg.Devices) > 0 {
containerDevices = make([]docker.Device, len(cfg.Devices))
for i, device := range cfg.Devices {
for i, devicePath := range cfg.Devices {
containerDevices[i] = docker.Device{
PathOnHost: device,
PathInContainer: device,
PathOnHost: devicePath,
PathInContainer: devicePath,
CgroupPermissions: "rwm",
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions spawnd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
yaml "gopkg.in/yaml.v2"
)

const versionNum = `0.5.4`
const versionNum = `0.5.5`
const defaultZombiePeriod = 2 * time.Minute
const persistEnvVar = "SPAWND_PERSIST_DIR"
const logReaderBufSize = 1024
Expand Down Expand Up @@ -514,8 +514,14 @@ func handleConfig(id int, msg *bw2.SimpleMessage) {
}

if trueCfg.UseHostNet && !cfgs[id].AllowHostNet {
alias := cfgs[id].Alias
err := fmt.Errorf("Spawnpoint %s does not allow use of host network stack", alias)
err := fmt.Errorf("Spawnpoint %s does not allow use of host network stack",
cfgs[id].Alias)
panic(err)
}

if len(trueCfg.Devices) > 0 && !cfgs[id].AllowDeviceMappings {
err := fmt.Errorf("Spawnpoint %s does not allow host devices to be mapped into containers",
cfgs[id].Alias)
panic(err)
}

Expand Down

0 comments on commit 83ae6af

Please sign in to comment.