Navigation Menu

Skip to content

Commit

Permalink
add /etc/nsswitch.conf so container reads /etc/hosts
Browse files Browse the repository at this point in the history
The golang resolver uses `/etc/nsswitch.conf` if it exists.
See golang/go#22846

Resolves jumanjihouse#64
  • Loading branch information
jumanjiman committed Sep 13, 2018
1 parent 2eb9f64 commit b9d88ea
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -26,7 +26,8 @@ The build takes about 30 seconds and results in a 5 MiB Docker image.
<br/>The runtime image contains **only**:

* a static binary,
* CA certificates, and
* CA certificates,
* `/etc/nsswitch.conf` so golang net resolver uses `/etc/hosts`, and
* `/etc/passwd` to provide an unprivileged user.

The container runs as an unprivileged user via the technique described in
Expand Down Expand Up @@ -160,3 +161,15 @@ You can use `docker-compose` with the `docker-compose.yaml` file in this git rep
"https://github.com": "A+"

2017/05/13 15:35:40 [INFO] All assessments complete; shutting down


### Scan internal sites

You can add entries to `/etc/hosts` via `docker run --add-host`
or via the docker-compose `extra_hosts` option.
However, websites to be scanned must be resolvable and reachable
by the [Qualys SSL Labs service](https://www.ssllabs.com/ssltest/).

Consider to use https://github.com/jumanjihouse/docker-testssl
if you need to scan internal sites that are not reachable from
the public Internet.
6 changes: 6 additions & 0 deletions ci/test
Expand Up @@ -52,4 +52,10 @@ info The sleeper container does not have the "ps" command, so we
info attach a regular container to the namespace of the sleeper container.
run docker run --rm -it --pid container:"${cid}" --network container:"${cid}" alpine:3.8 ps -o pid,user,group,comm |
grep -E -e run -e '1 1000 1000 sleeper'

info 'Check that /etc/hosts entries are used.'
info 'The sleeper container does not have the "ping" command, so we'
info 'attach a regular container to the namespace of the sleeper container.'
run docker run --rm -it --pid container:"${cid}" --network container:"${cid}" alpine:3.8 ping -c1 -W2 static-host.com

run docker-compose down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Expand Up @@ -31,6 +31,8 @@ services:
build:
context: sleeper/
dockerfile: Dockerfile
extra_hosts:
- 'static-host.com:127.0.0.1'

grade_github:
<<: *defaults
Expand Down
2 changes: 1 addition & 1 deletion scanner/Dockerfile
Expand Up @@ -48,7 +48,7 @@ CMD ["--help"]
ARG VERSION
COPY --from=scanner_builder /tmp/ssllabs-scan-${VERSION}/ssllabs-scan /
COPY --from=scanner_builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY passwd /etc/passwd
COPY . /

ARG CIRCLE_BUILD_URL
ARG BUILD_DATE
Expand Down
3 changes: 3 additions & 0 deletions scanner/etc/nsswitch.conf
@@ -0,0 +1,3 @@
# https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# https://golang.org/pkg/net/
hosts: files dns
File renamed without changes.

0 comments on commit b9d88ea

Please sign in to comment.