ScriptCollection 4.4.68__py3-none-any.whl → 4.4.70__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ScriptCollection/AgentRunner.py +48 -2
- ScriptCollection/AgentSandboxNetwork/SandboxEgressProxy.py +126 -0
- ScriptCollection/AgentSandboxNetwork/SandboxNetworkConfiguration.py +95 -0
- ScriptCollection/AgentSandboxNetwork/__init__.py +0 -0
- ScriptCollection/Executables.py +19 -0
- ScriptCollection/ScriptCollectionCore.py +13 -1
- ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py +16 -1
- ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py +36 -13
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +18 -12
- {scriptcollection-4.4.68.dist-info → scriptcollection-4.4.70.dist-info}/METADATA +2 -2
- {scriptcollection-4.4.68.dist-info → scriptcollection-4.4.70.dist-info}/RECORD +14 -11
- {scriptcollection-4.4.68.dist-info → scriptcollection-4.4.70.dist-info}/entry_points.txt +1 -0
- {scriptcollection-4.4.68.dist-info → scriptcollection-4.4.70.dist-info}/WHEEL +0 -0
- {scriptcollection-4.4.68.dist-info → scriptcollection-4.4.70.dist-info}/top_level.txt +0 -0
ScriptCollection/AgentRunner.py
CHANGED
|
@@ -11,6 +11,8 @@ from .OCIImages.OCIImageManager import OCIImageManager
|
|
|
11
11
|
from .TFCPS.ContainerBuildEnvironment import ContainerBuildEnvironment
|
|
12
12
|
from .TFCPS.TFCPS_Tools_General import TFCPS_Tools_General
|
|
13
13
|
from .AgentStatusReporting.AgentStatusReportingSession import AgentStatusReportingSession
|
|
14
|
+
from .AgentSandboxNetwork.SandboxNetworkConfiguration import SandboxNetworkConfiguration, SandboxNetworkMode
|
|
15
|
+
from .AgentSandboxNetwork.SandboxEgressProxy import SandboxEgressProxy
|
|
14
16
|
|
|
15
17
|
|
|
16
18
|
class CodingAgent(Enum):
|
|
@@ -26,6 +28,8 @@ class AgentRunnerConfiguration:
|
|
|
26
28
|
image: str = None
|
|
27
29
|
drop_capabilities: bool = None
|
|
28
30
|
provide_build_environment: bool = None
|
|
31
|
+
allowed_domains: list[str] = None
|
|
32
|
+
egress_proxy_image: str = None
|
|
29
33
|
|
|
30
34
|
@GeneralUtilities.check_arguments
|
|
31
35
|
def __init__(self):
|
|
@@ -33,6 +37,9 @@ class AgentRunnerConfiguration:
|
|
|
33
37
|
self.image = None
|
|
34
38
|
self.drop_capabilities = None
|
|
35
39
|
self.provide_build_environment = None
|
|
40
|
+
# None means that no allowlist is defined (unrestricted network-access); an empty list is an allowlist without domain (no network-access).
|
|
41
|
+
self.allowed_domains = None
|
|
42
|
+
self.egress_proxy_image = None
|
|
36
43
|
|
|
37
44
|
|
|
38
45
|
class SandboxBuildEnvironment:
|
|
@@ -65,6 +72,8 @@ class AgentRunner:
|
|
|
65
72
|
GeneralUtilities.assert_condition(interactive or prompt is not None, "A prompt is required when the agent is not run in interactive mode.")
|
|
66
73
|
self.__assert_is_git_root_dir(repository)
|
|
67
74
|
agentRunnerConfiguration: AgentRunnerConfiguration = self.__load_configuration(repository, configuration_overrides)
|
|
75
|
+
# The network-configuration is validated before anything is prepared or started, so an invalid allowlist is rejected without side-effects.
|
|
76
|
+
network_configuration = SandboxNetworkConfiguration(agentRunnerConfiguration.allowed_domains, agentRunnerConfiguration.egress_proxy_image)
|
|
68
77
|
initialization_script = self.__get_initialization_script(repository)
|
|
69
78
|
additional_folder_volume_arguments = self.__get_additional_folder_volume_arguments(additional_folders)
|
|
70
79
|
if mount_docker_socket:
|
|
@@ -73,7 +82,7 @@ class AgentRunner:
|
|
|
73
82
|
build_environment: SandboxBuildEnvironment = None
|
|
74
83
|
if agentRunnerConfiguration.provide_build_environment:
|
|
75
84
|
build_environment = self.__prepare_build_environment(repository)
|
|
76
|
-
return self.__run_sandbox(repository, agentRunnerConfiguration, prompt, interactive, initialization_script, additional_folder_volume_arguments, build_environment)
|
|
85
|
+
return self.__run_sandbox(repository, agentRunnerConfiguration, prompt, interactive, initialization_script, additional_folder_volume_arguments, build_environment, network_configuration)
|
|
77
86
|
|
|
78
87
|
@GeneralUtilities.check_arguments
|
|
79
88
|
def __print_docker_socket_warning(self) -> None:
|
|
@@ -176,10 +185,25 @@ class AgentRunner:
|
|
|
176
185
|
agentRunnerConfiguration.provide_build_environment = config_parser.getboolean(section, "provide_build_environment")
|
|
177
186
|
else:
|
|
178
187
|
agentRunnerConfiguration.provide_build_environment = False
|
|
188
|
+
|
|
189
|
+
# The allowlist and egress_proxy_image are not required either: without allowlist the network-access is unrestricted as before. The allowlist is
|
|
190
|
+
# the own section "AllowedDomains" with one entry per domain, whose value is a comment for the reader of the file (for example why the domain is
|
|
191
|
+
# needed); the comment does not influence the behavior. A missing section (no allowlist) and an empty section (allowlist without domain, which
|
|
192
|
+
# blocks the network-access) are distinguished deliberately. A domain which is listed twice is rejected by the parser.
|
|
193
|
+
allowed_domains_section = "AllowedDomains"
|
|
194
|
+
if configuration_overrides.allowed_domains is not None:
|
|
195
|
+
agentRunnerConfiguration.allowed_domains = configuration_overrides.allowed_domains
|
|
196
|
+
elif config_parser.has_section(allowed_domains_section):
|
|
197
|
+
agentRunnerConfiguration.allowed_domains = list(config_parser[allowed_domains_section].keys())
|
|
198
|
+
|
|
199
|
+
if configuration_overrides.egress_proxy_image is not None:
|
|
200
|
+
agentRunnerConfiguration.egress_proxy_image = configuration_overrides.egress_proxy_image
|
|
201
|
+
elif config_parser.has_option(section, "egress_proxy_image"):
|
|
202
|
+
agentRunnerConfiguration.egress_proxy_image = config_parser.get(section, "egress_proxy_image")
|
|
179
203
|
return agentRunnerConfiguration
|
|
180
204
|
|
|
181
205
|
@GeneralUtilities.check_arguments
|
|
182
|
-
def __run_sandbox(self, repository: str, agentRunnerConfiguration: AgentRunnerConfiguration, prompt: str, interactive: bool, initialization_script: str, additional_folder_volume_arguments: list[str], build_environment: SandboxBuildEnvironment) -> int:
|
|
206
|
+
def __run_sandbox(self, repository: str, agentRunnerConfiguration: AgentRunnerConfiguration, prompt: str, interactive: bool, initialization_script: str, additional_folder_volume_arguments: list[str], build_environment: SandboxBuildEnvironment, network_configuration: SandboxNetworkConfiguration) -> int:
|
|
183
207
|
# build_environment is None if the build-environment is not provided.
|
|
184
208
|
# The container always runs Linux.
|
|
185
209
|
# The repository is the folder given by the caller (which was asserted to be the git-root-directory before).
|
|
@@ -196,6 +220,10 @@ class AgentRunner:
|
|
|
196
220
|
with tempfile.NamedTemporaryFile("w", suffix=".sh", delete=False, newline="\n", encoding="utf-8") as entrypoint_file_handle:
|
|
197
221
|
host_entrypoint_file = entrypoint_file_handle.name
|
|
198
222
|
entrypoint_file_handle.write(entrypoint_script_content)
|
|
223
|
+
network_description = network_configuration.get_description()
|
|
224
|
+
if network_description is not None:
|
|
225
|
+
GeneralUtilities.write_message_to_stderr(network_description)
|
|
226
|
+
egress_proxy: SandboxEgressProxy = None
|
|
199
227
|
try:
|
|
200
228
|
# Make the entrypoint-script executable (chmod +x). On Linux-/macOS-hosts the execute-bit propagates into the container; on Windows-hosts this has no effect, which is why the script is additionally invoked via "sh" below.
|
|
201
229
|
os.chmod(host_entrypoint_file, 0o755)
|
|
@@ -216,6 +244,11 @@ class AgentRunner:
|
|
|
216
244
|
docker_command = docker_command + ["--volume", f"{initialization_script_absolute_path.replace(os.sep, '/')}:/Workspace/Temp/InitializationScript.sh:ro"]
|
|
217
245
|
if status_session is not None:
|
|
218
246
|
docker_command = docker_command + status_session.get_volume_arguments()
|
|
247
|
+
if network_configuration.get_mode() == SandboxNetworkMode.Allowlist:
|
|
248
|
+
# The egress-proxy is assigned before it is started, so the finally-block below also removes what a failing start created.
|
|
249
|
+
egress_proxy = SandboxEgressProxy(network_configuration.allowed_domains, self.__get_image_to_use(network_configuration.egress_proxy_image, host_repository_folder), self.verbose)
|
|
250
|
+
egress_proxy.start()
|
|
251
|
+
docker_command = docker_command + self.__get_network_arguments(network_configuration, egress_proxy)
|
|
219
252
|
# The environment of the docker-client; it differs from the one of this process only if the build-environment is provided.
|
|
220
253
|
docker_client_environment: dict[str, str] = None
|
|
221
254
|
if build_environment is not None:
|
|
@@ -243,8 +276,21 @@ class AgentRunner:
|
|
|
243
276
|
finally:
|
|
244
277
|
if status_session is not None:
|
|
245
278
|
status_session.stop()
|
|
279
|
+
if egress_proxy is not None:
|
|
280
|
+
egress_proxy.stop()
|
|
246
281
|
GeneralUtilities.ensure_file_does_not_exist(host_entrypoint_file)
|
|
247
282
|
|
|
283
|
+
@GeneralUtilities.check_arguments
|
|
284
|
+
def __get_network_arguments(self, network_configuration: SandboxNetworkConfiguration, egress_proxy: SandboxEgressProxy) -> list[str]:
|
|
285
|
+
# egress_proxy is the started egress-proxy in mode allowlist and None otherwise.
|
|
286
|
+
# Without allowlist no argument is added, so the sandbox is attached to the default bridge-network as before.
|
|
287
|
+
mode = network_configuration.get_mode()
|
|
288
|
+
if mode == SandboxNetworkMode.NoNetwork:
|
|
289
|
+
return ["--network", "none"]
|
|
290
|
+
if mode == SandboxNetworkMode.Allowlist:
|
|
291
|
+
return egress_proxy.get_sandbox_docker_arguments()
|
|
292
|
+
return []
|
|
293
|
+
|
|
248
294
|
@GeneralUtilities.check_arguments
|
|
249
295
|
def __get_image_to_use(self, configured_image: str, repository: str) -> str:
|
|
250
296
|
# If the configured image is an image-name defined in "<repository>/.ScriptCollection/OCIImages/ImageDefinition.csv" then the image (address including tag) is resolved
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
import tempfile
|
|
4
|
+
import uuid
|
|
5
|
+
from ..GeneralUtilities import GeneralUtilities
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SandboxEgressProxy:
|
|
9
|
+
"""Enforces an allowlist of domains for the agent-sandbox. For one run it creates an internal docker-network (which has no route to the outside)
|
|
10
|
+
and a Squid-container which is attached to this network and to the default bridge-network, so only the proxy can reach the outside.
|
|
11
|
+
The proxy only allows CONNECT to port 443 of the allowed domains (TLS is tunneled, not intercepted).
|
|
12
|
+
The sandbox is attached only to the internal network, gets the proxy announced by the usual proxy-environment-variables and has no DNS-server
|
|
13
|
+
for external names, so the restriction is enforced outside of the sandbox and can not be lifted from inside of it."""
|
|
14
|
+
proxy_port: int = 3128
|
|
15
|
+
squid_configuration_file_in_container: str = "/etc/squid/squid.conf"
|
|
16
|
+
access_log_file_in_container: str = "/var/log/squid/access.log"
|
|
17
|
+
__allowed_domains: list[str] = None
|
|
18
|
+
__image: str = None
|
|
19
|
+
__verbose: bool = None
|
|
20
|
+
__network_name: str = None
|
|
21
|
+
__proxy_container_name: str = None
|
|
22
|
+
__configuration_file: str = None
|
|
23
|
+
__network_was_created: bool = None
|
|
24
|
+
__proxy_container_was_created: bool = None
|
|
25
|
+
|
|
26
|
+
@GeneralUtilities.check_arguments
|
|
27
|
+
def __init__(self, allowed_domains: list[str], image: str, verbose: bool):
|
|
28
|
+
# allowed_domains must already be validated (see SandboxNetworkConfiguration). image is the image-address including tag.
|
|
29
|
+
GeneralUtilities.assert_condition(len(allowed_domains) > 0, "The egress-proxy requires at least one allowed domain.")
|
|
30
|
+
self.__allowed_domains = allowed_domains
|
|
31
|
+
self.__image = image
|
|
32
|
+
self.__verbose = verbose
|
|
33
|
+
# The run-id makes the names unique, so parallel runs do not collide. The prefix "scrais-" makes leftovers of a killed run recognizable.
|
|
34
|
+
run_id = uuid.uuid4().hex[:12]
|
|
35
|
+
self.__network_name = f"scrais-{run_id}"
|
|
36
|
+
self.__proxy_container_name = f"scrais-proxy-{run_id}"
|
|
37
|
+
self.__network_was_created = False
|
|
38
|
+
self.__proxy_container_was_created = False
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
@GeneralUtilities.check_arguments
|
|
42
|
+
def get_squid_configuration(allowed_domains: list[str]) -> str:
|
|
43
|
+
# "dstdomain" uses the same syntax as the allowlist (a leading dot includes the subdomains). "-n" disables reverse-DNS-lookups, so a CONNECT to an
|
|
44
|
+
# IP-address can not match because of its reverse name. Plain HTTP and every port except 443 are denied. Nothing is cached. The access-log is
|
|
45
|
+
# written unbuffered to a file in the container, so the denied requests can be read with "docker exec" (the output of Squid does not reach
|
|
46
|
+
# "docker logs" when the image runs Squid under a service-manager like pebble). The pinger is disabled because it needs the capability NET_RAW,
|
|
47
|
+
# which the proxy-container does not get.
|
|
48
|
+
lines = [
|
|
49
|
+
f"http_port {SandboxEgressProxy.proxy_port}",
|
|
50
|
+
f"acl allowed_domains dstdomain -n {' '.join(allowed_domains)}",
|
|
51
|
+
"acl https_port port 443",
|
|
52
|
+
"http_access deny !CONNECT",
|
|
53
|
+
"http_access deny CONNECT !https_port",
|
|
54
|
+
"http_access allow CONNECT allowed_domains",
|
|
55
|
+
"http_access deny all",
|
|
56
|
+
"cache deny all",
|
|
57
|
+
f"access_log stdio:{SandboxEgressProxy.access_log_file_in_container}",
|
|
58
|
+
"buffered_logs off",
|
|
59
|
+
"pinger_enable off",
|
|
60
|
+
]
|
|
61
|
+
return "\n".join(lines) + "\n"
|
|
62
|
+
|
|
63
|
+
@GeneralUtilities.check_arguments
|
|
64
|
+
def start(self) -> None:
|
|
65
|
+
# stop() must be called afterwards in any case (also if this function fails), because it removes everything which was created until then.
|
|
66
|
+
with tempfile.NamedTemporaryFile("w", suffix=".conf", delete=False, newline="\n", encoding="utf-8") as configuration_file_handle:
|
|
67
|
+
self.__configuration_file = configuration_file_handle.name
|
|
68
|
+
configuration_file_handle.write(SandboxEgressProxy.get_squid_configuration(self.__allowed_domains))
|
|
69
|
+
# The configuration-file must be readable by the (unprivileged) user of squid in the container.
|
|
70
|
+
os.chmod(self.__configuration_file, 0o644)
|
|
71
|
+
self.__run_docker(["network", "create", "--internal", self.__network_name])
|
|
72
|
+
self.__network_was_created = True
|
|
73
|
+
# The container is marked as created before "docker run", because a failing start can leave a created container behind.
|
|
74
|
+
self.__proxy_container_was_created = True
|
|
75
|
+
# Squid runs as an unprivileged user in the image and needs no capability, so the proxy-container gets none.
|
|
76
|
+
self.__run_docker(["run", "--detach", "--name", self.__proxy_container_name, "--network", self.__network_name, "--cap-drop", "all", "--security-opt", "no-new-privileges:true", "--volume", f"{self.__configuration_file.replace(os.sep, '/')}:{SandboxEgressProxy.squid_configuration_file_in_container}:ro", self.__image])
|
|
77
|
+
self.__run_docker(["network", "connect", "bridge", self.__proxy_container_name])
|
|
78
|
+
|
|
79
|
+
@GeneralUtilities.check_arguments
|
|
80
|
+
def get_sandbox_docker_arguments(self) -> list[str]:
|
|
81
|
+
# The proxy is announced in both spellings because tools differ in which one they read. The address is no secret, so the values are passed as arguments.
|
|
82
|
+
# "--dns 127.0.0.1" lets the resolution of external names fail (nothing listens there); the name of the proxy-container is still resolved by the
|
|
83
|
+
# embedded DNS of docker.
|
|
84
|
+
proxy_address = f"http://{self.__proxy_container_name}:{SandboxEgressProxy.proxy_port}"
|
|
85
|
+
result = ["--network", self.__network_name, "--dns", "127.0.0.1"]
|
|
86
|
+
for environment_variable_name in ["HTTPS_PROXY", "HTTP_PROXY", "https_proxy", "http_proxy"]:
|
|
87
|
+
result = result + ["--env", f"{environment_variable_name}={proxy_address}"]
|
|
88
|
+
return result
|
|
89
|
+
|
|
90
|
+
@GeneralUtilities.check_arguments
|
|
91
|
+
def stop(self) -> None:
|
|
92
|
+
# Removes everything which start() created. A failure of the removal does not hide the result of the run; it is reported with the name of the
|
|
93
|
+
# resource, so it can be removed manually.
|
|
94
|
+
if self.__proxy_container_was_created:
|
|
95
|
+
if self.__verbose:
|
|
96
|
+
self.__print_denied_requests()
|
|
97
|
+
self.__remove(["rm", "--force", self.__proxy_container_name], f"proxy-container '{self.__proxy_container_name}'")
|
|
98
|
+
self.__proxy_container_was_created = False
|
|
99
|
+
if self.__network_was_created:
|
|
100
|
+
self.__remove(["network", "rm", self.__network_name], f"network '{self.__network_name}'")
|
|
101
|
+
self.__network_was_created = False
|
|
102
|
+
if self.__configuration_file is not None:
|
|
103
|
+
GeneralUtilities.ensure_file_does_not_exist(self.__configuration_file)
|
|
104
|
+
self.__configuration_file = None
|
|
105
|
+
|
|
106
|
+
@GeneralUtilities.check_arguments
|
|
107
|
+
def __print_denied_requests(self) -> None:
|
|
108
|
+
access_log = subprocess.run(["docker", "exec", self.__proxy_container_name, "cat", SandboxEgressProxy.access_log_file_in_container], capture_output=True, text=True, check=False)
|
|
109
|
+
denied_requests = [line for line in access_log.stdout.splitlines() if "TCP_DENIED" in line]
|
|
110
|
+
if len(denied_requests) == 0:
|
|
111
|
+
GeneralUtilities.write_message_to_stderr("The egress-proxy denied no request.")
|
|
112
|
+
else:
|
|
113
|
+
GeneralUtilities.write_message_to_stderr("The egress-proxy denied the following requests:")
|
|
114
|
+
for denied_request in denied_requests:
|
|
115
|
+
GeneralUtilities.write_message_to_stderr(f" {denied_request}")
|
|
116
|
+
|
|
117
|
+
@GeneralUtilities.check_arguments
|
|
118
|
+
def __remove(self, docker_arguments: list[str], resource_description: str) -> None:
|
|
119
|
+
result = subprocess.run(["docker"] + docker_arguments, capture_output=True, text=True, check=False)
|
|
120
|
+
if result.returncode != 0:
|
|
121
|
+
GeneralUtilities.write_message_to_stderr(f"Warning: The {resource_description} of the sandbox could not be removed and must be removed manually: {result.stderr.strip()}")
|
|
122
|
+
|
|
123
|
+
@GeneralUtilities.check_arguments
|
|
124
|
+
def __run_docker(self, docker_arguments: list[str]) -> None:
|
|
125
|
+
result = subprocess.run(["docker"] + docker_arguments, capture_output=True, text=True, check=False)
|
|
126
|
+
GeneralUtilities.assert_condition(result.returncode == 0, f"\"docker {' '.join(docker_arguments)}\" failed with exit-code {result.returncode}: {result.stderr.strip()}")
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import ipaddress
|
|
2
|
+
import re
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from ..GeneralUtilities import GeneralUtilities
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SandboxNetworkMode(Enum):
|
|
8
|
+
Unrestricted = "unrestricted"
|
|
9
|
+
Allowlist = "allowlist"
|
|
10
|
+
NoNetwork = "none"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SandboxNetworkConfiguration:
|
|
14
|
+
"""The network-access of the agent-sandbox. Without allowlist (allowed_domains is None) the network-access is unrestricted. With an allowlist
|
|
15
|
+
everything except the listed domains is blocked: an allowlist with domains allows only these domains via HTTPS (enforced by an egress-proxy),
|
|
16
|
+
an allowlist without domain blocks the network-access completely.
|
|
17
|
+
An entry without leading dot allows exactly this host, an entry with leading dot allows the domain and all of its subdomains."""
|
|
18
|
+
__label_pattern = re.compile(r"^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$")
|
|
19
|
+
allowed_domains: list[str] = None
|
|
20
|
+
egress_proxy_image: str = None
|
|
21
|
+
|
|
22
|
+
@GeneralUtilities.check_arguments
|
|
23
|
+
def __init__(self, allowed_domains: list[str], egress_proxy_image: str):
|
|
24
|
+
# allowed_domains is None if no allowlist is defined. egress_proxy_image is only required if the allowlist contains at least one domain.
|
|
25
|
+
# Invalid configurations are rejected here, so nothing is started for them.
|
|
26
|
+
if allowed_domains is not None:
|
|
27
|
+
allowed_domains = [allowed_domain.lower() for allowed_domain in allowed_domains]
|
|
28
|
+
for allowed_domain in allowed_domains:
|
|
29
|
+
SandboxNetworkConfiguration.__assert_entry_is_valid(allowed_domain)
|
|
30
|
+
SandboxNetworkConfiguration.__assert_no_entry_is_redundant(allowed_domains)
|
|
31
|
+
self.allowed_domains = allowed_domains
|
|
32
|
+
self.egress_proxy_image = egress_proxy_image
|
|
33
|
+
if self.get_mode() == SandboxNetworkMode.Allowlist:
|
|
34
|
+
GeneralUtilities.assert_condition(egress_proxy_image is not None, "The value 'egress_proxy_image' is required because the allowlist (section 'AllowedDomains' or argument '--alloweddomain') contains at least one domain, but it is neither given as argument nor defined in the configuration-file.")
|
|
35
|
+
|
|
36
|
+
@GeneralUtilities.check_arguments
|
|
37
|
+
def get_mode(self) -> SandboxNetworkMode:
|
|
38
|
+
if self.allowed_domains is None:
|
|
39
|
+
return SandboxNetworkMode.Unrestricted
|
|
40
|
+
if len(self.allowed_domains) == 0:
|
|
41
|
+
return SandboxNetworkMode.NoNetwork
|
|
42
|
+
return SandboxNetworkMode.Allowlist
|
|
43
|
+
|
|
44
|
+
@GeneralUtilities.check_arguments
|
|
45
|
+
def get_description(self) -> str:
|
|
46
|
+
# The description of the restriction which is shown at start. It is None for the unrestricted network-access, so the output stays as before.
|
|
47
|
+
mode = self.get_mode()
|
|
48
|
+
if mode == SandboxNetworkMode.NoNetwork:
|
|
49
|
+
return "The sandbox has no network access."
|
|
50
|
+
if mode == SandboxNetworkMode.Allowlist:
|
|
51
|
+
return f"Network access of the sandbox is restricted to {', '.join(self.allowed_domains)} via HTTPS."
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
@GeneralUtilities.check_arguments
|
|
56
|
+
def __assert_entry_is_valid(entry: str) -> None:
|
|
57
|
+
host = entry.removeprefix(".")
|
|
58
|
+
invalid_entry_message = f"The allowlist-entry '{entry}' is invalid. Expected a hostname like 'example.com' (exactly this host) or '.example.com' (the domain and all of its subdomains) without scheme, port, path or wildcard."
|
|
59
|
+
GeneralUtilities.assert_condition(not SandboxNetworkConfiguration.__is_ip_address(host), f"The allowlist-entry '{entry}' is an IP-address, but only hostnames are allowed.")
|
|
60
|
+
labels = host.split(".")
|
|
61
|
+
GeneralUtilities.assert_condition(len(host) <= 253 and len(labels) >= 2, invalid_entry_message)
|
|
62
|
+
for label in labels:
|
|
63
|
+
GeneralUtilities.assert_condition(SandboxNetworkConfiguration.__label_pattern.match(label) is not None, invalid_entry_message)
|
|
64
|
+
|
|
65
|
+
@staticmethod
|
|
66
|
+
@GeneralUtilities.check_arguments
|
|
67
|
+
def __is_ip_address(host: str) -> bool:
|
|
68
|
+
try:
|
|
69
|
+
ipaddress.ip_address(host.strip("[]"))
|
|
70
|
+
return True
|
|
71
|
+
except ValueError:
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
@GeneralUtilities.check_arguments
|
|
76
|
+
def __assert_no_entry_is_redundant(allowed_domains: list[str]) -> None:
|
|
77
|
+
# A redundant entry is rejected because it shows a misunderstanding of the matching (and the egress-proxy would complain about overlapping entries).
|
|
78
|
+
for index, entry in enumerate(allowed_domains):
|
|
79
|
+
for other_index, other_entry in enumerate(allowed_domains):
|
|
80
|
+
if index == other_index:
|
|
81
|
+
continue
|
|
82
|
+
if entry == other_entry and other_index > index:
|
|
83
|
+
# A duplicate is reported only once (at its second occurrence).
|
|
84
|
+
continue
|
|
85
|
+
if SandboxNetworkConfiguration.__covers(other_entry, entry):
|
|
86
|
+
raise ValueError(f"The allowlist-entry '{entry}' is already covered by the allowlist-entry '{other_entry}'.")
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
@GeneralUtilities.check_arguments
|
|
90
|
+
def __covers(covering_entry: str, covered_entry: str) -> bool:
|
|
91
|
+
# Returns whether everything which is allowed by covered_entry is also allowed by covering_entry.
|
|
92
|
+
if covering_entry.startswith("."):
|
|
93
|
+
covered_host = covered_entry.removeprefix(".")
|
|
94
|
+
return covered_host == covering_entry[1:] or covered_host.endswith(covering_entry)
|
|
95
|
+
return covering_entry == covered_entry
|
|
File without changes
|
ScriptCollection/Executables.py
CHANGED
|
@@ -30,6 +30,8 @@ def RunAgentInSandbox() -> int:
|
|
|
30
30
|
parser.add_argument('-s','--dropcapabilities', default=None, required=False, choices=["true", "false"], help='Defines whether all capabilities should be dropped in the sandbox. Overrides the value from ".ScriptCollection/AgentSandboxConfiguration.ini".')
|
|
31
31
|
parser.add_argument('-a', '--additionalfolder', action='append', default=None, required=False, help='Folder which should additionally be mounted (read-write) into the sandbox under "/Workspace/Other/AdditionalResources/<folder-name>". Can be given multiple times.')
|
|
32
32
|
parser.add_argument('-b','--providebuildenvironment', default=None, required=False, choices=["true", "false"], help='Defines whether the sandbox gets the same build-environment as a build-container of "scbuildcodeunits -c" (required environment-variables, configuration-folder, custom scripts, image-registries, trusted root-CAs and registered package-sources). The agent can then read every secret of the TFCPS-configuration-folder. Overrides the value from ".ScriptCollection/AgentSandboxConfiguration.ini".')
|
|
33
|
+
parser.add_argument('--alloweddomain', action='append', default=None, required=False, help='Domain which the sandbox may reach via HTTPS: "example.com" allows exactly this host, ".example.com" the domain and all of its subdomains. If an allowlist is defined, everything except the allowlist is blocked. Can be given multiple times. If given at least once, it replaces the section "AllowedDomains" of ".ScriptCollection/AgentSandboxConfiguration.ini" completely.')
|
|
34
|
+
parser.add_argument('--egressproxyimage', default=None, required=False, help='Squid-image of the egress-proxy which enforces the allowlist: either an image-name defined in ".ScriptCollection/OCIImages/ImageDefinition.csv" or an image-address including tag. Required if the allowlist contains at least one domain. Overrides the value from ".ScriptCollection/AgentSandboxConfiguration.ini".')
|
|
33
35
|
parser.add_argument('-d','--mountdockersocket', action='store_true', required=False, default=False, help='Mounts the docker-socket of the host (/var/run/docker.sock) into the sandbox so that the agent can use docker. DANGEROUS: this effectively gives the agent administrator-access to the docker-daemon of the host and makes the restrictions of the sandbox ineffective. Can only be set via this argument (not in the configuration-file); a warning is printed to stderr.')
|
|
34
36
|
args = parser.parse_args()
|
|
35
37
|
repo=os.getcwd()
|
|
@@ -44,6 +46,8 @@ def RunAgentInSandbox() -> int:
|
|
|
44
46
|
configuration_overrides.drop_capabilities = args.dropcapabilities == "true"
|
|
45
47
|
if args.providebuildenvironment is not None:
|
|
46
48
|
configuration_overrides.provide_build_environment = args.providebuildenvironment == "true"
|
|
49
|
+
configuration_overrides.allowed_domains = args.alloweddomain
|
|
50
|
+
configuration_overrides.egress_proxy_image = args.egressproxyimage
|
|
47
51
|
additional_folders: list[str] = []
|
|
48
52
|
if args.additionalfolder is not None:
|
|
49
53
|
additional_folders = [GeneralUtilities.resolve_relative_path(additional_folder, os.getcwd()) for additional_folder in args.additionalfolder]
|
|
@@ -1432,3 +1436,18 @@ def ShowTrustedRootCAs() -> int:
|
|
|
1432
1436
|
for entry in entries:
|
|
1433
1437
|
GeneralUtilities.write_message_to_stdout(entry)
|
|
1434
1438
|
return 0
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
def WebpToPng() -> int:
|
|
1442
|
+
parser = argparse.ArgumentParser(description="Converts a webp-file to a png-file. If the webp-file is animated, only the first frame is converted.")
|
|
1443
|
+
parser.add_argument('-i', '--inputfile', required=True, help="Path to the webp-file which should be converted.")
|
|
1444
|
+
parser.add_argument('-o', '--outputfile', required=False, default=None, help="Path to the png-file which should be created. If not specified, the png-file is created in the folder of the input-file with the filename of the input-file and the extension \".png\".")
|
|
1445
|
+
parser.add_argument('-r', '--replace', action='store_true', required=False, default=False, help="Overwrites the output-file if it already exists. Without this flag the conversion fails if the output-file already exists.")
|
|
1446
|
+
args = parser.parse_args()
|
|
1447
|
+
input_file = GeneralUtilities.resolve_relative_path(args.inputfile, os.getcwd())
|
|
1448
|
+
if args.outputfile is None:
|
|
1449
|
+
output_file = os.path.splitext(input_file)[0] + ".png"
|
|
1450
|
+
else:
|
|
1451
|
+
output_file = GeneralUtilities.resolve_relative_path(args.outputfile, os.getcwd())
|
|
1452
|
+
ScriptCollectionCore().convert_webp_to_png(input_file, output_file, args.replace)
|
|
1453
|
+
return 0
|
|
@@ -34,13 +34,14 @@ import qrcode
|
|
|
34
34
|
import pycdlib
|
|
35
35
|
import send2trash
|
|
36
36
|
from pypdf import PdfReader, PdfWriter
|
|
37
|
+
from PIL import Image
|
|
37
38
|
from packaging.version import Version
|
|
38
39
|
from .GeneralUtilities import GeneralUtilities,Platform
|
|
39
40
|
from .ProgramRunnerBase import ProgramRunnerBase
|
|
40
41
|
from .ProgramRunnerPopen import ProgramRunnerPopen
|
|
41
42
|
from .SCLog import SCLog, LogLevel
|
|
42
43
|
|
|
43
|
-
version = "4.4.
|
|
44
|
+
version = "4.4.70"
|
|
44
45
|
__version__ = version
|
|
45
46
|
|
|
46
47
|
class VSCodeWorkspaceShellTask:
|
|
@@ -3649,6 +3650,17 @@ TXDX
|
|
|
3649
3650
|
elif content.endswith(b"\n") or content.endswith(b"\r"):
|
|
3650
3651
|
GeneralUtilities.write_binary_to_file(file, content[:-1])
|
|
3651
3652
|
|
|
3653
|
+
@GeneralUtilities.check_arguments
|
|
3654
|
+
def convert_webp_to_png(self, input_file: str, output_file: str, replace_existing_output_file: bool) -> None:
|
|
3655
|
+
if not os.path.isfile(input_file):
|
|
3656
|
+
raise ValueError(f"File '{input_file}' does not exist.")
|
|
3657
|
+
if os.path.exists(output_file) and not replace_existing_output_file:
|
|
3658
|
+
raise ValueError(f"File '{output_file}' already exists.")
|
|
3659
|
+
with Image.open(input_file) as image:
|
|
3660
|
+
if image.format != "WEBP":
|
|
3661
|
+
raise ValueError(f"File '{input_file}' is not a webp-file.")
|
|
3662
|
+
image.save(output_file, "PNG")
|
|
3663
|
+
|
|
3652
3664
|
@GeneralUtilities.check_arguments
|
|
3653
3665
|
def format_html_content(self, content: str, add_html_declaration: bool = False) -> str:
|
|
3654
3666
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import re
|
|
2
3
|
from urllib import request
|
|
3
4
|
import time
|
|
4
5
|
import ssl
|
|
@@ -101,7 +102,21 @@ class TFCPS_CodeUnitSpecific_Docker_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
101
102
|
|
|
102
103
|
@GeneralUtilities.check_arguments
|
|
103
104
|
def linting(self) -> None:
|
|
104
|
-
|
|
105
|
+
self.__warn_if_dockerfile_has_no_healthcheck()
|
|
106
|
+
|
|
107
|
+
@GeneralUtilities.check_arguments
|
|
108
|
+
def __warn_if_dockerfile_has_no_healthcheck(self) -> None:
|
|
109
|
+
dockerfile = os.path.join(self.get_codeunit_folder(), self.get_codeunit_name(), "Dockerfile")
|
|
110
|
+
if not TFCPS_CodeUnitSpecific_Docker_Functions.dockerfile_contains_healthcheck(GeneralUtilities.read_text_from_file(dockerfile)):
|
|
111
|
+
self._protected_sc.log.log(f'Dockerfile "{dockerfile}" does not contain a HEALTHCHECK-instruction. It is recommended to add one so that the state of a container of this image can be determined.', LogLevel.Warning)
|
|
112
|
+
|
|
113
|
+
@staticmethod
|
|
114
|
+
@GeneralUtilities.check_arguments
|
|
115
|
+
def dockerfile_contains_healthcheck(dockerfile_content: str) -> bool:
|
|
116
|
+
"""Returns whether the Dockerfile-content contains a HEALTHCHECK-instruction which defines a healthcheck.
|
|
117
|
+
Instructions are case-insensitive in a Dockerfile. 'HEALTHCHECK NONE' only disables a healthcheck inherited from the base-image,
|
|
118
|
+
so it does not count as a healthcheck."""
|
|
119
|
+
return re.search(r"^\s*HEALTHCHECK\s+(?!NONE\b)\S", dockerfile_content, re.MULTILINE | re.IGNORECASE) is not None
|
|
105
120
|
|
|
106
121
|
@GeneralUtilities.check_arguments
|
|
107
122
|
def do_common_tasks(self,current_codeunit_version:str )-> None:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import platform
|
|
2
3
|
import glob
|
|
3
4
|
import re
|
|
4
5
|
import shutil
|
|
@@ -52,13 +53,13 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
52
53
|
return result
|
|
53
54
|
|
|
54
55
|
@GeneralUtilities.check_arguments
|
|
55
|
-
def build(self,generate_open_api_spec:bool) -> None:
|
|
56
|
+
def build(self,generate_open_api_spec:bool, enable_windows_targeting_on_linux:bool) -> None:
|
|
56
57
|
runtimes: list[str] = self.get_runtimes()
|
|
57
58
|
if self.is_library:
|
|
58
|
-
self.standardized_tasks_build_for_dotnet_library_project(runtimes)
|
|
59
|
+
self.standardized_tasks_build_for_dotnet_library_project(runtimes, enable_windows_targeting_on_linux)
|
|
59
60
|
GeneralUtilities.assert_condition(not generate_open_api_spec,"OpenAPI-Specification can not be generated for a library.")
|
|
60
61
|
else:
|
|
61
|
-
self.standardized_tasks_build_for_dotnet_project(runtimes)
|
|
62
|
+
self.standardized_tasks_build_for_dotnet_project(runtimes, enable_windows_targeting_on_linux)
|
|
62
63
|
if generate_open_api_spec:
|
|
63
64
|
self.generate_openapi_file(runtimes[0])
|
|
64
65
|
|
|
@@ -164,7 +165,25 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
164
165
|
raise ValueError(f"The project \"{csproj_file}\" is built for the runtime(s) {', '.join(missing)}, but does not state them. Add \"<RuntimeIdentifiers>{';'.join(runtimes)}</RuntimeIdentifiers>\" to the project-file, so that the restore of the codeunit resolves the dependencies of these runtimes.")
|
|
165
166
|
|
|
166
167
|
@GeneralUtilities.check_arguments
|
|
167
|
-
|
|
168
|
+
@staticmethod
|
|
169
|
+
@GeneralUtilities.check_arguments
|
|
170
|
+
def get_windows_targeting_arguments(runtimes: list[str], host_operating_system: str, enable_windows_targeting_on_linux: bool) -> list[str]:
|
|
171
|
+
"""Returns the msbuild-arguments which allow to build the given windows-runtimes on a linux-host.
|
|
172
|
+
|
|
173
|
+
Projects which target windows (for example "net10.0-windows" with windows forms) can not be restored or built on a
|
|
174
|
+
non-windows-host by default (NETSDK1100). Setting EnableWindowsTargeting allows to compile them for windows on linux;
|
|
175
|
+
the result can still only be executed on windows. This is only done when it is explicitly enabled, because otherwise
|
|
176
|
+
the build would silently produce windows-binaries which were never executed on the build-host."""
|
|
177
|
+
if not enable_windows_targeting_on_linux:
|
|
178
|
+
return []
|
|
179
|
+
if host_operating_system != "Linux":
|
|
180
|
+
return []
|
|
181
|
+
if not any(runtime.startswith("win") for runtime in runtimes):
|
|
182
|
+
return []
|
|
183
|
+
return ["-p:EnableWindowsTargeting=true"]
|
|
184
|
+
|
|
185
|
+
@GeneralUtilities.check_arguments
|
|
186
|
+
def __standardized_tasks_build_for_dotnet_build(self, csproj_file: str, originaloutputfolder: str, files_to_sign: dict[str, str], commitid: str, runtimes: list[str], target_environmenttype_mapping: dict[str, str], copy_license_file_to_target_folder: bool, repository_folder: str, codeunit_name: str, enable_windows_targeting_on_linux: bool) -> None:
|
|
168
187
|
self._protected_sc.assert_is_git_repository(repository_folder)
|
|
169
188
|
csproj_filename = os.path.basename(csproj_file)
|
|
170
189
|
self._protected_sc.log.log(f"Build {csproj_filename}...")
|
|
@@ -184,12 +203,16 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
184
203
|
GeneralUtilities.ensure_directory_does_not_exist(os.path.join(csproj_file_folder, "obj"))
|
|
185
204
|
self._protected_sc.run_program("dotnet", "clean", csproj_file_folder)
|
|
186
205
|
self.__ensure_lock_files_exist(codeunit_folder, codeunit_name)
|
|
187
|
-
|
|
206
|
+
host_operating_system: str = platform.system()
|
|
207
|
+
# The restore covers all runtimes, so it needs the windows-targeting as soon as one of them is a windows-runtime.
|
|
208
|
+
restore_windows_targeting_arguments: list[str] = TFCPS_CodeUnitSpecific_DotNet_Functions.get_windows_targeting_arguments(runtimes, host_operating_system, enable_windows_targeting_on_linux)
|
|
209
|
+
self._protected_sc.run_program_argsasarray("dotnet", ["restore", "--locked-mode"]+restore_windows_targeting_arguments, codeunit_folder,print_live_output=self.get_verbosity()==LogLevel.Debug)
|
|
188
210
|
for runtime in runtimes:
|
|
189
211
|
outputfolder = originaloutputfolder+runtime
|
|
190
212
|
GeneralUtilities.ensure_directory_does_not_exist(outputfolder)
|
|
191
213
|
GeneralUtilities.ensure_directory_exists(outputfolder)
|
|
192
|
-
|
|
214
|
+
build_windows_targeting_arguments: list[str] = TFCPS_CodeUnitSpecific_DotNet_Functions.get_windows_targeting_arguments([runtime], host_operating_system, enable_windows_targeting_on_linux)
|
|
215
|
+
self._protected_sc.run_program_argsasarray("dotnet", ["build", "--no-restore", csproj_file_name, "-c", dotnet_build_configuration, "-o", outputfolder, "--runtime", runtime]+build_windows_targeting_arguments, csproj_file_folder,print_live_output=self.get_verbosity()==LogLevel.Debug)
|
|
193
216
|
if copy_license_file_to_target_folder:
|
|
194
217
|
license_file = os.path.join(repository_folder, "License.txt")
|
|
195
218
|
target = os.path.join(outputfolder, f"{codeunit_name}.License.txt")
|
|
@@ -231,12 +254,12 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
231
254
|
self._protected_sc.log.log(f"The lock-file \"{lock_file}\" does not exist, so the build-result of \"{csproj_file_name_without_extension}\" does not contain the versions which were used.", LogLevel.Warning)
|
|
232
255
|
|
|
233
256
|
@GeneralUtilities.check_arguments
|
|
234
|
-
def standardized_tasks_build_for_dotnet_project(self,runtimes:list[str]) -> None:
|
|
235
|
-
self.__standardized_tasks_build_for_dotnet_project(runtimes)
|
|
257
|
+
def standardized_tasks_build_for_dotnet_project(self,runtimes:list[str], enable_windows_targeting_on_linux:bool) -> None:
|
|
258
|
+
self.__standardized_tasks_build_for_dotnet_project(runtimes, enable_windows_targeting_on_linux)
|
|
236
259
|
|
|
237
260
|
@GeneralUtilities.check_arguments
|
|
238
|
-
def standardized_tasks_build_for_dotnet_library_project(self,runtimes:list[str]) -> None:
|
|
239
|
-
self.__standardized_tasks_build_for_dotnet_project(runtimes)
|
|
261
|
+
def standardized_tasks_build_for_dotnet_library_project(self,runtimes:list[str], enable_windows_targeting_on_linux:bool) -> None:
|
|
262
|
+
self.__standardized_tasks_build_for_dotnet_project(runtimes, enable_windows_targeting_on_linux)
|
|
240
263
|
self.__standardized_tasks_build_nupkg_for_dotnet_create_package(runtimes)
|
|
241
264
|
|
|
242
265
|
|
|
@@ -255,7 +278,7 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
255
278
|
return result
|
|
256
279
|
|
|
257
280
|
@GeneralUtilities.check_arguments
|
|
258
|
-
def __standardized_tasks_build_for_dotnet_project(self,runtimes:list[str]) -> None:
|
|
281
|
+
def __standardized_tasks_build_for_dotnet_project(self,runtimes:list[str], enable_windows_targeting_on_linux:bool) -> None:
|
|
259
282
|
target_environment_type: str=self.get_target_environment_type()
|
|
260
283
|
copy_license_file_to_target_folder: bool=True
|
|
261
284
|
codeunitname: str = self.get_codeunit_name()
|
|
@@ -270,8 +293,8 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
270
293
|
codeunit_folder = os.path.join(repository_folder, codeunitname)
|
|
271
294
|
csproj_file = os.path.join(codeunit_folder, codeunitname, codeunitname + ".csproj")
|
|
272
295
|
csproj_test_file = os.path.join(codeunit_folder, codeunitname+"Tests", codeunitname+"Tests.csproj")
|
|
273
|
-
self.__standardized_tasks_build_for_dotnet_build(csproj_file, os.path.join(outputfolder, "BuildResult_DotNet_"), files_to_sign, commitid, runtimes, target_environment_type, copy_license_file_to_target_folder, repository_folder, codeunitname)
|
|
274
|
-
self.__standardized_tasks_build_for_dotnet_build(csproj_test_file, os.path.join(outputfolder, "BuildResultTests_DotNet_"), files_to_sign, commitid, runtimes, target_environment_type, copy_license_file_to_target_folder, repository_folder, codeunitname)
|
|
296
|
+
self.__standardized_tasks_build_for_dotnet_build(csproj_file, os.path.join(outputfolder, "BuildResult_DotNet_"), files_to_sign, commitid, runtimes, target_environment_type, copy_license_file_to_target_folder, repository_folder, codeunitname, enable_windows_targeting_on_linux)
|
|
297
|
+
self.__standardized_tasks_build_for_dotnet_build(csproj_test_file, os.path.join(outputfolder, "BuildResultTests_DotNet_"), files_to_sign, commitid, runtimes, target_environment_type, copy_license_file_to_target_folder, repository_folder, codeunitname, enable_windows_targeting_on_linux)
|
|
275
298
|
self.generate_sbom_for_dotnet_project(codeunit_folder)
|
|
276
299
|
self.copy_source_files_to_output_directory()
|
|
277
300
|
|
|
@@ -202,7 +202,7 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
202
202
|
|
|
203
203
|
if not self.__fast_lane:
|
|
204
204
|
self.__do_project_linting(self.repository)
|
|
205
|
-
self.
|
|
205
|
+
self.__update_agent_images(self.repository)
|
|
206
206
|
self.search_for_secrets()
|
|
207
207
|
self.__normalize_line_endings_of_common_files()
|
|
208
208
|
|
|
@@ -242,25 +242,31 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
242
242
|
|
|
243
243
|
|
|
244
244
|
@GeneralUtilities.check_arguments
|
|
245
|
-
def
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
245
|
+
def __update_agent_images(self, repository_folder: str) -> None:
|
|
246
|
+
# The image of the sandbox and the image of its egress-proxy (which enforces the allowlist of the sandbox) follow the image-definition-file.
|
|
247
|
+
self.__update_agent_sandbox_image(repository_folder, "SCBuilder", "image")
|
|
248
|
+
self.__update_agent_sandbox_image(repository_folder, "Squid", "egress_proxy_image")
|
|
249
|
+
|
|
250
|
+
@GeneralUtilities.check_arguments
|
|
251
|
+
def __update_agent_sandbox_image(self, repository_folder: str, image: str, key: str) -> None:
|
|
252
|
+
"""Sets the value of the given key in "<repository>/.ScriptCollection/AgentSandboxConfiguration.ini" to the given image (address including tag)
|
|
253
|
+
as defined in "<repository>/.ScriptCollection/OCIImages/ImageDefinition.csv".
|
|
254
|
+
Nothing is done if one of these files does not exist or if the image-definition-file does not contain an entry for the image."""
|
|
249
255
|
image_definition_file = os.path.join(repository_folder, ".ScriptCollection", "OCIImages", "ImageDefinition.csv")
|
|
250
256
|
agent_sandbox_configuration_file = os.path.join(repository_folder, ".ScriptCollection", "AgentSandboxConfiguration.ini")
|
|
251
257
|
if not os.path.isfile(image_definition_file) or not os.path.isfile(agent_sandbox_configuration_file):
|
|
252
258
|
return
|
|
253
|
-
|
|
259
|
+
image_value: str = None
|
|
254
260
|
for line in GeneralUtilities.read_nonempty_lines_from_file(image_definition_file):
|
|
255
|
-
if line.startswith("
|
|
261
|
+
if line.startswith(f"{image};"):
|
|
256
262
|
columns = line.split(";")
|
|
257
|
-
|
|
263
|
+
image_value = f"{columns[1]}:{columns[2]}"
|
|
258
264
|
break
|
|
259
|
-
if
|
|
265
|
+
if image_value is None:
|
|
260
266
|
return
|
|
261
|
-
self.sc.log.log(f"Set
|
|
267
|
+
self.sc.log.log(f"Set '{key}' of agent-sandbox to '{image_value}'...", LogLevel.Debug)
|
|
262
268
|
section_header = "[AgentSandboxConfiguration]"
|
|
263
|
-
image_line = f"
|
|
269
|
+
image_line = f"{key} = {image_value}"
|
|
264
270
|
lines: list[str] = GeneralUtilities.read_lines_from_file(agent_sandbox_configuration_file)
|
|
265
271
|
updated_lines: list[str] = []
|
|
266
272
|
current_section: str = None
|
|
@@ -269,7 +275,7 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
269
275
|
stripped_line = line.strip()
|
|
270
276
|
if stripped_line.startswith("[") and stripped_line.endswith("]"):
|
|
271
277
|
current_section = stripped_line
|
|
272
|
-
elif current_section == section_header and re.match(
|
|
278
|
+
elif current_section == section_header and re.match(rf"^{re.escape(key)}\s*=", stripped_line):
|
|
273
279
|
line = image_line
|
|
274
280
|
image_was_set = True
|
|
275
281
|
updated_lines.append(line)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scriptcollection
|
|
3
|
-
Version: 4.4.
|
|
3
|
+
Version: 4.4.70
|
|
4
4
|
Summary: The ScriptCollection is the place for reusable scripts.
|
|
5
5
|
Author-email: Marius Göcke <marius.goecke@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
@@ -36,7 +36,7 @@ Requires-Dist: psutil>=7.2.2
|
|
|
36
36
|
Requires-Dist: pycdlib>=1.22.0
|
|
37
37
|
Requires-Dist: Pygments>=2.21.0
|
|
38
38
|
Requires-Dist: pylint>=4.1.3
|
|
39
|
-
Requires-Dist: pyOpenSSL>=
|
|
39
|
+
Requires-Dist: pyOpenSSL>=26.4.0
|
|
40
40
|
Requires-Dist: PyPDF>=6.21.1
|
|
41
41
|
Requires-Dist: pytest>=8.4.2
|
|
42
42
|
Requires-Dist: PyYAML>=6.0.3
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
ScriptCollection/AgentRunner.py,sha256=
|
|
1
|
+
ScriptCollection/AgentRunner.py,sha256=v3wRllPSjeIuIK6uhCfQLRdAm0Kpq-DOs7VVWUEIU2s,29866
|
|
2
2
|
ScriptCollection/ArbTranslationsOrganizer.py,sha256=3TO4fjkYADcHGyUXdiQk-RtfCxtf9ojuBS3CbZtgXBE,12218
|
|
3
3
|
ScriptCollection/CertificateUpdater.py,sha256=yZc7KESc1F_Mc6HP2UfLmNHRc2MvtVqp0t60J_CqY3s,9755
|
|
4
|
-
ScriptCollection/Executables.py,sha256=
|
|
4
|
+
ScriptCollection/Executables.py,sha256=HSj3Eo3Ro8pbdTcvWnCSKq_JlpIbX-7Fyt5TbsNpEOQ,86102
|
|
5
5
|
ScriptCollection/GeneralUtilities.py,sha256=kW6y52rdD-dJrjCtIgsdwYinz6FtclGj-xc_4tL1MUg,80022
|
|
6
6
|
ScriptCollection/HTTPMaintenanceOverheadHelper.py,sha256=TToNtyO1XzsMbBsTBf3o0xgOK0v4Jf03qw2Z0xb2nCk,2007
|
|
7
7
|
ScriptCollection/ProcessesRunner.py,sha256=wtNFdmj9klETTIDUSE90vaR5ClEX4V7dgJNVbp9_wi0,1381
|
|
@@ -12,10 +12,13 @@ ScriptCollection/ProgramRunnerSudo.py,sha256=vwKq-MOcqsgiKhSf-MBUDBC_UyaU8evP3Ro
|
|
|
12
12
|
ScriptCollection/RepositoryDiagramGenerator.py,sha256=K_u2NW_p4ozdWD50irJEkkcDVa70TcUJpZN63TeXSLw,7092
|
|
13
13
|
ScriptCollection/RepositoryHistoryAnalyzer.py,sha256=u9141B9D-Kef-9uo3yR7BXKUMzIKLVsesnYk7H-cWm4,6157
|
|
14
14
|
ScriptCollection/SCLog.py,sha256=Fjf8Pdi63cXHGMxL_aI6A0dwGm7QIfrv3czjvpSUlaM,4705
|
|
15
|
-
ScriptCollection/ScriptCollectionCore.py,sha256=
|
|
15
|
+
ScriptCollection/ScriptCollectionCore.py,sha256=TGrqGY-6FePu8d8ZY4zovOd_gVK24oP5uCqM4Httqh8,311272
|
|
16
16
|
ScriptCollection/TestKind.py,sha256=jqLJwNvQeyea7SZf-UFzMC9pM0znv4do7FIC1xq8u9M,1672
|
|
17
17
|
ScriptCollection/UnassignedVariablesCheck.py,sha256=8xNcp1D5HeOLO1a1NEerq2TsnpFhw7yzYPkaay-oisY,3804
|
|
18
18
|
ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
ScriptCollection/AgentSandboxNetwork/SandboxEgressProxy.py,sha256=taHYkvKCjUteJisZOYNY283m_DAs0odl-WmewlobwGQ,8385
|
|
20
|
+
ScriptCollection/AgentSandboxNetwork/SandboxNetworkConfiguration.py,sha256=OQFUbalueSt0XGq5sUjJLmmxb7VYi4JMk9vzl0GPB4A,5377
|
|
21
|
+
ScriptCollection/AgentSandboxNetwork/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
22
|
ScriptCollection/AgentStatusReporting/AgentStatus.py,sha256=eKz2RN1XEhPjaLxALmvtV-k2094RUTMEXT7HFKsSImg,563
|
|
20
23
|
ScriptCollection/AgentStatusReporting/AgentStatusEventChannel.py,sha256=LnAi5qA2NjRwcDEg8ALsOeHspO_CPcEs8A4GiaFd0bY,1732
|
|
21
24
|
ScriptCollection/AgentStatusReporting/AgentStatusRelay.py,sha256=JtfM5OQVnojUdGdiRipSZKePIk-A5L1SPxIMET1XYWM,3639
|
|
@@ -48,7 +51,7 @@ ScriptCollection/TFCPS/TFCPS_BuildCodeUnitsHook.py,sha256=67_DQwoH5bhxxSmwtuAeoW
|
|
|
48
51
|
ScriptCollection/TFCPS/TFCPS_CodeSpellCheck.py,sha256=zV62O7UiGjewx1yQUIWmUJ9D-5ipkV_f28uNhp-JWUs,5306
|
|
49
52
|
ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py,sha256=Rh7S84B8QbeWn5qJxRItoI7jquJYvFnNRi_WiX3FjWo,40414
|
|
50
53
|
ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py,sha256=CB0K8OZNtQESdS2pqX9RQqN-lI5M-cbmXYOR0rbuRlk,9741
|
|
51
|
-
ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=
|
|
54
|
+
ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=mMBCIUxocQjpGLwEs_Jdzr_zpxSqtzs_Gh3GcinaF0s,60412
|
|
52
55
|
ScriptCollection/TFCPS/TFCPS_CreateRelease.py,sha256=BVK3fpEyjcXYVHIb6YYLH7bWe6iKRaCtPrJ3tXAemYw,6582
|
|
53
56
|
ScriptCollection/TFCPS/TFCPS_FindingsSorter.py,sha256=3ChuKf-Myr3sBtQhYGw6dHlk93HO6PAH-Jq1oPYdW1s,4804
|
|
54
57
|
ScriptCollection/TFCPS/TFCPS_Generic.py,sha256=mRBcf7XuNWOSXbZYc3NuJow18AMZ30D6Z-BtyNYfNcM,2072
|
|
@@ -62,13 +65,13 @@ ScriptCollection/TFCPS/TFCPS_VisualRegressionTests.py,sha256=F90CF5kLCgV_M3yN696
|
|
|
62
65
|
ScriptCollection/TFCPS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
63
66
|
ScriptCollection/TFCPS/CPP/TFCPS_CodeUnitSpecific_CPP.py,sha256=BNZPMjGiWLMBH7QDtP06WEVLMnI38NLX4Dpd13bSbi4,16614
|
|
64
67
|
ScriptCollection/TFCPS/CPP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
65
|
-
ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py,sha256=
|
|
68
|
+
ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py,sha256=uNqZVKYLv5kZWxZNKvyyrSKja8LSlKaRBXjSmhl0-i0,23512
|
|
66
69
|
ScriptCollection/TFCPS/Docker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
67
70
|
ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationBase.py,sha256=bT6Gd5pQpZCw4OQz6HWkPCSn5z__eUUEisABLDSxd0o,200
|
|
68
71
|
ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py,sha256=QyjOfMY22JWCvKjMelHiDWbJiWqotOfebpJpgDUaoO4,237
|
|
69
72
|
ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationNoGenerate.py,sha256=i0zEGehj0sttxjjZtoq2KFSKp_ulxVyWp_ZgAhIY_So,241
|
|
70
73
|
ScriptCollection/TFCPS/DotNet/NuGetPackageSourceRegistration.py,sha256=E2TiFbwyPZvhozoWqLksc4uH50LbFAaVWOGfUo6for4,7050
|
|
71
|
-
ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py,sha256=
|
|
74
|
+
ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py,sha256=WlWfgfWKwU1PS58BgxQoFFr4_3R3YyYdhsCJYiV-kiM,67192
|
|
72
75
|
ScriptCollection/TFCPS/DotNet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
73
76
|
ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py,sha256=9PMxJFB4nyKGzl916UOCvHB5toIyLcWk-ZAM8vPdLxw,64571
|
|
74
77
|
ScriptCollection/TFCPS/Flutter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -84,8 +87,8 @@ ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=yyjWPMHQjPLkML
|
|
|
84
87
|
ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
85
88
|
ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py,sha256=ILVhJHvwG5TvPBBqSvyACYb7W9QnWrJpxKgHu8IQu4g,9249
|
|
86
89
|
ScriptCollection/TFCPS/TypeScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
87
|
-
scriptcollection-4.4.
|
|
88
|
-
scriptcollection-4.4.
|
|
89
|
-
scriptcollection-4.4.
|
|
90
|
-
scriptcollection-4.4.
|
|
91
|
-
scriptcollection-4.4.
|
|
90
|
+
scriptcollection-4.4.70.dist-info/METADATA,sha256=f2TidWG9qvOSpYEZOtREuj5AfEkZXG_hHBZqmPzEIB8,8032
|
|
91
|
+
scriptcollection-4.4.70.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
92
|
+
scriptcollection-4.4.70.dist-info/entry_points.txt,sha256=itrRUdhNeGltyisLNqXVjWadCqzemZy9MGFcoMf53CE,6385
|
|
93
|
+
scriptcollection-4.4.70.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
|
|
94
|
+
scriptcollection-4.4.70.dist-info/RECORD,,
|
|
@@ -86,3 +86,4 @@ scupdatedependenciesc = ScriptCollection.Executables:UpdateDependenciesC
|
|
|
86
86
|
scupdateimagesindockercomposefile = ScriptCollection.Executables:UpdateImagesInDockerComposeFile
|
|
87
87
|
scupdatelockfiles = ScriptCollection.Executables:UpdateLockFilesOfDotNetCodeUnits
|
|
88
88
|
scupdatetimestampinfile = ScriptCollection.Executables:UpdateTimestampInFile
|
|
89
|
+
scwebp2png = ScriptCollection.Executables:WebpToPng
|
|
File without changes
|
|
File without changes
|