ÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÇ徲ɨÃèºÍÎó²îÐÞ¸´
DockerÒѳÉΪ¿ª·¢ºÍÔËάְԱ²»¿É»òȱµÄ¹¤¾ßÖ®Ò»£¬ÓÉÓÚËüÄܹ»°ÑÓ¦ÓóÌÐòºÍÒÀÀµÏî´ò°üµ½ÈÝÆ÷ÖУ¬´Ó¶ø»ñµÃ¿ÉÒÆÖ²ÐÔ¡£È»¶ø£¬ÔÚʹÓÃDockerʱ£¬ÎÒÃDZØÐè×¢ÖØÈÝÆ÷µÄÇå¾²ÐÔ¡£ÈôÊÇÎÒÃDz»×¢ÖØ£¬ÈÝÆ÷ÖеÄÇå¾²Îó²î¿ÉÄܻᱻʹÓ㬵¼ÖÂÊý¾Ýй¶¡¢¾Ü¾øЧÀ͹¥»÷»òÆäËûΣÏÕ¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÌÖÂÛÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÇ徲ɨÃèºÍÎó²îÐÞ¸´£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
ÈÝÆ÷µÄÇ徲ɨÃè
ÈÝÆ÷µÄÇ徲ɨÃèÊÇÖ¸¼ì²âÈÝÆ÷ÖеÄDZÔÚÇå¾²Îó²î£¬²¢ÊµÊ±½ÓÄɲ½·¥¾ÙÐÐÐÞ¸´¡£ÈÝÆ÷ÖеÄÇ徲ɨÃè¿ÉÒÔͨ¹ýʹÓÃһЩ¿ªÔ´¹¤¾ßÀ´ÊµÏÖ¡£
1.1 ʹÓÃDocker Bench¾ÙÐÐÇ徲ɨÃè
Docker BenchÊÇÒ»ÖÖ¿ªÔ´¹¤¾ß£¬¿ÉÒÔ¾ÙÐÐDockerÈÝÆ÷µÄ»ù±¾Çå¾²¼ì²é¡£ÏÂÃæÊÇʹÓÃDocker Bench¾ÙÐÐÈÝÆ÷Ç徲ɨÃèµÄ°ì·¨£º
£¨1£©Ê×ÏÈ£¬×°ÖÃDocker Bench
docker pull docker/docker-bench-security
µÇ¼ºó¸´ÖÆ
£¨2£©È»ºó¶ÔÈÝÆ÷¾ÙÐÐɨÃè
docker run -it --net host --pid host --userns host --cap-add audit_control -e DOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST -v /etc:/etc:ro -v /var/lib:/var/lib:ro -v /usr/bin/docker-containerd:/usr/bin/docker-containerd:ro -v /usr/bin/docker-runc:/usr/bin/docker-runc:ro -v /usr/lib/systemd:/usr/lib/systemd:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --label docker_bench_security docker/docker-bench-security
µÇ¼ºó¸´ÖÆ
£¨3£©ÆÚ´ýɨÃèÍê³É£¬²¢Éó²é±¨¸æ
ɨÃèÍê³Éºó£¬ÎÒÃÇ¿ÉÒÔÉó²é±¨¸æ£¬²¢¾ÙÐÐÏìÓ¦µÄÐÞ¸´²½·¥¡£
1.2 ʹÓÃClair¾ÙÐÐÇ徲ɨÃè
ClairÊÇÒ»ÖÖ¿ªÔ´¹¤¾ß£¬¿ÉÒÔɨÃèDocker¾µÏñºÍÈÝÆ÷£¬ÒÔ¼ì²âÆäÖеÄÇå¾²Îó²î¡£ÏÂÃæÊÇʹÓÃClair¾ÙÐÐÈÝÆ÷Ç徲ɨÃèµÄ°ì·¨£º
£¨1£©Ê×ÏÈ£¬×°ÖÃClair
docker pull quay.io/coreos/clair:latest
µÇ¼ºó¸´ÖÆ
£¨2£©È»ºó£¬Æô¶¯Clair
docker run -p 6060:6060 -d --name clair quay.io/coreos/clair:latest
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
£¨3£©½ÓÏÂÀ´£¬×°ÖÃclairctl
go get -u github.com/jgsqware/clairctl
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
£¨4£©È»ºó£¬Ê¹ÓÃclairctl¶ÔÈÝÆ÷¾ÙÐÐɨÃè
clairctl analyze -l CONTAINER_NAME
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
£¨5£©ÆÚ´ýɨÃèÍê³É£¬²¢Éó²é±¨¸æ
ɨÃèÍê³Éºó£¬ÎÒÃÇ¿ÉÒÔͨ¹ýä¯ÀÀÆ÷»á¼ûClairµÄwebÒ³Ã棬²¢Éó²é±¨¸æ¡£
ÈÝÆ÷µÄÎó²îÐÞ¸´
ÈÝÆ÷µÄÎó²îÐÞ¸´ÊÇÖ¸ÐÞ¸´ÈÝÆ÷Öб£´æµÄÇå¾²Îó²î£¬´Ó¶ø°ü¹ÜÈÝÆ÷µÄÇå¾²ÐÔ¡£ÈÝÆ÷µÄÎó²îÐÞ¸´¿ÉÒÔ½ÓÄÉһЩ¿ªÔ´¹¤¾ßÀ´ÊµÏÖ¡£
2.1 ʹÓÃDocker Security Scanning¾ÙÐÐÎó²îÐÞ¸´
Docker Security ScanningÊÇDocker¹Ù·½ÌṩµÄÒ»ÖÖÇ徲ɨÃ蹤¾ß£¬¿ÉÒÔ¼ì²âDocker¾µÏñÖеÄÇå¾²Îó²î£¬²¢ÌṩÐÞ¸´½¨Òé¡£ÏÂÃæÊÇʹÓÃDocker Security Scanning¾ÙÐÐÈÝÆ÷Îó²îÐÞ¸´µÄ°ì·¨£º
£¨1£©Ê×ÏÈ£¬¿ªÍ¨Docker Security Scanning
ÔÚDocker HubÉÏ×¢²áÕ˺ÅÖ®ºó£¬ÔÚÇå¾²ÖÐÑëÖÐÆôÓÃDocker Security Scanning¡£
£¨2£©È»ºó£¬ÉÏ´«¾µÏñµ½Docker Hub
docker push DOCKERHUB_USERNAME/IMAGE_NAME:TAG
µÇ¼ºó¸´ÖÆ
£¨3£©ÆÚ´ýDocker Security ScanningÍê³ÉɨÃ裬²¢Éó²é±¨¸æ
ͨ¹ýä¯ÀÀÆ÷µÇ¼Docker Hub£¬²¢Éó²éDocker Security ScanningɨÃ豨¸æ£¬»ñÈ¡ÐÞ¸´½¨Òé¡£
2.2 ʹÓÃClair¾ÙÐÐÎó²îÐÞ¸´
Clair³ýÁË¿ÉÒÔÓÃÀ´¾ÙÐÐÈÝÆ÷Ç徲ɨÃ裬»¹¿ÉÒÔÓÃÀ´¾ÙÐÐÈÝÆ÷Îó²îÐÞ¸´¡£ÏÂÃæÊÇʹÓÃClair¾ÙÐÐÈÝÆ÷Îó²îÐÞ¸´µÄ°ì·¨£º
£¨1£©Ê×ÏÈ£¬Æô¶¯Clair
docker run -p 6060:6060 -d --name clair quay.io/coreos/clair:latest
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
£¨2£©È»ºó£¬×°ÖÃclairctl
go get -u github.com/jgsqware/clairctl
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
£¨3£©½Ó×Å£¬Ê¹ÓÃclairctl¶ÔÈÝÆ÷¾ÙÐÐɨÃè
clairctl analyze -l CONTAINER_NAME
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
£¨4£©×îºó£¬Ê¹ÓÃclairctlÖ´ÐÐÐÞ¸´²Ù×÷
clairctl fix -l CONTAINER_NAME
µÇ¼ºó¸´ÖÆ
ÐèҪעÖصÄÊÇ£¬ClairÖ»Äܹ»ÌṩÐÞ¸´½¨Ò飬¶ø²»¿É×Ô¶¯ÐÞ¸´Îó²î£¬Òò´ËÐÞ¸´²Ù×÷ÐèÒªÊÖ¶¯Íê³É¡£
×ܽá
ÈÝÆ÷µÄÇ徲ɨÃèºÍÎó²îÐÞ¸´ÊÇÈÝÆ÷Çå¾²ÖÎÀíÖеÄÖ÷Òª»·½Ú¡£±¾ÎÄÏÈÈÝÁË»ùÓÚDocker BenchºÍClairÕâÁ½ÖÖ¿ªÔ´¹¤¾ß¾ÙÐÐÈÝÆ÷Ç徲ɨÃèºÍÎó²îÐÞ¸´µÄÒªÁ죬²¢ÌṩÁËÏêϸ´úÂëʾÀý¡£Ê¹ÓÃÕâЩ¹¤¾ß£¬ÎÒÃÇ¿ÉÒÔʵʱ·¢Ã÷ºÍÐÞ¸´ÈÝÆ÷ÖÐDZÔÚµÄÇå¾²Îó²î£¬´Ó¶ø°ü¹ÜÈÝÆ÷µÄÇå¾²ÐÔ¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃDocker¾ÙÐÐÈÝÆ÷µÄÇ徲ɨÃèºÍÎó²îÐÞ¸´µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡