프로젝트를 진행하며 발견된 도커의 보안 취약점 정리

왜 Docker에 TLS를 적용해야하는가

docker에서 TLS를 적용하는 이유는 도커 데몬과 도커 클라이언트는 .scok 파일을 사용하여 통신한다.
로컬 외 다른 서버에서 도커 데몬을 컨트롤한다면 TLS로 암호화 및 인증을 처리 할 수 있다.

 

TLS 미적용 상태로 docker 데몬과 통신하기

window 로컬에서 wsl의 도커 데몬과 통신 한다.

 

도커 데몬 외부 포트실행

도커가 정지된 상태에서 도커 실행

# 모든 ip로부터 2375포트로 통신을 받고는다. 
$ sudo dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375

 

window에서 docker 데몬과 통신

wsl의 아이피 확인
ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet <wsl IP>

window의 cmd에서 curl로 컨테이너 목록확인

C:\>curl http://<wsl IP>:2375/containers/json

[{"Id":"8cfb351c87f181fa63481528f3d612a2b2a50445674b524e096c1917882deb7a","Names":["/syslog-server"],"Image":"rsyslog/syslog_appliance_alpine","ImageID":"sha256:93bb7d1f5f5a0e84f1f78c4f86ae8cf9506a2c00236155c4b5f068412d93613e","Command":"/home/appliance/starter.sh rsyslog","Created":1756086572,"Ports":[{"IP":"0.0.0.0","PrivatePort":514,"PublicPort":514,"Type":"udp"},{"IP":"::","PrivatePort":514,"PublicPort":514,"Type":"udp"},{"IP":"0.0.0.0","PrivatePort":514,"PublicPort":514,"Type":"tcp"},{"IP":"::","PrivatePort":514,"PublicPort":514,"Type":"tcp"}],"Labels":{"maintainer":"rgerhards@adiscon.com"},"State":"running","Status":"Up 4 seconds","HostConfig":{"NetworkMode":"syslog-net"},"NetworkSettings":{"Networks":{"syslog-net":{"IPAMConfig":null,"Links":null,"Aliases":null,"MacAddress":"2a:50:7f:6a:f1:b3","DriverOpts":null,"GwPriority":0,"NetworkID":"80450e2a3ccc34fd5b4f25d8c8773ce9e1cb355bcf7f5a31466b63cfdeeb036f","EndpointID":"5ab5770be84d72eac990c6a3610f02dcba3f36cf843a15290aaa50f4bdfe1b84","Gateway":"172.18.0.1","IPAddress":"172.18.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"DNSNames":null}}},"Mounts":[{"Type":"volume","Name":"2bba3f793ff91b48fc2ee3895dd87f9cc0ea86502948de174d3196a7ccdef457","Source":"","Destination":"/config","Driver":"local","Mode":"","RW":true,"Propagation":""},{"Type":"volume","Name":"1117767f3b009589cd0a9ad4421ea2732c8788fc0cc807469944d45bca0c44c0","Source":"","Destination":"/logs","Driver":"local","Mode":"","RW":true,"Propagation":""},{"Type":"bind","Source":"/var/log/syslog-docker","Destination":"/var/log","Mode":"","RW":true,"Propagation":"rprivate"},{"Type":"volume","Name":"47ba7ab691d625330627f900cf3fa9fcb7ab48abe2c09075049025c9e92aa02c","Source":"","Destination":"/work","Driver":"local","Mode":"","RW":true,"Propagation":""}]}]

 

TLS 적용

 

사설인증서 생성 및 적용

CA 생성

# 1. CA 개인키 생성
openssl genrsa -out ca.key 4096

# 2. CA 자체 서명 인증서 생성 (유효기간 10년)
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.pem

 

서버 인증서 생성 (CA 사용)

# 1. 서버 개인키 생성
openssl genrsa -out server.key 2048

# 2. 서버 CSR (Certificate Signing Request) 생성
openssl req -new -key server.key -out server.csr

# 3. CA로 서버 인증서 서명
openssl x509 -req -in server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out server.crt -days 365 -sha256
cp server.crt /etc/docker/certs.d/server-cert.pem
cp server.key /etc/docker/certs.d/server-key.pem
cp ca.pem /etc/docker/certs.d/ca.pem

/etc/docker/damon.json

{
  "tls": true,
  "tlsverify": true,
  "tlscacert": "/etc/docker/certs.d/ca.pem",
  "tlskey": "/etc/docker/certs.d/server-key.pem",
  "tlscert": "/etc/docker/certs.d/server-cert.pem"
}

 

도커 재기동

sudo dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375

# systemctl에 등록되어있다면
systemctl daemon-reload
systemctl restart docker

 


 

테스트

window CMD

C:\>curl  <wsl IP>:2375/containers/json
Client sent an HTTP request to an HTTPS server.

C:\>

wsl docker

2025/08/25 11:55:03 http: TLS handshake error from <window IP>:60942: client sent an HTTP request to an HTTPS server

+ Recent posts