Skip to content

Commit

Permalink
Fixing tests, and relaxing DNS rules when internet is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
cptanalatriste committed Dec 10, 2024
1 parent d1e4f23 commit 6a0c4d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions data_safe_haven/infrastructure/programs/declarative_sre.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def __call__(self) -> None:
"sre_dns_server",
self.stack_name,
SREDnsServerProps(
allow_workspace_internet=self.config.sre.allow_workspace_internet,
dockerhub_credentials=dockerhub_credentials,
location=self.config.azure.location,
resource_group_name=resource_group.name,
Expand Down
10 changes: 8 additions & 2 deletions data_safe_haven/infrastructure/programs/sre/dns_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ class SREDnsServerProps:

def __init__(
self,
*,
allow_workspace_internet: bool,
dockerhub_credentials: DockerHubCredentials,
location: Input[str],
resource_group_name: Input[str],
shm_fqdn: Input[str],
) -> None:
self.admin_username = "dshadmin"
self.allow_workspace_internet: bool = allow_workspace_internet
self.dockerhub_credentials = dockerhub_credentials
self.location = location
self.resource_group_name = resource_group_name
Expand Down Expand Up @@ -69,6 +72,9 @@ def __init__(
)

# Expand AdGuardHome YAML configuration
mustache_values: dict[str, object] = {
"allow_workspace_internet": props.allow_workspace_internet
}
adguard_adguardhome_yaml_contents = Output.all(
admin_username=props.admin_username,
# Only the first 72 bytes of the generated random string will be used but a
Expand All @@ -85,8 +91,8 @@ def __init__(
]
),
).apply(
lambda mustache_values: adguard_adguardhome_yaml_reader.file_contents(
mustache_values
lambda mustache_config: adguard_adguardhome_yaml_reader.file_contents(
mustache_config | mustache_values
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ dns:
querylog:
enabled: true
filters:
{{#allow_workspace_internet}}
user_rules: []
{{/allow_workspace_internet}}
{{^allow_workspace_internet}}
user_rules:
# https://github.com/AdguardTeam/AdGuardHome/wiki/Hosts-Blocklists#adblock-style-syntax
- "*.*"
{{#filter_allow}}
- "@@||{{.}}"
{{/filter_allow}}
{{/allow_workspace_internet}}
log:
verbose: true
# Note that because we are only providing a partial config file we need the
Expand Down
8 changes: 8 additions & 0 deletions tests/infrastructure/programs/sre/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,11 @@ def subnet_workspaces() -> network.GetSubnetResult:
address_prefix=SREIpRanges.workspaces.prefix,
id="subnet_workspaces_id",
)


@fixture
def subnet_monitoring() -> network.GetSubnetResult:
return network.GetSubnetResult(
address_prefix=SREIpRanges.monitoring.prefix,
id="subnet_monitoring_id",
)

0 comments on commit 6a0c4d7

Please sign in to comment.