Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying Firewall rules to provide Internet Access to T0/T1 #2327

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from

Conversation

cptanalatriste
Copy link
Contributor

@cptanalatriste cptanalatriste commented Dec 3, 2024

✅ Checklist

  • You have given your pull request a meaningful title (e.g. Enable foobar integration rather than 515 foobar).
  • You are targeting the appropriate branch. If you're not certain which one this is, it should be develop.
  • Your branch is up-to-date with the target branch (it probably was when you started, but it may have changed since then).

🚦 Depends on

⤴️ Summary

The proposed approach adds an extra field to the SRE config file (allow_workspace_internet ) and based on its value does the following: 1) If false , business as usual, 2) if true , we remove all the firewall's application rules, we add a network rule allowing connections to the internet, and remove user_rules DNS server configuration.

(@JimMadge After my changes)

  • allow_workspace_internet configuration value in the sre section (default false)
  • When allowed, compared to the default rules,
    • A network rule is added to allow outbound internet access from workspaces
    • The application rules to allow specific outbound access (snap, apt) are removed
  • Add new variable to templates and documentation
  • Add warnings about possible data leakage when allow_workspace_internet is true.

🌂 Related issues

Closes #2283

🔬 Tests

(@JimMadge After my changes)

Outbound internet access from workspace when allow_workspace_internet is true

Screenshot 2025-01-10 at 14 40 17

No outbound internet access from workspace when allow_workspace_internet is false

@cptanalatriste cptanalatriste requested a review from a team as a code owner December 3, 2024 09:09
@jemrobinson jemrobinson marked this pull request as draft December 3, 2024 09:12
Copy link
Contributor

@craddm craddm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can deploy an SRE, but can't actually connect to anything. At the moment, literally only traffic from workspaces is allowed. None of the container services can connect to the internet, so a user can't get to the remote desktop gateway, for example I misdescribed that a bit. Guacamole can't talk to the microsoft Auth servers over the internet, so it can't properly log you in.

@craddm
Copy link
Contributor

craddm commented Dec 11, 2024

Have tested a fresh deployment with internet access enabled, and can confirm it works!

Copy link

github-actions bot commented Dec 11, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  data_safe_haven/commands
  sre.py 57-65
  data_safe_haven/config
  config_sections.py
  sre_config.py
  data_safe_haven/infrastructure/common
  transformations.py
  data_safe_haven/infrastructure/components/wrapped
  log_analytics_workspace.py
  data_safe_haven/infrastructure/programs/sre
  dns_server.py 39
  firewall.py
  monitoring.py
Project Total  

This report was generated by python-coverage-comment-action

@cptanalatriste cptanalatriste marked this pull request as ready for review December 11, 2024 17:28
@cptanalatriste cptanalatriste changed the title [WIP] Modifying Firewall rules to provide Internet Access to T0/T1 Modifying Firewall rules to provide Internet Access to T0/T1 Dec 11, 2024
@JimMadge JimMadge requested review from craddm and jemrobinson January 7, 2025 10:59
.github/workflows/lint_code.yaml Outdated Show resolved Hide resolved
tests/mustache/AdGuardHome.mustache.config.json Outdated Show resolved Hide resolved
data_safe_haven/infrastructure/programs/sre/dns_server.py Outdated Show resolved Hide resolved
data_safe_haven/infrastructure/programs/sre/firewall.py Outdated Show resolved Hide resolved
data_safe_haven/infrastructure/programs/sre/firewall.py Outdated Show resolved Hide resolved
data_safe_haven/infrastructure/programs/sre/firewall.py Outdated Show resolved Hide resolved
tests/infrastructure/programs/sre/test_firewall.py Outdated Show resolved Hide resolved
@JimMadge
Copy link
Member

JimMadge commented Jan 7, 2025

I don't think I like adding TODO comments to code in a PR. I think they are too easy to miss and sidestep the issue/PR process. I think the two options are,

  1. fix it now
  2. open and issue

What does everyone else think?

data_safe_haven/infrastructure/programs/sre/dns_server.py Outdated Show resolved Hide resolved
data_safe_haven/infrastructure/programs/sre/firewall.py Outdated Show resolved Hide resolved
data_safe_haven/infrastructure/programs/sre/firewall.py Outdated Show resolved Hide resolved
data_safe_haven/infrastructure/programs/sre/firewall.py Outdated Show resolved Hide resolved
data_safe_haven/infrastructure/programs/sre/firewall.py Outdated Show resolved Hide resolved
tests/infrastructure/programs/sre/test_firewall.py Outdated Show resolved Hide resolved
tests/mustache/AdGuardHome.mustache.config.json Outdated Show resolved Hide resolved
@JimMadge JimMadge self-assigned this Jan 7, 2025
@JimMadge JimMadge force-pushed the 2283-internet-access-tier0-tier1 branch from 94a5682 to a7f9275 Compare January 9, 2025 15:07
@JimMadge JimMadge requested a review from a team as a code owner January 9, 2025 15:47
Copy link
Member

@jemrobinson jemrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks broadly OK but I have some suggested changes.

filename="${filename%.*}"
test_config=".github/resources/$filename.config.json"

if [ -e "$test_config" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to do this for all mustache files we want to expand? It's nicer than the hack of replacing all the mustache markers with array or variable that's used in the other if branch?

network.AzureFirewallApplicationRuleCollectionArgs(
action=network.AzureFirewallRCActionArgs(
type=network.AzureFirewallRCActionType.ALLOW
application_rule_collections_common = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we confirm that these rules are identical to the previous rules except where deliberately changed? This sounds difficult. One way to convince ourselves could be to make a separate PR from develop that just makes the change of putting the rules into the application_rule_collections_common list without changing the rules themselves. It would then be easier to see what changes are being made here.


if props.allow_workspace_internet:
application_rule_collections = application_rule_collections_common
network_rule_collections = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining why this needs to be a network rule not an application rule? I think possibly because application rules only apply to HTTP(S) but maybe I'm wrong.

Comment on lines +14 to +24
{{#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}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this logic be better as:

user_rules:
  # https://github.com/AdguardTeam/AdGuardHome/wiki/Hosts-Blocklists#adblock-style-syntax
  {{#filter_block}}
  - "{{.}}"
  {{/filter_block}}
  {{#filter_allow}}
  - "@@||{{.}}"
  {{/filter_allow}}

with the default being: filter_block = ["*.*"], filter_allow = ["some", "urls", "here"] and the allow-all being filter_block = [], filter_allow = ["*.*"]? I'm not totally sure whether this would work - thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we generate the @@|| prefixes in the calling script and just have

user_rules:
  # https://github.com/AdguardTeam/AdGuardHome/wiki/Hosts-Blocklists#adblock-style-syntax
  {{#filters}}
  - "{{.}}"
  {{/filters}}

which might be the simplest/cleanest of all.

Comment on lines +8 to +12
# Mock configuration.


class DataSafeHavenMocks(pulumi.runtime.Mocks):
def new_resource(self, args: pulumi.runtime.MockResourceArgs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Mock configuration.
class DataSafeHavenMocks(pulumi.runtime.Mocks):
def new_resource(self, args: pulumi.runtime.MockResourceArgs):
class DataSafeHavenMocks(pulumi.runtime.Mocks):
"""Configuration for Pulumi mocks"""
def new_resource(self, args: pulumi.runtime.MockResourceArgs):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Active support for T0/T1
4 participants