r/devops • DevOps Engineer & Educator • 16d ago

Discussion My zero-trust Ubuntu dev environment on Windows

As DevOps engineers, our laptops have access to Prod. Many of us have to maintain a dev environment also in our laptop for coding.

With the increase in supply chain attacks, how do you secure your local dev environments?

Do you think what I did below is good enough?

------------------

I built an Ubuntu dev environment on my Windows laptop with WSL for DevContainers.

These are the steps I did to build the Ubuntu WSL environment:

Step 1: Install WSL from Windows powershell

wsl --install

Step 2: Download and install Ubuntu WSL

I tried installing Ubuntu with `wsl --install -d ubuntu`. But for some reason, I kept getting timeouts. So I opted for the manual install.

Downloaded Ubuntu on WSL from https://ubuntu.com/download/wsl and imported from powershell.

wsl --import ubuntu-26.04 D:\WSL\Ubuntu\ D:\ubuntu-26.04.1-wsl-amd64.wsl

I chose D:\WSL\Ubuntu as the destination path so my Linux disk will be intact event if I had to re-install Windows.

Step 3: Isolate the Windows file system from Linux

By default, WSL use root user and mount your Windows home directory as the home directory in Linux.

C:\Users\myname>wsl -d ubuntu-26.04
myname@my-laptop:/mnt/c/Users/myname#

There are obvious security flows here. So, create new non-root user.

useradd -m -G sudo -s /bin/bash myname

And, set this user as the default in /etc/wsl.conf so you don't boot into root next time.

# /etc/wsl.conf
[user]
default=myname

Then make Windows file system read only on WSL Linux.

# /etc/wsl.conf
[automount]
enabled = true
root = /mnt/
options = "ro,noatime"

If some rogue library accidentally hacked into my WSL Linux, it cannot alter Windows file system now.

Step 4: Enforce mirrored networking

By default, WSL hides behind a NAT virtual switch, which breaks enterprise VPNs and blinds the Windows firewall to guest traffic.

So, change networking mode to mirror mode.

From Windows powershell open %USERPROFILE%\.wslconfig on notepad.

notepad "$env:USERPROFILE\.wslconfig"

In the file, set networking mode.

[wsl2]
networkingMode=mirrored
firewall=true

This forces the Linux guest to share the host's IP and routes every outbound Linux packet through the Windows Filtering Platform (WFP), allowing your host firewall to actively inspect and drop rogue traffic.

Step 5: Harden Linux box

On WSL Linux, block all incoming traffic.

sudo apt update && sudo apt install ufw -y
sudo ufw default deny incoming
sudo ufw default allow outbound
sudo ufw enable

Enable systemd, so the firewall rules are not lost when shutdown.

#/etc/wsl.conf
[boot]
systemd=true

Back in %USERPROFILE%\.wslconfig, enforce hard limits (ex - memory=8GB, processors=4) so a catastrophic memory leak or cryptominer inside the VM cannot cause DoS attack on Windows.

[wsl2]
# Hard limit on the maximum RAM the WSL virtual machine can consume
memory=8GB

# Hard limit on the maximum number of logical CPU cores the VM can use
processors=4

Step 6: Limit windows file execution from Linux

Default WSL allows Linux to execute Windows binaries. A reverse shell in Ubuntu can simply run powershell.exe -c "..." to attack the host. We can stop it like this:

/etc/wsl.conf
[interop]
enabled = false
appendWindowsPath = false

Now, the Linux kernel is completely blind to the existence of Windows executables. The host is now an impenetrable black box.

Step 7: Install rootless Podman (instead of Docker Desktop) to run DevContainers

Docker containers by default run with root privileges. It can be hardened. But I opted for Podman instead.

Install Rootless Podman natively inside the isolated Ubuntu environment.

sudo apt-get -y install podman

I run DevContainers on this.

1 Upvotes

13 comments sorted by

32

u/IridescentKoala 16d ago

Your first issue is letting windows anywhere near production.

5

u/SeaworthinessHour233 DevOps Engineer & Educator 16d ago

OK. But, I cannot help it. I have to tell it to the IT department.

But, do you really think that all devops are using macbooks?

4

u/Dangle76 15d ago

My last 3 companies over the last 14 years have all used MacBooks for dev

19

u/Teiktos 16d ago

Your first issue is windows

2

u/Least-Egg3663 15d ago

Right? Just run linux already

6

u/MartinMystikJonas 16d ago

I would recommend not mounting Win filesystem at all to prevent secrets exfiltration by compromised WSL. And limit WSL egress connections to only needed ports and deny everything else

4

u/xeroxedforsomereason 15d ago

you're worried about supply chain attacks and you didnt verify checksums on download. you call this zero trust and install UFW. cloud engineers dont know shit.

2

u/b34gl4 13d ago

you call this zero trust and install UFW

ELI5

2

u/tim_fo 16d ago

Would it not be better to have your access to your prod env in a secure linux on your wsl. Your should not make many mistakes in windows to put your prod env in danger. Not only mistakes but supply chain attacks and other security risks.

2

u/NullVoidXNilMission 15d ago

Depends on whatlanguage you're also developing on. I would advise to turn on the setting that doesn't immediately download a new version when available to guard against supply chain attacks. The default is usually 2 weeks. Also turn off automatically running scripts

2

u/MongooseWonderful198 15d ago edited 15d ago

One correction to Step 4: WSL’s Hyper-V firewall doesn’t require mirrored mode. Microsoft documents it as enabled by default on Windows 11 22H2+ with WSL 2.0.9+; firewall=true is also the default.

To inspect the effective WSL policy in PowerShell:

Get-NetFirewallHyperVVMSetting -PolicyStore ActiveStore -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}'

Look at DefaultOutboundAction and the applicable rules with your IT team. Enabling the firewall doesn’t establish an outbound allowlist, and switching to mirrored mode doesn’t establish one either. Microsoft’s policy docs cover those settings.

1

u/Il_Falco4 14d ago

Why not just podman desktop and have your de containers that way?

1

u/Witty-Way6516 3d ago

The interesting part of this setup is how much access remains shared between the host and the isolated environment. File mounts, forwarded credentials and Docker access can undermine separation without making it immediately obvious. Discussions around rapidfort and container security sometimes touch on similar boundaries, although host isolation has its own set of considerations.