시 놀로지 UID GID - si nolloji UID GID

잡담 도커의 guid puid에 대해서 16

5

아래 올라온 글을 보고

강좌라고 하기에는 너무 거창하고 또 그럴 실력도 안되지만

삽질을 통해 배운 내용을 같이 알면 좋을 것 같아 글을 적어봅니다.

도커 컨테이너로 만들어진 앱을 실행할 때, 많은 경우(주로 linuxserver.io 이미지가 그러하죠) puid/pgid를 기본 환경변수로 받습니다.

리눅스는 제가 느끼기에 윈도우에 비해 소유자와 권한에 대해서 매우 철저한 편인데 도커로 실행하는 앱, 또 앱이 쓰고 읽는 파일관련 권한도 결국에는 리눅스 위에 돌아가므로 여기에 대한 권한을 명확히 해줘야 합니다.

도커 컨테이너를 실행하고 htop 같은 것으로 모니터링 해보면 해당 앱이 특정 소유자 권한으로 실행되는 것을 쉽게 확인할 수 있죠. 환경(라이브러리 같은)은 지정된 가상 공간(컨테이너)을 참조하지면 결국 앱의 실행은 호스트에서 돌아가는 다른 프로세스와 똑같습니다. 이 도커기반 앱 실행의 사용자/권한을 원하는대로 컨트롤 하기 위한 옵션이 puid/pgid 입니다.

그러면 도커에서 사용자 관리는 어떻게 하는가?

도커는 루트 권한으로 돌아가기 때문에 이미지에서 사용자/소유권 처리 안해주면 그냥 루트권한으로 실행됩니다. 하지만 이 경우 도커 앱이 생성하는 모든 폴더는 루트만 접근 가능해지는 등등... 불편한 점 뿐만 아니라 보안을 생각할때 전지 전능한 루트권한을 3자 프로세스에 주는 것은 매우 위험하므로 도커에서조차도 지양하도록 하고 있죠.

그러면 어떻게 하느냐? 뭐 정답이란 없겠지만 보통 이런 방식을 씁니다.

일단 임시 유저를 하나 만듭니다. 더미 유저라는 편이 더 맞겠네요. 보통 호스트에서 쓰지 않는 user:group uid:gid로 지정을 합니다. abc:abc 911:911 뭐 이런식으로... 911은 왠만한 호스트 시스템에서 사용하지 않을법한 그런 대역이라서 그런걸로 알고 있습니다. id는 호스트와 공유되고 namespace라 할까? abc 이런건 컨테이너 안에서만 유효하더군요.

여기까지만 이미지를 만들때 미리 작업해 놓습니다. 아직 사용자가 어떤 유저로 실행을 원하는지 모르니까요.

그런 다음 사용자가 지정한 PUID/PGID가 있으면 임시로 만들어진 abc 유저의 id 911을 사용자가 지정한 id로 변경해줍니다. 볼륨 매핑처럼 사용자 매핑 같은거죠. 이 부분은 앱을 실행할 때 처리됩니다. 그런 뒤에 이 abc유저를 가지고 파일폴더 권한 설정, 앱 실행 등등을 처리하도록 합니다. 하지만 유저가 지정하지 않으면? 그냥 abc에 911로 그냥 실행하는거죠. 

컨테이너에서 들어가서 볼륨 매핑된 폴더를 ls 해보면 보통 소유자가 abc로 되어 있을겁니다. 하지만 호스트의 매핑된 동일 폴더를 ls 해보면 약간 이야기가 다릅니다. 만약 puid/pgid를 줬다면 호스트의 사용자로, 아니라면 듣도보도 못한 911로 소유권이 종종 바뀌는 것을 경험하게 됩니다.

권한 관련 옵션이 없는 도커앱은 아래의 경우를 생각해 볼 수 있고

1) 루트로 실행됨 (혹시라도 앱에 악성코드나 취약점이 있어서 호스트로 접근 가능하다면 보안 위협)

2) 랜덤 생성된 유저로 실행됨 (php-fpm이나 셀레니움 같이 백엔드 데몬만 떠있어서 요청을 처리하고 돌려주는 단순 기능이면 상관없음)

권한 관리가 되어 있는데도 제대로 지정해주지 않는 다음의 경우도 있겠네요.

1) 귀찮아서 puid=0 pgid=0 넣어서 루트로 실행한다. 위의 1)번과 동일한 상황

2) 지정해주지 않는다. == 도커 컨테이너에게만 abc라고 알려진 911 유저가 활개치고 다닐 수 있음.

정리하면 이렇습니다.

제가 만들어 쓰는 도커 이미지도 간단한거 빼고는 다 puid/pgid를 입력하게 되어 있으니 왠만해서는 입력해서 쓰시는걸 추천합니다.

SIGNATURE

회원가입일 : 2004-08-24
쪽지는 바로바로 확인 못합니다.
 :)

서명 더 보기 서명 가리기

도커로 어떤 이미지를 이용해 컨테이너를 생성할 때

환경변수에 PUID, PGID를 넣는 경우가 있다.

대부분은 100, 100 넣어도 잘 되나, 어떤 이미지는 문제가 생긴다.

자신의 PUID, PGID 를 알아두면 두고두고 유용하다.

putty를 이용하거나, 앞서 설치한 wetty를 이용해 ssh 에 접속하자

도커 docker wetty 설치 (putty 의 웹 버전)

검은 화면에 접속 후 id, password를 친 후 nas에 접속하자

그 후

id xxxx

를 친후 엔터를 누른다. xxx는 평소에 nas에 접속하고, 도커 컨테이너를 만들때 쓰는 시놀로지 DSM의 아이디이다.

그럼 몇가지가 나오는데 그중 UID=PUID, GID=PGID 이니 메모해두고 두고두고 잘 쓰면 된다.

관련

Resource icon

  • Author SynoMan
  • Creation date 16. Nov 2019

First, you need to SSH into your NAS.

When you are in your NAS with the user you want the ID for, just type id and hit Enter.

Now you'll get something like this:

uid=1031(your_nas_user) gid=100(users) groups=100(users), 101(administrators)

From that, you can read your UID is 1031, user group is 100, administrator group is 101 (if this user as an administrator).

This information is useful and needed for instance when using certain Docker images.

For instance, you can also type id http if you want to know the ID and group for http user.

Related resources

시 놀로지 UID GID - si nolloji UID GID

Tutorial - How to SSH into a NAS?

In DSM go to Control Panel > Terminal & SNMP > Terminal tab Check Enable SSH service and set your port (it is strongly recommended not to use port 22, but to change it to something else). Open Terminal (Mac) (on Windows machine open CMD...

시 놀로지 UID GID - si nolloji UID GID
www.synoforum.com


시 놀로지 UID GID - si nolloji UID GID

Do you remember my article where I explained how to find your NAS user ID (PUID) and group ID (PGID)? In said article, you needed to use some terminal commands to find these values. Many of you have asked me if there is a method to find these values without having to use the terminal. In today’s article I will explain how to discover what are your NAS user ID (PUID) and group ID (PGID) without the need to use the terminal. And it will only take you 5 seconds :-).

  • STEP 1

Please Support My work by Making a Donation.

  • STEP 2

Make sure you have enabled Email Notifications in your NAS.

  • STEP 3

Go to Control Panel / Task Scheduler / Create / Scheduled Task / User-defined script. Follow the instructions in the image below.

시 놀로지 UID GID - si nolloji UID GID

  • STEP 4

Once you click on User-defined script a new window will open. Follow the instructions below:

  1. General: In the Task field type in “My UID and GID“. Uncheck the “Enabled” option and select your current NAS user from the drop-down menu.
  2. Schedule: Select Run on the following date then select “Do not repeat“.
  3. Task Settings: Check “Send run details by email“, add your email then copy paste the code below in the Run command area. After that click OK.
id

시 놀로지 UID GID - si nolloji UID GID

Note: Be careful enter only lowercase, not uppercase letters. id not ID.
Note: You can also use the command id user instead id to discover user PGID and PUID that are not in the admin group.

  • STEP 5

After you click OK on STEP 4, select your “My UID and GID” Task then click the “Run” tab. You will be asked to run My UID and GID – click Yes. Follow the instructions in the image below.

시 놀로지 UID GID - si nolloji UID GID

  • STEP 6

If you have correctly followed all the steps described above, you will receive an email with the user id and group id values.

시 놀로지 UID GID - si nolloji UID GID

Note: Remember to add your email address at STEP 4.
Note: In the Task field at STEP 4 type in id and remember to use only lower case letter not upper case.
Note: This information is useful and you may need it, for example, when using certain Docker containers. PUID values and PGID values are sometimes requested as Environment Variables for different Docker containers.
Note: These values often dictate the user/group that the Docker container will be running as. So if the Docker container accesses a specific drive share, with specific permissions, then the PUID and PGID values will specify the user/group that will be used by the Docker container.
Note: You can save and run this task whenever you need it.

This post was updated on Wednesday / August 10th, 2022 at 10:24 PM