LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-12-2022, 04:43 AM   #1
pantdk
Member
 
Registered: Oct 2011
Location: New Delhi
Posts: 248
Blog Entries: 3

Rep: Reputation: 17
Disable root access directly


I am new to the docker. I am trying to disable direct root login into the container. For that I did few things but unable to fix it any input will help a lot

I can login directly from user and user into the sudoers but when put user as Root then I login directly

Quote:
Quote:
root@ip-10-11-175-238:~# docker exec -it 9ec767e2c4ae /bin/bash
dpant@9ec767e2c4ae:/$ ls -la /root
ls: cannot open directory '/root': Permission denied
dpant@9ec767e2c4ae:/$


root@ip-10-11-175-238:~# docker exec -it --user root 2fba98d9d60e /bin/bash root@2fba98d9d60e:/home/ubuntu#
I can obstruct the Root from the first option where I have set password on root and also on the user which sudo access, But when I try from Root then all everything is open for me I want to deploy the container on other environment but no one can access it

Regards Dk

Last edited by pantdk; 08-12-2022 at 03:06 PM.
 
Old 08-12-2022, 08:51 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,622

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by pantdk View Post
I am new to the docker. I am trying to disable direct root login into the container. For that I did few things but unable to fix it any input will help a lot

I can login directly from user and user into the sudoers but when put user as Root then I login directly
Code:
root@ip-10-11-175-238:~# docker exec -it  9ec767e2c4ae /bin/bash
dpant@9ec767e2c4ae:/$ ls -la /root
ls: cannot open directory '/root': Permission denied
dpant@9ec767e2c4ae:/$

root@ip-10-11-175-238:~# docker exec -it --user root 2fba98d9d60e /bin/bash root@2fba98d9d60e:/home/ubuntu#
I can obstruct the Root from the first option where I have set password on root and also on the user which sudo access, But when I try from Root then all everything is open for me I want to deploy the container on other environment but no one can access it

Regards Dk
*AGAIN*, as you have been asked MANY times, put things in CODE tags...not sure why that's an issue.

And you *AGAIN* omit anything in the way of details, such as anything about this system, or the 'few things' that you actually did try....do you expect us to guess? Start with the Docker documentation:
https://docs.docker.com/engine/security/seccomp/

Can also run the image as a different user, but again...ANYONE can type in "su - " and if they know the root password, escalate things. What, exactly, are you trying to accomplish??
 
Old 08-12-2022, 10:27 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by TB0ne View Post
Can also run the image as a different user, but again...ANYONE can type in "su - " and if they know the root password, escalate things. What, exactly, are you trying to accomplish??
From my side I think it is the usual xy-problem, but I have no idea about the original issue and also I think it is just a bad design, but without details hard to say anything.
 
1 members found this post helpful.
Old 08-12-2022, 01:54 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,622

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by pan64 View Post
From my side I think it is the usual xy-problem, but I have no idea about the original issue and also I think it is just a bad design, but without details hard to say anything.
Totally agree. Not enough info to do anything with.
 
Old 08-12-2022, 03:31 PM   #5
pantdk
Member
 
Registered: Oct 2011
Location: New Delhi
Posts: 248

Original Poster
Blog Entries: 3

Rep: Reputation: 17
Sorry "TB0ne" to miss the CODE tags.

Actually, I have two websites with python and another on react. Both are hosted on docker through the jenkins pipeline and everything is working fine.
Now we need to deploy the same container into the other environment using our jenkins pipeline. Therefore, we made the connectivity. But now the challenge is that they didn't want to share their code with anyone. Therefore, I am trying to block the Root direct access on the container.
I try to with chattr but it is also not working also try to remove the root nologin but nothing works.

I think container is required root privilege to bring up all the service.


Quote:
FROM ubuntu:latest
RUN apt-get update && apt-get -y install sudo
RUN apt-get update && apt-get install -y openssh-server
RUN echo "rootocker!" | chpasswd
RUN useradd -m dpant && echo "dpant:dpant@123" | chpasswd && echo 'dpant ALL=(ALL) ALL' > /etc/sudoers.d/dpant
USER dpant
CMD /bin/bash
RUN touch /home/dpant/testing
RUN echo "hello world" > /home/dpant/testing
RUN chattr +i /home/dpant/testing
~
Quote:
chsh -s /usr/sbin/nologin root

Quote:
Sending build context to Docker daemon 3.072kB
Step 1/10 : FROM ubuntu:latest
---> 27941809078c
Step 2/10 : RUN apt-get update && apt-get -y install sudo
---> Using cache
---> 38c511cc70d8
Step 3/10 : RUN apt-get update && apt-get install -y openssh-server
---> Using cache
---> c084e975f28d
Step 4/10 : RUN echo "rootocker!" | chpasswd
---> Using cache
---> 6ef1c1a0763b
Step 5/10 : RUN useradd -m dpant && echo "dpant:dpant@123" | chpasswd && echo 'dpant ALL=(ALL) ALL' > /etc/sudoers.d/dpant
---> Using cache
---> 9219222f2996
Step 6/10 : USER dpant
---> Using cache
---> 77276ce995b4
Step 7/10 : CMD /bin/bash
---> Using cache
---> 3bc167c22966
Step 8/10 : RUN touch /home/dpant/testing
---> Using cache
---> 222ee7f258e1
Step 9/10 : RUN echo "hello world" > /home/dpant/testing
---> Using cache
---> 79ccfb6980af
Step 10/10 : RUN chattr +i /home/dpant/testing
---> Running in 528d399a26a5
chattr: Operation not permitted while setting flags on /home/dpant/testing
The command '/bin/sh -c chattr +i /home/dpant/testing' returned a non-zero code: 1
 
Old 08-13-2022, 10:18 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,622

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by pantdk View Post
Sorry "TB0ne" to miss the CODE tags.
Right...as you've said many times before, and *STILL* haven't done.
Quote:
Code:
FROM ubuntu:latest
RUN apt-get update && apt-get -y install sudo
RUN apt-get update && apt-get install -y openssh-server
RUN echo "rootocker!" | chpasswd
RUN useradd -m dpant && echo "dpant:dpant@123" | chpasswd && echo 'dpant ALL=(ALL) ALL' > /etc/sudoers.d/dpant
USER dpant
CMD /bin/bash
RUN touch /home/dpant/testing
RUN echo "hello world" > /home/dpant/testing
RUN chattr +i /home/dpant/testing
Code:
chsh -s /usr/sbin/nologin root

Sending build context to Docker daemon 3.072kB
Step 1/10 : FROM ubuntu:latest
---> 27941809078c
Step 2/10 : RUN apt-get update && apt-get -y install sudo
---> Using cache
---> 38c511cc70d8
Step 3/10 : RUN apt-get update && apt-get install -y openssh-server
---> Using cache
---> c084e975f28d
Step 4/10 : RUN echo "rootocker!" | chpasswd
---> Using cache
---> 6ef1c1a0763b
Step 5/10 : RUN useradd -m dpant && echo "dpant:dpant@123" | chpasswd && echo 'dpant ALL=(ALL) ALL' > /etc/sudoers.d/dpant
---> Using cache
---> 9219222f2996
Step 6/10 : USER dpant
---> Using cache
---> 77276ce995b4
Step 7/10 : CMD /bin/bash
---> Using cache
---> 3bc167c22966
Step 8/10 : RUN touch /home/dpant/testing
---> Using cache
---> 222ee7f258e1
Step 9/10 : RUN echo "hello world" > /home/dpant/testing
---> Using cache
---> 79ccfb6980af
Step 10/10 : RUN chattr +i /home/dpant/testing
---> Running in 528d399a26a5
chattr: Operation not permitted while setting flags on /home/dpant/testing
The command '/bin/sh -c chattr +i /home/dpant/testing' returned a non-zero code: 1
Actually, I have two websites with python and another on react. Both are hosted on docker through the jenkins pipeline and everything is working fine. Now we need to deploy the same container into the other environment using our jenkins pipeline. Therefore, we made the connectivity. But now the challenge is that they didn't want to share their code with anyone. Therefore, I am trying to block the Root direct access on the container. I try to with chattr but it is also not working also try to remove the root nologin but nothing works. I think container is required root privilege to bring up all the service.
Again, you omit things...who is "they", and "their code"??? Did you read the Docker documentation about security, and did you pay attention to the fact that even though you disable root logins, you can *STILL* type in "sudo" or "su" as a regular user, and get root privileges?
 
Old 08-13-2022, 12:54 PM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by pantdk View Post
they didn't want to share their code with anyone.
So you want to run that code without allowing to inspect it? I guess docker is not the right way to do that. By the way, what kind of code (language) is it? I'm afraid you have two possibilities: 1. put that code into the docker image, in that case it will be available (obviously within and together with that image). 2. do not share that code and it will not be accessible.
 
Old 08-18-2022, 09:12 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,647
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
It is also worth mentioning here that "root access," in the specific context of a container, is "just part of the overall illusion."

The host does not actually perceive that the process is running with uid=0, yet the process perceives that it is the master of its own world. (In fact, it has no idea what its host-side uid/gid "actually" is ... It neither knows nor cares 'how the trick is done,' nor even that a 'trick' is being performed.)

"Inside the phone booth, Clark Kent believes that he is Superman, because it appears that he can fly. And that is good enough for him."

Note also that some containerization technologies do give you the very-dangerous option to allow this status to be(!!!) "host-side actual," with all of the dreadful implications that this portends. But, AFAIK, "Docker is not one of them."

Last edited by sundialsvcs; 08-18-2022 at 09:23 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Disable remote root access but allow local root access-- possible? bskrakes Linux - Security 4 02-21-2019 04:02 PM
I want to grant 'shutdown' previlege to a non-root user to do directly from console jagadee76 Linux - General 6 12-29-2004 03:16 AM
Suse 9.1 Incorrect root password directly after install pinniewooh Linux - Laptop and Netbook 5 10-01-2004 01:04 AM
root files: create as root:root or root:wheel? pcass Linux - Security 1 02-07-2004 04:14 PM
Boot Directly into Root ? abw Red Hat 7 11-26-2003 06:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration