ScriptCollection 4.4.68__py3-none-any.whl → 4.4.69__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.
@@ -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
@@ -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]
@@ -40,7 +40,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
40
40
  from .ProgramRunnerPopen import ProgramRunnerPopen
41
41
  from .SCLog import SCLog, LogLevel
42
42
 
43
- version = "4.4.68"
43
+ version = "4.4.69"
44
44
  __version__ = version
45
45
 
46
46
  class VSCodeWorkspaceShellTask:
@@ -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.__update_agent_sandbox_image(self.repository)
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 __update_agent_sandbox_image(self, repository_folder: str) -> None:
246
- """Sets the value "image" in "<repository>/.ScriptCollection/AgentSandboxConfiguration.ini" to the SCBuilder-image (address including tag)
247
- defined in "<repository>/.ScriptCollection/OCIImages/ImageDefinition.csv".
248
- Nothing is done if one of these files does not exist or if the image-definition-file does not contain an entry for SCBuilder."""
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
- scbuilder_image: str = None
259
+ image_value: str = None
254
260
  for line in GeneralUtilities.read_nonempty_lines_from_file(image_definition_file):
255
- if line.startswith("SCBuilder;"):
261
+ if line.startswith(f"{image};"):
256
262
  columns = line.split(";")
257
- scbuilder_image = f"{columns[1]}:{columns[2]}"
263
+ image_value = f"{columns[1]}:{columns[2]}"
258
264
  break
259
- if scbuilder_image is None:
265
+ if image_value is None:
260
266
  return
261
- self.sc.log.log(f"Set image of agent-sandbox to '{scbuilder_image}'...", LogLevel.Debug)
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"image = {scbuilder_image}"
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(r"^image\s*=", stripped_line):
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.68
3
+ Version: 4.4.69
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
@@ -1,7 +1,7 @@
1
- ScriptCollection/AgentRunner.py,sha256=m6uYei6dCqrIGPN6YQvtrqFWFxWDqSQi3DtH82f79Zg,26181
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=JWxzWKpLqZM0oJBhq_LP8cnLxNN9l4APqAROrTOeS_w,83902
4
+ ScriptCollection/Executables.py,sha256=N_tAJcDRS2rniRXYFZPWQs7ar_g8HkaR0EddAJ7CZiw,84901
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=jIBrMaE0DI8HU6kk8LYg1mY4jPMUPtoFw-SLUYQ3lvg,310633
15
+ ScriptCollection/ScriptCollectionCore.py,sha256=C4S0Kk1T3asMF4zlKPNTnGm5QZYBO1LdiO9QalUzOmE,310633
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=ECnHGnhqdYpOj-2mmGrSrqMQe1JZw2lr0M_Ui-ACBMA,59956
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
@@ -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.68.dist-info/METADATA,sha256=y_9VqqKqcCh3owvuuFyOoOxE9hi84h3bKbipoZKoyC8,8032
88
- scriptcollection-4.4.68.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
89
- scriptcollection-4.4.68.dist-info/entry_points.txt,sha256=ukXPbwM_VSzeSUOLRwWwq4aVAsfFKSzOjQnPkcJH59w,6333
90
- scriptcollection-4.4.68.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
91
- scriptcollection-4.4.68.dist-info/RECORD,,
90
+ scriptcollection-4.4.69.dist-info/METADATA,sha256=fqKQHSsZZgSjWeFgvRP3DTWtmqpCvRr-hHmCjdaRhQo,8032
91
+ scriptcollection-4.4.69.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
92
+ scriptcollection-4.4.69.dist-info/entry_points.txt,sha256=ukXPbwM_VSzeSUOLRwWwq4aVAsfFKSzOjQnPkcJH59w,6333
93
+ scriptcollection-4.4.69.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
94
+ scriptcollection-4.4.69.dist-info/RECORD,,