mirror of
https://github.com/openai/codex.git
synced 2026-11-03 08:22:30 +00:00
Set exclude to true by default in app server (#8281)
This commit is contained in:
1 parent
8f0b383621
commit
9fb9ed6cea
4 files changed
+50
-11
No files matched your search
@@ -474,17 +474,17 @@ pub type EnvironmentVariablePattern = WildMatchPattern<'*', '?'>;
|
|||||||
/// Deriving the `env` based on this policy works as follows:
|
/// Deriving the `env` based on this policy works as follows:
|
||||||
/// 1. Create an initial map based on the `inherit` policy.
|
/// 1. Create an initial map based on the `inherit` policy.
|
||||||
/// 2. If `ignore_default_excludes` is false, filter the map using the default
|
/// 2. If `ignore_default_excludes` is false, filter the map using the default
|
||||||
/// exclude pattern(s), which are: `"*KEY*"` and `"*TOKEN*"`.
|
/// exclude pattern(s), which are: `"*KEY*"`, `"*SECRET*"`, and `"*TOKEN*"`.
|
||||||
/// 3. If `exclude` is not empty, filter the map using the provided patterns.
|
/// 3. If `exclude` is not empty, filter the map using the provided patterns.
|
||||||
/// 4. Insert any entries from `r#set` into the map.
|
/// 4. Insert any entries from `r#set` into the map.
|
||||||
/// 5. If non-empty, filter the map using the `include_only` patterns.
|
/// 5. If non-empty, filter the map using the `include_only` patterns.
|
||||||
#[derive(Debug, Clone, PartialEq, Default)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ShellEnvironmentPolicy {
|
pub struct ShellEnvironmentPolicy {
|
||||||
/// Starting point when building the environment.
|
/// Starting point when building the environment.
|
||||||
pub inherit: ShellEnvironmentPolicyInherit,
|
pub inherit: ShellEnvironmentPolicyInherit,
|
||||||
|
|
||||||
/// True to skip the check to exclude default environment variables that
|
/// True to skip the check to exclude default environment variables that
|
||||||
/// contain "KEY" or "TOKEN" in their name.
|
/// contain "KEY", "SECRET", or "TOKEN" in their name. Defaults to true.
|
||||||
pub ignore_default_excludes: bool,
|
pub ignore_default_excludes: bool,
|
||||||
|
|
||||||
/// Environment variable names to exclude from the environment.
|
/// Environment variable names to exclude from the environment.
|
||||||
@@ -504,7 +504,7 @@ impl From<ShellEnvironmentPolicyToml> for ShellEnvironmentPolicy {
|
|||||||
fn from(toml: ShellEnvironmentPolicyToml) -> Self {
|
fn from(toml: ShellEnvironmentPolicyToml) -> Self {
|
||||||
// Default to inheriting the full environment when not specified.
|
// Default to inheriting the full environment when not specified.
|
||||||
let inherit = toml.inherit.unwrap_or(ShellEnvironmentPolicyInherit::All);
|
let inherit = toml.inherit.unwrap_or(ShellEnvironmentPolicyInherit::All);
|
||||||
let ignore_default_excludes = toml.ignore_default_excludes.unwrap_or(false);
|
let ignore_default_excludes = toml.ignore_default_excludes.unwrap_or(true);
|
||||||
let exclude = toml
|
let exclude = toml
|
||||||
.exclude
|
.exclude
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -531,6 +531,19 @@ impl From<ShellEnvironmentPolicyToml> for ShellEnvironmentPolicy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ShellEnvironmentPolicy {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
inherit: ShellEnvironmentPolicyInherit::All,
|
||||||
|
ignore_default_excludes: true,
|
||||||
|
exclude: Vec::new(),
|
||||||
|
r#set: HashMap::new(),
|
||||||
|
include_only: Vec::new(),
|
||||||
|
use_profile: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_core_inherit_and_default_excludes() {
|
fn test_core_inherit_defaults_keep_sensitive_vars() {
|
||||||
let vars = make_vars(&[
|
let vars = make_vars(&[
|
||||||
("PATH", "/usr/bin"),
|
("PATH", "/usr/bin"),
|
||||||
("HOME", "/home/user"),
|
("HOME", "/home/user"),
|
||||||
@@ -90,7 +90,32 @@ mod tests {
|
|||||||
("SECRET_TOKEN", "t"),
|
("SECRET_TOKEN", "t"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let policy = ShellEnvironmentPolicy::default(); // inherit Core, default excludes on
|
let policy = ShellEnvironmentPolicy::default(); // inherit All, default excludes ignored
|
||||||
|
let result = populate_env(vars, &policy);
|
||||||
|
|
||||||
|
let expected: HashMap<String, String> = hashmap! {
|
||||||
|
"PATH".to_string() => "/usr/bin".to_string(),
|
||||||
|
"HOME".to_string() => "/home/user".to_string(),
|
||||||
|
"API_KEY".to_string() => "secret".to_string(),
|
||||||
|
"SECRET_TOKEN".to_string() => "t".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_core_inherit_with_default_excludes_enabled() {
|
||||||
|
let vars = make_vars(&[
|
||||||
|
("PATH", "/usr/bin"),
|
||||||
|
("HOME", "/home/user"),
|
||||||
|
("API_KEY", "secret"),
|
||||||
|
("SECRET_TOKEN", "t"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let policy = ShellEnvironmentPolicy {
|
||||||
|
ignore_default_excludes: false, // apply KEY/SECRET/TOKEN filter
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
let result = populate_env(vars, &policy);
|
let result = populate_env(vars, &policy);
|
||||||
|
|
||||||
let expected: HashMap<String, String> = hashmap! {
|
let expected: HashMap<String, String> = hashmap! {
|
||||||
@@ -162,6 +187,7 @@ mod tests {
|
|||||||
|
|
||||||
let policy = ShellEnvironmentPolicy {
|
let policy = ShellEnvironmentPolicy {
|
||||||
inherit: ShellEnvironmentPolicyInherit::All,
|
inherit: ShellEnvironmentPolicyInherit::All,
|
||||||
|
ignore_default_excludes: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -383,8 +383,8 @@ Codex spawns subprocesses (e.g. when executing a `local_shell` tool-call suggest
|
|||||||
[shell_environment_policy]
|
[shell_environment_policy]
|
||||||
# inherit can be "all" (default), "core", or "none"
|
# inherit can be "all" (default), "core", or "none"
|
||||||
inherit = "core"
|
inherit = "core"
|
||||||
# set to true to *skip* the filter for `"*KEY*"` and `"*TOKEN*"`
|
# set to true to *skip* the filter for `"*KEY*"`, `"*SECRET*"`, and `"*TOKEN*"`
|
||||||
ignore_default_excludes = false
|
ignore_default_excludes = true
|
||||||
# exclude patterns (case-insensitive globs)
|
# exclude patterns (case-insensitive globs)
|
||||||
exclude = ["AWS_*", "AZURE_*"]
|
exclude = ["AWS_*", "AZURE_*"]
|
||||||
# force-set / override values
|
# force-set / override values
|
||||||
@@ -396,7 +396,7 @@ include_only = ["PATH", "HOME"]
|
|||||||
| Field | Type | Default | Description |
|
| Field | Type | Default | Description |
|
||||||
| ------------------------- | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------------- | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `inherit` | string | `all` | Starting template for the environment:<br>`all` (clone full parent env), `core` (`HOME`, `PATH`, `USER`, …), or `none` (start empty). |
|
| `inherit` | string | `all` | Starting template for the environment:<br>`all` (clone full parent env), `core` (`HOME`, `PATH`, `USER`, …), or `none` (start empty). |
|
||||||
| `ignore_default_excludes` | boolean | `false` | When `false`, Codex removes any var whose **name** contains `KEY`, `SECRET`, or `TOKEN` (case-insensitive) before other rules run. |
|
| `ignore_default_excludes` | boolean | `true` | When `false`, Codex removes any var whose **name** contains `KEY`, `SECRET`, or `TOKEN` (case-insensitive) before other rules run. |
|
||||||
| `exclude` | array<string> | `[]` | Case-insensitive glob patterns to drop after the default filter.<br>Examples: `"AWS_*"`, `"AZURE_*"`. |
|
| `exclude` | array<string> | `[]` | Case-insensitive glob patterns to drop after the default filter.<br>Examples: `"AWS_*"`, `"AZURE_*"`. |
|
||||||
| `set` | table<string,string> | `{}` | Explicit key/value overrides or additions – always win over inherited values. |
|
| `set` | table<string,string> | `{}` | Explicit key/value overrides or additions – always win over inherited values. |
|
||||||
| `include_only` | array<string> | `[]` | If non-empty, a whitelist of patterns; only variables that match _one_ pattern survive the final step. (Generally used with `inherit = "all"`.) |
|
| `include_only` | array<string> | `[]` | If non-empty, a whitelist of patterns; only variables that match _one_ pattern survive the final step. (Generally used with `inherit = "all"`.) |
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ exclude_slash_tmp = false
|
|||||||
[shell_environment_policy]
|
[shell_environment_policy]
|
||||||
# inherit: all (default) | core | none
|
# inherit: all (default) | core | none
|
||||||
inherit = "all"
|
inherit = "all"
|
||||||
# Skip default excludes for names containing KEY/TOKEN (case-insensitive). Default: false
|
# Skip default excludes for names containing KEY/SECRET/TOKEN (case-insensitive). Default: true
|
||||||
ignore_default_excludes = false
|
ignore_default_excludes = true
|
||||||
# Case-insensitive glob patterns to remove (e.g., "AWS_*", "AZURE_*"). Default: []
|
# Case-insensitive glob patterns to remove (e.g., "AWS_*", "AZURE_*"). Default: []
|
||||||
exclude = []
|
exclude = []
|
||||||
# Explicit key/value overrides (always win). Default: {}
|
# Explicit key/value overrides (always win). Default: {}
|
||||||
|
|||||||
Reference in new issue
Block a user