Skip to content

Commit 502d567

Browse files
committedNov 18, 2024
Pass SUDO_RS_IS_UNSTABLE in the test suite where necessary
For FreeBSD we will be passing it by default from the test framework, but in case of nested sudo invocations, the outer sudo invocation will remove the env var, so we need to explicitly pass it again.
1 parent b73c8e4 commit 502d567

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed
 

‎README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ via the usual commands `sudo` and `su` instead, prepend `/usr/lib/cargo/bin` to
4040

4141
### Fedora
4242

43-
If you are running Fedora 38 or later, you can use:
43+
If you are running Fedora 38 or later, you can use:
4444
```sh
4545
sudo dnf install sudo-rs
4646
```
@@ -86,6 +86,11 @@ cargo build --release
8686
This produces a binary `target/release/sudo`. However, this binary must have
8787
the setuid flag set and must be owned by the root user in order to provide any
8888
useful functionality. Consult your operating system manual for details.
89+
On operating systems other than Linux we also require an environment variable
90+
`SUDO_RS_IS_UNSTABLE` to be set, and it must have the value
91+
`I accept that my system may break unexpectedly`. This because we are in an
92+
early stage of supporting non-Linux OSes. If you are unsure about how to set
93+
this up, then the current version of sudo is not intended for you.
8994

9095
Sudo-rs needs the sudoers configuration file. The sudoers configuration file
9196
will be loaded from `/etc/sudoers-rs` if that file exists, otherwise the

‎test-framework/sudo-compliance-tests/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const PAMD_SUDO_PAM_PERMIT: &str = "auth sufficient pam_permit.so";
3535

3636
const OG_SUDO_STANDARD_LECTURE: &str= "\nWe trust you have received the usual lecture from the local System\nAdministrator. It usually boils down to these three things:\n\n #1) Respect the privacy of others.\n #2) Think before you type.\n #3) With great power comes great responsibility.";
3737

38+
const SUDO_RS_IS_UNSTABLE: &str =
39+
"SUDO_RS_IS_UNSTABLE=I accept that my system may break unexpectedly";
40+
3841
const SUDO_ENV_DEFAULT_PATH: &str = "/usr/bin:/bin:/usr/sbin:/sbin";
3942
const SUDO_ENV_DEFAULT_TERM: &str = "unknown";
4043

‎test-framework/sudo-compliance-tests/src/sudo/env_reset.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use sudo_test::{Command, Env, User};
55

66
use crate::{
77
helpers, Result, SUDOERS_ROOT_ALL_NOPASSWD, SUDO_ENV_DEFAULT_PATH, SUDO_ENV_DEFAULT_TERM,
8-
USERNAME,
8+
SUDO_RS_IS_UNSTABLE, USERNAME,
99
};
1010

1111
// NOTE if 'env_reset' is not in `/etc/sudoers` it is enabled by default
@@ -24,7 +24,7 @@ fn some_vars_are_set() -> Result<()> {
2424

2525
// run sudo in an empty environment
2626
let stdout = Command::new("env")
27-
.args(["-i", &sudo_abs_path, &env_abs_path])
27+
.args(["-i", SUDO_RS_IS_UNSTABLE, &sudo_abs_path, &env_abs_path])
2828
.output(&env)?
2929
.stdout()?;
3030
let mut sudo_env = helpers::parse_env_output(&stdout)?;
@@ -115,7 +115,14 @@ fn user_dependent_vars() -> Result<()> {
115115

116116
// run sudo in an empty environment
117117
let stdout = Command::new("env")
118-
.args(["-i", &sudo_abs_path, "-u", USERNAME, &env_abs_path])
118+
.args([
119+
"-i",
120+
SUDO_RS_IS_UNSTABLE,
121+
&sudo_abs_path,
122+
"-u",
123+
USERNAME,
124+
&env_abs_path,
125+
])
119126
.output(&env)?
120127
.stdout()?;
121128
let mut sudo_env = helpers::parse_env_output(&stdout)?;
@@ -169,6 +176,7 @@ fn some_vars_are_preserved() -> Result<()> {
169176
let stdout = Command::new("env")
170177
.args([
171178
"-i",
179+
SUDO_RS_IS_UNSTABLE,
172180
&format!("HOME={home}"),
173181
&format!("MAIL={mail}"),
174182
&format!("SHELL={shell}"),
@@ -223,6 +231,7 @@ fn vars_whose_values_start_with_parentheses_are_removed() -> Result<()> {
223231
let stdout = Command::new("env")
224232
.args([
225233
"-i",
234+
SUDO_RS_IS_UNSTABLE,
226235
"DISPLAY=() display",
227236
"PATH=() path",
228237
"TERM=() term",

‎test-framework/sudo-compliance-tests/src/sudo/sudo_ps1.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use sudo_test::{Command, Env};
22

3-
use crate::{helpers, EnvList, Result, SUDOERS_ROOT_ALL_NOPASSWD};
3+
use crate::{helpers, EnvList, Result, SUDOERS_ROOT_ALL_NOPASSWD, SUDO_RS_IS_UNSTABLE};
44

55
// see 'environment' section in `man sudo`
66
// "SUDO_PS1: If set, PS1 will be set to its value for the program being run."
@@ -14,7 +14,7 @@ fn ps1_env_var_is_set_when_sudo_ps1_is_set() -> Result<()> {
1414

1515
// run sudo in an empty environment
1616
let stdout = Command::new("env")
17-
.args(["-i"])
17+
.args(["-i", SUDO_RS_IS_UNSTABLE])
1818
.arg(format!("SUDO_PS1={ps1}"))
1919
.args([&sudo_abs_path, &env_abs_path])
2020
.output(&env)?
@@ -36,7 +36,7 @@ fn ps1_env_var_is_not_set_when_sudo_ps1_is_set_and_flag_login_is_used() -> Resul
3636

3737
// run sudo in an empty environment
3838
let stdout = Command::new("env")
39-
.args(["-i"])
39+
.args(["-i", SUDO_RS_IS_UNSTABLE])
4040
.arg("SUDO_PS1=abc")
4141
.args([&sudo_abs_path, "-i", &env_abs_path])
4242
.output(&env)?
@@ -60,7 +60,7 @@ fn can_start_with_parentheses() -> Result<()> {
6060

6161
// run sudo in an empty environment
6262
let stdout = Command::new("env")
63-
.args(["-i"])
63+
.args(["-i", SUDO_RS_IS_UNSTABLE])
6464
.arg(format!("SUDO_PS1={ps1}"))
6565
.args([&sudo_abs_path, &env_abs_path])
6666
.output(&env)?

‎test-framework/sudo-compliance-tests/src/sudo/timestamp.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use sudo_test::{Command, Env, User};
22

3-
use crate::{Result, PASSWORD, USERNAME};
3+
use crate::{Result, PASSWORD, SUDO_RS_IS_UNSTABLE, USERNAME};
44

55
mod remove;
66
mod reset;
@@ -132,7 +132,7 @@ fn cached_credential_not_shared_with_target_user_that_are_not_self() -> Result<(
132132
let output = Command::new("sh")
133133
.arg("-c")
134134
.arg(format!(
135-
"echo {PASSWORD} | sudo -u {second_target_user} -S true; sudo -u {second_target_user} sudo -S true"
135+
"echo {PASSWORD} | sudo -u {second_target_user} -S true; sudo -u {second_target_user} env '{SUDO_RS_IS_UNSTABLE}' sudo -S true"
136136
))
137137
.as_user(USERNAME)
138138
.output(&env)?;
@@ -164,7 +164,7 @@ fn cached_credential_shared_with_target_user_that_is_self_on_the_same_tty() -> R
164164
Command::new("sh")
165165
.arg("-c")
166166
.arg(format!(
167-
"echo {PASSWORD} | sudo -S true; sudo -u {USERNAME} sudo -n true"
167+
"echo {PASSWORD} | sudo -S true; sudo -u {USERNAME} env '{SUDO_RS_IS_UNSTABLE}' sudo -n true"
168168
))
169169
.as_user(USERNAME)
170170
.tty(true)

0 commit comments

Comments
 (0)
Please sign in to comment.