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

use allow/deny instead of the colored alternatives #9019

Merged
merged 8 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/task_dir_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func setEnvvars(envBuilder *taskenv.Builder, fsi drivers.FSIsolation, taskDir *a

// Set the host environment variables for non-image based drivers
if fsi != drivers.FSIsolationImage {
filter := strings.Split(conf.ReadDefault("env.blacklist", cconfig.DefaultEnvBlacklist), ",")
filter := strings.Split(conf.ReadDefault("env.blacklist", cconfig.DefaultEnvDenylist), ",")
greut marked this conversation as resolved.
Show resolved Hide resolved
envBuilder.SetHostEnvvars(filter)
}
}
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/validate_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func validateTask(task *structs.Task, taskEnv *taskenv.TaskEnv, conf *config.Con
var mErr multierror.Error

// Validate the user
unallowedUsers := conf.ReadStringListToMapDefault("user.blacklist", config.DefaultUserBlacklist)
unallowedUsers := conf.ReadStringListToMapDefault("user.denylist", config.DefaultUserDenylist)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to update ReadStringListToMapDefault to do the same sort of thing we've done with ReadStringListToMap so that we can keep backwards compatibility with user.blacklist.

checkDrivers := conf.ReadStringListToMapDefault("user.checked_drivers", config.DefaultUserCheckedDrivers)
if _, driverMatch := checkDrivers[task.Driver]; driverMatch {
if _, unallowed := unallowedUsers[task.User]; unallowed {
Expand Down
7 changes: 4 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,10 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulServic
return nil, fmt.Errorf("fingerprinting failed: %v", err)
}

// Build the white/blacklists of drivers.
allowlistDrivers := cfg.ReadStringListToMap("driver.whitelist")
blocklistDrivers := cfg.ReadStringListToMap("driver.blacklist")
// Build the allow/denylists of drivers.
// white/blacklist are there for backward compatible reasons only.
allowlistDrivers := cfg.ReadStringListToMap("driver.allowlist", "driver.whitelist")
blocklistDrivers := cfg.ReadStringListToMap("driver.denylist", "driver.blocklist", "driver.blacklist")
greut marked this conversation as resolved.
Show resolved Hide resolved

// Setup the csi manager
csiConfig := &csimanager.Config{
Expand Down
26 changes: 14 additions & 12 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ import (
)

var (
// DefaultEnvBlacklist is the default set of environment variables that are
// DefaultEnvDenylist is the default set of environment variables that are
// filtered when passing the environment variables of the host to a task.
// duplicated in command/agent/host, update that if this changes.
DefaultEnvBlacklist = strings.Join([]string{
DefaultEnvDenylist = strings.Join([]string{
"CONSUL_TOKEN",
"CONSUL_HTTP_TOKEN",
"VAULT_TOKEN",
"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN",
"GOOGLE_APPLICATION_CREDENTIALS",
}, ",")

// DefaultUserBlacklist is the default set of users that tasks are not
// DefaultUserDenylist is the default set of users that tasks are not
// allowed to run as when using a driver in "user.checked_drivers"
DefaultUserBlacklist = strings.Join([]string{
DefaultUserDenylist = strings.Join([]string{
"root",
"Administrator",
}, ",")

// DefaultUserCheckedDrivers is the set of drivers we apply the user
// blacklist onto. For virtualized drivers it often doesn't make sense to
// denylist onto. For virtualized drivers it often doesn't make sense to
// make this stipulation so by default they are ignored.
DefaultUserCheckedDrivers = strings.Join([]string{
"exec",
Expand Down Expand Up @@ -420,15 +420,17 @@ func (c *Config) ReadDurationDefault(id string, defaultValue time.Duration) time
return val
}

// ReadStringListToMap tries to parse the specified option as a comma separated list.
// ReadStringListToMap tries to parse the specified option(s) as a comma separated list.
// If there is an error in parsing, an empty list is returned.
func (c *Config) ReadStringListToMap(key string) map[string]struct{} {
s := strings.TrimSpace(c.Read(key))
func (c *Config) ReadStringListToMap(keys ...string) map[string]struct{} {
list := make(map[string]struct{})
if s != "" {
for _, e := range strings.Split(s, ",") {
trimmed := strings.TrimSpace(e)
list[trimmed] = struct{}{}
for _, key := range keys {
s := strings.TrimSpace(c.Read(key))
if s != "" {
for _, e := range strings.Split(s, ",") {
trimmed := strings.TrimSpace(e)
list[trimmed] = struct{}{}
}
}
}
return list
Expand Down
18 changes: 9 additions & 9 deletions client/fingerprint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@ func (fm *FingerprintManager) getNode() *structs.Node {
}

// Run starts the process of fingerprinting the node. It does an initial pass,
// identifying whitelisted and blacklisted fingerprints/drivers. Then, for
// identifying allowlisted and denylisted fingerprints/drivers. Then, for
// those which require periotic checking, it starts a periodic process for
// each.
func (fp *FingerprintManager) Run() error {
// First, set up all fingerprints
cfg := fp.getConfig()
whitelistFingerprints := cfg.ReadStringListToMap("fingerprint.whitelist")
whitelistFingerprintsEnabled := len(whitelistFingerprints) > 0
blacklistFingerprints := cfg.ReadStringListToMap("fingerprint.blacklist")
allowlistFingerprints := cfg.ReadStringListToMap("fingerprint.allowlist", "fingerprint.whitelist")
allowlistFingerprintsEnabled := len(allowlistFingerprints) > 0
denylistFingerprints := cfg.ReadStringListToMap("fingerprint.denylist", "fingerprint.blacklist")

fp.logger.Debug("built-in fingerprints", "fingerprinters", fingerprint.BuiltinFingerprints())

var availableFingerprints []string
var skippedFingerprints []string
for _, name := range fingerprint.BuiltinFingerprints() {
// Skip modules that are not in the whitelist if it is enabled.
if _, ok := whitelistFingerprints[name]; whitelistFingerprintsEnabled && !ok {
// Skip modules that are not in the allowlist if it is enabled.
if _, ok := allowlistFingerprints[name]; allowlistFingerprintsEnabled && !ok {
skippedFingerprints = append(skippedFingerprints, name)
continue
}
// Skip modules that are in the blacklist
if _, ok := blacklistFingerprints[name]; ok {
// Skip modules that are in the denylist
if _, ok := denylistFingerprints[name]; ok {
skippedFingerprints = append(skippedFingerprints, name)
continue
}
Expand All @@ -99,7 +99,7 @@ func (fp *FingerprintManager) Run() error {
}

if len(skippedFingerprints) != 0 {
fp.logger.Debug("fingerprint modules skipped due to white/blacklist",
fp.logger.Debug("fingerprint modules skipped due to allow/denylist",
"skipped_fingerprinters", skippedFingerprints)
}

Expand Down
8 changes: 4 additions & 4 deletions client/fingerprint_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestFingerprintManager_Run_InBlacklist(t *testing.T) {
require := require.New(t)
testClient, cleanup := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
"fingerprint.whitelist": " arch,memory,foo,bar ",
"fingerprint.blacklist": " cpu ",
"fingerprint.allowlist": " arch,memory,foo,bar ",
"fingerprint.denylist": " cpu ",
}
})
defer cleanup()
Expand Down Expand Up @@ -96,8 +96,8 @@ func TestFingerprintManager_Run_Combination(t *testing.T) {

testClient, cleanup := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
"fingerprint.whitelist": " arch,cpu,memory,foo,bar ",
"fingerprint.blacklist": " memory,host ",
"fingerprint.allowlist": " arch,cpu,memory,foo,bar ",
"fingerprint.denylist": " memory,host ",
}
})
defer cleanup()
Expand Down
2 changes: 1 addition & 1 deletion command/acl_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Usage: nomad acl policy <subcommand> [options] [args]
This command groups subcommands for interacting with ACL policies. Nomad's ACL
system can be used to control access to data and APIs. ACL policies allow a
set of capabilities or actions to be granted or whitelisted. For a full guide
set of capabilities or actions to be granted or allowlisted. For a full guide
see: https://www.nomadproject.io/guides/acl.html
Create an ACL policy:
Expand Down
2 changes: 1 addition & 1 deletion command/agent/testdata/obj-len-one.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
client {
options {
driver.whitelist = "docker"
driver.allowlist = "docker"
}
}
2 changes: 1 addition & 1 deletion command/agent/testdata/obj-len-one.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"client": {
"options": {
"driver.whitelist": "docker"
"driver.allowlist": "docker"
}
},
"server": {}
Expand Down
13 changes: 12 additions & 1 deletion drivers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,21 @@ func PluginLoader(opts map[string]string) (map[string]interface{}, error) {
conf["volumes"] = volConf

// capabilities
if v, ok := opts["docker.caps.whitelist"]; ok {
if v, ok := opts["docker.caps.allowlist"]; ok {
conf["allow_caps"] = strings.Split(v, ",")
}

// backward compatible configuration
if v, ok := opts["docker.caps.whitelist"]; ok {
vs := strings.Split(v, ",")
switch conf["allow_caps"].(type) {
case []string:
conf["allow_caps"] = append(conf["allow_caps"].([]string), vs...)
greut marked this conversation as resolved.
Show resolved Hide resolved
default:
conf["allow_caps"] = vs
}
}

// privileged containers
if v, err := strconv.ParseBool(opts["docker.privileged.enabled"]); err == nil {
conf["allow_privileged"] = v
Expand Down
2 changes: 1 addition & 1 deletion drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
}
}
if len(missingCaps) > 0 {
return c, fmt.Errorf("Docker driver doesn't have the following caps whitelisted on this Nomad agent: %s", missingCaps)
return c, fmt.Errorf("Docker driver doesn't have the following caps allowlisted on this Nomad agent: %s", missingCaps)
}
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/docker/driver_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// be mounted into Docker containers on macOS without needing dev performing
// special setup.
//
// macOS sets tempdir as `/var`, which Docker does not whitelist as a path that
// macOS sets tempdir as `/var`, which Docker does not allowlist as a path that
// can be bind-mounted.
func TestMain(m *testing.M) {
tmpdir := fmt.Sprintf("/tmp/nomad-docker-tests-%d", time.Now().Unix())
Expand Down
32 changes: 16 additions & 16 deletions drivers/docker/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,50 +1235,50 @@ func TestDockerDriver_Capabilities(t *testing.T) {
Name string
CapAdd []string
CapDrop []string
Whitelist string
Allowlist string
StartError string
}{
{
Name: "default-whitelist-add-allowed",
Name: "default-allowlist-add-allowed",
CapAdd: []string{"fowner", "mknod"},
CapDrop: []string{"all"},
},
{
Name: "default-whitelist-add-forbidden",
Name: "default-allowlist-add-forbidden",
CapAdd: []string{"net_admin"},
StartError: "net_admin",
},
{
Name: "default-whitelist-drop-existing",
Name: "default-allowlist-drop-existing",
CapDrop: []string{"fowner", "mknod"},
},
{
Name: "restrictive-whitelist-drop-all",
Name: "restrictive-allowlist-drop-all",
CapDrop: []string{"all"},
Whitelist: "fowner,mknod",
Allowlist: "fowner,mknod",
},
{
Name: "restrictive-whitelist-add-allowed",
Name: "restrictive-allowlist-add-allowed",
CapAdd: []string{"fowner", "mknod"},
CapDrop: []string{"all"},
Whitelist: "fowner,mknod",
Allowlist: "fowner,mknod",
},
{
Name: "restrictive-whitelist-add-forbidden",
Name: "restrictive-allowlist-add-forbidden",
CapAdd: []string{"net_admin", "mknod"},
CapDrop: []string{"all"},
Whitelist: "fowner,mknod",
Allowlist: "fowner,mknod",
StartError: "net_admin",
},
{
Name: "permissive-whitelist",
Name: "permissive-allowlist",
CapAdd: []string{"net_admin", "mknod"},
Whitelist: "all",
Allowlist: "all",
},
{
Name: "permissive-whitelist-add-all",
Name: "permissive-allowlist-add-all",
CapAdd: []string{"all"},
Whitelist: "all",
Allowlist: "all",
},
}

Expand All @@ -1299,8 +1299,8 @@ func TestDockerDriver_Capabilities(t *testing.T) {
d := dockerDriverHarness(t, nil)
dockerDriver, ok := d.Impl().(*Driver)
require.True(t, ok)
if tc.Whitelist != "" {
dockerDriver.config.AllowCaps = strings.Split(tc.Whitelist, ",")
if tc.Allowlist != "" {
dockerDriver.config.AllowCaps = strings.Split(tc.Allowlist, ",")
}

cleanup := d.MkAllocDir(task, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ client {

options {
# Allow jobs to run as root
"user.blacklist" = ""
"user.denylist" = ""

# Allow rawexec jobs
"driver.raw_exec.enable" = "1"
Expand Down
Loading