A CI job mounts `/var/run/docker.sock` into a container to build images. Is that acceptable?
IntermediateScenarioContainer and IaC Security
Answer
Situation read → Docker socket access equals root on the host. Any process in that container can start a privileged container.
What I'd do →
- Replace with daemonless builders: BuildKit rootless, Kaniko, Buildah or ko.
- If you must use Docker, run on ephemeral VMs isolated from other workloads.
- Never share the socket on runners that build untrusted code from forks.
- Add a policy rule that rejects hostPath mounts of the socket.
Why → You remove the privilege instead of trying to monitor it.
Interview tip → Note Kaniko is now archived upstream; mention BuildKit or Buildah as current options.
More on Container and IaC Security
A team asks whether to use `ubuntu`, `alpine` or a distroless base image. How do you advise?Beginner`trivy image` shows 300 vulnerabilities in your app image. How do you bring this down?BeginnerA Dockerfile runs the app as root. How do you fix it and prove the fix?IntermediateCheckov fails a Terraform PR because an S3 bucket allows public access. What do you change?BeginnerHow do you set up image scanning so nothing vulnerable reaches production?IntermediateAn image passed scanning three weeks ago and runs in production. A new critical CVE is published today. What happens next?Intermediate