Skip to content

Commit

Permalink
client: add NOMAD_LICENSE to default env deny list
Browse files Browse the repository at this point in the history
By default we should not expose the NOMAD_LICENSE environment variable
to tasks.

Also refactor where the DefaultEnvDenyList lives so we don't have to
maintain 2 copies of it. Since client/config is the most obvious
location, keep it there as a pointer to its unfortunate home buried deep
in command/agent/host. Since the agent uses this list as well for the
/agent/host endpoint the list must be accessible from both command/agent
and client.
  • Loading branch information
schmichael committed Sep 21, 2021
1 parent 2c607fc commit 08cf268
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
10 changes: 2 additions & 8 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/hashicorp/nomad/client/lib/cgutil"
"github.com/hashicorp/nomad/command/agent/host"

log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/state"
Expand All @@ -23,14 +24,7 @@ import (
var (
// 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.
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",
}, ",")
DefaultEnvDenylist = strings.Join(host.DefaultEnvDenyList, ",")

// DefaultUserDenylist is the default set of users that tasks are not
// allowed to run as when using a driver in "user.checked_drivers"
Expand Down
22 changes: 12 additions & 10 deletions command/agent/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,22 @@ func environment() map[string]string {
return env
}

// DefaultEnvDenyList is the default set of environment variables that are
// filtered when passing the environment variables of the host to the task.
var DefaultEnvDenyList = []string{
"CONSUL_TOKEN",
"CONSUL_HTTP_TOKEN",
"VAULT_TOKEN",
"NOMAD_LICENSE",
"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN",
"GOOGLE_APPLICATION_CREDENTIALS",
}

// makeEnvRedactSet creates a set of well known environment variables that should be
// redacted in the output
func makeEnvRedactSet() map[string]struct{} {
// Duplicated from config.DefaultEnvBlacklist in order to avoid an import cycle
configDefault := []string{
"CONSUL_TOKEN",
"CONSUL_HTTP_TOKEN",
"VAULT_TOKEN",
"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN",
"GOOGLE_APPLICATION_CREDENTIALS",
}

set := make(map[string]struct{})
for _, e := range configDefault {
for _, e := range DefaultEnvDenyList {
set[e] = struct{}{}
}

Expand Down

0 comments on commit 08cf268

Please sign in to comment.