Top Banner
Globalcode – Open4education Protegendo Docker Guilherme Oki
26

Protegendo Docker

Mar 18, 2018

Download

Technology

guilhermeoki
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Protegendo Docker

Globalcode – Open4education

Protegendo DockerGuilherme Oki

Page 2: Protegendo Docker

Globalcode – Open4education

Quem sou eu?• SRE na Stone Pagamentos• Apaixonado por open source• Entusiasta da cultura e do desenvolvimento ágil

Page 3: Protegendo Docker

Globalcode – Open4education

O que é Docker?

"Docker is about running random crap

from the internet as root on your host"

Page 4: Protegendo Docker

Globalcode – Open4education

O que são containers?

Page 5: Protegendo Docker

Globalcode – Open4education

Por que eles precisam de proteção?

Page 6: Protegendo Docker

Globalcode – Open4education

O que precisa de proteção?

• Application• Containers <-> Containers• Containers <-> Hosts

Page 7: Protegendo Docker

Globalcode – Open4education

Como proteger?

Page 8: Protegendo Docker

Globalcode – Open4education

Capabilities• Capabilities foram adicionadas no kernel há 15 anos atrás.• Tenta dividir o poder de root• Lista atuais capabilities no Docker

• getpcaps 1• Algumas capabilities

• chow• kill• setuid• dac_override

• Enabled by default"nothing should need this. If your container need this, it's probably doing something

horrible." Steve Grubb, security expert at Red Hat

Page 9: Protegendo Docker

Globalcode – Open4education

Quais capabilities eu realmente preciso no meu container?

• Entre em modo permissivo• setsebool virt_sandbox_use_all_caps=0• setenforce 0

• Execute seu container com todas as caps.• docker run --cap-add all IMAGE ...

• Isto irá gerar uma mensagem sobre as capabilities usadas• grep capability /var/log/audit/audit.log

"type=AVC msg=audit(1495655327.756:44343): avc: denied { syslog } for pid=5246 comm="rsyslogd" capability=34 scontext=system_u:system_r:container_t:s0:c795,c887 tcontext=system_u:system_r:container_t:s0:c795,c887 tclass=capability2 "

• cap_name[31]="cap_setfcap"• cap_name[32]="cap_mac_override"• cap_name[33]="cap_mac_admin"• cap_name[34]="cap_syslog"

Page 10: Protegendo Docker

Globalcode – Open4education

Limite o recurso disponível• Recurso do cgroups• Memory

• --memory• Swap

• --memory-swap• CPU

• --cpu-shares• DISK I/O

• --device-read-iops• --device-write-iops

Page 11: Protegendo Docker

Globalcode – Open4education

Linux Security Modules

Page 12: Protegendo Docker

Globalcode – Open4education

SELinux

Page 13: Protegendo Docker

Globalcode – Open4education

SELinux• Type Enforcement e Multi Category Security ( MCS )

• sandbox_lxc_process = "system_u:system_r:container_t:s0"• cada container s0:c1, s0:c2, …

• Adicione este parâmetro no docker daemon para habilitar o SELinux• --selinux-enabled

Page 14: Protegendo Docker

Globalcode – Open4education

AppArmor• Profile padrão é o docker-default• Para carregar o profile padrão

• --security-opt apparmor=docker-default• Você pode gerenciar syscalls, capabilities e paths• Você pode utilizar um gerador de profiles

• https://github.com/jessfraz/bane

Page 15: Protegendo Docker

Globalcode – Open4education

Use patch de segurança para o Kernel

Page 16: Protegendo Docker

Globalcode – Open4education

Seccomp• Docker tem um profile padrão para seccomp• Adicione este parâmetro para usar um custom profile

• --security-opt seccomp:custom.json{

"defaultAction": "SCMP_ACT_ALLOW",

"syscalls": [

{

"name": "chown",

"action": "SCMP_ACT_ERRNO"

},

{

"name": "chmod",

"action": "SCMP_ACT_ERRNO"

}

]

}

Page 17: Protegendo Docker

Globalcode – Open4education

Como funciona uid/gid?

Page 18: Protegendo Docker

Globalcode – Open4education

Read only images

• docker run --read-only IMAGE

Page 19: Protegendo Docker

Globalcode – Open4education

Limpe seus container

• Dockerfile• RUN for i in `find / -not \( -path /proc -prune \) -perm +6000 -type f`; chmod a-s $i;

done

Page 20: Protegendo Docker

Globalcode – Open4education

Escaneie seus containers

Page 21: Protegendo Docker

Globalcode – Open4education

Assine sua imagem

Page 22: Protegendo Docker

Globalcode – Open4education

Futuro - Rootless containers

• Runc executando como usuário não-privilegiado• Alguns problemas com cgroups• Alguns problemas com host network

Page 23: Protegendo Docker

Globalcode – Open4education

Futuro - Intel Clear Containers

• Pula diretamente para o Kernel Linux usando kvmtool• In-place Kernel Load• Suporte para Docker Containers• Boot em 0.2 seconds• Slim Kernel

Page 24: Protegendo Docker

Globalcode – Open4education

Dúvidas?

Page 25: Protegendo Docker

Globalcode – Open4education

Obrigado! :-)

Page 26: Protegendo Docker