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.