-
Notifications
You must be signed in to change notification settings - Fork 814
Description
I'm working on trying to figure out if there's a way to have pgweb automatically refresh the password from the connect backend on some interval. It doesn't appear like there's a way to do that easily so I wanted to bring it up.
For context, at my company we use AWS RDS Aurora with IAM authentication. We run pgweb as a Kubernetes Deployment for each database we spin up. We made a sidecar that handles generating the sigv4 token and hooks up to pgweb's --connect-backend and that all works great for the most part.
The issue is that once that token expires (after one hour) pgweb doesn't attempt to get a new token automatically. Even setting the idle timeout to a low value like 5 minutes will just cause it to disconnect and not automatically reconnect. Simply refreshing the page doesn't seem to work either; you have to navigate to / which triggers a call to /connect/:resource to reconnect and get a new token from the connect backend. It's an easy workaround but the UX isn't great and we get quite a number of support requests from other teams about this.
I came up with a patch that sorta fixes the issue but it's a bit hacky.
diff --git a/pkg/api/middleware.go b/pkg/api/middleware.go
index 14b3c28..47dc629 100644
--- a/pkg/api/middleware.go
+++ b/pkg/api/middleware.go
@@ -40,7 +40,7 @@ func dbCheckMiddleware() gin.HandlerFunc {
// Determine the database connection handle for the session
conn := DbSessions.Get(sid)
if conn == nil {
- badRequest(c, errNotConnected)
+ ConnectWithBackend(c)
return
}
I just wanted to start a discussion about potential solutions. I've got some bandwidth to submit PRs if that would be helpful.