Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied in /usr/share/dotnet #327

Closed
2 of 5 tasks
wzchua opened this issue Sep 30, 2022 · 22 comments
Closed
2 of 5 tasks

Permission denied in /usr/share/dotnet #327

wzchua opened this issue Sep 30, 2022 · 22 comments
Assignees
Labels
bug Something isn't working

Comments

@wzchua
Copy link

wzchua commented Sep 30, 2022

Description:
Runner does not have permission to install in the default directory

Task version:
3.0.0

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Repro steps:
Use action with selfhosted ubuntu runner with non-root user permissions

Expected behavior:
Install dotnet

Actual behavior:
Permission denied

I tried using the env DOTNET_INSTALL_DIR but it doesn't seem to work

@wzchua wzchua added bug Something isn't working needs triage labels Sep 30, 2022
@IvanZosimov IvanZosimov self-assigned this Sep 30, 2022
@IvanZosimov
Copy link
Contributor

Hi, @wzchua 👋 Thanks for the issue, we will check it out and get back to you with updates.

@IvanZosimov
Copy link
Contributor

@wzchua, could you try to change your permissions? For example, you can try to use chown command.

@wzchua
Copy link
Author

wzchua commented Sep 30, 2022

Hi, I don't have sudo permission.
I would prefer an option to install in a non-root location

@andrewgbell
Copy link

We have the same issue, was fine on v2.

@IvanZosimov
Copy link
Contributor

IvanZosimov commented Sep 30, 2022

Hi, @andrewgbell 👋 Thank you for the feedback, we are working on this issue.

@austindrenski
Copy link

austindrenski commented Sep 30, 2022

Hi all, just wanted to add that my org observed this today on self-hosted Windows instances, so it's not Linux specific.

Partial logs below:

jobs:
  build:
    runs-on: [self-hosted, windows, x64, docker] 

    steps:
    - name: checkout
      uses: actions/checkout@v3

    - name: setup dotnet
      uses: actions/setup-dotnet@v3
      with:
        source-url: ***
      env:
        DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
        NUGET_AUTH_TOKEN: ${{ secrets.*** }}
        NUGET_CERT_REVOCATION_MODE: offline
2022-09-30T13:24:15.0335561Z ##[group]Run actions/setup-dotnet@v3.0.0
2022-09-30T13:24:15.0335811Z with:
2022-09-30T13:24:15.0336048Z   source-url: ***
2022-09-30T13:24:15.0336274Z env:
2022-09-30T13:24:15.0336438Z   NUGET_CERT_REVOCATION_MODE: offline
2022-09-30T13:24:15.0336652Z   DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
2022-09-30T13:24:15.0339612Z   NUGET_AUTH_TOKEN: ***
2022-09-30T13:24:15.0339776Z ##[endgroup]
2022-09-30T13:24:15.4714642Z [command]"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command & 'C:\actions-runner\_work\_actions\actions\setup-dotnet\v3.0.0\externals\install-dotnet.ps1' -Version 6.0.200 -InstallDir "'C:\Program Files\dotnet'"
2022-09-30T13:24:15.8617396Z dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
2022-09-30T13:24:15.8621048Z dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
2022-09-30T13:24:15.8625830Z dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
2022-09-30T13:24:15.8627570Z dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
2022-09-30T13:24:15.8628079Z 
2022-09-30T13:24:19.1426067Z dotnet-install: Extracting the archive.
2022-09-30T13:24:20.7262114Z dotnet-install: Failed to extract package. Exception: Exception calling "ExtractToFile" with "3" argument(s): "Access to the path 'C:\Program Files\dotnet\dotnet.exe' is denied."
2022-09-30T13:24:20.8172985Z �[91mParentContainsErrorRecordException: �[0mC:\actions-runner\_work\_actions\actions\setup-dotnet\v3.0.0\externals\install-dotnet.ps1:816
2022-09-30T13:24:20.8173474Z �[96mLine |
2022-09-30T13:24:20.8189808Z �[96m 816 | �[0m …             �[96m[System.IO.Compression.ZipFileExtensions]::ExtractToFile(�[0m …
2022-09-30T13:24:20.8190164Z �[96m     | �[91m               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-09-30T13:24:20.8190482Z �[91m�[96m     | �[91mException calling "ExtractToFile" with "3" argument(s): "Access to the path 'C:\Program
2022-09-30T13:24:20.8190956Z �[96m     | �[91mFiles\dotnet\dotnet.exe' is denied."
2022-09-30T13:24:20.8191213Z �[0m
2022-09-30T13:24:20.8890612Z ##[error]Failed to install dotnet 1. dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.

dotnet-install: Extracting the archive.

@mathieu-benoit
Copy link

Same issue here while trying to update from v2 to v3:

dotnet-install: Attempting to download using primary link https://dotnetcli.azureedge.net/dotnet/Sdk/7.0.100-rc.1.22431.12/dotnet-sdk-7.0.100-rc.1.22431.12-linux-x64.tar.gz
dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/7.0.100-rc.1.22431.12/dotnet-sdk-7.0.100-rc.1.22431.12-linux-x64.tar.gz
cp: cannot create directory '/usr/share/dotnet/host/fxr/7.0.0-rc.1.22426.10/': Permission denied
cp: cannot create directory '/usr/share/dotnet/packs/Microsoft.AspNetCore.App.Ref/7.0.0-rc.1.22427.2/': Permission denied
cp: cannot create directory '/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.linux-x64/7.0.0-rc.1.22426.10/': Permission denied
cp: cannot create directory '/usr/share/dotnet/packs/Microsoft.NETCore.App.Ref/7.0.0-rc.1.22426.10/': Permission denied
cp: cannot create directory '/usr/share/dotnet/sdk-manifests/7.0.100-rc.1/': Permission denied
cp: cannot create directory '/usr/share/dotnet/sdk-manifests/7.0.100/': Permission denied
cp: cannot create directory '/usr/share/dotnet/sdk/7.0.100-rc.1.22431.[12](https://github.com/GoogleCloudPlatform/microservices-demo/actions/runs/3159612194/jobs/5143214019#step:3:13)/': Permission denied
mkdir: cannot create directory ‘/usr/share/dotnet/sdk/7.0.100-rc.1.22431.12’: Permission denied
cp: cannot create directory '/usr/share/dotnet/sdk/7.0.100-rc.1.22431.12/DotnetTools/dotnet-dev-certs/7.0.0-rc.1.22427.2/': No such file or directory
mkdir: cannot create directory ‘/usr/share/dotnet/sdk/7.0.100-rc.1.22431.12’: Permission denied
cp: cannot create directory '/usr/share/dotnet/sdk/7.0.100-rc.1.[22](https://github.com/GoogleCloudPlatform/microservices-demo/actions/runs/3159612194/jobs/5143214019#step:3:23)431.12/DotnetTools/dotnet-user-jwts/7.0.0-rc.1.22427.2/': No such file or directory
mkdir: cannot create directory ‘/usr/share/dotnet/sdk/7.0.100-rc.1.22431.12’: Permission denied
cp: cannot create directory '/usr/share/dotnet/sdk/7.0.100-rc.1.2[24](https://github.com/GoogleCloudPlatform/microservices-demo/actions/runs/3159612194/jobs/5143214019#step:3:25)31.12/DotnetTools/dotnet-user-secrets/7.0.0-rc.1.22427.2/': No such file or directory
mkdir: cannot create directory ‘/usr/share/dotnet/sdk/7.0.100-rc.1.22431.12’: Permission denied
cp: cannot create directory '/usr/share/dotnet/sdk/7.0.100-rc.1.22431.12/DotnetTools/dotnet-watch/7.0.100-rc.1.22429.2/': No such file or directory
cp: cannot create directory '/usr/share/dotnet/shared/Microsoft.AspNetCore.App/7.0.0-rc.1.22427.2/': Permission denied
cp: cannot create directory '/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.0-rc.1.224[26](https://github.com/GoogleCloudPlatform/microservices-demo/actions/runs/3159612194/jobs/5143214019#step:3:27).10/': Permission denied
cp: cannot create directory '/usr/share/dotnet/templates/7.0.0-rc.1.224[27](https://github.com/GoogleCloudPlatform/microservices-demo/actions/runs/3159612194/jobs/5143214019#step:3:28).2/': Permission denied
cp: cannot create regular file '/usr/share/dotnet/LICENSE.txt': Permission denied
cp: cannot create regular file '/usr/share/dotnet/dotnet': Permission denied
cp: cannot create regular file '/usr/share/dotnet/ThirdPartyNotices.txt': Permission denied
dotnet_install: Error: Failed to verify the version of installed `.NET Core SDK`.

Self-hosted Ubuntu GH action runner.

Was working with v2.

@IvanZosimov
Copy link
Contributor

IvanZosimov commented Oct 4, 2022

Hi, @wzchua, @andrewgbell, @austindrenski and @mathieu-benoit 👋 The new patch version was just released to fix the issue with DOTNET_INSTALL_DIR environment variable. If your user doesn't have permissions to write SDK's files into the default directory, you can use DOTNET_INSTALL_DIR to specify any other directory that suits you:

jobName:
  runs-on: self-hosted
  env:
    DOTNET_INSTALL_DIR: "path/to/directory"
  steps:
    - uses: actions/setup-dotnet@v3.0.1 # as soon as major tag is updated, v3 can be used
      with:
        dotnet-version: '7.0'

Please, give us your feedback in the comments. If you have any additional questions, feel free to ask.

@andrewgbell
Copy link

Hi @IvanZosimov. Does this now have to be defined when the agent doesn't have root? Just curious as this wasn't the case previously, so has the default install directory changed?

@IvanZosimov
Copy link
Contributor

@andrewgbell, you are right. The default directory was changed (it's breaking change), details and motivation can be found here.

@austindrenski
Copy link

@IvanZosimov Thanks for getting a patch out so quickly!

Unfortunately, it looks like there may be something funky happening with the environment variable expansion. Not sure if setup-dotnet or dotnet-install.ps1 is to blame (or user error, for that matter), but I've had to revert my org's self-hosted workflows back from @v3.0.1 to @v2 for the time being.

I've attached two examples with logs below in hopes that you might be able to help make some sense of what I'm seeing.

N.B. *** in the examples is for sanitization and is unrelated to the actual issue.

1. %LocalAppData%/Microsoft/dotnet

Based on https://docs.microsoft.com/dotnet/core/tools/dotnet-install-script:

  • -InstallDir|--install-dir <DIRECTORY>

    Specifies the installation path. The directory is created if it doesn't exist. The default value is %LocalAppData%\Microsoft\dotnet on Windows and $HOME/.dotnet on Linux/macOS. Binaries are placed directly in this directory.

Note that this example "succeeds", but then later fails with this:

error MSB4019: The imported project "C:\actions-runner\_work\dotnet\***\***\%LocalAppData%\Microsoft\dotnet\sdk\6.0.200\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props" was not found. Confirm that the expression in the Import declaration "%LocalAppData%\Microsoft\dotnet\sdk\6.0.200\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props" is correct, and that the file exists on disk.
jobs:
  build:
    runs-on: [self-hosted, windows, x64, docker] 

    steps:
    - name: checkout
      uses: actions/checkout@v3

    - name: setup dotnet
      uses: actions/setup-dotnet@v3.0.1
      with:
        source-url: ***
      env:
        DOTNET_INSTALL_DIR: '%LocalAppData%/Microsoft/dotnet'
        DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
        NUGET_AUTH_TOKEN: ${{ secrets.*** }}
        NUGET_CERT_REVOCATION_MODE: offline
2022-10-04T17:01:20.5580442Z ##[group]Run actions/setup-dotnet@v3.0.1
2022-10-04T17:01:20.5580699Z with:
2022-10-04T17:01:20.5580940Z   source-url: ***
2022-10-04T17:01:20.5581177Z env:
2022-10-04T17:01:20.5581341Z   NUGET_CERT_REVOCATION_MODE: offline
2022-10-04T17:01:20.5581558Z   DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
2022-10-04T17:01:20.5596000Z   DOTNET_INSTALL_DIR: %LocalAppData%/Microsoft/dotnet
2022-10-04T17:01:20.5596590Z   NUGET_AUTH_TOKEN: ***
2022-10-04T17:01:20.5596825Z ##[endgroup]
2022-10-04T17:01:21.0412651Z [command]"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command & 'C:\actions-runner\_work\_actions\actions\setup-dotnet\v3.0.1\externals\install-dotnet.ps1' -Version 6.0.200
2022-10-04T17:01:21.3987198Z dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
2022-10-04T17:01:21.3991462Z dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
2022-10-04T17:01:21.3994431Z dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
2022-10-04T17:01:21.3999293Z dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
2022-10-04T17:01:21.3999845Z 
2022-10-04T17:01:24.8197535Z dotnet-install: Extracting the archive.
2022-10-04T17:01:46.7207643Z dotnet-install: Adding to current process PATH: "C:\actions-runner\_work\dotnet\***\%LocalAppData%\Microsoft\dotnet\". Note: This change will not be visible if PowerShell was run as a child process.
2022-10-04T17:01:46.8000586Z dotnet-install: Note that the script does not resolve dependencies during installation.
2022-10-04T17:01:46.8607687Z dotnet-install: To check the list of dependencies, go to https://docs.microsoft.com/dotnet/core/install/windows#dependencies
2022-10-04T17:01:46.8882572Z dotnet-install: Installed version is 6.0.200
2022-10-04T17:01:46.9814088Z dotnet-install: Installation finished
2022-10-04T17:01:47.0615065Z dotnet-auth: Finding any source references in C:\actions-runner\_work\dotnet\***\NuGet.Config, writing a new temporary configuration file with credentials to C:\actions-runner\_work\dotnet\nuget.config

2. ~/AppData/Local/Microsoft/dotnet

Based on guidance from https://github.com/actions/cache#windows-environment-variables:

Windows environment variables

Please note that Windows environment variables (like %LocalAppData%) will NOT be expanded by this action. Instead, prefer using ~ in your paths which will expand to HOME directory. For example, instead of %LocalAppData%, use ~\AppData\Local. For a list of supported default environment variables, see this page.

jobs:
  build:
    runs-on: [self-hosted, windows, x64, docker] 

    steps:
    - name: checkout
      uses: actions/checkout@v3

    - name: setup dotnet
      uses: actions/setup-dotnet@v3.0.1
      with:
        source-url: ***
      env:
        DOTNET_INSTALL_DIR: '~/AppData/Local/Microsoft/dotnet'
        DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
        NUGET_AUTH_TOKEN: ${{ secrets.*** }}
        NUGET_CERT_REVOCATION_MODE: offline
2022-10-04T17:14:04.4317358Z ##[group]Run actions/setup-dotnet@v3.0.1
2022-10-04T17:14:04.4317798Z with:
2022-10-04T17:14:04.4318126Z   source-url: ***
2022-10-04T17:14:04.4318408Z env:
2022-10-04T17:14:04.4318575Z   NUGET_CERT_REVOCATION_MODE: offline
2022-10-04T17:14:04.4318793Z   DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
2022-10-04T17:14:04.4321432Z   DOTNET_INSTALL_DIR: ~/AppData/Local/Microsoft/dotnet
2022-10-04T17:14:04.4321883Z   NUGET_AUTH_TOKEN: ***
2022-10-04T17:14:04.4322048Z ##[endgroup]
2022-10-04T17:14:04.8794749Z [command]"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command & 'C:\actions-runner\_work\_actions\actions\setup-dotnet\v3.0.1\externals\install-dotnet.ps1' -Version 6.0.200
2022-10-04T17:14:05.2646655Z dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
2022-10-04T17:14:05.2649256Z dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
2022-10-04T17:14:05.2652041Z dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
2022-10-04T17:14:05.2656843Z dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
2022-10-04T17:14:05.2657286Z 
2022-10-04T17:14:05.5760470Z dotnet-install: .NET Core SDK with version '6.0.200' is already installed.
2022-10-04T17:14:05.5833301Z dotnet-install: Adding to current process PATH: "C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\dotnet\". Note: This change will not be visible if PowerShell was run as a child process.
2022-10-04T17:14:05.6498497Z ##[error]ENOENT: no such file or directory, scandir 'C:\actions-runner\_work\dotnet\***\~\AppData\Local\Microsoft\dotnet\sdk'

@austindrenski
Copy link

I don't read much TS, so please disregard if this is just normal language behavior, but took a look at #329 and noticed what seemed like an inconsistency in how process.env is being passed around, so figured I'd bubble on the off-chance it's relevant:

/**
 * Interface for exec options
 */
export interface ExecOptions {
  /** optional working directory.  defaults to current */
  cwd?: string

  /** optional envvar dictionary.  defaults to current process's env */
  env?: {[key: string]: string}

https://github.com/actions/toolkit/blob/4fbc5c941a57249b19562015edbd72add14be93d/packages/exec/src/interfaces.ts#L9-L10

            // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
            const getExecOutputOptions = {
                ignoreReturnCode: true,
                env: process.env
            };

https://github.com/actions/setup-dotnet/pull/329/files#diff-3d2b59189eeedc2d428ddd632e97658fe310f587f7cb63b01f9b98ffc11c0197R360-R364

    // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
    const getExecOutputOptions = {
      ignoreReturnCode: true,
      env: process.env as {string: string}
    };

https://github.com/actions/setup-dotnet/pull/329/files#diff-36a9847d245bd66dd946fe257334eb7bbe0c728d37d53df8b8173c7e3eecd5b2R238-R242

@wzchua
Copy link
Author

wzchua commented Oct 5, 2022

I configured it to ~/.dotnet. It works but it depends on some implicit resolution of ~.

dotnet-install: Adding to current process PATH: `/home/user/runner/_work/repo1/repo1/~/.dotnet`. Note: This change will be visible only when sourcing script.

@lanwin
Copy link

lanwin commented Oct 5, 2022

Same problem here..self hosted Ubuntu.

@IvanZosimov
Copy link
Contributor

Hi, @wzchua, @andrewgbell, @austindrenski, @mathieu-benoit, @lanwin 👋 Sorry for the late answer, the logic of processing DOTNET_INSTALL_DIR was updated. Could you please, test the action in your workflows and leave your feedback, specify the main branch instead of v3 like that:

 - uses: actions/setup-dotnet@main

@knowledgebreak
Copy link

knowledgebreak commented Oct 11, 2022 via email

@andrewgbell
Copy link

Hi, @wzchua, @andrewgbell, @austindrenski, @mathieu-benoit, @lanwin 👋 Sorry for the late answer, the logic of processing DOTNET_INSTALL_DIR was updated. Could you please, test the action in your workflows and leave your feedback, specify the main branch instead of v3 like that:

 - uses: actions/setup-dotnet@main

Tried it using main instead of v3 and worked in the same way. Also tried regressing leaving out the install directory and failed in the same way as previous as well on v3. So from a user perspective, v3 seems to be the same as main to me.

@IvanZosimov
Copy link
Contributor

Hi, @andrewgbell 👋 Could you, please, clarify that you didn't have any problems with main except having to set DOTNET_INSTALL_DIR explicitly, which is expected? We added support for the relative paths and for paths with ~.

@andrewgbell
Copy link

Hi, yes, comparing v3 to main there was no difference for me, both worked, using the following:

env:
  DOTNET_INSTALL_DIR: "./.dotnet"

steps:
- uses: actions/setup-dotnet@v3.0.1
  with:
    dotnet-version: '6.x'

@IvanZosimov
Copy link
Contributor

@wzchua, I'm going to close this issue, as the new patch version of the actions was released and it fixes the problems that were stated in the issue and in the comments below. If you have any additional questions, feel free to ping me.

@NissesSenap
Copy link

It would probably be good update the docs to include instructions to set

env:
  DOTNET_INSTALL_DIR: "./.dotnet"

On self hosted linux nodes.

@clarity99
Copy link

this solution pollutes your working directory so git commands or versioning tools that except clean working directory will fail!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants