Skip to content

It's difficult to correctly construct values for common environment variables #8667

Closed

Description

@exarkun

Environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH combine values that are usually contributed from many different pieces of software.

For example, one image might install a Python library to /opt/acme and set PYTHONPATH to this value:

ENV PYTHONPATH /opt/acme

An image based on this one might install another Python library in /usr/local/lib/yoyodyne. It might try to cooperate with the underlying image:

ENV PYTHONPATH $PYTHONPATH:/usr/local/lib/yoyodyne

This may prove correct, yielding a value for the variable in the container of /opt/acme:/usr/local/lib/yoyodyne. However, it requires the author of the second image to know about the construction of the first image. It also requires them to keep themselves updated about changes to the construction of the first image. If a future version changes the way the software is installed so that PYTHONPATH no longer need be set then unless the Dockerfile for the second image is updated, the value for PYTHONPATH becomes :/usr/local/lib/yoyodyne (notice the leading :). This mostly works but it introduces an extra unintended path to the Python module search path. This may not cause any problems - or it might break the image (in a worst case outcome, perhaps it breaks the image quietly, by leaving everything with the appearance of working but introducing a subtle security issue where the Python application packaged in the second image begins evaluating arbitrary user-supplied Python code).

If full shell-style variable substitution were supported then this could be avoided by a diligent Dockerfile author:

ENV PYTHONPATH ${PYTHONPATH:+${PYTHONPATH}:}/usr/local/lib/yoyodyne

The first part of this says "If PYTHONPATH is set, substitute its value followed by :. If it is not set, substitute the empty string". The result of this substitution is then concatenated with the literal /usr/local/lib/yoyodyne. This produces either /opt/acme:/usr/local/lib/yoyodyne if PYTHONPATH is already set to /opt/acme or /usr/local/lib/yoyodyne if PYTHONPATH is not already set.

There are probably other solutions to this problem too. The more complicated shell substitution is mostly given as an example of how some existing systems account for this problem and offer a solution for it.

Activity

  1. exarkun commented on Oct 20, 2014

    @exarkun
    ContributorAuthor

    ping @erikh (as requested)

  2. jessfraz commented on Feb 26, 2015

    @jessfraz
    Contributor
  3. duglin commented on Feb 26, 2015

    @duglin
    Contributor

    support for more advanced env var substitution would be a good thing - just non-trivial. I'll put it on our todo list but it may not happen for a while.

  4. duglin commented on Mar 1, 2015

    @duglin
    Contributor

    See #10431

  5. added
    kind/enhancement
    on Mar 2, 2015
  6. jessfraz commented on Mar 2, 2015

    @jessfraz
    Contributor

    closing as dup then of #8667

  7. jessfraz commented on Mar 2, 2015

    @jessfraz
    Contributor

    sorry wrong one, this one stays open

  8. added
    kind/enhancement
    and removed
    kind/enhancement
    on Mar 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/builderexp/beginnerkind/enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions