Docker
TMA-DOCKER-5.9
Ensure that only needed ports are open on the container
Opis
The Dockerfile for a container image defines the ports which are opened by default on a container instance. The list of ports are relevant to the application you are running within the container and should only be open if they are needed. A container can be run with only the ports defined in the Dockerfile for its image or can alternatively be arbitrarily passed run time parameters to open a list of ports. Reported as a manual review item: the audit needs a site-specific judgement.
Kako se proverava
Metod provere: Ručni pregled
You should list all the running instances of containers and their associated port mappings by executing the command below: docker ps --quiet | xargs docker inspect --format '{{ .Id }}: Ports={{ .NetworkSettings.Ports }}' You should then review the list and ensure that all the ports mapped are in fact genuinely required by each container.
Kako se ispravlja
Metod ispravke: Smernica ili zakrpa infrastrukture
You should ensure that the Dockerfile for each container image only exposes needed ports. You can also completely ignore the list of ports defined in the Dockerfile by NOT using -P (UPPERCASE) or the --publish-all flag when starting the container. Instead, use the -p (lowercase) or --publish flag to explicitly define the ports that you need for a particular container instance. For example: docker run --interactive --tty --publish 5000 --publish 5001 --publish 5002 centos /bin/bash
Svojstva
- Operativni sistemi
- Bilo koji
- Oznake
- dockermanual
- Referenca
- CIS Docker Benchmark v1.9.0 - 5.9 Ensure that only needed ports are open on the container