Skip to content

Commit 2c53fa7

Browse files
tillfriedrichg
andauthored
passthrough (#40)
* Fix(auth): use crypto/subtle to compare strings Related: #37 Signed-off-by: till <[email protected]> * Update(gateway): support passthrough For: #36 Signed-off-by: till <[email protected]> * Update gateway/middleware.go --------- Signed-off-by: till <[email protected]> Co-authored-by: Friedrich Gonzalez <[email protected]>
1 parent 68bed96 commit 2c53fa7

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

gateway/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Tenant struct {
4040
Username string `yaml:"username"`
4141
Password string `yaml:"password"`
4242
ID string `yaml:"id"`
43+
Passthrough bool `yaml:"passthrough"`
4344
}
4445

4546
func Init(filePath string) (Config, error) {

gateway/gateway_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestStartGateway(t *testing.T) {
6969
testCases := []struct {
7070
name string
7171
authHeader string
72+
orgID string
7273
config *Config
7374
paths []string
7475
expectedStatus int
@@ -220,6 +221,31 @@ func TestStartGateway(t *testing.T) {
220221
authHeader: "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password")),
221222
expectedStatus: http.StatusOK,
222223
},
224+
{
225+
name: "passthrough config",
226+
config: &Config{
227+
Tenants: []Tenant{
228+
{
229+
Authentication: "basic",
230+
Username: "username",
231+
Password: "password",
232+
Passthrough: true,
233+
},
234+
},
235+
Distributor: Upstream{
236+
URL: distributorServer.URL,
237+
Paths: []string{
238+
"/test/distributor",
239+
},
240+
},
241+
},
242+
paths: []string{
243+
"/test/distributor",
244+
},
245+
authHeader: "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password")),
246+
orgID: "orgID",
247+
expectedStatus: http.StatusOK,
248+
},
223249
{
224250
name: "not found route",
225251
config: &Config{
@@ -348,6 +374,11 @@ func TestStartGateway(t *testing.T) {
348374
for _, path := range tc.paths {
349375
req, _ := http.NewRequest("GET", mockServer.URL+path, nil)
350376
req.Header.Set("Authorization", tc.authHeader)
377+
378+
if tc.orgID != "" {
379+
req.Header.Set("X-Scope-OrgID", tc.orgID)
380+
}
381+
351382
resp, err := client.Do(req)
352383
if err != nil {
353384
t.Fatal(err)

gateway/middleware.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ func (tenant *Tenant) basicAuth(w http.ResponseWriter, r *http.Request) bool {
5858
return false
5959
}
6060

61-
r.Header.Set("X-Scope-OrgID", tenant.ID)
61+
if !tenant.Passthrough {
62+
r.Header.Set("X-Scope-OrgID", tenant.ID)
63+
}
6264
return true
6365
}
6466

0 commit comments

Comments
 (0)