ããã«ã¡ã¯ã主ã«æ¤ç´¢å¨ããæ å½ãã¦ããã¨ã³ã¸ãã¢ã®ä¼è¤ã§ãã
ãã®è¨äºã¯ Enigmo Advent Calendar 2020 ã® 17 æ¥ç®ã®è¨äºã§ãã
ã¿ãªããã¯é©åãªDockerfileãæ¸ãã¦ãã¾ããï¼ã¨ããããã¤ã¡ã¼ã¸ã®ãã«ããåºæ¥ãã°ãããã¨ãªã£ã¦ãã¾ãããï¼ ä»åã¯èªæã®æå³ãè¾¼ãã¦ãæ¹ãã¦Dockefileã®ãã¹ããã©ã¯ãã£ã¹ã«ã¤ãã¦è§¦ãã¤ã¤ã ããããDockerfileãæ¸ããã«ã³ã³ããã¤ã¡ã¼ã¸ããã«ãããæ¹æ³ã¨ã³ã³ããã»ãã¥ãªãã£ã«é¢ããå 容ã«ã¤ãã¦ã¾ã¨ãã¦ã¿ã¾ããã
- Dockerfileã®ãã¹ããã©ã¯ãã£ã¹
- Dockerfileãæ¸ããªãã¨ããé¸æè¢
- ã»ãã¥ãªãã£ã«ã¤ãã¦
- ã¾ã¨ã
Dockerfileã®ãã¹ããã©ã¯ãã£ã¹
ãåç¥ã®æ¹ãå¤ãã¨æãã¾ããããã¡ããDocker社ãæ¨å¥¨ãããã¹ããã©ã¯ãã£ã¨ãªã£ã¦ãã¾ãã ãã£ãããªã®ã§äºä¾ã交ãã¦ããã¤ãããã¯ã¢ãããã¦ã¿ã¾ãã
ã¤ã¡ã¼ã¸ãµã¤ãºã¯æ¥µåå°ããããã
- 軽éãªãã¼ã¹ã¤ã¡ã¼ã¸ãé¸æãã
- Docker社ã®æ¨å¥¨ã¯debian
- ä¸è¦ãªããã±ã¼ã¸ã¯ã¤ã³ã¹ãã¼ã«ããªã
- ã¬ã¤ã¤ã¯ãªãã¹ãæ¸ãã
- RUN/COPY/ADDã ããã¬ã¤ã¤ãå¢ããã®ã§ããã使ç¨ããã¨ãã«æèãã¾ãããã
- RUNã§å®è¡ããã³ãã³ãã¯æ¥µå
&&
ã§é£çµãã - å¯è½ãªå ´åã¯ãã«ãã¹ãã¼ã¸ãã«ããå©ç¨ãã
- ADDã使ç¨ããã¢ã³ããã¿ã¼ã³(ä¸è¨ã®ä¾ã§ã¯ADDã«ãã£ã¦å§ç¸®ãã¡ã¤ã«ãå«ãã ã¬ã¤ã¤ãä½è¨ã«ä½æããã¦ãã¾ã)
-
ADD http://example.com/big.tar.xz /usr/src/things/ RUN tar -xJf /usr/src/things/big.tar.xz -C /usr/src/things RUN make -C /usr/src/things all
æ¨å¥¨ä¾
RUN mkdir -p /usr/src/things \ && curl -SL http://example.com/big.tar.xz \ | tar -xJC /usr/src/things \ && make -C /usr/src/things all
-
- RUNã§å®è¡ããã³ãã³ãã¯æ¥µå
- RUN/COPY/ADDã ããã¬ã¤ã¤ãå¢ããã®ã§ããã使ç¨ããã¨ãã«æèãã¾ãããã
ãã«ããã£ãã·ã¥ãæ´»ç¨ããã
ã¤ã¡ã¼ã¸ããã«ãããã¨ããDockerã¯Dockerfileã«æ¸ãããå½ä»¤ãä¸ããé çªã«å®æ½ãã¾ãã
ãã®éãåå½ä»¤æ¯ã«ãã£ãã·ã¥å
ã§åå©ç¨ã§ããæ¢åã®ã¤ã¡ã¼ã¸ãæ¢ãã¾ããããªããã°ä»¥éã®ãã£ãã·ã¥ã¯ç ´æ£ããã¾ãã
ãã®ãããæ´æ°é »åº¦ãé«ããã®ãDockerfileã®å¾ãã®æ¹ã«è¨è¼ãããã¨ãéè¦ã«ãªãã¾ãã
ä¾ãã°ä¸è¨ã¯app
ã¨ããã¢ããªã±ã¼ã·ã§ã³ã³ã¼ããå«ããã£ã¬ã¯ããªãã³ã³ããã«ã³ãã¼ãã
pip installã«ãã£ã¦å¿
è¦ãªã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ããä¾ã§ãã
COPY app /tmp/ RUN pip install --requirement /tmp/requirements.txt
- æ¨å¥¨ä¾
COPY requirements.txt /tmp/ RUN pip install --requirement /tmp/requirements.txt COPY app /tmp/
ä¸è¦ããã¨åè
ã®æ¹ãã¬ã¤ã¤ãå°ãªãåãè¯ãããã«è¦ãã¾ããã
app
é
ä¸ã®ã³ã¼ãã«å¤æ´ãå
¥ããã³ã«ã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«ãè¡ããã
ãã®åãã«ãæéã伸ã³ã¦ãã¾ãã¾ãã
Dockerfileã«é¢ããæ©ã¿ã©ãã
ããã¾ã§Dockerfileã«é¢ãããã¹ããã©ã¯ãã£ã¹ã«ã¤ãã¦è§¦ãã¦ãã¾ããããDockerfileãä½æãã¡ã³ãããã®ã£ã¦å¤§å¤ã§ã¯ãªãã§ããï¼
- ã©ã®ãã¼ã¹ã¤ã¡ã¼ã¸ã使ç¨ãã¹ããï¼
- ã¤ã¡ã¼ã¸ãµã¤ãºã大ãããªãããã
- ã¤ã¡ã¼ã¸ãµã¤ãºã®åæ¸ãé å¼µã£ã¦ããæéã溶ãã(éçºä½æ¥ã«å°å¿µãããã®ã«ããã)
- Dockerfileèªä½ã®ã¡ã³ããè¾ã
- ã¤ã¡ã¼ã¸ãµã¤ãºãå°ãããããã¨æãã¨Dockerfileèªä½ã®å¯èªæ§ãä¸ããã¨ããã¤ãã¿
- ãã¹ããã©ã¯ãã£ã¹ãæèãããã¨ãèªä½ãè¾ã
- ã»ãã¥ãªãã£çãªæ¸å¿µ
- 使ç¨ãããã¼ã¹ã¤ã¡ã¼ã¸ã«èå¼±æ§ãå«ã¾ãã¦ããªãããªã©
Dockerfileãæ¸ããªãã¨ããé¸æè¢
ããã§ç¶ãã¦ã®ã話ãBuildpackã«ã¤ãã¦ã§ãã ãã¡ããå©ç¨ãããã¨ã§Dockerfileãæ¸ããã¨ãªããã½ã¼ã¹ã³ã¼ãããã³ã³ããã¤ã¡ã¼ã¸ãçæãããã¨ãå¯è½ã«ãªãã¨ãããã®ã§ãã
Buildpack
- 2011å¹´ã«Herokuãèæ¡ãã
Cloud Foundry
ãGitlab
ãKnative
çã§æ¡ç¨ããã¦ããä»çµã¿- ä¾ãã°Gitlabã§ã¯Auto DevOps(Auto Build)ã§å©ç¨ããã¦ãã¾ã
- æ§ã ãªè¨èªã®Buildpackã使ã£ã¦ã¦ã¼ã¶ã®ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãã«å¯¾ãã¦ããå¤å®ããããã«ããããã¤ã¡ã¼ã¸åãã¨ãã£ãä¸é£ã®æµããå®æ½ããäºã«ãã£ã¦ãåºç¤ä¸ã§åä½å¯è½ãªå½¢ã«ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ããçµã¿ç«ã¦ã
Cloud Native Buildpacks
- ä¸è¨ã®Herokuãªãªã¸ãã«ã¨å¼ã°ããBuildpackãç¹å®ã®å®è¡åºç¤ã§ããåä½ããªãã¨ããã§ãã¡ãªããããã£ãã®ã«å¯¾ããDockerã®æ¥éãªæ®åãèæ¯ã«ãOCIã¤ã¡ã¼ã¸ã®ãããªã³ã³ããæ¨æºãæ¡ç¨ããã¤ã¡ã¼ã¸ãä½æãããã¨å§ã¾ã£ãã®ãCloud Native Buildpacks(以é CNBã¨ç¥) Projectã§ãã
- Herokuã¨Pivotalãä¸å¿ã¨ãªã£ã¦2018å¹´1æã«CNCFåä¸ã§ã¹ã¿ã¼ãããç¾æç¹ã§CNCFã®Sandboxããã¸ã§ã¯ãã¨ããç«ã¡ä½ç½®ã«ãªã£ã¦ãã¾ã
- 以éã¯ãã¡ãã®CNBã«ã¤ãã¦ã®æ¦è¦ã«ã¤ãã¦è¨è¼ãã¾ã
CNBã®ä»çµã¿
CNBãå©ç¨ãã¦ã¤ã¡ã¼ã¸ãçæããéã¯ãã«ãã¼
ã¨ãããã®ãæå®ãã¾ãã
ãã«ãã¼ã¯ã¢ããªã®ãã«ãæ¹æ³ã«é¢ãããã¹ã¦ã®é¨åã¨æ
å ±ããã³ãã«ããã¤ã¡ã¼ã¸ã¨ãªã£ã¦ãããè¤æ°ã®buildpack
ãlifecycle
ãstack
ã§æ§æããã¦ãã¾ãã
- buildpack
- ã½ã¼ã¹ã³ã¼ããæ¤æ»ããã¢ããªã±ã¼ã·ã§ã³ãã©ããã«ããå®è¡ãããã決ãã
- lifecycle
- buildpackã®å®è¡ã調æ´ããæçµçãªã¤ã¡ã¼ã¸ãçµã¿ç«ã¦ã
- stack
- ãã«ãåã³å®è¡ç°å¢ç¨ã®ã³ã³ããã¤ã¡ã¼ã¸ã®ãã¢
ãã¢
åºæ¬çã«CNBãå©ç¨ãã¦éç¨ãã¦ããéã«ã¯ãèªåã®ãã«ãã¼ãä½æãããã¨ã«ãªãã¨æãã¾ãã ä»åã¯ã試ãã¨ãããã¨ã§ããã§ã«ãããã«ãã¼ã使ã£ã¦è©¦ãã¦ã¿ããã¨æãã¾ãã
- åææ¡ä»¶
- ãã¼ã«ã«ç°å¢ã«
Docker
åã³Buildpack
ãã¤ã³ã¹ãã¼ã«æ¸ã¿ã§ãããã¨
- ãã¼ã«ã«ç°å¢ã«
- ãµã³ãã«ã³ã¼ã
- Flaskãå©ç¨ããWebã¢ããªã±ã¼ã·ã§ã³(åç´ã«Hello Worldã¨åºåããã ãã®ãã®)
- æ§æã¨ãã¦ã¯ä¸è¨ã®éãã§æä½éã®ãã¡ã¤ã«ã®ã¿é ç½®ãã¦ãã¾ãã
. âââ requirements.txt âââ src âââ __init__.py âââ app.py âââ templates âââ index.html
- ãã«ã
ããã§ã¯packã³ãã³ãã使ã£ã¦ãã«ããã¦ã¿ã¾ãããã
$ pack build sample-cnb:0.0.1 Please select a default builder with: pack set-default-builder <builder-image> Suggested builders: Google: gcr.io/buildpacks/builder:v1 Ubuntu 18 base image with buildpacks for .NET, Go, Java, Node.js, and Python Heroku: heroku/buildpacks:18 heroku-18 base image with buildpacks for Ruby, Java, Node.js, Python, Golang, & PHP Paketo Buildpacks: paketobuildpacks/builder:base Ubuntu bionic base image with buildpacks for Java, .NET Core, NodeJS, Go, Ruby, NGINX and Procfile Paketo Buildpacks: paketobuildpacks/builder:full Ubuntu bionic base image with buildpacks for Java, .NET Core, NodeJS, Go, PHP, Ruby, Apache HTTPD, NGINX and Procfile Paketo Buildpacks: paketobuildpacks/builder:tiny Tiny base image (bionic build image, distroless-like run image) with buildpacks for Java Native Image and Go Tip: Learn more about a specific builder with: pack inspect-builder <builder-image>
packã³ãã³ããå®è¡ããã¨ä¸è¨ã®ããã«ãã«ãã¼ãæå®ããã¨è¨ããã¾ãã ä»åã¯ããã§ããããããã¦ãã Google Cloud Buildpacks ãå©ç¨ãã¦å®è¡ãã¾ãã
$ pack build sample-cnb:0.0.1 --builder gcr.io/buildpacks/builder:v1 v1: Pulling from buildpacks/builder Digest: sha256:f0bb866219220921cbc094ca7ac2baf7ee4a7f32ed965ed2d5e2abbf20e2b255 Status: Image is up to date for gcr.io/buildpacks/builder:v1 v1: Pulling from buildpacks/gcp/run Digest: sha256:83eb67ec38bb38c275d732b07775231e7289e0e2b076b12d5567a0c401873eb7 Status: Image is up to date for gcr.io/buildpacks/gcp/run:v1 ===> DETECTING google.python.runtime 0.9.1 google.python.missing-entrypoint 0.9.0 google.utils.label 0.0.1 ===> ANALYZING Previous image with name "sample-cnb:0.0.1" not found ===> RESTORING ===> BUILDING === Python - Runtime ([email protected]) === Using runtime version from .python-version: 3.7.8 Installing Python v3.7.8 Upgrading pip to the latest version and installing build tools -------------------------------------------------------------------------------- Running "/layers/google.python.runtime/python/bin/python3 -m pip install --upgrade pip setuptools wheel" Collecting pip Downloading pip-20.3.1-py2.py3-none-any.whl (1.5 MB) Collecting setuptools Downloading setuptools-51.0.0-py3-none-any.whl (785 kB) Collecting wheel Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB) Installing collected packages: pip, setuptools, wheel Attempting uninstall: pip Found existing installation: pip 20.1.1 Uninstalling pip-20.1.1: Successfully uninstalled pip-20.1.1 Attempting uninstall: setuptools Found existing installation: setuptools 47.1.0 Uninstalling setuptools-47.1.0: Successfully uninstalled setuptools-47.1.0 Successfully installed pip-20.3.1 setuptools-51.0.0 wheel-0.36.2 Done "/layers/google.python.runtime/python/bin/python3 -m pip inst..." (6.427479028s) === Python - pip ([email protected]) === Failure: (ID: 194879d1) Failed to run /bin/build: for Python, an entrypoint must be manually set, either with "GOOGLE_ENTRYPOINT" env var or by creating a "Procfile" file -------------------------------------------------------------------------------- Sorry your project couldn't be built. Our documentation explains ways to configure Buildpacks to better recognise your project: -> https://github.com/GoogleCloudPlatform/buildpacks/blob/main/README.md If you think you've found an issue, please report it: -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new -------------------------------------------------------------------------------- ERROR: failed to build: exit status 1 ERROR: failed to build: executing lifecycle: failed with status code: 145
ä»åº¦ã¯ä¸è¨ã®ãããªã¨ã©ã¼ãåºåããã¾ãã
ã©ãããDockerfileã®entrypointã«ç¸å½ãã GOOGLE_ENTRYPOINT
ãè¨å®ããå¿
è¦ãããããã§ãã
該å½ã®ãªãã·ã§ã³ã追å ãã¦ä¸è¨ã®éãåãã©ã¤ãã¦ã¿ã¾ãã
$ pack build sample-cnb:0.0.1 --builder gcr.io/buildpacks/builder:v1 --env GOOGLE_ENTRYPOINT="flask run --host 0.0.0.0 --port 5000" ãçç¥ã Adding cache layer 'google.python.pip:pip' Adding cache layer 'google.python.pip:pipcache' Successfully built image sample-cnb:0.0.1
ä¸è¨ã®ããã«Successfully
ã¨åºåãããã°ç¡äºã«ã³ã³ããã¤ã¡ã¼ã¸ã®ãã«ãã¯å®äºãã¦ãã¾ãã
ä½æãããã¤ã¡ã¼ã¸ã確èªãã¦ã¿ã¾ãããã
REPOSITORY TAG IMAGE ID CREATED SIZE sample-cnb 0.0.1 4c60a192da62 40 years ago 289MB
sample-cnb
ã¨ããã¤ã¡ã¼ã¸ãä½æããã¦ãããã¨ã確èªã§ãã¾ããã
ããã§æ°ã«ãªãã®ã¯ä½ææ¥ã40 years ago
ã¨ãªã£ã¦ãããã¨ã§ãã
ããã«ã¤ãã¦ã¯å
¬å¼ãµã¤ãã«è¨è¼ãããã¾ãããã
ã©ãããåç¾å¯è½ãªãã«ããç®çã¨ããæå³çãªè¨è¨ã®ããã§ãã
- ã³ã³ããèµ·å
ãã«ãããã³ã³ãããèµ·åãã¦æ£å¸¸ã«åä½ãããã¨ã確èªãã¾ãã ä¸è¨ã³ãã³ãã§ã³ã³ãããèµ·åãã¦ã
$ docker run --rm -p 5000:5000 -e FLASK_ENV=development sample-cnb:0.0.1
ãã¡ãã«ã¢ã¯ã»ã¹ããã¨ãä¸è¨ã®ç»é¢ã表示ããããã¨ã確èªã§ãã¾ããã
Dockerfileã使ã£ããã«ã
æå¾ã«æ¯è¼ã®ããã«Dockerfileãå©ç¨ãããã«ããè¡ãã¾ãã- Dockerfileã®æºå
FROM python:3.7 WORKDIR /app COPY requirements.txt /app RUN pip install -r requirements.txt COPY src /app/ ENV FLASK_APP=/app/app.py ENTRYPOINT ["flask", "run"] CMD ["--host", "0.0.0.0", "--port", "5000"]
ãã«ã
$ docker build -t sample-df:0.0.1 .
æ¯è¼
Dockerfileãã¼ã¹ã§ãã«ãããã¤ã¡ã¼ã¸ã¯ä¸è¨ã®éãã¨ãªãã¾ãã CNBã§ä½æããã¤ã¡ã¼ã¸ã®æ¹ã軽éãªOSãå©ç¨ããã¦ãããã¨ãåããã¾ã
REPOSITORY TAG IMAGE ID CREATED SIZE sample-df 0.0.1 9a5c14fd1846 14 seconds ago 928MB
CNBã®ã¡ãªãã
CNBã®ã¡ãªããããã£ã¨ã¾ã¨ããã¨ä¸è¨ã®ãããªæãã«ãªããã¨æãã¾ãã
- éçºã«æ³¨åã§ãã
- éçºè ã¯Dockerfileãä½æãã¡ã³ããããã¨ããéæ¾ããã
- æç¶å¯è½ãªéç¨
- ã¹ã±ã¼ã©ãã«ãªã»ãã¥ãªãã£å¯¾å¿
- æ£å¨ããã¡ãªDockerfileãã¹ã¦ã«ããã¦èå¼±æ§å¯¾å¿ãªã©ãã¦ããã®ã¯ç¾å®çã§ã¯ãªã
- ã¹ã±ã¼ã©ãã«ãªã»ãã¥ãªãã£å¯¾å¿
ã»ãã¥ãªãã£ã«ã¤ãã¦
ç§ã®ã³ã³ããã»ãã¥ãªãã£ã«å¯¾ããç¥èã¨ãã¦ã¯ãä¸è¨ã®ãããªã¬ãã«ã®ãã®ã§ããã
- ã³ã³ããã«ãããã»ãã¥ãªãã£ã£ã¦ä½ããã°ããã®ï¼
- ããããã³ã³ããã«éããä½ãããã°ã»ãã¥ãªãã£ã¡ããã¨ãã¦ã¾ãã£ã¦è¨ããã®ï¼
ã¨ãã訳ã§ã³ã³ããã«ãããã»ãã¥ãªãã£åºæºããã¼ã«ã¨ãã¦ã¯ã©ããã£ããã®ãããã®ãã調æ»ããçµæãã¾ã¨ãã¾ãã
æ¦è¦
ã³ã³ããã«ãããã»ãã¥ãªãã£åºæº
- CISãã³ããã¼ã¯ 1
- ã»ãã¥ãªãã£ã«é¢ããåºæºã容æã«å®è¡å¯è½ãªãã³ããã¼ã¯ã¨ãã¦æä¾
- ããã®èª¬æãåãããããã£ãã§ã
- NIST
- ã³ã³ããã»ãã¥ãªãã£ã«é¢ããåºæº
ã³ã³ããã®èå¼±æ§ã¹ãã£ã³
- ã³ã³ããç°å¢ããªã³ãã¬åæ§ã«OSã®ã©ã¤ãã©ãªãããã±ã¼ã¸ãªã©ããæ§æããããããããã¾ã§éãèå¼±æ§å¯¾çãå¿ é ã§ãã
- ããã«å ãã¦ã³ã³ããã¤ã¡ã¼ã¸ãã©ã³ã¿ã¤ã ç°å¢ã®èå¼±æ§ã«ãé æ ®ããå¿ è¦ããã
ãã¼ã«ã®æ´»ç¨
ã¨ããããæ軽ã«ä¸è¨ã®ã»ãã¥ãªãã£åºæºãã§ãã¯ã¨èå¼±æ§ã¹ãã£ã³ãè¡ãããã¨ããã¢ããã¼ã·ã§ã³ã®å ã以åããæ°ã«ãªããã¼ã«ãããã¯ã¢ãããã¾ããã
dockle
https://github.com/goodwithtech/dockle
æ¦è¦
- CIS Benchmarkã«å¯¾å¿
- ãã¹ããã©ã¯ãã£ã¹ã®ãã§ãã¯
使ãæ¹
dockle [ã¤ã¡ã¼ã¸å]
trivy
https://github.com/aquasecurity/trivy
- æ¦è¦
- ã³ã³ããã®èå¼±æ§ã¹ãã£ã³ãã¼ã«
- 使ãæ¹
trivy [ã¤ã¡ã¼ã¸å]
ãã¢
ããã§ä¸è¨ã§ä½æããã³ã³ããã¤ã¡ã¼ã¸(Dockerfileããä½æããã¤ã¡ã¼ã¸ã¨CNBã§ä½æããã¤ã¡ã¼ã¸)ãããããã®ãã¼ã«ã«ãããå ´åã«ã©ããã£ãçµæã«ãªãã確èªãã¦ã¿ããã¨æãã¾ãã
Dockerfileãã¼ã¹
ã¾ãã¯Dockerfileãããã«ãããã¤ã¡ã¼ã¸ã®æ¹ã§ãã
- dockle
- WARNã¬ãã«ã1件æ¤ç¥ããã¾ããã
$ dockle sample-df:0.0.1 WARN - CIS-DI-0001: Create a user for the container * Last user should not be root INFO - CIS-DI-0005: Enable Content trust for Docker * export DOCKER_CONTENT_TRUST=1 before docker pull/build INFO - CIS-DI-0006: Add HEALTHCHECK instruction to the container image * not found HEALTHCHECK statement INFO - CIS-DI-0008: Confirm safety of setuid/setgid files * setuid file: usr/bin/chfn urwxr-xr-x * setgid file: usr/bin/ssh-agent grwxr-xr-x * setuid file: usr/lib/openssh/ssh-keysign urwxr-xr-x * setuid file: bin/umount urwxr-xr-x * setgid file: usr/bin/wall grwxr-xr-x * setuid file: bin/mount urwxr-xr-x * setuid file: usr/bin/gpasswd urwxr-xr-x * setuid file: usr/bin/passwd urwxr-xr-x * setgid file: usr/bin/chage grwxr-xr-x * setuid file: bin/su urwxr-xr-x * setuid file: bin/ping urwxr-xr-x * setgid file: usr/bin/expiry grwxr-xr-x * setuid file: usr/bin/newgrp urwxr-xr-x * setuid file: usr/bin/chsh urwxr-xr-x * setgid file: sbin/unix_chkpwd grwxr-xr-x
- trivy
- ãã¡ãã¯å¤§éã®åºåçµæã表示ããããããµããªã®ã¿è²¼ã£ã¦ããã¾ãã CRITICALãªãã®ã69件æ¤ç¥ããã¦ãããã¨ãåããã¾ãã
$ trivy sample-df:0.0.1 sample-df:0.0.1 (debian 10.2) ============================= Total: 2401 (UNKNOWN: 23, LOW: 1291, MEDIUM: 520, HIGH: 498, CRITICAL: 69)
CNBãã¼ã¹
ç¶ãã¦CNBã§ãã«ãããã¤ã¡ã¼ã¸ã®æ¹ã確èªãã¦ã¿ã¾ãã
- dockle
- ãã¡ãã¯WARNã¬ãã«ã®ãã®ã¯1件ããªããINFOã¬ãã«ã®ãã®ã ããæ¤ç¥ããã¾ããã
$ dockle sample-cnb:0.0.1 INFO - CIS-DI-0005: Enable Content trust for Docker * export DOCKER_CONTENT_TRUST=1 before docker pull/build INFO - CIS-DI-0006: Add HEALTHCHECK instruction to the container image * not found HEALTHCHECK statement INFO - CIS-DI-0008: Confirm safety of setuid/setgid files * setgid file: usr/bin/expiry grwxr-xr-x * setuid file: bin/umount urwxr-xr-x * setgid file: usr/bin/chage grwxr-xr-x * setuid file: usr/bin/newgrp urwxr-xr-x * setgid file: usr/bin/wall grwxr-xr-x * setuid file: usr/bin/chsh urwxr-xr-x * setuid file: bin/su urwxr-xr-x * setuid file: usr/bin/passwd urwxr-xr-x * setuid file: usr/bin/gpasswd urwxr-xr-x * setuid file: usr/bin/chfn urwxr-xr-x * setuid file: bin/mount urwxr-xr-x * setgid file: sbin/unix_chkpwd grwxr-xr-x * setgid file: sbin/pam_extrausers_chkpwd grwxr-xr-x
- trivy
- ãã¡ãããµããªã®ã¿è²¼ãã¾ãããCRITICALã«é¢ãã¦ã¯0件ã¨ãªã£ã¦ãã¾ã
$ trivy sample-cnb:0.0.1 2020-12-14T19:22:18.244+0900 INFO Detecting Ubuntu vulnerabilities... sample-cnb:0.0.1 (ubuntu 18.04) =============================== Total: 75 (UNKNOWN: 0, LOW: 53, MEDIUM: 20, HIGH: 2, CRITICAL: 0)
ãã®çµæãããGoogle Cloud Buidpackãå©ç¨ãã¦ãã«ãããã¤ã¡ã¼ã¸ã®æ¹ã軽éãã¤ã»ãã¥ã¢ãªç°å¢ã§ãããã¨ãåããã¨æãã¾ãã
CIã¸ã®çµã¿è¾¼ã¿
ä¸ã§ç´¹ä»ãããã¼ã«ã¯ããããCIã«çµã¿è¾¼ãã§ä½¿ç¨ãããã¨ãæ³å®ãã¦ä½ããã¦ãã¾ãã ä¸è¨ã®ããã«ãªãã·ã§ã³ãæå®ãã¦ä½¿ããã¨ã§ãCIã®ã¿ã¤ãã³ã°ã§å®è¡&確èªããããããªã£ã¦ãã¾ãã
- dockle
dockle --exit-code 1 [ã¤ã¡ã¼ã¸å]
- trivy
trivy --exit-code 1 --severity CRITICAL --no-progress [ã¤ã¡ã¼ã¸å]
ã¾ã¨ã
ä»åã¯Dockerfileã®ãã¹ããã©ã¯ãã£ã¹ã®ããããã¨ãCNBãå©ç¨ããã³ã³ããã¤ã¡ã¼ã¸ã®ãã«ãæ¹æ³ãã»ãã¥ãªãã£ã«é¢ãã¦ããã£ã¨ã¾ã¨ãã¦ã¿ã¾ããã
ä»å¾ãã³ã³ãããã¼ã¹ã®ã¢ããªã±ã¼ã·ã§ã³éçºãé²ãã¨ã ããã¾ã§å人ããã¼ã ã¬ãã«ã§ä»»ãã¦ããDockerfileã®ä½æã管çãç ´ç¶»ããã®ã§ã¯ã¨æãã¾ããã CNBã«ã¯çµç¹ã¨ãã¦çµ±å¶ã®ã¨ããã³ã³ããä½æãã»ãã¥ãªãã£åºæºãç¶ç¶çã«æºãããã¨ã®æ段ãæä¾ããã¦ããã®ã§ã ãã®è¾ºãããã¾ãæ´»ç¨ãã¦ããå¿ è¦æ§ãæãã§ãã¾ãã
ã»ãã¥ãªãã£ã«ã¤ãã¦ãæ¤ç¥ã®ä»çµã¿ã ãã§ãªããæ¥ã ã®éç¨ã®ä¸ã§ããã«å¯¾å¿ãã¦ãããã¨ãããã¨ã大äºã ã¨æãã®ã§ã ä»å¾ã試è¡é¯èª¤ããªããå°ããã¤åé²ãã¦ãããã°ã¨æã£ã¦ãã¾ãã
ææ¥ã®è¨äºã®æ å½ã¯ã¤ã³ãã©ã¨ã³ã¸ãã¢ã®å±±å£ããã§ããã楽ãã¿ã«ã
æ ªå¼ä¼ç¤¾ã¨ãã°ã¢ æ£ç¤¾å¡ã®æ±äººä¸è¦§
-
CIS(Center for Internet Security)ã¨ã¯ãç±³å½ã®NSA(National Security Agency/å½å®¶å®å ¨ä¿éå±)ãDISA(Difense Informaton Systems Agency/å½é²æ å ±ã·ã¹ãã å±)ãNIST(National Institute of Standards and Technology/ç±³å½ç«æ¨æºæè¡ç 究æ)ãªã©ã®ç±³å½æ¿åºæ©é¢ã¨ãä¼æ¥ãå¦è¡æ©é¢ãªã©ãååãã¦ãã¤ã³ã¿ã¼ãããã»ã»ãã¥ãªãã£æ¨æºåã«åãçµãå£ä½ã®å称↩