Skip to content

Commit 4454ba5

Browse files
committed
Add X-Real-Ip header to HTTP request (for when accessing Heimdall directly instead of through Traefik)
1 parent 1cbf9fe commit 4454ba5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

auth/heimdall/heimdall.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"errors"
1010
"io"
1111
"log"
12+
"net"
1213
"net/http"
1314
"os"
1415
"slices"
@@ -82,6 +83,10 @@ func (a *HeimdallAuth) directoryUpdater(dir directory.Directory[resource.Resourc
8283
}
8384

8485
req.Header.Add("Authorization", config.BeaconToken)
86+
ips, err := net.LookupIP(config.ContainerName)
87+
if err == nil && len(ips) > 0 {
88+
req.Header.Add("X-Real-Ip", ips[0].String())
89+
}
8590
resp, err := a.client.Do(req)
8691
if err != nil {
8792
return err
@@ -128,6 +133,10 @@ func (a *HeimdallAuth) getAuthEntry(client *types.Client, username, token string
128133
return nil, err
129134
}
130135
req.Header.Add("Authorization", token)
136+
ips, err := net.LookupIP(config.ContainerName)
137+
if err == nil && len(ips) > 0 {
138+
req.Header.Add("X-Real-Ip", ips[0].String())
139+
}
131140
resp, err := a.client.Do(req)
132141
if err != nil {
133142
return nil, err

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var (
3131
HeimdallUsernamesURL string = GetString("HEIMDALL_USERNAMES_URL", "https://lighthouse.uni-kiel.de/api/internal/users")
3232
BeaconUsername string = GetString("BEACON_USERNAME", "")
3333
BeaconToken string = GetString("BEACON_TOKEN", "")
34+
ContainerName string = GetString("CONTAINER_NAME", "beacon")
3435

3536
// legacy
3637
LegacyDatabaseHost string = GetString("DB_HOST", "localhost")

0 commit comments

Comments
 (0)