Run The Bridge

docker Rotary 본문

Cloud/오픈소스

docker Rotary

anfrhrl5555 2022. 2. 23. 14:28
728x90
반응형

0. What is Container Image Signatures

컨테이너에 서명이라고 하니까 되게 낯설게 느껴진다.

 

내가 생각한 바로는 흔히들 인증서를 생성하고, 그 인증서에 대해 서명을 받는다.

 

Digicert와 같은 회사들이 이 인증서는 올바른 인증서라고 보장해준다.

그러면 해당 개념을 컨테이너로 가져와서 적용하면 어떻게 될까?

 

컨테이너 이미지가 변조되거나, 신뢰할 수 없을 때 우리는 서명을 통해 해당 컨테이너의 무결성 상태를 알 수 있다.

 

만약 변조되거나 신뢰할 수 없다면 서명이 똑바로 되어있지 않을 것이다.(예상)

 

결론적으로 컨테이너 이미지의 출처를 확인하고, 이미지의 무결성 확인과 시스템에서 검증된 이미지만 사용할 수 있도록 하는 것. 즉, 이미지 서명을 통해 신뢰성을 향상시킬 수 있다.


1. Docker Notary(공증인)

Docker Contents Trust(DCT)

docker registry에사 송, 수신되는 데이터에 대한 디지털 서명 기능을 제공한다.
Docker에서 사용되는 image를 서명/검증해주어 image에 대한 신뢰를 제공하는 기술이며 DCT를 통해 image를 push 하는 사람은 image를 서명할 수 있고 pull 받은 사용자는 image가 신뢰된 사용자에 의해 서명되어 있음을 보장할 수 있다. 또한 image의 tag를 통해 image의 무결성을 검증할 수 있다.

 

<기존 방식의 Docker image pull 과정>

 

<DCT Enabled 후 Docker image pull 과정>

Docker Contents Trust(DCT) 설정 방법

[DCT Enable 설정]
export DOCKER_CONTENT_TRUST=1

[DCT Disable 설정]
export DOCKER_CONTENT_TRUST=0

2. Docker Rotary

Notary service는 Notary Server 및 Signer로 구성되고 TUF라고 불리는 DB에 image가 저장된다.

 

Client는 저장소에 있는 image에 대해 Root, Targets, Snapsoht, MetaData를 생성하고 서명한 뒤에 Notary Server에 Metadata를 upload한다.

root@localhost ~/.docker/trust/tuf/10.10.0.50:5000/centos/metadata # ls
root.json  snapshot.json  targets.json  timestamp.json

이미지 서명 방법

※ 사전에 docker hub 같은 외부 저장소에서 image를 pull 했다는 가정하에 진행한다.

※ private Registry를 기준으로 테스트를 진행

※ 소프트웨어 및 환경구성

SW 버전
Docker v20.10.12
Notary v0.7.0
CentOS 7.9

※ github에 docker-compose로 작성된 notary를 이용하여 구축한다.

git clone https://github.com/theupdateframework/notary.git
cd notary
docker-compose up

- docker hub나 외부 저장소에서 image를 땡겨온다.
1. docker pull [이미지명:버전] 

- tag명을 개인 레지스트리로 변경한다.
2. docker tag [이미지명:버전] [레지스트리 IP]:5000/[이미지명:버전]

- 개인 저장소로 푸쉬
3. docker push [레지스트리 IP]:5000/[이미지명:버전] 

- export 설정
4. export DOCKER_CONTENT_TRUST_SERVER=https://notary-server:4443
   export DOCKER_CONTENT_TRUST=1  # DCT Enabled
# (DOCKER_CONTENT_TRUST_SERVER=https://notary.docker.io)

- 키 생성
5. docker trust key generate [이름]
※ docker trust key generate [이름] --dir [디렉토리]

- 이미지에 키 추가
6. docker trust signer add --key [이름].pub [이름] [레지스트리 IP]:5000/[이미지명:버전]

private registry에 push 했을 때 ‘Signing and pushing trust metadata’를 볼 수 있다.

 

최초로 이미지를 push하면 root key를 생성하는데, 한 번 최초로 생성한 이후로는 처음 생성한 password를 계속 사용한다.

생성한 root 키는 root 디렉토리 아래에 존재하며 cat으로 확인 시, 키의 상세내용을 확인할 수 있다.

/root/.docker/trust/private

에러 발생 시 해결방법

Error contacting notary server: x509

→ docker push 과정에서 인증이 되지 않은 상태로 image가 push된다.

Notary server를 바라볼 수 있도록 설정해주어야 한다.
cd ~/notary
cp fixtures/root-ca.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust
export DOCKER_CONTENT_TRUST_SERVER=https://notary-server:4443

/etc/hosts에 notary-server 등록

# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 notary-server

이미지 서명 확인 방법

이미지에 키를 추가하면 현재 Signers는 위에서 생성한 키 이름인 centos-7이 들어가 있다.

 

그리고 SignedTags 값은 현재 Repo Admin으로 tag까지 변경시켜주어야 한다.

sign태그 확인하는 방법

# docker trust inspect [레지스트리 IP]:5000/[이미지명:버전]
root@localhost ~ # docker trust inspect [레지스트리 IP]:5000/centos:7
[
    {
        "Name": "192.168.200.120:5000/centos:7",
        "SignedTags": [
            {
                "SignedTag": "7",
                "Digest": "e4ca2ed0202e76be184e75fb26d14bf974193579039d5573fb2348664deef76e",
                "Signers": [
                    "Repo Admin"
                ]
            }
        ],
        "Signers": [
            {
                "Name": "centos-7",
                "Keys": [
                    {
                        "ID": "c1fd18203b14656b096ef1afa2396766e81aa209b2f4f775250f9dd74e0a80ea"
                    }
                ]
            }
        ],
        "AdministrativeKeys": [
            {
                "Name": "Root",
                "Keys": [
                    {
                        "ID": "32e85613634f06d8557eff2baea840116da0ff5f4ca69282e94a1aa953db2293"
                    }
                ]
            },
            {
                "Name": "Repository",
                "Keys": [
                    {
                        "ID": "0bcbf8a86a23c90e76745ca6e73ce53352d42607ce5a95fdf0ff70885aba8b27"
                    }
                ]
            }
        ]
    }
]

이미지 사인

# docker trust sign [레지스트리 IP]:5000/[이미지명:버전]
docker trust sign [레지스트리 IP]:5000/centos:7
Signing and pushing trust metadata for [레지스트리 IP]:5000/centos:7
Existing signatures for tag 7 digest e4ca2ed0202e76be184e75fb26d14bf974193579039d5573fb2348664deef76e from:

재확인

# docker trust inspect [레지스트리 IP]:5000/[이미지명:버전]
root@localhost ~ # docker trust inspect [레지스트리 IP]:5000/centos:7
[
    {
        "Name": "192.168.200.120:5000/centos:7",
        "SignedTags": [
            {
                "SignedTag": "7",
                "Digest": "e4ca2ed0202e76be184e75fb26d14bf974193579039d5573fb2348664deef76e",
                "Signers": [
                    "centos-7"
                ]
            }
        ],
        "Signers": [
            {
                "Name": "centos-7",
                "Keys": [
                    {
                        "ID": "c1fd18203b14656b096ef1afa2396766e81aa209b2f4f775250f9dd74e0a80ea"
                    }
                ]
            }
        ],
        "AdministrativeKeys": [
            {
                "Name": "Root",
                "Keys": [
                    {
                        "ID": "32e85613634f06d8557eff2baea840116da0ff5f4ca69282e94a1aa953db2293"
                    }
                ]
            },
            {
                "Name": "Repository",
                "Keys": [
                    {
                        "ID": "0bcbf8a86a23c90e76745ca6e73ce53352d42607ce5a95fdf0ff70885aba8b27"
                    }
                ]
            }
        ]
    }
]

sign된 이미지의 무결성 검증방법

1. sign된 이미지인 centos7를 test/cenots:7 이라는 이름으로 tag을 변경한다.

root@localhost ~ # docker tag [레지스트리 IP]:5000/centos:7 test/centos:7

2. docker trust inspect로 확인해보면 sign이 되어있지 않다고 나온다.

root@localhost ~ # docker trust inspect test/centos:7
[]
No signatures or cannot access test/centos:7

3. 참고자료

https://www.trendmicro.com/vinfo/us/security/news/virtualization-and-cloud/docker-content-trust-what-it-is-and-how-it-secures-container-images

 

Docker Content Trust: What It Is and How It Secures Container Images - Security News

Docker Content Trust: What It Is and How It Secures Container Images Can your container image be trusted? Learn how Docker Content Trust (DCT) employs digital signatures for container image verification and manages trusted collections of content.

www.trendmicro.com

https://www.cncf.io/blog/2021/07/28/enforcing-image-trust-on-docker-containers-using-notary/

https://ikcoo.tistory.com/112

 

10. Notary Service 란?

Notary Service [Container image 인증 관련 글 목록] Notary Service 란? Docker Notary : Docker Content Trust (DCT) DCT를 사용해서 Dcoker Hub에 서명된 Trust Image Push 하기 Notary와 DCT를 사용해서 Priv..

ikcoo.tistory.com

https://ikcoo.tistory.com/115

 

13. Notary와 DCT를 사용해서 Private Registry에 서명된 Trust Image Push 하기

Notary와 DCT를 사용해서 Private Registry에 서명된 Trust Image Push 하기 [Container image 인증 관련 글 목록] Notary Service 란? Docker Notary : Docker Content Trust (DCT) DCT를 사용해서 Dcoker Hub에..

ikcoo.tistory.com


감사합니다!

728x90
반응형

'Cloud > 오픈소스' 카테고리의 다른 글

harbor  (0) 2022.02.22
CRI-O project  (0) 2022.02.21
Podman  (2) 2022.02.16
ArgoCD 구축해보기  (0) 2021.12.28
(Storage) Ceph Storage 구축해보기  (0) 2021.12.26
Comments