Skip to content

Bind-mounted files in /etc allow for resource depletion #13152

Closed

Description

@stefanberger

The file /etc/resolv.conf, /etc/hostname, and /etc/hosts are mounted read-write into containers. A malicious user can make these files as large as the filesystem allows and deplete the storage resource of the host. The following patch attempts to resolve the issue by introducing a new command line option --etc-inside.

https://github.com/stefanberger/docker/commit/9c216dde70e23cd8587228c7b6cfbd10552051d5.patch

Activity

  1. cpuguy83 commented on May 12, 2015

    @cpuguy83
    Member

    Closing as this is not really a bug.
    A user can create huge files anywhere in the container FS and it will fill up the host's disk.
    Additionally you can create your container with --read-only (though mounted in files may still be mounted rw in 1.6, pretty sure this is fixed at least on master).

  2. stefanberger commented on May 12, 2015

    @stefanberger
    ContributorAuthor

    A container FS can have size limitations installed, limiting it to 2G for example. R/W access to these files circumvents these quotas.

    Check out dm.basesize at https://docs.docker.com/reference/commandline/cli/

    "[dm.baseize] Specifies the size to use when creating the base device, which limits the size of images and containers. The default value is 10G. Note, thin devices are inherently "sparse", so a 10G device which is mostly empty doesn't use 10 GB of space on the pool. However, the filesystem will use more space for the empty case the larger the device is."

    You can maybe close this bug, but I would still suggest that a command line option should be introduced that has docker writing the 3 files in /etc into the container. For a multi-tenant environment it seems necessary to restrict access to the host's filesystem and not let quotas be circumvented.

    --read-only IMO causes a lot of problems since /var then would have to be moved and updates (yum update, apt-get ) to existing programs do not work so easily.

  3. cpuguy83 commented on May 12, 2015

    @cpuguy83
    Member

    That's a good point. I'll re-open.

    Though I would not consider DM's container size settings to be any real quota.

  4. stefanberger commented on May 13, 2015

    @stefanberger
    ContributorAuthor

    How can we move this forward?

  5. coolljt0725 commented on May 15, 2015

    @coolljt0725
    Contributor

    I suggest --read-only could be more fine, the user can specify which file to be mount as read-only.
    For example --read-only:/etc/hosts will only mount /etc/hosts as read-only and --read-only:all will mount the whole filesystem as read-only.
    At this situation the user can mount hosts hostname resolv.conf as read-only and others are read-write

  6. stefanberger commented on May 15, 2015

    @stefanberger
    ContributorAuthor

    It depends on the environment where --read-only can be applied. If a user doesn't have control over the parameters passed to the docker for running the container, since for example the container is used in a multi-tenant cloud, he cannot do that. Yet, the user may want to have control over the contents of these files and therefore. having them inside the container in r/w mode seems necessary. A cloud provider could provide the --read-only:/etc/hosts but would take away control over the file from the user.

  7. added
    kind/feature
    on May 17, 2015
  8. added
    kind/bug
    and removed
    kind/feature
    on May 18, 2015
  9. duglin commented on May 18, 2015

    @duglin
    Contributor

    @ewindisch any thoughts on this one?

  10. ewindisch commented on May 19, 2015

    @ewindisch
    Contributor

    @cpuguy83 The difference between these files and the container's filesystem are that the filesystem is different. With devicemapper for instance, files into the container's FS might be writing into an ext4 filesystem created just for that container, but writing to /etc/hosts will write into the /var/lib/docker/containers directory of the host, no matter the selected graph driver.

    @coolljt0725 I think that's a legitimate suggestion.

    @stefanberger I think considerations specific to multi-tenant are out of scope. A cloud provider in that case should have a customized AppArmor or SELinux policy protecting these files.

  11. stefanberger commented on Jun 1, 2015

    @stefanberger
    ContributorAuthor

    @ewindisch : You take away any control from users if you restrict access to the files. Users cannot update /etc/hosts anymore to add new hosts to the lookup list etc.

  12. stefanberger commented on Jul 5, 2015

    @stefanberger
    ContributorAuthor

    @ewindisch : Here's now a solution that lets the user provide the three network files using the -v option while preventing the docker daemon from mounting the files it created over them, which was hiding the user-provided files.

    https://github.com/stefanberger/docker/commit/7ca899a16bc68091638d89ea109e1172c7fc69f6.patch

  13. stefanberger commented on Jul 10, 2015

    @stefanberger
    ContributorAuthor

    @ewindisch : Do you have any comments to the above referenced patch?

  14. ewindisch commented on Jul 10, 2015

    @ewindisch
    Contributor

    @stefanberger I'm happy with allowing '-v' for those files, overriding the mounts for these files. At a glance, I still have some questions about that patch and I'm not sure it's as clean as I'd like it... but that can be sorted out if you make a PR.

    @coolljt0725, I have a PR in review which defaults these files to read-only when the container is such. Please feel free to offer a patch if you'd like to set more granular r/o masks: #13669

  15. ewindisch commented on Jul 10, 2015

    @ewindisch
    Contributor

    @stefanberger also, I do not propose we do not allow users to modify these files at all. I do think they should be read-only if the container is set as such. My patch does this. Your patch would allow overriding this for read-only containers, by passing in a read/write volume, so I think they would be complementary.

  16. thaJeztah commented on Jul 26, 2015

    @thaJeztah
    Member

    closing because #14613 was merged. Thanks @stefanberger !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions