Clean env on subprocess (#2819)

* Clean env on subprocess

* use new format
This commit is contained in:
Pascal Vizeli 2021-04-16 16:01:36 +02:00 committed by GitHub
parent 9db95c188a
commit 092d526749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -2,10 +2,11 @@
import asyncio import asyncio
from ipaddress import IPv4Address from ipaddress import IPv4Address
import logging import logging
import os
from pathlib import Path from pathlib import Path
import re import re
import socket import socket
from typing import Any from typing import Any, Dict
_LOGGER: logging.Logger = logging.getLogger(__name__) _LOGGER: logging.Logger = logging.getLogger(__name__)
@ -96,3 +97,12 @@ async def remove_folder(folder: Path, content_only: bool = False) -> None:
return return
_LOGGER.error("Can't remove folder %s: %s", folder, error_msg) _LOGGER.error("Can't remove folder %s: %s", folder, error_msg)
def clean_env() -> Dict[str, str]:
"""Return a clean env from system."""
new_env = {}
for key in ("HOME", "PATH", "PWD", "CWD", "SHLVL"):
if value := os.environ.get(key):
new_env[key] = value
return new_env

View File

@ -9,6 +9,7 @@ from typing import Optional, Set, Tuple, Union
import async_timeout import async_timeout
from . import clean_env
from ..exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted from ..exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted
_LOGGER: logging.Logger = logging.getLogger(__name__) _LOGGER: logging.Logger = logging.getLogger(__name__)
@ -64,6 +65,7 @@ async def vcn_validate(
stdin=asyncio.subprocess.DEVNULL, stdin=asyncio.subprocess.DEVNULL,
stdout=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL,
env=clean_env(),
) )
async with async_timeout.timeout(10): async with async_timeout.timeout(10):

View File

@ -12,6 +12,7 @@ import xml.etree.ElementTree as ET
import sentry_sdk import sentry_sdk
from . import clean_env
from ..exceptions import ( from ..exceptions import (
DBusFatalError, DBusFatalError,
DBusInterfaceError, DBusInterfaceError,
@ -234,6 +235,7 @@ class DBus:
stdin=asyncio.subprocess.DEVNULL, stdin=asyncio.subprocess.DEVNULL,
stdout=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
env=clean_env(),
) )
data, error = await proc.communicate() data, error = await proc.communicate()
@ -320,6 +322,7 @@ class DBusSignalWrapper:
stdin=asyncio.subprocess.DEVNULL, stdin=asyncio.subprocess.DEVNULL,
stdout=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
env=clean_env(),
) )
return self return self