Azure / Azure/azure-cli

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

Open
#14,151 15 comments 4 reactions 0 assignees View on GitHub
act-platform-engineering-squad customer-reported DevOps Service Attention
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

**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](https://user-images.githubusercontent.com/25000903/86135028-7da61d80-bb14-11ea-932e-49c851da5c9a.png)

![image](https://user-images.githubusercontent.com/25000903/86134254-97933080-bb13-11ea-8a40-2f8f4f825519.png)

![image](https://user-images.githubusercontent.com/25000903/86134392-c14c5780-bb13-11ea-9760-af5da654239e.png)

![image](https://user-images.githubusercontent.com/25000903/86134621-112b1e80-bb14-11ea-9d22-e55cd7c52590.png)]

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](https://user-images.githubusercontent.com/25000903/86135462-0cb33580-bb15-11ea-8928-a91a1c73680e.png)

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
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
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
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
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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.