diff --git a/.gitignore b/.gitignore index eecd054bd1f755876a36a0cf32f3ea453a5495f9..3d93457fb39820e9c519e7211a367bef440120ba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.swp .idea/ bin/ +vendor/ release/ cover.html cover.out diff --git a/.travis.yml b/.travis.yml index 7768626584ca725c9fd488a77f4023b51236d71d..d64fbf8316e45e96a62f9c420679a6c0a7ace1fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ language: go go: - 1.8 install: -- go get github.com/tools/godep +- go get github.com/Masterminds/glide - go get github.com/mattn/goveralls script: - make test diff --git a/Makefile b/Makefile index 5b3f5158c1439b29447cc4a644ab7e622eba9fae..882a752ec37bc0071687f05898e5f5e144e5f45c 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ PACKAGES=$(shell go list ./...) LFLAGS ?= -X main.gitsha=${GIT_SHA} -X main.compiled=${BUILD_TIME} VETARGS ?= -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr -.PHONY: test authors changelog build docker static release lint cover vet +.PHONY: test authors changelog build docker static release lint cover vet glide-install default: build @@ -21,18 +21,15 @@ golang: @echo "--> Go Version" @go version -version: - @sed -i "s/const gitSHA =.*/const gitSHA = \"${GIT_SHA}\"/" doc.go - -build: +build: golang deps @echo "--> Compiling the project" @mkdir -p bin - godep go build -ldflags "${LFLAGS}" -o bin/${NAME} + go build -ldflags "${LFLAGS}" -o bin/${NAME} static: golang deps @echo "--> Compiling the static binary" @mkdir -p bin - CGO_ENABLED=0 GOOS=linux godep go build -a -tags netgo -ldflags "-w ${LFLAGS}" -o bin/${NAME} + CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags "-w ${LFLAGS}" -o bin/${NAME} docker-build: @echo "--> Compiling the project" @@ -45,9 +42,9 @@ docker-build: docker-test: @echo "--> Running the docker test" docker run --rm -ti -p 3000:3000 \ - -v ${ROOT_DIR}/config.yml:/etc/keycloak/config.yml:ro \ - -v ${ROOT_DIR}/tests:/opt/tests:ro \ - ${REGISTRY}/${AUTHOR}/${NAME}:${VERSION} --config /etc/keycloak/config.yml + -v ${ROOT_DIR}/config.yml:/etc/keycloak/config.yml:ro \ + -v ${ROOT_DIR}/tests:/opt/tests:ro \ + ${REGISTRY}/${AUTHOR}/${NAME}:${VERSION} --config /etc/keycloak/config.yml docker-release: @echo "--> Building a release image" @@ -83,9 +80,14 @@ authors: @echo "--> Updating the AUTHORS" git log --format='%aN <%aE>' | sort -u > AUTHORS +glide-install: + @echo "--> Installing dependencies" + @glide install + deps: @echo "--> Installing build dependencies" - @go get github.com/tools/godep + @go get github.com/Masterminds/glide + @$(MAKE) glide-install vet: @echo "--> Running go vet $(VETARGS) ." @@ -120,20 +122,23 @@ format: bench: @echo "--> Running go bench" - @godep go test -bench=. + @go test -bench=. coverage: @echo "--> Running go coverage" - @godep go test -coverprofile cover.out - @godep go tool cover -html=cover.out -o cover.html + @go test -coverprofile cover.out + @go tool cover -html=cover.out -o cover.html cover: @echo "--> Running go cover" - @godep go test --cover + @go test --cover -test: deps +test: @echo "--> Running the tests" - @godep go test -v + @if [ ! -d "vendor" ]; then \ + make glide-install; \ + fi + @go test -v @$(MAKE) golang @$(MAKE) gofmt @$(MAKE) vet diff --git a/forwarding.go b/forwarding.go index 43f1741bd9378432ee40dedb5eea359f2c2ba3b0..7e1ddab25cf17531abbaf6f7ffc6ecc3268ba9d1 100644 --- a/forwarding.go +++ b/forwarding.go @@ -200,10 +200,8 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) { return func(req *http.Request, resp *http.Response) { hostname := req.Host req.URL.Host = hostname - - // step: does the host being signed? + // does the host being signed? if len(r.config.ForwardingDomains) == 0 || containsSubString(hostname, r.config.ForwardingDomains) { - // step: sign the outbound request with the access token req.Header.Set("X-Forwarded-Agent", prog) req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", state.token.Encode())) } diff --git a/glide.lock b/glide.lock new file mode 100644 index 0000000000000000000000000000000000000000..fe1cab3b5d46d327429634a481c8cd9d4e055b75 --- /dev/null +++ b/glide.lock @@ -0,0 +1,146 @@ +hash: b61fcd2b523ddfcacf31c69e7f46b2fd9286d0c6555029efe8a45de3552d25b2 +updated: 2017-06-12T14:55:48.532550213+01:00 +imports: +- name: github.com/armon/go-proxyproto + version: 609d6338d3a76ec26ac3fe7045a164d9a58436e7 +- name: github.com/beorn7/perks + version: 3ac7bf7a47d159a033b107610db8a1b6575507a4 + subpackages: + - quantile +- name: github.com/boltdb/bolt + version: 144418e1475d8bf7abbdc48583500f1a20c62ea7 +- name: github.com/coreos/pkg + version: 447b7ec906e523386d9c53be15b55a8ae86ea944 + subpackages: + - health + - httputil + - timeutil +- name: github.com/davecgh/go-spew + version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d + subpackages: + - spew +- name: github.com/dgrijalva/jwt-go + version: 2268707a8f0843315e2004ee4f1d021dc08baedf +- name: github.com/fsnotify/fsnotify + version: fd9ec7deca8bf46ecd2a795baaacf2b3a9be1197 +- name: github.com/gambol99/go-oidc + version: 2111f98a1397a35f1800f4c3c354a7abebbef75c + subpackages: + - http + - jose + - key + - oauth2 + - oidc +- name: github.com/gambol99/goproxy + version: e713e5909438245be49ef559e74dd904833ebe90 +- name: github.com/go-resty/resty + version: 39c3db9c7bb4f9718ac143a83a924441521caf73 +- name: github.com/golang/protobuf + version: 0c1f6d65b5a189c2250d10e71a5506f06f9fa0a0 + subpackages: + - proto +- name: github.com/jonboulle/clockwork + version: ed104f61ea4877bea08af6f759805674861e968d +- name: github.com/labstack/echo + version: eac431df0dbad8ba6cc313fba37f1d4275c317e8 + subpackages: + - middleware +- name: github.com/labstack/gommon + version: e8995fb26e646187d33cff439b18609cfba23088 + subpackages: + - bytes + - color + - log + - random +- name: github.com/mattn/go-colorable + version: 9cbef7c35391cca05f15f8181dc0b18bc9736dbb +- name: github.com/mattn/go-isatty + version: 56b76bdf51f7708750eac80fa38b952bb9f32639 +- name: github.com/matttproud/golang_protobuf_extensions + version: c12348ce28de40eed0136aa2b644d0ee0650e56c + subpackages: + - pbutil +- name: github.com/pmezard/go-difflib + version: 792786c7400a136282c1664665ae0a8db921c6c2 + subpackages: + - difflib +- name: github.com/prometheus/client_golang + version: 488edd04dc224ba64c401747cd0a4b5f05dfb234 + subpackages: + - prometheus +- name: github.com/prometheus/client_model + version: fa8ad6fec33561be4280a8f0514318c79d7f6cb6 + subpackages: + - go +- name: github.com/prometheus/common + version: 3a184ff7dfd46b9091030bf2e56c71112b0ddb0e + subpackages: + - expfmt + - internal/bitbucket.org/ww/goautoneg + - model +- name: github.com/prometheus/procfs + version: abf152e5f3e97f2fafac028d2cc06c1feb87ffa5 +- name: github.com/PuerkitoBio/purell + version: 0bcb03f4b4d0a9428594752bd2a3b9aa0a9d4bd4 +- name: github.com/PuerkitoBio/urlesc + version: 5bd2802263f21d8788851d5305584c82a5c75d7e +- name: github.com/stretchr/testify + version: f6abca593680b2315d2075e0f5e2a9751e3f431a + subpackages: + - assert + - require + - vendor/github.com/davecgh/go-spew/spew + - vendor/github.com/pmezard/go-difflib/difflib +- name: github.com/unrolled/secure + version: 4b41e52ab568cbfd31eda3612d98192da1575c77 +- name: github.com/urfave/cli + version: 0bdeddeeb0f650497d603c4ad7b20cfe685682f6 +- name: github.com/valyala/bytebufferpool + version: e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7 +- name: github.com/valyala/fasttemplate + version: dcecefd839c4193db0d35b88ec65b4c12d360ab0 +- name: go.uber.org/atomic + version: 0506d69f5564c56e25797bf7183c28921d4c6360 +- name: go.uber.org/zap + version: 54371c67da1bc746325e5582e48521a5db5d64ca + subpackages: + - buffer + - internal/bufferpool + - internal/color + - internal/exit + - internal/multierror + - zapcore +- name: golang.org/x/crypto + version: 453249f01cfeb54c3d549ddb75ff152ca243f9d8 + subpackages: + - acme + - acme/autocert +- name: golang.org/x/net + version: bc3663df0ac92f928d419e31e0d2af22e683a5a2 + subpackages: + - context + - context/ctxhttp + - idna + - publicsuffix +- name: golang.org/x/sys + version: 833a04a10549a95dc34458c195cbad61bbb6cb4d + subpackages: + - unix +- name: golang.org/x/text + version: f28f36722d5ef2f9655ad3de1f248e3e52ad5ebd + subpackages: + - transform + - unicode/norm + - width +- name: gopkg.in/bsm/ratelimit.v1 + version: db14e161995a5177acef654cb0dd785e8ee8bc22 +- name: gopkg.in/redis.v4 + version: 889409de38315d22b114fb5980f705e6fa48c6a2 + subpackages: + - internal + - internal/consistenthash + - internal/hashtag + - internal/pool +- name: gopkg.in/yaml.v2 + version: 49c95bdc21843256fb6c4e0d370a05f24a0bf213 +testImports: [] diff --git a/glide.yaml b/glide.yaml index 8540d33f7afbf8a114b81155cca8f5e60b382395..ef0561192bae2a0e1787bf14b0e2978b6798c2ba 100644 --- a/glide.yaml +++ b/glide.yaml @@ -35,7 +35,7 @@ import: - oauth2 - oidc - package: github.com/gambol99/goproxy - version: c3b6ff1178d68ec9e93f7c996f41a3df89931d9f + version: e713e5909438245be49ef559e74dd904833ebe90 - package: github.com/go-resty/resty version: 39c3db9c7bb4f9718ac143a83a924441521caf73 - package: github.com/golang/protobuf diff --git a/server.go b/server.go index c82711232f93811320569a9fcc3352077297c91f..2120fc190e098238400eb7b65238c9a8c800c9d8 100644 --- a/server.go +++ b/server.go @@ -231,18 +231,18 @@ func (r *oauthProxy) createForwardingProxy() error { } forwardingHandler := r.forwardProxyHandler() - // step: set the http handler + // set the http handler proxy := r.upstream.(*goproxy.ProxyHttpServer) r.router = proxy - // step: setup the tls configuration + // setup the tls configuration if r.config.TLSCaCertificate != "" && r.config.TLSCaPrivateKey != "" { ca, err := loadCA(r.config.TLSCaCertificate, r.config.TLSCaPrivateKey) if err != nil { return fmt.Errorf("unable to load certificate authority, error: %s", err) } - // step: implement the goproxy connect method + // implement the goproxy connect method proxy.OnRequest().HandleConnectFunc( func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) { return &goproxy.ConnectAction{ @@ -252,7 +252,7 @@ func (r *oauthProxy) createForwardingProxy() error { }, ) } else { - // step: use the default certificate provided by goproxy + // use the default certificate provided by goproxy proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm) } @@ -275,7 +275,6 @@ func (r *oauthProxy) createForwardingProxy() error { }) proxy.OnRequest().DoFunc(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) { ctx.UserData = time.Now() - // step: forward into the handler forwardingHandler(req, ctx.Resp) return req, ctx.Resp })