diff --git a/.claude/agents/security-reviewer.md b/.claude/agents/security-reviewer.md index 30271bd..dcf1c44 100644 --- a/.claude/agents/security-reviewer.md +++ b/.claude/agents/security-reviewer.md @@ -48,9 +48,12 @@ Review like an attacker who controls the agent machine. and attached; `password=` and similar; `Authorization:`; long random-looking strings). The broker does the masking, not the client. - The broker itself checks environment variable names against - `[A-Z_][A-Z0-9_]{0,63}` and remote user names against + `[A-Z_][A-Z0-9_]{0,63}` and against the deny list of DESIGN.md section 5 + (`api.DeniedVar`: names that make a program print, store or run the + value), and remote user names against `[A-Za-z0-9._][A-Za-z0-9._-]{0,31}`. It never relies on checks done by - the client. + the client. A new tool or name that prints, stores or runs a value + belongs on the deny list. **SSH signing** - The broker parses the data to sign itself. It signs only an SSH diff --git a/DESIGN.md b/DESIGN.md index 94ba583..a95f725 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -111,7 +111,8 @@ nodkey run --secret GH_TOKEN=github-token \ ``` 1. The client checks its arguments: 1 to 32 `--secret` options, each - variable name valid and there only once, and the command after `--`. + variable name valid, not on the deny list (see "Variable names that the + broker refuses" below) and there only once, and the command after `--`. It looks for the command in `PATH`, as a shell does, and takes the absolute path of the file that it found: a relative path starts from the real working directory, not from `$PWD`, and the path is not @@ -151,13 +152,14 @@ nodkey run --secret GH_TOKEN=github-token \ 3. The broker takes the client name only from the pinned TLS key (section 10). It refuses a body that is not a valid request (400). Then it checks that there are 1 to 32 variables, that each variable name matches - `[A-Z_][A-Z0-9_]{0,63}` and is there only once, that each secret name - exists in the broker config, and that this client may use it. If any - check fails, the answer is **deny** (403), and the audit log gets the - request with only the names that passed. No message is sent for a name - the client may not use. (The client checks the variable names too, but - only to give a quick error. The broker does not trust the client's - checks.) + `[A-Z_][A-Z0-9_]{0,63}`, is not on the deny list below and is there + only once, that each secret name exists in the broker config, and that + this client may use it. If any check fails, the answer is **deny** + (403), and the audit log gets the request with only the names that + passed. No message is sent for a name the client may not use, or for a + variable on the deny list, and no grant or rule covers it. (The client + checks the variable names too, but only to give a quick error. The + broker does not trust the client's checks.) 4. The broker makes the claimed text safe (section 7), and checks the rules and grants. If a grant or a "never ask" rule covers every name, it skips to step 6. @@ -212,6 +214,139 @@ runs `bw sync --force`, which downloads the whole vault, so it never hands out a value from an old copy of the vault. A sync without `--force` would depend on the broker's clock (section 16). +### Variable names that the broker refuses + +The variable name decides what the command does with the value. With some +names, common programs print the value, write it into a file or a file +name, send it to a server, or run it: as a command, as code or as options. +The person sees the name in the message (`as:`), but may not know what it +means. So the broker refuses these names in step 3: before any message, +grant or rule, as for any other check. The audit log gets the `request` +entry and a `denied` entry with cause `not_allowed`. The broker's log says +why, with a fixed text and the entry of the list, such as `PATH` or +`LD_*`, never with the name that the client sent. The client refuses +these names too, before it asks anyone: it prints the usage and a clear +last line, and exits with 64 (section 15). + +The broker refuses each name in the first column below. `LD_*` means +every name that starts with `LD_`. The match is exact, on the name in +upper case: `LD_*` refuses `LD_PRELOAD`, but not `LDAP_PASSWORD`. Each +entry was checked on 2026-10-15 on Ubuntu 24.04, with a made-up value, +unless the table says otherwise. A test checks that this table and the +list in the code (`api.DeniedVar`) are the same. + +| name | what programs do with the value | +|---|---| +| `LD_*` | The dynamic loader prints a library in `LD_PRELOAD` or `LD_AUDIT` that it cannot load, and an `LD_DEBUG` option that it does not know. It writes a file named after `LD_DEBUG_OUTPUT`, and loads code from `LD_PRELOAD` and `LD_LIBRARY_PATH`. | +| `DYLD_*` | The same for the dynamic loader of macOS. Not checked; no use on Linux. | +| `GCONV_*` | glibc loads character set modules, which are code, from the directories in `GCONV_PATH`. Not checked. | +| `GLIBC_TUNABLES` | The dynamic loader prints a value that it does not know. | +| `RESOLV_*` | glibc prints a `RESOLV_MULTI` or `RESOLV_REORDER` that is not `on` or `off`, when a program looks up a host name. | +| `LANG`, `LANGUAGE`, `LC_*` | bash prints an `LC_ALL` that is not a locale. perl prints all of them when the locale is not valid. ssh sends `LANG` and the `LC_` names to the server: Debian and Ubuntu set `SendEnv LANG LC_*`. | +| `TZ` | `date` prints the leading letters of the value as the name of the time zone, when the rest reads as an offset from UTC. | +| `TERM` | `tput` and `clear` print a terminal that they do not know. | +| `PATH` | It decides which programs run. GNU `which` prints it when it does not find a program. (Not checked: Ubuntu has another `which`.) | +| `HOME` | Programs make their files under it: npm makes `/.npm` in the working directory. git and bash print paths under it in errors. | +| `TMPDIR`, `TMP`, `TEMP` | Node.js programs print them when they cannot make a temporary file there. Node.js reads `TMP` and `TEMP` when `TMPDIR` is not set. `mktemp` prints `TMPDIR` too. | +| `SHELL` | ssh runs a `ProxyCommand` with it, and `script` runs it. Both print a shell that they cannot run. | +| `EDITOR`, `VISUAL` | `git commit` and `crontab -e` run the editor, and print an editor that they cannot run. | +| `PAGER` | git and man run it when they write to a terminal. | +| `MANPAGER` | man runs it, before `PAGER`, when it writes to a terminal. | +| `BROWSER` | `gh browse` and `sensible-browser` run it. | +| `EMAIL` | `git commit` writes it into the commit as the email address when `user.email` is not set. | +| `SSLKEYLOGFILE` | curl and Python write the keys of each TLS connection to a file named after the value. | +| `CURL_CA_BUNDLE`, `SSL_CERT_FILE`, `REQUESTS_CA_BUNDLE` | curl and Python requests print the path of a CA file that they cannot load. | +| `WGETRC` | wget prints a config file that it cannot read. | +| `BASH_ENV`, `ENV` | bash for a script, and an interactive sh, expand the value, which can run commands, and run the file it names. | +| `SHELLOPTS`, `BASH_XTRACEFD`, `BASH_COMPAT` | bash prints a value that is not valid, every time it starts. | +| `PS0`, `PS1`, `PS2`, `PS3`, `PS4` | The shell prints them as prompts, most of them after an expansion that can run commands: `PS4` before each command that `set -x` traces, `PS3` for `select`, the others in an interactive shell. | +| `PROMPT_COMMAND` | An interactive bash runs it before each prompt. | +| `TIMEFORMAT` | bash prints it after `time`. | +| `HISTFILE` | An interactive bash writes its history to a file named after the value. | +| `GIT_*` | git runs `GIT_EDITOR`, `GIT_SEQUENCE_EDITOR`, `GIT_PAGER`, `GIT_ASKPASS`, `GIT_SSH`, `GIT_SSH_COMMAND`, `GIT_PROXY_COMMAND` and `GIT_EXTERNAL_DIFF`. It prints a `GIT_TRACE` or `GIT_TRACE2` name whose value is not a number, `true`, `false` or an absolute path. It stops and prints the value of `GIT_DIR`, `GIT_CONFIG_NOSYSTEM`, `GIT_AUTHOR_DATE` and many more names when the value is not valid. It writes `GIT_AUTHOR_NAME` and the other author and committer names into each commit, and makes files named after `GIT_INDEX_FILE`, `GIT_WORK_TREE` and others. In a test of everyday commands (`status`, `add`, `commit`, `log`, `fetch`, `push` and more), about 60 names of git 2.43 showed the value. New versions of git add names. | +| `SSH_ASKPASS` | ssh-add and git run it to ask for a passphrase or a password. | +| `SUDO_ASKPASS` | sudo runs it to ask for the password: with `-A`, and also without `-A` when there is no terminal and `DISPLAY` is set. It prints `unable to run` and the value when it cannot run it. The name also invites a mistake: the sudo password as the value. | +| `SSH_SK_HELPER`, `SSH_SK_PROVIDER` | ssh-keygen and ssh run the helper, or load the library, for a security key, and print a name that they cannot use. | +| `GNUPGHOME` | gpg prints paths under it. | +| `RSYNC_RSH`, `RSYNC_CONNECT_PROG` | rsync runs them, and prints a command that it cannot run. | +| `TIME_STYLE`, `QUOTING_STYLE` | ls prints a value that is not valid. | +| `GZIP`, `BZIP2`, `BZIP`, `ZSTD_CLEVEL` | gzip, bzip2 and zstd read them as options, also when tar runs them, and print a value that they cannot use. | +| `MAKEFLAGS`, `GNUMAKEFLAGS` | make reads each letter of the value as an option. With a `p` in it, make prints its database, with every variable of the environment and its value, so also the other secrets of the command. | +| `CC`, `CXX`, `CFLAGS`, `CXXFLAGS`, `CPPFLAGS`, `LDFLAGS`, `LDLIBS`, `TARGET_ARCH` | The built-in rules of make print them in each command that they run, and run `CC` and `CXX` as the compiler. | +| `GH_BROWSER`, `GH_EDITOR`, `GH_PAGER` | gh runs them. (`GH_EDITOR` and `GH_PAGER` not checked.) | +| `GH_REPO` | gh prints a value that is not `OWNER/REPO`. | +| `GH_HOST` | gh connects to the host that it names, and prints the name when it cannot. | +| `DOCKER_HOST`, `DOCKER_CONTEXT`, `DOCKER_API_VERSION` | docker prints a value that it cannot use. It connects to the host in `DOCKER_HOST`. | +| `COMPOSE_FILE`, `COMPOSE_ENV_FILES` | docker compose prints a file that it cannot open. | +| `TF_CLI_ARGS` | terraform reads it as options, and prints a value that it cannot use. Its forms for one command, such as `TF_CLI_ARGS_plan`, are lower case, so nodkey refuses them anyway. | +| `TF_CLI_CONFIG_FILE`, `TF_PLUGIN_CACHE_DIR` | terraform prints them. | +| `TF_WORKSPACE` | `terraform init` and `terraform plan` make a directory `terraform.tfstate.d/`. | +| `TF_LOG_PATH` | terraform writes its log to a file named after the value. | +| `NPM_CONFIG_*` | npm reads its settings from them, also in upper case. `npm run` runs `NPM_CONFIG_SCRIPT_SHELL`. `NPM_CONFIG_CACHE` and `NPM_CONFIG_LOGS_DIR` make a directory named after the value. npm prints others, such as `NPM_CONFIG_PROXY`: `npm warn invalid config proxy=""`. | +| `GOMEMLIMIT` | Every Go program, such as gh or docker, prints a value that is not valid, and stops. | +| `GOFLAGS`, `GOTOOLCHAIN`, `GOPATH`, `GOROOT`, `GOEXPERIMENT`, `GO111MODULE`, `GOOS`, `GOARCH`, `GOTMPDIR` | The go command prints a value that it cannot use, and stops. | +| `GOCACHEPROG` | The go command runs it. | +| `CGO_CFLAGS`, `CGO_CPPFLAGS`, `CGO_LDFLAGS` | `go build` with cgo passes them to the C compiler, which prints them. | +| `JAVA_TOOL_OPTIONS`, `_JAVA_OPTIONS`, `JDK_JAVA_OPTIONS` | java prints "Picked up" and the value every time it starts, and reads the value as options. | +| `JDK_ALTERNATE_VM` | java does not start, and prints the value. | +| `JAVA_HOME` | gradlew prints a value that is not a Java directory. | +| `JAVA_OPTS`, `GRADLE_OPTS`, `MAVEN_OPTS` | gradlew and mvn pass them to java as options, and java prints a value that is not an option. (`MAVEN_OPTS` not checked: mvn was not installed.) | +| `NODE_OPTIONS` | Node.js reads it as options, such as `--require`, which runs code. It prints a value that starts with `-` and is not an option that it allows. | +| `NODE_EXTRA_CA_CERTS` | Node.js prints the value when it cannot load the file, at its first TLS connection. | +| `NODE_V8_COVERAGE`, `NODE_COMPILE_CACHE`, `NODE_REDIRECT_WARNINGS` | Node.js makes a directory or a file named after the value. | +| `NODE_REPL_EXTERNAL_MODULE` | An interactive Node.js runs the module it names, and prints a module that is not there. | +| `PYTHONHOME`, `PYTHONPLATLIBDIR` | Python cannot start, and prints its path settings with the value. | +| `PYTHONEXECUTABLE`, `PYTHONIOENCODING`, `PYTHONWARNINGS` | Python prints the value: as the name of the program, or as a value that is not valid. | +| `PYTHONSTARTUP` | An interactive Python runs the file it names, and prints a name that it cannot open. | +| `PYTHONPYCACHEPREFIX` | Python makes a directory named after the value. | +| `PERL5OPT` | perl reads it as options, such as `-M`, which loads a module, and prints a module that it cannot find. | +| `PERL5LIB`, `PERLLIB` | perl prints them as part of its search path when a module is missing. | +| `PERLIO`, `PERL_SIGNALS`, `PERL_PERTURB_KEYS` | perl prints a value that it does not know (`PERLIO` only with `-w`). | +| `RUBYOPT` | ruby reads it as options, such as `-r`, which loads a library, and prints a library that it cannot find. Not checked: ruby was not installed. | +| `RUSTC_WRAPPER` | cargo runs it. Not checked: Rust was not installed. | +| `RUSTFLAGS` | cargo passes them to rustc, which prints a flag that it does not know. Not checked. | +| `RUSTUP_TOOLCHAIN` | rustup prints a toolchain that is not installed. Not checked. | +| `CARGO_TARGET_DIR` | cargo makes a directory named after the value. Not checked. | + +Not on the list, on purpose: + +- `NODE_PATH`, `PYTHONPATH` and `RUBYLIB`: the runtime skips a directory + that is not there, quietly, and does not print it. (`RUBYLIB` was not + checked: ruby was not installed.) +- `IFS`: bash, dash, zsh and busybox `sh` ignore it in the environment. +- `LESSOPEN`: less runs it only when it holds `%s` exactly once. + Otherwise less says so, without the value. +- `GOPROXY`, `HTTP_PROXY`, `HTTPS_PROXY` and `ALL_PROXY`: their URL can + hold a password on purpose, and curl does not print the password. +- Names that hold a secret on purpose, such as `GH_TOKEN`, + `NODE_AUTH_TOKEN`, `NPM_TOKEN`, `AWS_SECRET_ACCESS_KEY`, + `LDAP_PASSWORD`, `DOCKER_PASSWORD`, `CARGO_REGISTRY_TOKEN`, and + Terraform's `TF_TOKEN_` and `TF_VAR_` names. So there is no `DOCKER_*` + or `TF_*` prefix. + +The prefixes also refuse some names that hold a secret on purpose: +`GIT_CONFIG_VALUE_0` (for example an `http.extraHeader` for git), +`GIT_CREDENTIALS` of semantic-release, `LD_ACCESS_TOKEN` and `LD_SDK_KEY` +of LaunchDarkly, and `NPM_CONFIG__AUTH` of npm. Give such a secret to the +program in another way, such as a git credential helper that reads +`GH_TOKEN`, or `NPM_TOKEN` in `.npmrc` for npm. + +The list has limits: + +- It covers the dynamic loader and the C library, the shells, git, ssh, + sudo, make, gh, docker, terraform, npm, the runtimes and build tools of + Go, Java, Node.js, Python, Perl, Ruby and Rust, and names that many + programs use. It cannot hold every name of every program. Many other + programs print a setting that is not valid, such as `UNZIP` for unzip + or `COLUMNS` for `ls -C`, and some run a command from a name of their + own. The person should deny a secret in a name that is not made for a + secret. +- The agent sets the rest of the environment of the command, and the + message does not show it. It can set `LD_PRELOAD` there itself. So the + list stops mistakes, and simple tricks with the name that the person + sees. It does not stop a hostile agent (THREAT-MODEL.md section 5, + item 1). + ## 6. Flow: an SSH login ``` @@ -1428,8 +1563,9 @@ a field of its certificate, or a line break: with `time=`, and a value with a line break is quoted and escaped. The broker never logs claimed text, and cuts each value to 1 KiB. So no line can start with `audit anchor ` (section 9), and none comes near the - 48 KiB at which journald splits a line. It logs at most 20 SSH logins - that a check refused in a minute, and counts the others. + 48 KiB at which journald splits a line. It logs at most 20 requests in + a minute that a check refused, SSH logins (section 6) and variables on + the deny list (section 5), and counts the others. ## 11. Decision 2: loading keys after a restart diff --git a/THREAT-MODEL.md b/THREAT-MODEL.md index 1985272..7afd016 100644 --- a/THREAT-MODEL.md +++ b/THREAT-MODEL.md @@ -351,12 +351,26 @@ names, `-p`, options of some programs such as `redis-cli -a`, values after keys such as `password=` or `"token":`, headers, passwords in URLs, PEM blocks, known token shapes, and long random-looking words. A field longer than 64 KiB is not shown at all, so no field is cut before it is masked. +The variable name decides what the command does with the value. With some +names, common programs print the value, write it into a file or a file +name, send it to a server, or run it, for example `LD_PRELOAD`, +`JAVA_TOOL_OPTIONS`, `GIT_TRACE`, `PS4` or `PYTHONWARNINGS`. The person +sees the name in the message, but may not know what it means. So the +broker refuses these names, before any message, grant or rule, and the +client refuses them before it asks. DESIGN.md section 5 lists them, with +the reason for each. Risk that remains: masking is best effort and finds the common forms only. A secret in another form is shown as it is, for example a plain word (`htpasswd -b users.txt dev SECRET`) or an option of a program the broker does not know. A hostile agent can always get a secret past masking. The claimed text stays a claim. The command itself may print a secret; version -1 does not filter the command's output. +1 does not filter the command's output. The deny list of variable names +covers common programs only: a setting of another program can still show +its value, such as `UNZIP` for unzip. The agent also sets the rest +of the command's environment, which the message does not show, so a +hostile agent can set `LD_PRELOAD` there and read any value (section 5, +item 1). The deny list stops mistakes and simple tricks with the name that +the person sees. **T16. The broker host is broken into.** Everything is lost. Advice: a dedicated user, the systemd sandbox settings in the example unit @@ -637,10 +651,11 @@ once, and many requests one after the other. A request that a limit denies, or that comes after the approver stopped, costs the client nothing, so the broker writes the entries of at most 20 such requests of a client in a minute, and counts the others in its log; it also logs at -most 20 refused SSH logins a minute. Every other request writes at least -two audit entries, also when it is denied, such as one for a name that -does not exist, so such a client can still fill the disk over time. All -of this uses memory, CPU and disk on the broker host. That is a denial of +most 20 lines a minute about SSH logins and variable names that a check +refused. Every other request writes at least two audit entries, also +when it is denied, such as one for a name that does not exist, so such a +client can still fill the disk over time. All of this uses memory, CPU +and disk on the broker host. That is a denial of service, not a way to get a secret or an approval. The answer is a firewall that lets only the agent machines reach the broker port (DESIGN.md section 10), and a check of the log's size. diff --git a/internal/api/api.go b/internal/api/api.go index dee4f2c..1df1b9f 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -19,6 +19,8 @@ import ( "net/http" "net/textproto" "regexp" + "slices" + "strings" ) // The paths of the broker. Each takes POST only. @@ -112,9 +114,85 @@ var varPattern = regexp.MustCompile(`^[A-Z_][A-Z0-9_]{0,63}$`) // ValidVar reports whether name is an environment variable name that the // broker accepts: it matches [A-Z_][A-Z0-9_]{0,63}. The client checks it -// to give a quick error; the broker checks it again. +// to give a quick error; the broker checks it again. The broker also +// refuses the names of the deny list (DeniedVar). func ValidVar(name string) bool { return varPattern.MatchString(name) } +// The deny list of variable names (DESIGN.md section 5). The variable +// name decides what the command does with the value. With these names, +// common programs print the value, write it into a file or a file name, +// send it to a server, or run it: as a command, as code or as options. A +// name is refused when it is in deniedVars, or starts with a prefix in +// deniedVarPrefixes. DESIGN.md section 5 gives the reason for each entry; +// a test checks that it lists exactly these. +var ( + deniedVarPrefixes = []string{ + "DYLD_", // the dynamic loader of macOS + "GCONV_", // glibc loads character set modules, which are code, from GCONV_PATH + "GIT_", // git runs, prints or stores the value of most of its GIT_ names + "LC_", // bash and perl print a locale that is not valid; ssh sends LC_ names to the server + "LD_", // the dynamic loader prints LD_PRELOAD, LD_AUDIT and LD_DEBUG, and loads code + "NPM_CONFIG_", // npm runs NPM_CONFIG_SCRIPT_SHELL, and makes or prints its other settings + "RESOLV_", // the glibc resolver prints a RESOLV_MULTI or RESOLV_REORDER that is not valid + } + deniedVars = []string{ + // The C library, the terminal, and names that many programs use. + "BROWSER", "EDITOR", "EMAIL", "GLIBC_TUNABLES", "HOME", "LANG", "LANGUAGE", "MANPAGER", "PAGER", + "PATH", "SHELL", "SSLKEYLOGFILE", "TEMP", "TERM", "TMP", "TMPDIR", "TZ", "VISUAL", + // CA files of curl and Python requests, and the config of wget. + "CURL_CA_BUNDLE", "REQUESTS_CA_BUNDLE", "SSL_CERT_FILE", "WGETRC", + // sh, dash and bash. + "BASH_COMPAT", "BASH_ENV", "BASH_XTRACEFD", "ENV", "HISTFILE", "PROMPT_COMMAND", + "PS0", "PS1", "PS2", "PS3", "PS4", "SHELLOPTS", "TIMEFORMAT", + // ssh, sudo, gpg, rsync, ls, and the compression programs that tar + // runs. + "SSH_ASKPASS", "SSH_SK_HELPER", "SSH_SK_PROVIDER", "SUDO_ASKPASS", "GNUPGHOME", "RSYNC_CONNECT_PROG", + "RSYNC_RSH", "QUOTING_STYLE", "TIME_STYLE", "BZIP", "BZIP2", "GZIP", "ZSTD_CLEVEL", + // make, and C and C++ builds. + "CC", "CFLAGS", "CPPFLAGS", "CXX", "CXXFLAGS", "GNUMAKEFLAGS", "LDFLAGS", "LDLIBS", "MAKEFLAGS", + "TARGET_ARCH", + // gh, docker and terraform. + "GH_BROWSER", "GH_EDITOR", "GH_HOST", "GH_PAGER", "GH_REPO", + "COMPOSE_ENV_FILES", "COMPOSE_FILE", "DOCKER_API_VERSION", "DOCKER_CONTEXT", "DOCKER_HOST", + "TF_CLI_ARGS", "TF_CLI_CONFIG_FILE", "TF_LOG_PATH", "TF_PLUGIN_CACHE_DIR", "TF_WORKSPACE", + // The runtimes and build tools of Go, Java, Node.js, Perl, Python, + // Ruby and Rust. + "CGO_CFLAGS", "CGO_CPPFLAGS", "CGO_LDFLAGS", "GO111MODULE", "GOARCH", "GOCACHEPROG", + "GOEXPERIMENT", "GOFLAGS", "GOMEMLIMIT", "GOOS", "GOPATH", "GOROOT", "GOTMPDIR", "GOTOOLCHAIN", + "GRADLE_OPTS", "JAVA_HOME", "JAVA_OPTS", "JAVA_TOOL_OPTIONS", "JDK_ALTERNATE_VM", + "JDK_JAVA_OPTIONS", "MAVEN_OPTS", "_JAVA_OPTIONS", + "NODE_COMPILE_CACHE", "NODE_EXTRA_CA_CERTS", "NODE_OPTIONS", "NODE_REDIRECT_WARNINGS", + "NODE_REPL_EXTERNAL_MODULE", "NODE_V8_COVERAGE", + "PERL5LIB", "PERL5OPT", "PERLIO", "PERLLIB", "PERL_PERTURB_KEYS", "PERL_SIGNALS", + "PYTHONEXECUTABLE", "PYTHONHOME", "PYTHONIOENCODING", "PYTHONPLATLIBDIR", + "PYTHONPYCACHEPREFIX", "PYTHONSTARTUP", "PYTHONWARNINGS", + "RUBYOPT", + "CARGO_TARGET_DIR", "RUSTC_WRAPPER", "RUSTFLAGS", "RUSTUP_TOOLCHAIN", + } +) + +// DeniedVar reports whether the broker refuses the variable name because +// of the deny list of DESIGN.md section 5: the name is on the list, or +// starts with a prefix on it, such as "LD_". prefix is that prefix, or "" +// when the name itself is on the list. The match is exact: "LD_" does not +// match "LDAP_PASSWORD", and "ld_preload" is not a valid name anyway +// (ValidVar). The client checks it to give a clear error; the broker +// checks it again. +func DeniedVar(name string) (prefix string, denied bool) { + for _, p := range deniedVarPrefixes { + if strings.HasPrefix(name, p) { + return p, true + } + } + return "", slices.Contains(deniedVars, name) +} + +// DenyList returns the deny list of DeniedVar: the names and the +// prefixes, in new slices. +func DenyList() (names, prefixes []string) { + return slices.Clone(deniedVars), slices.Clone(deniedVarPrefixes) +} + // shortCodePattern is the form of a short code: 4 characters from // 23456789abcdefghjkmnpqrstuvwxyz (DESIGN.md section 7). var shortCodePattern = regexp.MustCompile(`^[2-9a-hjkmnp-z]{4}$`) diff --git a/internal/api/api_test.go b/internal/api/api_test.go index 812e6b2..7a071bd 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -7,8 +7,11 @@ import ( "log/slog" "net/http" "net/textproto" + "os" + "path/filepath" "reflect" "regexp" + "slices" "strings" "testing" @@ -443,6 +446,134 @@ func TestValidVar(t *testing.T) { } } +// TestDeniedVar: every name on the deny list is refused, and every name +// that starts with a prefix on it. Names that hold secrets on purpose, and +// names that only look like an entry, pass: a prefix matches only at the +// start and with its "_", and a name only as a whole. +func TestDeniedVar(t *testing.T) { + names, prefixes := DenyList() + if len(names) == 0 || len(prefixes) == 0 { + t.Fatal("the deny list is empty") + } + for _, name := range names { + if prefix, denied := DeniedVar(name); !denied || prefix != "" { + t.Errorf("DeniedVar(%q) = %q, %v; want \"\", true", name, prefix, denied) + } + } + for _, p := range prefixes { + for _, name := range []string{p, p + "X", p + "PRELOAD_2", p + strings.Repeat("A", 64-len(p))} { + if prefix, denied := DeniedVar(name); !denied || prefix != p { + t.Errorf("DeniedVar(%q) = %q, %v; want %q, true", name, prefix, denied, p) + } + } + } + // Some names on the list, and the prefix that refuses them, if any. + // TF_CLI_ARGS is a name on the list. terraform reads its forms for one + // command, such as TF_CLI_ARGS_plan, only in lower case, which + // ValidVar refuses. + for _, tt := range []struct{ name, prefix string }{ + {"LD_PRELOAD", "LD_"}, {"LC_ALL", "LC_"}, {"GIT_SSH_COMMAND", "GIT_"}, + {"NPM_CONFIG_SCRIPT_SHELL", "NPM_CONFIG_"}, {"TF_CLI_ARGS", ""}, {"JAVA_OPTS", ""}, {"PATH", ""}, + {"MAKEFLAGS", ""}, {"GOFLAGS", ""}, {"GH_HOST", ""}, {"DOCKER_HOST", ""}, {"SUDO_ASKPASS", ""}, + {"MANPAGER", ""}, + } { + if prefix, denied := DeniedVar(tt.name); !denied || prefix != tt.prefix { + t.Errorf("DeniedVar(%q) = %q, %v; want %q, true", tt.name, prefix, denied, tt.prefix) + } + } + for _, ok := range []string{ + "GH_TOKEN", "GITHUB_TOKEN", "GITLAB_TOKEN", "AWS_SECRET_ACCESS_KEY", "LDAP_PASSWORD", "NODE_AUTH_TOKEN", + "NPM_TOKEN", "HOMEBREW_GITHUB_API_TOKEN", "PGPASSWORD", "SSH_PRIVATE_KEY", "DB_PASSWORD", + "DOCKER_PASSWORD", "CARGO_REGISTRY_TOKEN", "EMAIL_PASSWORD", "TF_TOKEN_EXAMPLE_COM", "TF_VAR_DB_PASSWORD", + "GOPROXY", "HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY", + "LD", "LDX_PRELOAD", "XLD_PRELOAD", "LC", "GIT", "MY_GIT_TOKEN", "DYLD", "GCONV", "RESOLV", + "PATHS", "HOME_DIR", "TERM_TOKEN", "PS", "PS5", "ENVIRONMENT", "LANGFUSE_SECRET_KEY", "CC_TOKEN", + "NPM_CONFIG", "MY_NPM_CONFIG_X", "TF_CLI_ARG", "TF_LOG", "TF_IN_AUTOMATION", "DOCKER_CONFIG_TOKEN", + "NODE_PATH", "PYTHONPATH", "RUBYLIB", "IFS", "LESSOPEN", + // Lower case is not on the list; ValidVar refuses it anyway, also + // Terraform's own forms of TF_TOKEN_ and TF_VAR_. + "ld_preload", "path", "TF_TOKEN_example_com", "TF_VAR_db_password", + } { + if prefix, denied := DeniedVar(ok); denied { + t.Errorf("DeniedVar(%q) = %q, true; want false", ok, prefix) + } + } +} + +// TestDenyListIsClean: each entry is a valid name, each prefix ends with +// "_", no entry is there twice, and no name or prefix is covered by +// another prefix. DenyList returns copies, so a caller cannot change the +// list. +func TestDenyListIsClean(t *testing.T) { + names, prefixes := DenyList() + seen := make(map[string]bool) + for _, e := range slices.Concat(names, prefixes) { + if !ValidVar(e) || seen[e] { + t.Errorf("the entry %q is not a valid name, or is there twice", e) + } + seen[e] = true + } + for _, p := range prefixes { + if !strings.HasSuffix(p, "_") { + t.Errorf("the prefix %q does not end with _", p) + } + for _, q := range prefixes { + if p != q && strings.HasPrefix(p, q) { + t.Errorf("the prefix %q covers the prefix %q", q, p) + } + } + } + for _, name := range names { + if prefix, _ := DeniedVar(name); prefix != "" { + t.Errorf("the prefix %q covers the name %q", prefix, name) + } + } + names[0], prefixes[0] = "GH_TOKEN", "NPM_" + if _, denied := DeniedVar("GH_TOKEN"); denied { + t.Error("DenyList shares its names with the list") + } + if _, denied := DeniedVar("NPM_TOKEN"); denied { + t.Error("DenyList shares its prefixes with the list") + } +} + +// TestDenyListAsInDesign: the table of DESIGN.md section 5 lists exactly +// the names and the prefixes of the deny list, in its first column. A +// prefix is written as LD_*. +func TestDenyListAsInDesign(t *testing.T) { + doc, err := os.ReadFile(filepath.Join("..", "..", "DESIGN.md")) + if err != nil { + t.Fatal(err) + } + _, section, ok := strings.Cut(string(doc), "\n### Variable names that the broker refuses\n") + if !ok { + t.Fatal("DESIGN.md section 5 has no list of the variable names that the broker refuses") + } + section, _, _ = strings.Cut(section, "\n#") + var inDoc []string + for line := range strings.Lines(section) { + cell, ok := strings.CutPrefix(line, "| ") + if !ok { + continue + } + cell, _, _ = strings.Cut(cell, " |") + for i, part := range strings.Split(cell, "`") { + if i%2 == 1 { + inDoc = append(inDoc, part) + } + } + } + names, prefixes := DenyList() + for _, p := range prefixes { + names = append(names, p+"*") + } + slices.Sort(names) + slices.Sort(inDoc) + if !slices.Equal(inDoc, names) { + t.Errorf("DESIGN.md lists %q;\nthe deny list has %q", inDoc, names) + } +} + func TestShortCode(t *testing.T) { h := func(values ...string) textproto.MIMEHeader { return textproto.MIMEHeader{textproto.CanonicalMIMEHeaderKey(ShortCodeHeader): values} diff --git a/internal/api/types.go b/internal/api/types.go index 6bc14f1..6715aed 100644 --- a/internal/api/types.go +++ b/internal/api/types.go @@ -136,7 +136,8 @@ func (r *SecretsRequest) UnmarshalJSON(data []byte) error { // SecretRef is one variable of a SecretsRequest. type SecretRef struct { // Var is the environment variable, such as "GH_TOKEN". The broker - // checks it with ValidVar. A message shows it as claimed text. + // checks it with ValidVar and DeniedVar. A message shows it as + // claimed text. Var string `json:"var"` // Name is the name of a [secret.*] section, such as "github-token". Name string `json:"name"` diff --git a/internal/broker/broker.go b/internal/broker/broker.go index 4ef5fca..d709e59 100644 --- a/internal/broker/broker.go +++ b/internal/broker/broker.go @@ -18,10 +18,11 @@ // 4. It reads the body strictly (transport.ReadJSON into the types of // package api), with their caps, while it holds one of the few places // for reading bodies (maxBodiesPerClient, maxBodies). -// 5. It checks every input itself: variable names, the names of secrets -// and keys against the config and the client's lists, the remote user -// name, and for an SSH login the data to sign and the session-bind -// (sshauth.Key.Check), before any message or place in a queue. +// 5. It checks every input itself: variable names, also against the deny +// list (api.DeniedVar), the names of secrets and keys against the +// config and the client's lists, the remote user name, and for an SSH +// login the data to sign and the session-bind (sshauth.Key.Check), +// before any message or place in a queue. // 6. It makes the claimed text safe (claim.Mask and claim.Line, or // claim.Command), and builds an approval.Request from checked data // only. @@ -100,8 +101,9 @@ const ( // whose audit entries the broker writes in a minute: requests denied // for a limit, and requests refused after the approver stopped. refusedEntriesPerMinute = 20 - // refusedLinesPerMinute is the most log lines in a minute about SSH - // logins that a check refused, for all clients together. + // refusedLinesPerMinute is the most log lines in a minute about + // requests that a check refused, for all clients together: SSH logins, + // and requests for secrets with a variable on the deny list. refusedLinesPerMinute = 20 ) @@ -176,7 +178,8 @@ type Service struct { clientBodies map[string]chan struct{} // refusedEntries limits the audit entries of refused requests, by - // client; refusedLines limits the log lines about refused SSH logins. + // client; refusedLines limits the log lines about requests that a + // check refused: SSH logins, and variables on the deny list. refusedEntries map[string]*rateLimit refusedLines *rateLimit @@ -254,7 +257,7 @@ func New(p Parts) (*Service, error) { }) } s.refusedLines = newRateLimit(refusedLinesPerMinute, func(n int) { - s.log.Info("broker: did not log refused SSH login requests, to keep the log small", slog.Int("dropped", n), + s.log.Info("broker: did not log refused requests, to keep the log small", slog.Int("dropped", n), slog.Int("limit_per_minute", refusedLinesPerMinute)) }) s.bg.Add(1) diff --git a/internal/broker/limits_test.go b/internal/broker/limits_test.go index f29516c..8ff6684 100644 --- a/internal/broker/limits_test.go +++ b/internal/broker/limits_test.go @@ -97,7 +97,7 @@ func TestRefusedLoginLinesAreLimited(t *testing.T) { t.Errorf("%d lines about refused logins, want %d", n, refusedLinesPerMinute) } e.svc.Close() - logs := waitLog(t, e.logs, "did not log refused SSH login requests") + logs := waitLog(t, e.logs, "did not log refused requests") if !strings.Contains(logs, "dropped=5") { t.Errorf("the log does not count the lines it dropped:\n%s", logs) } diff --git a/internal/broker/secrets.go b/internal/broker/secrets.go index a678f0e..7ec8706 100644 --- a/internal/broker/secrets.go +++ b/internal/broker/secrets.go @@ -33,9 +33,11 @@ func (rq *request) secrets(ctx context.Context, r *http.Request) { rq.pre.Command, rq.pre.Reason = cl.Command, cl.Reason rq.releaseBody() if !ok { - // No message for a name the client may not use (DESIGN.md - // section 5). The audit log gets only the names that passed. + // No message for a name the client may not use, or for a + // variable on the deny list (DESIGN.md section 5). The audit log + // gets only the names that passed. rq.deny(rq.pre, audit.CauseNotAllowed, "", http.StatusForbidden) + rq.logDeniedVar(req.Secrets) return } res, rc, ok := rq.decide(ctx, &approval.Request{ @@ -82,16 +84,18 @@ func (rq *request) secrets(ctx context.Context, r *http.Request) { } // checkSecrets checks the variables and the secret names of req: 1 to -// api.MaxSecrets variables, each with a valid name, none twice, and each -// secret in the config and allowed for client. It returns the secret names -// in the order of the request, for the core, and the names that passed, -// once each, for the audit log. +// api.MaxSecrets variables, each with a valid name that is not on the +// deny list (api.DeniedVar), none twice, and each secret in the config and +// allowed for client. It returns the secret names in the order of the +// request, for the core, and the names that passed, once each, for the +// audit log. func (s *Service) checkSecrets(client string, req *api.SecretsRequest) (names, passed []string, ok bool) { ok = len(req.Secrets) > 0 && len(req.Secrets) <= api.MaxSecrets vars := make(map[string]bool, len(req.Secrets)) seen := make(map[string]bool, len(req.Secrets)) for _, ref := range req.Secrets { - if !api.ValidVar(ref.Var) || vars[ref.Var] { + _, denied := api.DeniedVar(ref.Var) + if !api.ValidVar(ref.Var) || denied || vars[ref.Var] { ok = false } vars[ref.Var] = true @@ -109,6 +113,32 @@ func (s *Service) checkSecrets(client string, req *api.SecretsRequest) (names, p return names, passed, ok } +// logDeniedVar logs why the broker refused a request with a variable on +// the deny list (DESIGN.md section 5): a fixed text, and the entry of the +// list, such as PATH or LD_*. It never logs a name that the client chose: +// for a prefix, it logs only the prefix. An agent can send many such +// requests, so these lines are limited per minute, together with those +// about refused SSH logins. +func (rq *request) logDeniedVar(refs []api.SecretRef) { + for _, ref := range refs { + prefix, denied := api.DeniedVar(ref.Var) + if !denied { + continue + } + entry := prefix + "*" + if prefix == "" { + entry = ref.Var // equal to a name on the list + } + if rq.s.refusedLines.allow() { + rq.s.log.Info("broker: refused a request for secrets: a variable is on the deny list, because "+ + "programs show or run the value of such a variable (DESIGN.md section 5)", + slog.String("request_id", rq.sub.RequestID), slog.String("client", rq.client), + slog.String("deny_list", entry)) + } + return + } +} + // fetch gets the value of each secret of names from its store, once each, // in order. It needs the receipt of the decision. The values go to // rq.values too, so they are cleared on every path. Any error denies the diff --git a/internal/broker/secrets_test.go b/internal/broker/secrets_test.go index 1a64e6a..d6b79e8 100644 --- a/internal/broker/secrets_test.go +++ b/internal/broker/secrets_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "net/http" + "slices" "strings" "testing" "time" @@ -358,6 +359,118 @@ func TestSecretsBrokerChecks(t *testing.T) { } } +// TestSecretsDeniedVars: the broker refuses every variable on the deny +// list, and every variable that starts with a prefix on it (DESIGN.md +// section 5), before any message, grant or rule: 403 at once, without a +// short code, a message, a notice or a fetch. The audit log records each +// request as not_allowed, with only the secret names that passed, and +// never the variable. +func TestSecretsDeniedVars(t *testing.T) { + e := newEnv(t, envOptions{}) + laptop, ci := e.httpClient("laptop"), e.httpClient("ci") + // "Approve 15 min" makes a grant for github-token; backup-token has a + // "never ask" rule for ci. Neither may cover a variable on the list. + p := e.start(laptop, api.PathSecrets, secretsRequest("GH_TOKEN", "github-token")) + e.tap(e.waitAsked(1)[0].Prompt.RequestID, audit.AnswerApproveWindow) + secretsOf(t, p.wait(t)) + fetched, entries := e.main.fetched(), len(e.audit.all()) + // A made-up end for names that start with a prefix. It must never + // reach the audit log or the log. + tail := canary() + names, prefixes := api.DenyList() + for _, prefix := range prefixes { + names = append(names, prefix, prefix+tail) + } + for _, name := range names { + for _, c := range []struct { + client *http.Client + secret string + }{{laptop, "github-token"}, {ci, "backup-token"}} { + before := len(e.audit.all()) + res := e.post(t.Context(), c.client, api.PathSecrets, secretsRequest(name, c.secret)) + if res.err != nil || res.status != http.StatusForbidden || res.code != "" { + t.Errorf("%s=%s: status %d, %v, short code %q; want 403 at once", name, c.secret, res.status, + res.err, res.code) + continue + } + got := e.audit.waitFor(t, before+2)[before:] + mustEvents(t, got, "request denied:not_allowed") + if s := subjectOf(got[0]); !slices.Equal(s.Secrets, []string{c.secret}) || s.Kind != audit.KindSecrets { + t.Errorf("%s=%s: the audit log has %+v", name, c.secret, s) + } + } + } + // One variable on the list denies the whole request. + req := secretsRequest("GH_TOKEN", "github-token") + req.Secrets = append(req.Secrets, api.SecretRef{Var: "LD_PRELOAD", Name: "npm-token"}) + mustStatus(t, e.post(t.Context(), laptop, api.PathSecrets, req), http.StatusForbidden) + events := e.audit.all() + mustEvents(t, requestEvents(events, lastRequestID(t, events)), "request denied:not_allowed") + // Two entries for each request: two clients for each name, and the + // last request. + if n, want := len(events)-entries, 2*(2*len(names)+1); n != want { + t.Errorf("%d new audit entries, want %d", n, want) + } + if len(e.approver.Asked()) != 1 || len(e.approver.Notices()) != 0 || e.main.fetched() != fetched { + t.Errorf("messages %d, notices %d, fetches %d; want only the message and the fetch before", + len(e.approver.Asked()), len(e.approver.Notices()), e.main.fetched()-fetched) + } + if all := encodeEvents(t, events) + e.logs.String(); strings.Contains(all, tail) { + t.Error("a variable that the client chose is in the audit log or the log") + } +} + +// TestSecretsDeniedVarLog: the log says why the broker refused a request +// with a variable on the deny list, with a fixed text and the entry of the +// list: the name, or the prefix with "*", never the client's name. +func TestSecretsDeniedVarLog(t *testing.T) { + e := newEnv(t, envOptions{}) + c := e.httpClient("laptop") + tail := canary() + for _, name := range []string{"PATH", "GIT_" + tail} { + mustStatus(t, e.post(t.Context(), c, api.PathSecrets, secretsRequest(name, "github-token")), + http.StatusForbidden) + } + logs := e.logs.String() + for _, entry := range []string{"PATH", "GIT_*"} { + if !strings.Contains(logs, "a variable is on the deny list") || !strings.Contains(logs, "deny_list="+entry) { + t.Errorf("the log does not say that %s is on the deny list:\n%s", entry, logs) + } + } + if strings.Contains(logs, tail) { + t.Error("the log holds a variable that the client chose") + } + // Other refusals do not name the deny list. + before := strings.Count(e.logs.String(), "deny list") + mustStatus(t, e.post(t.Context(), c, api.PathSecrets, secretsRequest("gh_token", "github-token")), + http.StatusForbidden) + if strings.Count(e.logs.String(), "deny list") != before { + t.Error("the log blames the deny list for a variable name that is not valid") + } +} + +// TestSecretsVarsNotOnDenyList: names that hold secrets on purpose, and +// names that only look like an entry of the deny list, still get their +// values. +func TestSecretsVarsNotOnDenyList(t *testing.T) { + e := newEnv(t, envOptions{}) + e.approver.Auto(audit.AnswerApproveOnce) + vars := []string{"GH_TOKEN", "GITHUB_TOKEN", "AWS_SECRET_ACCESS_KEY", "LDAP_PASSWORD", "NODE_AUTH_TOKEN", + "NPM_TOKEN", "HOMEBREW_GITHUB_API_TOKEN", "SSH_PRIVATE_KEY", "DOCKER_PASSWORD", "CARGO_REGISTRY_TOKEN", + "TF_TOKEN_EXAMPLE_COM", "TF_VAR_DB_PASSWORD", "GOPROXY", "HTTPS_PROXY", "LC", "GIT", "PATHS", "PS5"} + req := secretsRequest("GH_TOKEN", "github-token") + req.Secrets = nil + for _, v := range vars { + req.Secrets = append(req.Secrets, api.SecretRef{Var: v, Name: "github-token"}) + } + got := secretsOf(t, e.post(t.Context(), e.httpClient("laptop"), api.PathSecrets, req)) + for _, v := range vars { + if got[v] != e.values["github-token"] { + t.Errorf("%s did not get its value", v) + } + } +} + // TestBadBodies: a body that is not a valid request is refused with 400 // and recorded as denied, without a message. func TestBadBodies(t *testing.T) { diff --git a/internal/client/request_test.go b/internal/client/request_test.go index e2323b0..475234c 100644 --- a/internal/client/request_test.go +++ b/internal/client/request_test.go @@ -76,6 +76,50 @@ func TestRunUsage(t *testing.T) { } } +// TestRunDeniedVars: nodkey run refuses every variable on the deny list, +// and every variable that starts with a prefix on it (DESIGN.md section +// 5), before it asks anyone: it prints the usage and a clear last line, +// exits with 64, sends no request and starts nothing. Names that hold +// secrets on purpose, or only look like an entry, pass. +func TestRunDeniedVars(t *testing.T) { + t.Parallel() + fb := newFakeBroker(t, func(http.ResponseWriter, *http.Request) { + t.Error("a request reached the broker") + }) + type test struct{ name, want string } + var tests []test + names, prefixes := api.DenyList() + for _, name := range names { + tests = append(tests, test{name, "nodkey refuses the variable " + name + + ", because programs show or run its value"}) + } + for _, p := range prefixes { + want := "nodkey refuses variables that start with " + p + ", because programs show or run their values" + tests = append(tests, test{p, want}, test{p + "X", want}) + } + for _, tt := range tests { + fx := &fakeExec{} + code, stderr := runIn(t.Context(), testRunner(fb.b, nil, fx), "--secret", "GH_TOKEN=github-token", + "--secret", tt.name+"=npm-token", "--", self(t)) + want := "nodkey: --secret " + tt.name + "=...: " + tt.want + " (exit 64)" + if last := lastLine(stderr); code != exitUsage || last != want || !strings.HasPrefix(stderr, runUsage) { + t.Errorf("%s: exit code %d, last line %q; want 64, the usage and %q", tt.name, code, safe(last), want) + } + if len(fx.ran()) != 0 { + t.Errorf("%s: the command started", tt.name) + } + } + if n := fb.requests.Load(); n != 0 { + t.Errorf("%d requests reached the broker, want none", n) + } + for _, ok := range []string{"GH_TOKEN", "GITHUB_TOKEN", "AWS_SECRET_ACCESS_KEY", "LDAP_PASSWORD", "NODE_AUTH_TOKEN", + "NPM_TOKEN", "DOCKER_PASSWORD", "CARGO_REGISTRY_TOKEN", "TF_TOKEN_EXAMPLE_COM", "GOPROXY", "HTTPS_PROXY"} { + if _, err := parseArgs([]string{"--secret", ok + "=github-token", "--", "gh"}); err != nil { + t.Errorf("%s: %v", ok, err) + } + } +} + // TestParseArgs: the forms of the options, as the flag package reads // them. Everything after "--" is the command, also its own options. func TestParseArgs(t *testing.T) { diff --git a/internal/client/run.go b/internal/client/run.go index ffa7274..a0d51d8 100644 --- a/internal/client/run.go +++ b/internal/client/run.go @@ -42,7 +42,9 @@ on the phone. Then run COMMAND, with the value of the secret NAME in the environment variable VAR. nodkey never prints a value. --secret VAR=NAME a secret for COMMAND; 1 to 32 of them. VAR must match - [A-Z_][A-Z0-9_]{0,63}. NAME is a secret of the broker. + [A-Z_][A-Z0-9_]{0,63}, and must not be a name whose + value programs show or run, such as PATH, LD_PRELOAD + or GIT_SSH_COMMAND. NAME is a secret of the broker. --reason TEXT why COMMAND needs the secrets. Without it, the reason is the environment variable NODKEY_REASON. @@ -272,9 +274,9 @@ type runOptions struct { // options are never read as options of nodkey run. // // It checks what the broker checks too, to give a quick error: 1 to -// api.MaxSecrets variables, each name valid (api.ValidVar) and there only -// once, and each secret name 1 to api.MaxName bytes. The broker checks -// all of it again. +// api.MaxSecrets variables, each name valid (api.ValidVar), not on the +// deny list (api.DeniedVar) and there only once, and each secret name 1 +// to api.MaxName bytes. The broker checks all of it again. func parseArgs(args []string) (*runOptions, error) { o := &runOptions{} vars := make(map[string]bool) @@ -351,11 +353,18 @@ func splitOption(arg string) (name, value string, hasValue bool) { // parseSecret reads the value of --secret: VAR=NAME. func parseSecret(value string) (api.SecretRef, error) { v, name, ok := strings.Cut(value, "=") + prefix, denied := api.DeniedVar(v) switch { case !ok: return api.SecretRef{}, errors.New("--secret needs VAR=NAME, such as GH_TOKEN=github-token") case !api.ValidVar(v): return api.SecretRef{}, fmt.Errorf("--secret: the variable name %.64q must match [A-Z_][A-Z0-9_]{0,63}", v) + case denied && prefix != "": + return api.SecretRef{}, fmt.Errorf("--secret %s=...: nodkey refuses variables that start with %s, "+ + "because programs show or run their values", v, prefix) + case denied: + return api.SecretRef{}, fmt.Errorf("--secret %s=...: nodkey refuses the variable %s, "+ + "because programs show or run its value", v, v) case name == "" || len(name) > api.MaxName: return api.SecretRef{}, fmt.Errorf("--secret %s=...: the secret name must have 1 to %d bytes", v, api.MaxName)