docker-airflow icon indicating copy to clipboard operation
docker-airflow copied to clipboard

Cant run code as root

Open fatjoni opened this issue 4 years ago • 10 comments

I am binding a directory from another container with root ownership from a python Operator i need to delete one file in that directory. I cant make it. If i change user owner or impersonate_user to root, i get this: 'No such file or directory: 'sudo': 'sudo'.

I have tried tons and tons of configurations but failed every single time, unless the directory's owner is airflow which is impossible for the other container to make.

fatjoni avatar Jul 16 '20 16:07 fatjoni

take a look at https://github.com/puckel/docker-airflow/issues/135

chris-aeviator avatar Jul 23 '20 14:07 chris-aeviator

@chris-aeviator my problem is that i want to run it from the beginning as root, to execute airflow as root not to just gain temporary access to the container as root.

fatjoni avatar Sep 29 '20 12:09 fatjoni

I am facing similar issue i couldn't get root access and i need the root access to install some apps( like git) while running my dag files.

NatnaelSisay avatar Nov 03 '21 01:11 NatnaelSisay

usually you should do that in a docker file while building the container. That means whenever you need more dependencies inside your airflow container(s), you'll edit your docker file and rebuild.

installing in the dockerfile is done with

RUN apt get install […] and then rebuild the docker container with docker build -t …

chris-aeviator avatar Nov 03 '21 06:11 chris-aeviator

In the file Dockerfile

# FROM apache/airflow:2.2.1-python3.9 FROM puckel/docker-airflow:1.10.9 RUN apt-get update RUN apt-get install -y git

when i try to build a new image shows the following error message.

`ERROR [2/3] RUN apt-get update 1.5s

[2/3] RUN apt-get update: #6 0.551 Reading package lists... #6 0.572 E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied) executor failed running [/bin/sh -c apt-get update]: exit code: 100 `

NatnaelSisay avatar Nov 04 '21 06:11 NatnaelSisay

Try to rebuild the airflow Dockerfile (not FROM) and set ADDITIONAL_DEV_APT_DEPS…airflow is a pain to setup for new use cases…

chris-aeviator avatar Nov 04 '21 08:11 chris-aeviator

Maybe add USER root in the Dockerfile will help? Mine is like:

FROM apache/airflow:2.2.4
USER root
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y git && \
    apt-get install -y vim
USER airflow
COPY requirements.txt /requirements.txt
RUN pip3 install --user --upgrade pip
RUN pip3 install --no-cache-dir --user -r /requirements.txt

and i get git/vim installed in the end

wendeehsu avatar Mar 06 '22 06:03 wendeehsu

In the file Dockerfile

# FROM apache/airflow:2.2.1-python3.9 FROM puckel/docker-airflow:1.10.9 RUN apt-get update RUN apt-get install -y git

when i try to build a new image shows the following error message.

`ERROR [2/3] RUN apt-get update 1.5s

[2/3] RUN apt-get update: #6 0.551 Reading package lists... #6 0.572 E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied) executor failed running [/bin/sh -c apt-get update]: exit code: 100 `

You should try with User Root because the image set Airflow for user default, and the update and upgrade run with root user only.

FROM puckel/docker-airflow:1.10.9
USER root
RUN apt-get update
RUN apt-get install -y git
USER airflow

Remember to change the user after installing. If you want to set up the airflow with sudo, just try:

USER root
RUN usermod -aG sudo airflow
RUN echo "airflow:123123" | chpasswd

and install subversion, sudo for container

TrieuLe0801 avatar Jul 04 '22 08:07 TrieuLe0801

without root is very hard to do many working. security is only important for Operation. No need for many use cases.

woodlyer avatar Sep 26 '23 03:09 woodlyer

without root is very hard to do many working. security is only important for Operation. No need for many use cases.

Same here. I just a normal developer, want to start docker airflow with my project quickly. Why should I care about so many security issues even in docker container? I hope we can have an approach to work with root.

Well, for anyone is looking for a way to pip install package under root, you can simply do python -m pip install {you lib} instead of pip install {you lib}.

vincentwyshan avatar Nov 13 '23 16:11 vincentwyshan