Skip to content

Commit 9562547

Browse files
authored
Support setting username of username and password (#21)
* Support setting username of username and password Sometimes when using basic auth only the username will be set while at other times botht the username and password is set. The proxy should use the username as the token only when the password component is not set. Otherwise it should use the password to authenticate. Update to Golang 1.16 * Bump chart version
1 parent a10d3a7 commit 9562547

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.15 as builder
1+
FROM golang:1.16 as builder
22
RUN mkdir /build
33
ADD . /build/
44
WORKDIR /build

charts/azdo-proxy/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: azdo-proxy
33
description: A Helm chart for azdo-proxy
44
type: application
5-
version: v0.3.5
6-
appVersion: v0.3.5
5+
version: v0.3.6
6+
appVersion: v0.3.6

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/xenitab/azdo-proxy
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/go-logr/logr v0.2.0

main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,20 @@ func livenessHandler(log logr.Logger) func(http.ResponseWriter, *http.Request) {
150150
func proxyHandler(p *httputil.ReverseProxy, log logr.Logger, a *auth.Authorization, domain string, pat string) func(http.ResponseWriter, *http.Request) {
151151
return func(w http.ResponseWriter, r *http.Request) {
152152
// If basic auth is missing return error to force client to retry
153-
username, _, ok := r.BasicAuth()
153+
username, password, ok := r.BasicAuth()
154154
if !ok {
155155
w.Header().Set("WWW-Authenticate", "Basic realm=\"Restricted\"")
156156
http.Error(w, "Missing basic authentication", http.StatusUnauthorized)
157157
return
158158
}
159159

160+
t := username
161+
if len(password) > 0 {
162+
t = password
163+
}
164+
160165
// Check basic auth with local auth configuration
161-
err := auth.IsPermitted(a, r.URL.EscapedPath(), username)
166+
err := auth.IsPermitted(a, r.URL.EscapedPath(), t)
162167
if err != nil {
163168
log.Error(err, "Received unauthorized request")
164169
http.Error(w, "User not permitted", http.StatusForbidden)

0 commit comments

Comments
 (0)