canonical / snapcraft

Package, distribute, and update any app for Linux and IoT.
https://snapcraft.io
GNU General Public License v3.0
1.18k stars 445 forks source link

WSL2: Cannot use `$SNAPCRAFT_STORE_CREDENTIALS` for login #5000

Closed JGCarroll closed 1 month ago

JGCarroll commented 2 months ago

Bug Description

WSL2 doesn't run with a proper desktop session and must authenticate with the SNAPCRAFT_STORE_CREDENTIALS environment variable. This has traditionally worked for years.

Having tried recently, this no longer works, Snapcraft will unconditionally complain about lack of system keyring and refuse to consider the environment variable.

To Reproduce

james@James-Desktop:~/pinta-snap$ export SNAPCRAFT_STORE_CREDENTIALS=$(cat ../token)
james@James-Desktop:~/pinta-snap$ snapcraft upload pinta_2.1.2_amd64.snap --release=stable
snapcraft internal error: NoKeyringError('No keyring found to store or retrieve credentials from.')

Environment

james@James-Desktop:~/pinta-snap$ snapcraft version
snapcraft 8.3.2
james@James-Desktop:~/pinta-snap$ snap version
snap                         2.63+22.04ubuntu0.1
snapd                        unavailable
series                       16
Windows Subsystem for Linux  -
kernel                       5.15.153.1-microsoft-standard-WSL2 (amd64)

Windows environment: Fully updated Windows 11 22H2 (latest GA release)

snapcraft.yaml

N/A

Relevant log output

2024-08-23 20:06:17.990 Starting snapcraft, version 8.3.2
2024-08-23 20:06:17.990 Log verbosity level set to BRIEF
2024-08-23 20:06:17.990 Configuring application...
2024-08-23 20:06:17.990 Preparing application...
2024-08-23 20:06:17.990 Build plan: platform=None, build_for=None
2024-08-23 20:06:17.991 Running snapcraft upload on host
2024-08-23 20:06:18.013 snapcraft internal error: NoKeyringError('No keyring found to store or retrieve credentials from.')
2024-08-23 20:06:18.015 Traceback (most recent call last):
2024-08-23 20:06:18.015   File "/snap/snapcraft/12378/lib/python3.10/site-packages/craft_application/application.py", line 530, in run
2024-08-23 20:06:18.015     return_code = dispatcher.run() or 0
2024-08-23 20:06:18.015   File "/snap/snapcraft/12378/lib/python3.10/site-packages/craft_cli/dispatcher.py", line 487, in run
2024-08-23 20:06:18.015     return self._loaded_command.run(self._parsed_command_args)
2024-08-23 20:06:18.015   File "/snap/snapcraft/12378/lib/python3.10/site-packages/snapcraft/commands/upload.py", line 114, in run
2024-08-23 20:06:18.015     client = store.StoreClientCLI()
2024-08-23 20:06:18.015   File "/snap/snapcraft/12378/lib/python3.10/site-packages/snapcraft/store/client.py", line 179, in __init__
2024-08-23 20:06:18.015     self.store_client = get_client(ephemeral=ephemeral)
2024-08-23 20:06:18.015   File "/snap/snapcraft/12378/lib/python3.10/site-packages/snapcraft/store/client.py", line 161, in get_client
2024-08-23 20:06:18.015     client = craft_store.UbuntuOneStoreClient(
2024-08-23 20:06:18.015   File "/snap/snapcraft/12378/lib/python3.10/site-packages/craft_store/ubuntu_one_store_client.py", line 47, in __init__
2024-08-23 20:06:18.015     super().__init__(
2024-08-23 20:06:18.015   File "/snap/snapcraft/12378/lib/python3.10/site-packages/craft_store/base_client.py", line 77, in __init__
2024-08-23 20:06:18.015     self._auth = Auth(
2024-08-23 20:06:18.015   File "/snap/snapcraft/12378/lib/python3.10/site-packages/craft_store/auth.py", line 201, in __init__
2024-08-23 20:06:18.015     raise errors.NoKeyringError
2024-08-23 20:06:18.015 craft_store.errors.NoKeyringError: No keyring found to store or retrieve credentials from.
2024-08-23 20:06:18.015 Full execution log: '/home/james/.local/state/snapcraft/log/snapcraft-20240823-200617.989721.log'

Additional context

No response

mr-cal commented 2 months ago

We've made some changes to keyring handling in Snapcraft 8 (here and here), but the behavior you are experiencing hasn't changed.

I'm not sure what would make this occur, but we will need to reproduce this.

JGCarroll commented 2 months ago

I actually rolled back to Snapcraft 7 to try validate I wasn't going crazy (I am, but not on this aspect).

It's not just Snapcraft 8 that's broken, 7 and below seem to do the same now too, albeit the errors will be vaguely different.

I'd avoided WSL2 for a few months from around April (some LTS release may have tempted me...), but prior to then it was fully functional both since Microsoft officially supported Systemd in late 2022, and well before that with the systemd PID hacks.

(Weirdly WSL2 is a nice-ish environment to test on because I get decent Wayland support on NVidia ;))

mr-cal commented 2 months ago

Do you happen to be using Wayland in this VM?

There is a related failure for keyrings when ssh'ing into a machine Ubuntu Desktop machine. gnome-keyring pops up a gui prompt to unlock the keyring. This doesn't show up at the terminal and the keyring fails to unlock. In this scenario, this will fall back to a file-based keyring storage, so it may be unrelated to your problem.

JGCarroll commented 2 months ago

WSL2 has a built in Wayland and XWayland server for about the last 2 years, so every up to date version should have Wayland automatically.

What they don't have is a full desktop session, so e.g DBus is off the cards, I wouldn't expect the keyring popup to ever work in WSL2 itself, but the environment variable has always historically worked.

I can try unsetting $DISPLAY and $WAYLAND_DISPLAY prior to running Snapcraft to see if that makes a difference; I'm not sure how you "remove" those packages entirely because, in WSL2, the Wayland/XWayland servers are actually in a third VM (Microsofts CBL-Mariner), and so not trivially separated from the Linux environment you're actually using. But ultimately that's just a specific technical implementation that's always been the case (since it was enabled in 2022 anyway).

JGCarroll commented 1 month ago

I've just tried this again today and it's no longer proving to be a problem. With the amount of components involved it's difficult to say what's changed, but on the latest updates (Windows/WSL/Ubuntu/Snap/Snapcraft), everything now works as expected.

Since there's no real point trying to work out what's broken now that it's fixed, I'll mark this as closed.