Page MenuHomePhabricator

Consider adding `--no-install-recommends` to generated `apt-get install ...` commands
Closed, DeclinedPublic

Description

Flagged a https://semgrep.dev/ run against Blubber generated Dockerfiles used by Toolhub.

severity:info rule:security.semgrep-rules.generic.dockerfile.best-practice.missing-no-install-recommends: This 'apt-get install' is missing '--no-install-recommends'. This prevents unnecessary packages from being installed, thereby reducing image size. Add '--no-install-recommends'.

Adding this flag could reduce container size, but may also break new container builds for some project which are relying on recommended packages for needed functionality. A safer way to introduce this would be as an opt-in flag in the Blubber config (apt.install_recommends?), possibly with a timeline for phasing out the flag and making this default behavior.

Event Timeline

Our containers already disable installing recommended packages via apt configuration:

km@cashew ~/g/o/puppet> podman run --rm -it docker-registry.wikimedia.org/bullseye:latest
root@717147d95234:/# cat /etc/apt/apt.conf.d/00InstallRecommends 
APT::Install-Recommends "false";

I don't know whether it would be worth adding in this flag to satisfy the linter.

As noted by @Legoktm, this is handled by global config for apt that is baked into our base images. This makes potentially makes Blubber a bit less reusable with arbitrary base images, but as long as it is a Wikimedia specific tool this is fine.