Implement the driver whitelist

This commit is contained in:
Alex Dadgar
2015-11-19 16:39:21 -08:00
parent f5a0d94eed
commit 5eb8bc25bf
2 changed files with 29 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
@@ -494,9 +495,28 @@ func (c *Client) fingerprintPeriodic(name string, f fingerprint.Fingerprint, d t
// setupDrivers is used to find the available drivers
func (c *Client) setupDrivers() error {
// Build the whitelist of drivers.
userWhitelist := strings.TrimSpace(c.config.ReadDefault("driver.whitelist", ""))
whitelist := make(map[string]struct{})
if userWhitelist != "" {
for _, driver := range strings.Split(userWhitelist, ",") {
trimmed := strings.TrimSpace(driver)
whitelist[trimmed] = struct{}{}
}
}
whitelistEnabled := len(whitelist) > 0
var avail []string
var whitelisted []string
driverCtx := driver.NewDriverContext("", c.config, c.config.Node, c.logger)
for name := range driver.BuiltinDrivers {
// Skip fingerprinting drivers that are not in the whitelist if it is
// enabled.
if _, ok := whitelist[name]; whitelistEnabled && !ok {
whitelisted = append(whitelisted, name)
continue
}
d, err := driver.NewDriver(name, driverCtx)
if err != nil {
return err
@@ -509,7 +529,13 @@ func (c *Client) setupDrivers() error {
avail = append(avail, name)
}
}
c.logger.Printf("[DEBUG] client: available drivers %v", avail)
if len(whitelisted) != 0 {
c.logger.Printf("[DEBUG] client: drivers disabled by whitelist: %v", whitelisted)
}
return nil
}

View File

@@ -12,6 +12,9 @@ client {
# this should be like "nomad.service.consul:4647" and a system
# like Consul used for service discovery.
servers = ["127.0.0.1:4647"]
options {
"driver.whitelist" = " exec, qemu "
}
}
# Modify our port to avoid a collision with server1