Skip to main content

Working with XKF from Windows

The reason for this documentation is that we are using a number of Linux-based tools to be able to have a good integration with Windows, we recommend to use Linux as a base for this. This document is verified using Ubuntu version 20.04 but other distributions will most likely work.

Installation of WSL2 - Windows Subsystem for Linux​

Install via Powershell

Installation is also possible via Microsoft Store. Search for β€œlinux”.

Make sure that Windows Subsystem for Linux is enabled as a feature in Windows.

In Windows: Go to Control Panel β†’ Programs and Features.

In the left-hand menu, select β€œTurn Windows features on or off”

wsl-enable

Install Docker-Desktop​

Download and install Docker.

Once installation is complete, verify that the application works. We experienced issues when trying to start Docker-desktop within a managed organization using AD accounts, this caused an error with us not being members of a group called β€œdocker-usersβ€œ. To solve this, open up β€œComputer Management” in Windows as an administrator. Navigate to β€œlocal users and groups” β†’ Groups and locate the "docker-users" group and double-click.Press β€œAdd” and search for β€œAuthenticated Users” and add to the group.

Now sign out from Windows and sign back in, and the Docker application should work.

Verify in settings that the WSL2-based engine is used.

docker1

Also under settings, go to Resources β†’ WSL Integration and verify that you have access to the WSL integration with your installed WSL (in this case Ubuntu), and make sure it is checked.

docker2

To verify functionality:

In your Ubuntu WSL2 instance - Run the command:

docker run hello-world

Wait for the image to be pulled and if everything works properly the output should be:

Hello from Docker! This message shows that your installation appears to be working correctly.

Utilising Make with WSL2, Terraform and Docker​

We have noticed when running Terraform from within our Ubuntu instance, that there appears to be some network issues. We saw quite slow network connections, probably caused by the TCP connection, which resulted in the following error:

β”‚ Error: Failed to install provider β”‚ β”‚ Error while installing hashicorp/azurerm v2.64.0: local error: tls: bad record MAC

We ran the Terraform command again - and it worked perfectly.

Issues​

File lock issues​

If your .azure folder is mounted towards Windows from your WSL2 environment we have seen potential lock issues when running terraform and azure-cli 2.32.0, this might apply to other versions as well.

We think this have something to do with how WSL2 and Windows manages locking of files, to workaround you can make sure that your .azure folder is only in your Linux environment.

Assuming that you have not defined a custom AZURE_CONFIG_DIR you can perform the following to verify you are mounting your .azure folder to Windows:

$ cd
$ ls -la
drwx------ 61 user1 user1 4096 Jan 14 09:21 .
drwxr-xr-x 4 root root 4096 Feb 12 2021 ..
drwxr-xr-x 7 user1 user1 4096 Dec 12 13:04 .azure -> /mnt/c/Users/user1/.azure

Running the following commands will create a new .azure folder in your current working directory and tell azure-cli to use that folder to store its login data. Remember that the export command only is per terminal. You can make the config persistent by adding the export command to your .bashrc file located in your home folder.

export AZURE_CONFIG_DIR=$(pwd)/.azure
# Store Azure CLI configuration here
[ -d $(pwd)/.azure ] || mkdir $(pwd)/.azure
# login to azure agaiin
az login

This is a example how the traceback look liked when we encountered this error:

β”‚ Error: getting authenticated object ID: Error parsing json result from the Azure CLI: Error waiting for the Azure CLI: exit status 1: ERROR: The command failed with an unexpected error. Here is the traceback:
β”‚ ERROR: [Errno 2] No such file or directory
β”‚ Traceback (most recent call last):
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 352, in handler
β”‚ client = self.client_factory(self.cli_ctx) if self.client_factory else None
β”‚ TypeError: get_graph_client_signed_in_users() missing 1 required positional argument: '_'
β”‚
β”‚ During handling of the above exception, another exception occurred:
β”‚
β”‚ Traceback (most recent call last):
β”‚ File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 231, in invoke
β”‚ cmd_result = self.invocation.execute(args)
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 657, in execute
β”‚ raise ex
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 720, in _run_jobs_serially
β”‚ results.append(self._run_job(expanded_arg, cmd_copy))
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 712, in _run_job
β”‚ return cmd_copy.exception_handler(ex)
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/role/commands.py", line 69, in graph_err_handler
β”‚ raise ex
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 691, in _run_job
β”‚ result = cmd_copy(params)
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 328, in __call__
β”‚ return self.handler(*args, **kwargs)
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 354, in handler
β”‚ client = self.client_factory(self.cli_ctx, command_args) if self.client_factory else None
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/role/commands.py", line 89, in get_graph_client_signed_in_users
β”‚ return _graph_client_factory(cli_ctx).signed_in_user
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/role/_client_factory.py", line 25, in _graph_client_factory
β”‚ resource=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 335, in get_login_credentials
β”‚ credential = self._create_credential(account, client_id=client_id)
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 588, in _create_credential
β”‚ return identity.get_user_credential(username_or_sp_id)
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/auth/identity.py", line 182, in get_user_credential
β”‚ return UserCredential(self.client_id, username, **self._msal_app_kwargs)
β”‚ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/auth/msal_authentication.py", line 41, in __init__
β”‚ accounts = self.get_accounts(username)
β”‚ File "/opt/az/lib/python3.6/site-packages/msal/application.py", line 872, in get_accounts
β”‚ accounts = self._find_msal_accounts(environment=self.authority.instance)
β”‚ File "/opt/az/lib/python3.6/site-packages/msal/application.py", line 912, in _find_msal_accounts
β”‚ query={​​"environment": environment}​​)
β”‚ File "/opt/az/lib/python3.6/site-packages/msal_extensions/token_cache.py", line 53, in find
β”‚ with CrossPlatLock(self._lock_location):
β”‚ File "/opt/az/lib/python3.6/site-packages/msal_extensions/cache_lock.py", line 29, in __enter__
β”‚ file_handle = self._lock.__enter__()
β”‚ File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 199, in __enter__
β”‚ return self.acquire()
β”‚ File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 161, in acquire
β”‚ fh = self._prepare_fh(fh)
β”‚ File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 194, in _prepare_fh
β”‚ fh.truncate(0)
β”‚ FileNotFoundError: [Errno 2] No such file or directory
β”‚ To open an issue, please run: 'az feedback'
β”‚
β”‚ with provider["registry.terraform.io/hashicorp/azuread"],
β”‚ on main.tf line 19, in provider "azuread":
β”‚ 19: provider "azuread" {​​}​​