|
11 | 11 | inherit (lib) mkIf optionalString;
|
12 | 12 | #TODO: Move this to a common place
|
13 | 13 | name = "business";
|
| 14 | + proxyUserName = "proxy-user"; |
| 15 | + proxyGroupName = "proxy-admin"; |
14 | 16 | tiiVpnAddr = "151.253.154.18";
|
15 |
| - vpnOnlyAddr = "${tiiVpnAddr},jira.tii.ae,access.tii.ae,confluence.tii.ae,i-service.tii.ae,catalyst.atrc.ae"; |
| 17 | + pacFileName = "ghaf.pac"; |
| 18 | + pacServerAddr = "127.0.0.1:8000"; |
| 19 | + pacFileUrl = "http://${pacServerAddr}/${pacFileName}"; |
16 | 20 | netvmEntry = builtins.filter (x: x.name == "net-vm") config.ghaf.networking.hosts.entries;
|
17 | 21 | netvmAddress = lib.head (builtins.map (x: x.ip) netvmEntry);
|
18 |
| - adminvmEntry = builtins.filter (x: x.name == "admin-vm") config.ghaf.networking.hosts.entries; |
19 |
| - adminvmAddress = lib.head (builtins.map (x: x.ip) adminvmEntry); |
20 | 22 | # Remove rounded corners from the text editor window
|
21 | 23 | gnomeTextEditor = pkgs.gnome-text-editor.overrideAttrs (oldAttrs: {
|
22 | 24 | postPatch =
|
|
25 | 27 | echo -e '\nwindow { border-radius: 0px; }' >> src/style.css
|
26 | 28 | '';
|
27 | 29 | });
|
| 30 | + |
| 31 | + _ghafPacFileFetcher = |
| 32 | + let |
| 33 | + pacFileDownloadUrl = "https://raw.githubusercontent.com/tiiuae/ghaf-rt-config/refs/heads/main/network/proxy/ghaf.pac"; |
| 34 | + proxyServerUrl = "http://${netvmAddress}:${toString config.ghaf.reference.services.proxy-server.bindPort}"; |
| 35 | + logTag = "ghaf-pac-fetcher"; |
| 36 | + in |
| 37 | + pkgs.writeShellApplication { |
| 38 | + name = "ghafPacFileFetcher"; |
| 39 | + runtimeInputs = [ |
| 40 | + pkgs.coreutils # Provides 'mv', 'rm', etc. |
| 41 | + pkgs.curl # For downloading PAC files |
| 42 | + pkgs.inetutils # Provides 'logger' |
| 43 | + ]; |
| 44 | + text = '' |
| 45 | + # Variables |
| 46 | + TEMP_PAC_PATH=$(mktemp) |
| 47 | + LOCAL_PAC_PATH="/etc/proxy/${pacFileName}" |
| 48 | +
|
| 49 | + # Logging function with timestamp |
| 50 | + log() { |
| 51 | + logger -t "${logTag}" "$1" |
| 52 | + } |
| 53 | +
|
| 54 | + log "Starting the pac file fetch process..." |
| 55 | +
|
| 56 | + # Fetch the pac file using curl with a proxy |
| 57 | + log "Fetching pac file from ${pacFileDownloadUrl} using proxy ${proxyServerUrl}..." |
| 58 | + http_status=$(curl --proxy "${proxyServerUrl}" -s -o "$TEMP_PAC_PATH" -w "%{http_code}" "${pacFileDownloadUrl}") |
| 59 | +
|
| 60 | + log "HTTP status code: $http_status" |
| 61 | +
|
| 62 | + # Check if the fetch was successful |
| 63 | + if [[ "$http_status" -ne 200 ]]; then |
| 64 | + log "Error: Failed to download pac file from ${pacFileDownloadUrl}. HTTP status code: $http_status" |
| 65 | + rm -f "$TEMP_PAC_PATH" # Clean up temporary file |
| 66 | + exit 2 |
| 67 | + fi |
| 68 | +
|
| 69 | + # Verify the downloaded file is not empty |
| 70 | + if [[ ! -s "$TEMP_PAC_PATH" ]]; then |
| 71 | + log "Error: The downloaded pac file is empty." |
| 72 | + rm -f "$TEMP_PAC_PATH" # Clean up temporary file |
| 73 | + exit 3 |
| 74 | + fi |
| 75 | +
|
| 76 | + # Log the download success |
| 77 | + log "Pac file downloaded successfully. Proceeding with update..." |
| 78 | +
|
| 79 | + # Copy the content from the temporary pac file to the target file |
| 80 | + log "Copying the content from temporary file to the target pac file at $LOCAL_PAC_PATH..." |
| 81 | +
|
| 82 | + # Check if the copy was successful |
| 83 | + if cat "$TEMP_PAC_PATH" > "$LOCAL_PAC_PATH"; then |
| 84 | + log "Pac file successfully updated at $LOCAL_PAC_PATH." |
| 85 | + else |
| 86 | + log "Error: Failed to update the pac file at $LOCAL_PAC_PATH." |
| 87 | + rm -f "$TEMP_PAC_PATH" # Clean up temporary file |
| 88 | + exit 4 |
| 89 | + fi |
| 90 | +
|
| 91 | + # Clean up temporary file |
| 92 | + rm -f "$TEMP_PAC_PATH" |
| 93 | +
|
| 94 | + log "Pac file fetch and update process completed successfully." |
| 95 | + exit 0 |
| 96 | + ''; |
| 97 | + }; |
| 98 | + |
28 | 99 | in
|
29 | 100 | {
|
30 | 101 | name = "${name}";
|
|
36 | 107 | pkgs.openconnect
|
37 | 108 | gnomeTextEditor
|
38 | 109 | pkgs.xarchiver
|
39 |
| - |
| 110 | + pkgs.busybox |
40 | 111 | ]
|
41 | 112 | ++ lib.optionals config.ghaf.profiles.debug.enable [ pkgs.tcpdump ]
|
42 | 113 | ++ lib.optionals config.ghaf.givc.enable [ pkgs.open-normal-extension ];
|
|
71 | 142 | applications = [
|
72 | 143 | {
|
73 | 144 | name = "google-chrome";
|
74 |
| - command = "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland ${config.ghaf.givc.idsExtraArgs} --load-extension=${pkgs.open-normal-extension}"; |
| 145 | + command = "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/google-chrome-stable --proxy-pac-url=${pacFileUrl} --enable-features=UseOzonePlatform --ozone-platform=wayland ${config.ghaf.givc.idsExtraArgs} --load-extension=${pkgs.open-normal-extension}"; |
75 | 146 | args = [ "url" ];
|
76 | 147 | }
|
77 | 148 | {
|
78 | 149 | name = "outlook";
|
79 |
| - command = "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland --app=https://outlook.office.com/mail/ ${config.ghaf.givc.idsExtraArgs} --load-extension=${pkgs.open-normal-extension}"; |
| 150 | + command = "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/google-chrome-stable --proxy-pac-url=${pacFileUrl} --enable-features=UseOzonePlatform --ozone-platform=wayland --app=https://outlook.office.com/mail/ ${config.ghaf.givc.idsExtraArgs} --load-extension=${pkgs.open-normal-extension}"; |
80 | 151 | }
|
81 | 152 | {
|
82 | 153 | name = "office";
|
83 |
| - command = "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland --app=https://microsoft365.com ${config.ghaf.givc.idsExtraArgs} --load-extension=${pkgs.open-normal-extension}"; |
| 154 | + command = "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/google-chrome-stable --proxy-pac-url=${pacFileUrl} --enable-features=UseOzonePlatform --ozone-platform=wayland --app=https://microsoft365.com ${config.ghaf.givc.idsExtraArgs} --load-extension=${pkgs.open-normal-extension}"; |
84 | 155 | }
|
85 | 156 | {
|
86 | 157 | name = "teams";
|
87 |
| - command = "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland --app=https://teams.microsoft.com ${config.ghaf.givc.idsExtraArgs} --load-extension=${pkgs.open-normal-extension}"; |
| 158 | + command = "${config.ghaf.givc.appPrefix}/run-waypipe ${config.ghaf.givc.appPrefix}/google-chrome-stable --proxy-pac-url=${pacFileUrl} --enable-features=UseOzonePlatform --ozone-platform=wayland --app=https://teams.microsoft.com ${config.ghaf.givc.idsExtraArgs} --load-extension=${pkgs.open-normal-extension}"; |
88 | 159 | }
|
89 | 160 | {
|
90 | 161 | name = "gpclient";
|
|
107 | 178 |
|
108 | 179 | reference = {
|
109 | 180 | programs.google-chrome.enable = true;
|
110 |
| - |
111 | 181 | services.globalprotect = {
|
112 | 182 | enable = true;
|
113 | 183 | csdWrapper = "${pkgs.openconnect}/libexec/openconnect/hipreport.sh";
|
|
149 | 219 | # Enable dconf and icon pack for gnome text editor
|
150 | 220 | programs.dconf.enable = true;
|
151 | 221 | environment.systemPackages = [ pkgs.adwaita-icon-theme ];
|
| 222 | + # Define a new group for proxy management |
| 223 | + users.groups.${proxyGroupName} = { }; # Create a group named proxy-admin |
| 224 | + |
| 225 | + # Define a new user with a specific username |
| 226 | + users.users.${proxyUserName} = { |
| 227 | + isSystemUser = true; |
| 228 | + description = "Proxy User for managing allowlist and services"; |
| 229 | + # extraGroups = [ "${proxyGroupName}" ]; # Adding to 'proxy-admin' for specific access |
| 230 | + group = "${proxyGroupName}"; |
| 231 | + }; |
| 232 | + |
| 233 | + environment.etc."proxy/${pacFileName}" = { |
| 234 | + text = ''''; |
| 235 | + user = "${proxyUserName}"; # Owner is proxy-user |
| 236 | + group = "${proxyGroupName}"; # Group is proxy-admin |
| 237 | + mode = "0664"; # Permissions: read/write for owner/group, no permissions for others |
| 238 | + }; |
| 239 | + |
| 240 | + systemd.services.pacServer = { |
| 241 | + description = "Http server to make PAC file accessible for web browsers"; |
| 242 | + wantedBy = [ "multi-user.target" ]; |
| 243 | + after = [ "network.target" ]; |
| 244 | + serviceConfig = { |
| 245 | + ExecStart = "${pkgs.busybox}/bin/busybox httpd -f -p ${pacServerAddr} -h /etc/proxy"; |
| 246 | + # Ensure ghafFetchUrl starts after the network is up |
| 247 | + Type = "simple"; |
| 248 | + # Restart policy on failure |
| 249 | + Restart = "always"; # Restart the service if it fails |
| 250 | + RestartSec = "15s"; # Wait 15 seconds before restarting |
| 251 | + User = "${proxyUserName}"; |
| 252 | + }; |
| 253 | + }; |
| 254 | + |
| 255 | + systemd.services.ghafPacFileFetcher = { |
| 256 | + description = "Fetch ghaf pac file periodically with retries if internet is available"; |
| 257 | + |
| 258 | + serviceConfig = { |
| 259 | + ExecStart = "${_ghafPacFileFetcher}/bin/ghafPacFileFetcher"; |
| 260 | + # Ensure ghafFetchUrl starts after the network is up |
| 261 | + Type = "simple"; |
| 262 | + # Restart policy on failure |
| 263 | + Restart = "on-failure"; # Restart the service if it fails |
| 264 | + RestartSec = "15s"; # Wait 15 seconds before restarting |
| 265 | + User = "${proxyUserName}"; |
| 266 | + }; |
| 267 | + }; |
| 268 | + |
| 269 | + systemd.timers.ghafPacFileFetcher = { |
| 270 | + description = "Run ghafPacFileFetcher periodically"; |
| 271 | + wantedBy = [ "timers.target" ]; |
| 272 | + timerConfig = { |
| 273 | + User = "${proxyUserName}"; |
| 274 | + Persistent = true; # Ensures the timer runs after a system reboot |
| 275 | + OnCalendar = "daily"; # Set to your desired schedule |
| 276 | + OnBootSec = "90s"; |
| 277 | + }; |
| 278 | + }; |
152 | 279 |
|
153 | 280 | #Firewall Settings
|
154 | 281 | networking = {
|
155 |
| - proxy = { |
156 |
| - default = "http://${netvmAddress}:${toString config.ghaf.reference.services.proxy-server.bindPort}"; |
157 |
| - noProxy = "192.168.101.10,${adminvmAddress},127.0.0.1,localhost,${vpnOnlyAddr}"; |
158 |
| - }; |
159 | 282 | firewall = {
|
160 | 283 | enable = true;
|
161 | 284 | extraCommands = ''
|
|
170 | 293 | # Default policy
|
171 | 294 | iptables -P INPUT DROP
|
172 | 295 |
|
| 296 | + iptables -A INPUT -i lo -j ACCEPT |
| 297 | + iptables -A OUTPUT -o lo -j ACCEPT |
| 298 | +
|
173 | 299 | # Block any other unwanted traffic (optional)
|
174 | 300 | iptables -N logreject
|
175 | 301 | iptables -A logreject -j LOG
|
|
0 commit comments