|
38 | 38 | logger = logging.getLogger(__name__)
|
39 | 39 | tracer = trace.get_tracer()
|
40 | 40 |
|
| 41 | +DISTROS_MISSING_WHITELIST_ENVIRONMENT_FOR_SU = ["almalinux-8"] |
| 42 | + |
41 | 43 |
|
42 | 44 | def verbose_called_process_error(excp: subprocess.CalledProcessError) -> str:
|
43 | 45 | """Return a verbose message containing debug information of a `CalledProcessError` exception."""
|
@@ -276,6 +278,10 @@ def execute(
|
276 | 278 | def _add_trace_context(
|
277 | 279 | kwargs: dict, preserve_env: list[str] | None, sudo: bool
|
278 | 280 | ) -> tuple[list[str] | None, dict]:
|
| 281 | + current_distro = os.environ.get("DISTRO") |
| 282 | + if current_distro in DISTROS_MISSING_WHITELIST_ENVIRONMENT_FOR_SU: |
| 283 | + logger.info(f"Don't add trace context for {current_distro}") |
| 284 | + return preserve_env, kwargs |
279 | 285 | if trace_env := trace.context_for_environment():
|
280 | 286 | orig_env = kwargs["env"] if kwargs.get("env") else dict(os.environ)
|
281 | 287 | kwargs["env"] = {**orig_env, **trace_env}
|
@@ -329,6 +335,12 @@ def _cmd_as_user(username: str, preserve_env: list[str] | None = None) -> list[s
|
329 | 335 | """Extend commandline by adopting rol oe desired user."""
|
330 | 336 | base_cmd = ["su", "-l", username]
|
331 | 337 | if preserve_env:
|
| 338 | + current_distro = os.environ.get("DISTRO") |
| 339 | + if current_distro in DISTROS_MISSING_WHITELIST_ENVIRONMENT_FOR_SU: |
| 340 | + raise RuntimeError( |
| 341 | + f"Calling 'su' with '--whitelist-environment' is not supported under {current_distro}. " |
| 342 | + f"Fix the callsites." |
| 343 | + ) |
332 | 344 | base_cmd += ["--whitelist-environment", ",".join(preserve_env)]
|
333 | 345 | base_cmd += ["-c"]
|
334 | 346 | return base_cmd
|
|
0 commit comments