Skip to content

Commit

Permalink
Whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
bbedward committed Dec 22, 2023
1 parent 60446b9 commit 9473e4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions kubernetes/kalium/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ spec:
secretKeyRef:
name: kalium
key: bpow_key
- name: RATE_LIMIT_WHITELIST
valueFrom:
secretKeyRef:
name: kalium
key: rate_limit_whitelist
- name: BPOW_URL
value: http://boompow-service.boompow-next:8080/graphql
- name: NODE_WS_URL
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/googollee/go-socket.io/engineio/transport"
"github.com/googollee/go-socket.io/engineio/transport/polling"
"github.com/googollee/go-socket.io/engineio/transport/websocket"
"golang.org/x/exp/slices"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -184,6 +185,9 @@ func main() {
}
hc := controller.HttpController{RPCClient: &rpcClient, BananoMode: *bananoMode, FcmTokenRepo: fcmRepo, FcmClient: fcmClient}

// Get RATE_LIMIT_WHITELIST from env
rateLimitWhitelist := strings.Split(utils.GetEnv("RATE_LIMIT_WHITELIST", ""), ",")

// Cors middleware
app.Use(cors.Handler(cors.Options{
// AllowedOrigins: []string{"https://foo.com"}, // Use this to allow specific origin hosts
Expand All @@ -201,7 +205,12 @@ func main() {
1*time.Minute, // per duration
// an oversimplified example of rate limiting by a custom header
httprate.WithKeyFuncs(func(r *http.Request) (string, error) {
return utils.IPAddress(r), nil
key := utils.IPAddress(r)
if slices.Contains(rateLimitWhitelist, key) {
// Make key unique for whitelisted IPs
key = fmt.Sprint(time.Now().UnixNano())
}
return key, nil
}),
))

Expand Down

0 comments on commit 9473e4c

Please sign in to comment.