question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PermissionError: [Errno 13] Permission denied: '/.azure' when run as container in Jenkins docker agent pipeline !

See original GitHub issue

Sorry but this problem still persistent if you using “Jenkins Docker in Docker” If you using Azure CLI container run in you local laptop it will works fine but if you use it for run as container in Jenkins pipeline you will face permission problem because “az” executed bin need to run as root !!!

image

image

image

image]

because Jenkins didn’t give you “root user” to the container because security issues in privilege escalation attack ! So if you type anycommand relate to “root user” you will get broken output even “whoami” command !!! The way to fix is you give additional user argument to container while run it on Jenkins pipeline

Quick and Dirty way to fixing this problem

agent {
   docker {
        image 'mcr.microsoft.com/azure-cli:2.8.0'
        args "--user root --privileged"
    }
}

image

You will fix this problem !!! But why do “Azure CLI need root user ?” I don’t know about internal code in Azure CLI so hope Microsoft Team can help to fix this problem without needed az bin executed as root. Thank you very much 😭😭😭 Tracing error

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/__main__.py", line 33, in <module>
    az_cli = get_default_cli()
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 599, in get_default_cli
    from azure.cli.core.azlogging import AzCliLogging
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/azlogging.py", line 30, in <module>
    from azure.cli.core.commands.events import EVENT_INVOKER_PRE_CMD_TBL_TRUNCATE
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 28, in <module>
    from azure.cli.core.extension import get_extension
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/extension/__init__.py", line 18, in <module>
    az_config = CLIConfig(config_dir=GLOBAL_CONFIG_DIR, config_env_var_prefix=ENV_VAR_PREFIX)
  File "/usr/local/lib/python3.6/site-packages/knack/config.py", line 38, in __init__
    ensure_dir(config_dir)
  File "/usr/local/lib/python3.6/site-packages/knack/util.py", line 111, in ensure_dir
    raise e
  File "/usr/local/lib/python3.6/site-packages/knack/util.py", line 108, in ensure_dir
    os.makedirs(d)
  File "/usr/local/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/.azure'

_Originally posted by @wdrdres3qew5ts21 in https://github.com/Azure/azure-cli/issues/613#issuecomment-651812788_

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
andreadecortecommented, Oct 15, 2021

A workaround is to redefine a custom image from the azure-cli one with a custom user as below

FROM mcr.microsoft.com/azure-cli:latest
RUN mkdir -p /home/user && adduser --disabled-password user
USER user
WORKDIR /home/user
0reactions
Vinaysv18commented, Oct 13, 2022

use USER root this worked for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix the Jenkins Docker error: Permission denied when trying ...
To fix the Jenkins Docker permission denied error, just run a usermod command in the terminal and reboot.
Read more >
Getting “Permission Denied” error when pulling a docker ...
Solution: · log in the container as root user, since user jenkins cannot perform the operation. docker exec -it -u root jenkins bash...
Read more >
Docker: PermissionError: [Errno 13] Permission denied
I got this when I was running docker-compose. Got permission denied while trying to connect to the Docker daemon socket at ...
Read more >
Fix the Jenkins Docker Permission denied when trying to ...
There's an easy fix to the Jenkins Docker permission error that spits something like this out in the console of your Jenkins build...
Read more >
Azure Pipeline "Permission denied" when building Docker ...
Related Query · Azure Pipeline "Permission denied" when building Docker Image · Docker not found when building docker image using Docker Jenkins container...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found