Skip to content

Commit a901c3f

Browse files
committed
Merge branch 'pr/apanzerj/444'
2 parents b266705 + 07d1482 commit a901c3f

File tree

7 files changed

+80
-10
lines changed

7 files changed

+80
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
Coming soon! Please document any work in progress here as part of your PR. It will be moved to the next tag when released.
66

7+
## v0.36.0
8+
9+
- [run Docker containers as non-root user](https://github.com/vouch/vouch-proxy/pull/444)
10+
11+
Permissions may need to be adjusted for `/config/secret` and `/config/config.yml` in Docker environemnts. See the [README](https://github.com/vouch/vouch-proxy#running-from-docker)
12+
713
## v0.35.1
814

915
- [include DocumentRoot if configured in error pages](https://github.com/vouch/vouch-proxy/pull/439)

Dockerfile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# voucher/vouch-proxy
1+
# quay.io/vouch/vouch-proxy
22
# https://github.com/vouch/vouch-proxy
33
FROM golang:1.16 AS builder
44

5+
ARG UID=999
6+
ARG GID=999
57
LABEL maintainer="[email protected]"
68

79
RUN mkdir -p ${GOPATH}/src/github.com/vouch/vouch-proxy
810
WORKDIR ${GOPATH}/src/github.com/vouch/vouch-proxy
911

12+
RUN groupadd -g $GID vouch \
13+
&& useradd --system vouch --uid=$UID --gid=$GID
14+
1015
COPY . .
1116

12-
# RUN go-wrapper download # "go get -d -v ./..."
13-
# RUN ./do.sh build # see `do.sh` for vouch build details
14-
# RUN go-wrapper install # "go install -v ./..."
1517

1618
RUN ./do.sh goget
1719
RUN ./do.sh gobuildstatic # see `do.sh` for vouch-proxy build details
@@ -20,7 +22,12 @@ RUN ./do.sh install
2022
FROM scratch
2123
LABEL maintainer="[email protected]"
2224
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
25+
COPY --from=builder /etc/passwd /etc/passwd
26+
COPY --from=builder /etc/group /etc/group
2327
COPY --from=builder /go/bin/vouch-proxy /vouch-proxy
28+
29+
USER vouch
30+
2431
EXPOSE 9090
2532
ENTRYPOINT ["/vouch-proxy"]
2633
HEALTHCHECK --interval=1m --timeout=5s CMD [ "/vouch-proxy", "-healthcheck" ]

Dockerfile.alpine

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# voucher/vouch-proxy
1+
# quay.io/vouch/vouch-proxy
22
# https://github.com/vouch/vouch-proxy
33
FROM golang:1.16 AS builder
44

5+
ARG UID=999
6+
ARG GID=999
57
LABEL maintainer="[email protected]"
68

79
RUN mkdir -p ${GOPATH}/src/github.com/vouch/vouch-proxy
@@ -13,6 +15,9 @@ RUN ./do.sh goget
1315
RUN ./do.sh gobuildstatic # see `do.sh` for vouch-proxy build details
1416
RUN ./do.sh install
1517

18+
RUN groupadd -g $GID vouch \
19+
&& useradd --system vouch --uid=$UID --gid=$GID
20+
1621
FROM alpine:latest
1722
LABEL maintainer="[email protected]"
1823
ENV VOUCH_ROOT=/
@@ -22,7 +27,12 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certifi
2227
RUN apk add --no-cache bash
2328
COPY do.sh /do.sh
2429

30+
COPY --from=builder /etc/passwd /etc/passwd
31+
COPY --from=builder /etc/group /etc/group
2532
COPY --from=builder /go/bin/vouch-proxy /vouch-proxy
33+
34+
USER vouch
35+
2636
EXPOSE 9090
2737
ENTRYPOINT ["/vouch-proxy"]
2838
HEALTHCHECK --interval=1m --timeout=5s CMD [ "/vouch-proxy", "-healthcheck" ]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Vouch Proxy supports many OAuth and OIDC login providers and can enforce authent
2828
- [OAuth2 Server Library for PHP](https://github.com/vouch/vouch-proxy/issues/99)
2929
- [HomeAssistant](https://developers.home-assistant.io/docs/en/auth_api.html)
3030
- [OpenStax](https://github.com/vouch/vouch-proxy/pull/141)
31+
- [Ory Hydra](https://github.com/vouch/vouch-proxy/issues/288)
3132
- [Nextcloud](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/oauth2.html)
3233
- most other OpenID Connect (OIDC) providers
3334

@@ -317,6 +318,8 @@ docker run -d \
317318
quay.io/vouch/vouch-proxy
318319
```
319320

321+
As of `v0.36.0` the docker process in the container runs as user `vouch` with UID 999 and GID 999. You may need to set the permissions of `/config/config.yml` and `/config/secret` to correspond to be readable by this user, or otherwise use `docker run --user $UID:$GID ...` or perhaps build the docker container from source and use the available ARGs for UID and GID.
322+
320323
Automated container builds for each Vouch Proxy release are available from [quay.io](https://quay.io/repository/vouch/vouch-proxy). Each release produces..
321324

322325
a minimal go binary container built from `Dockerfile`

do.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ if [ -z "$VOUCH_ROOT" ]; then
1111
export VOUCH_ROOT=${GOPATH}/src/github.com/vouch/vouch-proxy/
1212
fi
1313

14-
IMAGE=voucher/vouch-proxy:latest
15-
ALPINE=voucher/vouch-proxy:alpine
14+
IMAGE=quay.io/vouch/vouch-proxy:latest
15+
ALPINE=quay.io/vouch/vouch-proxy:alpine-latest
1616
GOIMAGE=golang:1.16
1717
NAME=vouch-proxy
1818
HTTPPORT=9090
@@ -394,7 +394,7 @@ usage() {
394394
$0 bug_report domain.com [badstr2..] - print config file and log removing secrets and each provided string
395395
$0 gogo [gocmd] - run, build, any go cmd
396396
$0 stats - simple metrics (lines of code in project, number of go files)
397-
$0 watch [cmd] - watch the $CWD for any change and re-reun the [cmd]
397+
$0 watch [cmd] - watch the \$CWD for any change and re-reun the [cmd] (defaults to 'go run main.go')
398398
$0 license [file] - apply the license to the file
399399
400400
do is like make

pkg/cfg/cfg.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"io/ioutil"
2121
"net/http"
2222
"os"
23+
"os/user"
2324
"path"
2425
"path/filepath"
2526
"reflect"
@@ -193,6 +194,7 @@ func Configure() {
193194

194195
if !didConfigFromEnv && configFileErr != nil {
195196
// then it's probably config file not found
197+
logSysInfo()
196198
log.Fatal(configFileErr)
197199
}
198200

@@ -207,7 +209,6 @@ func Configure() {
207209
if *CmdLine.port != -1 {
208210
Cfg.Port = *CmdLine.port
209211
}
210-
211212
logConfigIfDebug()
212213
}
213214

@@ -285,6 +286,7 @@ func parseConfigFile() error {
285286
}
286287
err := viper.ReadInConfig() // Find and read the config file
287288
if err != nil { // Handle errors reading the config file
289+
288290
return fmt.Errorf("%w: %s", errConfigNotFound, err)
289291
}
290292

@@ -677,3 +679,44 @@ func SigningKey() (interface{}, error) {
677679

678680
return key, nil
679681
}
682+
683+
// Check that we have read permission for this file
684+
// https://stackoverflow.com/questions/60128401/how-to-check-if-a-file-is-executable-in-go
685+
func canRead(file string) bool {
686+
stat, err := os.Stat(file)
687+
if err != nil {
688+
log.Debug(err)
689+
return false
690+
}
691+
692+
m := stat.Mode()
693+
return m&0400 != 0
694+
}
695+
696+
// detect if we're in a docker environment
697+
func isDocker() bool {
698+
return canRead("/.dockerenv")
699+
}
700+
701+
func logSysInfo() {
702+
if isDocker() {
703+
log.Warn("detected Docker environment, beware of Docker userid and permissions changes in v0.36.0")
704+
}
705+
u, err := user.Current()
706+
if err != nil {
707+
log.Error(err)
708+
}
709+
g, err := user.LookupGroupId(u.Gid)
710+
if err != nil {
711+
log.Error(err)
712+
}
713+
p, err := os.FindProcess(os.Getpid())
714+
if err != nil {
715+
log.Error(err)
716+
}
717+
exe, err := os.Executable()
718+
if err != nil {
719+
log.Error(err)
720+
}
721+
log.Debugf("%s was executed as '%s' (pid: %d) running as user %s (uid: %s) with group %s (gid: %s)", Branding.FullName, exe, p.Pid, u.Username, u.Uid, g.Name, u.Gid)
722+
}

pkg/cfg/jwt.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ func getOrGenerateJWTSecret() string {
3535
b = []byte(rstr)
3636
err = ioutil.WriteFile(secretFile, b, 0600)
3737
if err != nil {
38-
log.Debug(err)
38+
log.Error(err)
39+
logSysInfo()
3940
}
4041
}
4142
return string(b)

0 commit comments

Comments
 (0)