crystal-lang / shards

Dependency manager for the Crystal language
Other
758 stars 99 forks source link

Windows: A required privilege is not held by the client #556

Closed watzon closed 1 year ago

watzon commented 1 year ago

Stumbled on this today while trying to install shards for a project. Fresh git clone. Seems like Windows requires some funky permissions for symlinking and it's not possible to do without some admin rights. The full error is as follows:

...
Fetching https://github.com/sija/backtracer.cr.git
Fetching https://github.com/ysbaddaden/pool.git
Installing db (0.10.1)
Unhandled exception: Error creating symlink: '..' -> 'C:\\Users\\cawat\\Projects\\personal\\tourmaline\\lib\\db\\lib': A required privilege is not held by the client. (File::AccessDeniedError)
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +122870 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +122766 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +122730 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +8771 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +604316 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +578409 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +1847241 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +1871668 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +1870894 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +1869488 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +1867803 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +104443 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +1638098 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +1625797 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +5762 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +2280857 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +2280634 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +75065 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +75347 in '??'
  from C:\Users\cawat\scoop\apps\crystal\current\shards.exe +2816924 in '??'
  from C:\WINDOWS\System32\KERNEL32.DLL +74829 in 'BaseThreadInitThunk'
  from C:\WINDOWS\SYSTEM32\ntdll.dll +384904 in 'RtlUserThreadStart'
watzon commented 1 year ago

Installing sudo with scoop and then doing sudo shards install works, but obviously it would be good to avoid giving admin rights to a program that can execute arbitrary code.

luislavena commented 1 year ago

@watzon Looking at Crystal's code (here) seems that it uses the expected unprivileged flag (from Windows docs)

if not mistaken, that might be due Developer Mode needs to be turned on at least once for symlinks to work: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development

Are you able to test enabling developer mode without having to do sudo or an Administrator prompt?

straight-shoota commented 1 year ago

I think this issue needs some attention in order to improve the user experience on Windows.

Enabling developer mode allows creating symlinks.

So the very least we can do is catch the symlink error and display a helpful message that recommends enabling developer mode (or admin rights alternatively). We can even check if developer mode is enabled (Go implementation).

It would be ideal if it worked out of the box without developer mode. But I don't think there is a viable path for that. git also requires developer mode to checkout symlinks on Windows.