Restoring cache fails with "Permission Denied"

If you are utilizing Workflows and either saving and restoring cache or persisting your Workspaces, keep in mind the users and directories involved. If you are using CircleCI convenience images, each Docker container runs under the same user with the same base permissions. If you save your cache in a job that uses one image, and it is restored in another, make sure they have compatible permissions.

If you receive the error "Permission denied" when restoring your cache, check where it had been saved in the previous job. A common instance of this is when using an image as the root user and saving cache, then attempting to restore that cache in a later job with a user who does not have root access.

The same error will cause files in a persisted workspace to be missing as well if the permissions are not set correctly.



You can see here in this `Restoring Cache` step, the cache was originally saved to `/root/tmp` as the original image was running as root and had it's working directory set to `~/tmp`. In this part of the Workflow, running under the CircleCI user, we do not have access to the `/root` folder.

If possible, use the same image across multiple jobs. If this is not possible, try setting your working directory to a common location between the two images (`/tmp` may work for some). You may need to change or set file permissions before saving your cache.

Example: Use `chmod -R 777 ./workingDirectory` to give full read/write access to these files.

The best option is to use a common image among your jobs. If the convenience images we provide are missing something essential to your project, consider customizing one of our images.

Architecture Permissions Issues

Caches generated in environments can also run into permissions issues when they are restored in environments that use a different architecture. To prevent these issues try adding the {arch} variable to your cache key. This will make sure that caches are unique to the environment they're generated in.

- restore_cache: 
key: '-v1-node-cache-{{ checksum "yarn.lock" }}-{{ arch}}'
- run: name: Install App command: yarn
- save_cache:
key: '-v1-node-cache-{{ checksum "yarn.lock" }}-{{ arch }}'
- node_modules
Was this article helpful?
5 out of 24 found this helpful