Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read config file when referenced through nested symbolic links #3753

Closed
HCanber opened this issue Dec 15, 2017 · 1 comment · Fixed by #3799
Closed

Cannot read config file when referenced through nested symbolic links #3753

HCanber opened this issue Dec 15, 2017 · 1 comment · Fixed by #3799
Labels
theme/operator-usability Replaces UX. Anything related to making things easier for the practitioner type/bug Feature does not function as expected
Milestone

Comments

@HCanber
Copy link

HCanber commented Dec 15, 2017

Version: 1.0.1, 1.0.2

Description of the Issue (and unexpected/desired result)

Consul does not start as it's unable to read config files for the specific structure below. It works in 1.0.0.

I have a structure with symbolic links that looks like this:

/
+-- consul
    +-- config
        +-- dir
        |   +-- server.json
        +-- link_dir -> dir
        +-- server.json -> link_dir/server.json

This kind of structure is created by Kuberenetes when mounting volumes, see kelseyhightower/consul-on-kubernetes#23
The structure above is exactly the same as in the linked issue, except I've simplified the names.

Reproduction steps

  1. Create a file named Dockerfile with the content

    FROM consul:1.0.1
    RUN mkdir -p /consul/config/dir && \
      echo '{"node_name":"foobar"}' > /consul/config/dir/server.json && \
      ln -s dir /consul/config/link_dir && \
      ln -s link_dir/server.json /consul/config/server.json
  2. Build image:

    docker build -t consul-test .
  3. See content of /consul/config

    docker run -t --name=dev-consul --entrypoint ls consul-test -al /consul/config/  &&\
    docker rm dev-consul >/dev/null
    total 12
    drwxr-xr-x    1 consul   consul        4096 Dec 15 15:40 .
    drwxr-xr-x    1 consul   consul        4096 Dec  1 19:14 ..
    drwxr-xr-x    2 root     root          4096 Dec 15 15:40 dir
    lrwxrwxrwx    1 root     root             3 Dec 15 15:40 link_dir -> dir
    lrwxrwxrwx    1 root     root            20 Dec 15 15:40 server.json -> link_dir/server.json
    
  4. See the content of server.json

    docker run -t --name=dev-consul --entrypoint cat consul-test  /consul/config/server.json  &&\
    docker rm dev-consul >/dev/null
    {"node_name":"foobar"}
  5. Start consul with server.json as config file

    docker run --name=dev-consul -e CONSUL_BIND_INTERFACE=eth0 consul-test agent -dev -client 0.0.0.0 -config-file=/consul/config/server.json -log-level=TRACE ;\
    docker rm dev-consul >/dev/null

    It fails with:

    ==> Found address '172.17.0.2' for interface 'eth0', setting bind option...
    ==> config: ReadFile failed on /consul/config/link_dir: read /consul/config/link_dir: is a directory
    
  6. To prove that it works in version 1.0.0, modify the content of Dockerfile to use image consul:1.0.0. Build the image and start Consul:

    docker build -t consul-test .
    docker run --name=dev-consul -e CONSUL_BIND_INTERFACE=eth0 consul-test agent -dev -client 0.0.0.0 -config-file=/consul/config/server.json -log-level=TRACE ;\
    docker rm dev-consul >/dev/null

    Consul will start correctly. Press Ctrl+C to exit

  7. To cleanup execute

    docker rmi consul-test

I have verified that it does not work in version 1.0.2 either. I used 1.0.1 in this example as 1.0.2 hasn't been released to Docker Hub.

@jameshartig
Copy link
Contributor

jameshartig commented Jan 12, 2018

The problem is that the consul Dockerfile by default (without a way to prevent it) looks for config files in /consul/config (see: https://github.com/hashicorp/docker-consul/blob/master/0.X/docker-entrypoint.sh#L45). Since you have non files in there, it fails. I'm working on a PR.

jameshartig added a commit to jameshartig/consul that referenced this issue Jan 12, 2018
Docker/Openshift/Kubernetes mount the config file as a symbolic link and
IsDir returns true if the file is a symlink. Before calling IsDir, the
symlink should be resolved to determine if it points at a file or
directory.

Fixes hashicorp#3753
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/operator-usability Replaces UX. Anything related to making things easier for the practitioner type/bug Feature does not function as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants