download-artifact icon indicating copy to clipboard operation
download-artifact copied to clipboard

Permission denied error for downloaded artifact

Open EmilyGraceSeville7cf opened this issue 3 years ago • 3 comments

Hello! I have this repo with the following ci.yml:

name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Mono Build
        run: |
          chmod +x build.sh && ./build.sh
        
      - name: Upload Artifacts
        uses: actions/upload-artifact@v2
        with:
          name: library
          path: bin/autodeploytonugettest.dll
          retention-days: 1
  
  lint:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Markdown Check
        run: |
          sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share
          npm install -g markdownlint-cli
          markdownlint *.md
      
      - name: Shell Check
        if: always()
        run: |
          sudo apt-get install shellcheck
          shellcheck *.sh
      - name: Download Artifacts
        uses: actions/download-artifact@v2
        if: always()
        with:
          name: library
          path: bin/autodeploytonugettest.dll
      
      - name: CSharp Check
        if: always()
        run: |
          sudo apt update
          sudo apt-get install gendarme
          chmod +r bin/
          cd bin/
          chmod +r autodeploytonugettest.dll
          gendarme -- autodeploytonugettest.dll

Everything works well except the last command gendarme -- autodeploytonugettest.dll which fails with:

An uncaught exception occured. Please fill a bug report at https://bugzilla.novell.com/
Stack trace: System.UnauthorizedAccessException: Access to the path '/home/runner/work/CSharp---Exercise---Other---Auto-deploy-to-NuGet/CSharp---Exercise---Other---Auto-deploy-to-NuGet/bin/autodeploytonugettest.dll' is denied.
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x000e0] in <533173d24dae460899d2b10975534bb0>:0 
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <533173d24dae460899d2b10975534bb0>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at Mono.Cecil.ModuleDefinition.GetFileStream (System.String fileName, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x0001c] in <c2b12ab5b3544f9088836118a10c93c9>:0 
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x00000] in <c2b12ab5b3544f9088836118a10c93c9>:0 
  at Mono.Cecil.AssemblyDefinition.ReadAssembly (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x00000] in <c2b12ab5b3544f9088836118a10c93c9>:0 
  at Gendarme.ConsoleRunner.AddAssembly (System.String filename) [0x0001b] in <e8e05298cccb4938b5f01696042669b0>:0 
  at Gendarme.ConsoleRunner.AddFiles (System.String name) [0x000cf] in <e8e05298cccb4938b5f01696042669b0>:0 
  at Gendarme.ConsoleRunner.Execute (System.String[] args) [0x000f7] in <e8e05298cccb4938b5f01696042669b0>:0 
Error: Process completed with exit code 4.

Why it happens even when I use sudo command to run gendarme? How to correctly setup permissions here?

EmilyGraceSeville7cf avatar Apr 07 '21 12:04 EmilyGraceSeville7cf

Also had this issue myself:

Total number of files that will be downloaded: 1
events.js:187
      throw er; // Unhandled 'error' event
      ^

Error: EACCES: permission denied, open '/home/runner/work/<repo_name>/<repo_name>/<file_from_earlier_step.json>'
Emitted 'error' event on WriteStream instance at:
    at internal/fs/streams.js:294:12
    at FSReqCallback.oncomplete (fs.js:146:23) {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/home/runner/work/<repo_name>/<repo_name>/<file_from_earlier_step.json>'
}

nbmbd1 avatar Apr 22 '21 17:04 nbmbd1

I had this issue and did a chmod on the destination directory

mallen5050 avatar Oct 26 '21 23:10 mallen5050

Instead of creating same issue will post it here.

Run actions/download-artifact@v3
Starting download for All-mods
Directory structure has been setup for the artifact
Total number of files that will be downloaded: 1
node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: EACCES: permission denied, open '/home/runner/work/*/*/build/*/*.pk3'
Emitted 'error' event on WriteStream instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/home/runner/work/*/*/build/*/*.pk3'
}

I did tried with chmod and chown without success. There is also similiar issue that is closed and points to the container being non root in which file being downloaded is created

    The current suspicion is that the issue occurs because the docker image has a non-root user specified.

Originally posted by @alexplischke in https://github.com/actions/download-artifact/issues/58#issuecomment-677927239

But in in my case there is only root user Another solution that I think would be good to test would be settting

    container:
      image: name_of_container
      options: --user root

rafal1137 avatar Oct 16 '22 21:10 rafal1137