Posted in : Hyper-V, Linux, Microsoft, Other, Powershell, Ubuntu, Windows Av Stina Perbo Utas Översätt med Google ⟶

3 years ago

Like most of the users in the world, I’m running a Managed Window 10 client, we enforce many polices such as applocker and more to enforce policies. This can sometimes be an problem when working with developer tools. Due to this problem businesses often look the other way when it comes to developers and their clients. From personal experience I see that They are often excluded from the overall security measures or just not joined into the domain at all.
According to Stack Overflow about 45% of people identifying as ”Professional Developers” run Windows as their main desktop operating system. If most of these are exluded from the standard security we have a major issue.
The main issue is not that developers need to execute/install unsigned or generally untrusted tools and compile and execute code. The problem is that developers get exceptions to run this in their standard domain-joined Windows clients. The same Windows client that has access to all company resources. It only requires a simple user error to install some virus or otherwise malicious program and the computer is comprimised. Or we could just block everything and stop the productivity of our developers.
Neither of the above is clearly a good option, so what’s the solution?

Windows Subsystem for Linux (WSL) 2

WSL has existed for some time, but with windows Version 2004 (build 19041) WSL 2  introducing important changes such as a real Linux kernel through a subset of Hyper-V features. This allows us to do some cool stuff like starting VS Code from inside the Linux operating system, giving us a terminal with our windows folders mounted.
There are several blogposts out there on how to install a linux distro using wsl2, but I’d like to combine some of them and show what has worked for me.


WSL2 has some pre-requisites. First you need to upgrade your windows client to atleast build 19041 (released may 2020).
When that’s done simply run the powershell script (elevated) on your machine and then reboot.

Start-process ""
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:Microsoft-Hyper-V-All /all /norestart
dism.exe /online /enable-feature /featurename:Containers /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Invoke-RestMethod '' -OutFile "$env:temp\wsl_update_x64.msi"
Start-Process -FilePath msiexec -Wait -ArgumentList "/a `"$env:temp\wsl_update_x64.msi`" /qn"

Now you need to install your linux distro of choice. I went with Ubuntu 18.04 (since this is the latest ubuntu that supports Powershell core). Linux can be installed using windows store, so just go to the store and download + launch the desired distro. After that you need to configure the distro to run wsl version 2.
The below powershell script launches the Ubuntu 18.04 store site and waits for you to initalize the os. then configures wsl. If you choose another distro, then type wsl –version –verbose to find out the name,

Start-Process ""
Read-Host 'Press enter when you have installed and configured ubuntu to continue'
wsl --set-default-version 2
wsl --set-version Ubuntu-18.04 2

Now that you’re done you should be able to see ubuntu from the Windows Terminal, or if you’re just using cmd or powershell simply type ”wsl” and you should be able to enter the linux environment.
Windows Terminal Linux
And even though you can access your local files, only the c:\ becomes mounted, and as such the vm cannot read company documents and files in case of some security breach within the linux vm.

Now you just install all the tools you need, the lines of code below installs my most used. Powershell Core 7, Kubectl, Terraform, Az CLI.

curl -LO "$(curl -s"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
## Set alias k = kubectl
alias k='kubectl'
sudo git clone /opt/kubectx
sudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx
sudo ln -s /opt/kubectx/kubens /usr/local/bin/kubens
#powershell core 7
sudo apt-get update
sudo apt-get install liblttng-ust0
apt --fix-broken install
sudo dpkg -i powershell-lts_7.0.3-1.ubuntu.18.04_amd64.deb
sudo apt-get install -f
pwsh -command {write-host 'test'}
#Az cli
sudo apt-get update
sudo apt-get install -y ca-certificates curl apt-transport-https lsb-release gnupg
curl -sL |
    gpg --dearmor |
    sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] $AZ_REPO main" |
    sudo tee /etc/apt/sources.list.d/azure-cli.list
sudo apt-get update
sudo apt-get install azure-cli
az --version
# unzip
sudo apt install unzip
# Terraform. Check latest version at
curl > /tmp/
mkdir -p ${HOME}/bin
(cd ${HOME}/bin && unzip /tmp/
if [[ -z $(grep 'export PATH=${HOME}/bin:${PATH}' ~/.bashrc) ]]; then
  echo 'export PATH=${HOME}/bin:${PATH}' >> ~/.bashrc
  source ~/.bashrc
terraform version

Now that that’s done you’re probably wondering how to run Visual Studio Code with integration to your Windows Client.
To do this, simply type ”wsl code .” from an elevated promt, cmd or powershell. If you’re actively working from within your linux machine simply type ”code .” and VS code will start.Visual Studio Code
All that’s left now is to start developing!
I hope this was helpful!

Tags : build, Container, deploy, Developer, How to, kubectl, Kubernetes, Linux, Microsoft, Security, terraform, ubuntu, Visual Studio Code, VSCode, Windows, Windows 10, Windows Server 2019, WSL, WSL2

Personlig rådgivning

Vi erbjuder personlig rådgivning med författaren för 1400 SEK per timme. Anmäl ditt intresse i här så återkommer vi så snart vi kan.

Add comment

Your comment will be revised by the site if needed.