Replies: 2 comments 1 reply
-
Hey, thanks for the write-up and suggestion. There's not something like this in GraphQL-Pro right now, but here are a couple of other options:
What do you think about trying one of those approaches? |
Beta Was this translation helpful? Give feedback.
-
My currently stable solution that allows me to use my existing middleware as-is, which I want so the response is still a 401 and not a routing error. Thanks for the inspiration, @rmosolgo (There is certainly room to make this cleaner, but this achieves the basics of what I wanted. Auth isn't enabled for local dev where the IAP isn't available.) scope :_internal do
internal_app = ->(next_app) do
Rack::Builder.new do
if ENV.fetch("SECURE_INTERNAL_ROUTES", "on") == "on"
use(Security::Middleware::GoogleIapAuth)
end
run(next_app)
end
end
mount internal_app.(Sidekiq::Web), at: "/sidekiq"
mount internal_app.(graphql_frontend_lazy_routes.dashboard), at: "/graphql/frontend/dashboard"
end Edit: I decided the route constraint is better since it will return a 404 which doesn't leak the presence of a valid endpoint. scope :_internal do
constraints(lambda do |request|
next true if ENV.fetch("SECURE_INTERNAL_ROUTES", "on") == "off"
Security::Middleware::GoogleIapAuth::RouteConstraint.new.matches?(request)
end) do
mount Sidekiq::Web, at: "/sidekiq"
mount graphql_frontend_lazy_routes.dashboard, at: "/graphql/frontend/dashboard"
end
end |
Beta Was this translation helpful? Give feedback.
-
The GraphQL dashboard is great. Nice for getting an overview of how your system is being used.
In our release environments, routes to such internal applications are protected by ingress configuration to ensure a user is authenticated at the ingress level (the Google Identity-Aware Proxy). This allows staff to access it, authenticated by our Google accounts, and the public has no access. Great.
For belt-and-suspenders though, we have Rack middleware that verifies that the user is actually authenticated. We don't want our applications trusting that the auth proxy is actually working. (When the auth proxy works, it adds a request header with hashes we can verify with public keys, etc etc).
Sidekiq has first-class support for this with Sidekiq.use
In our Sidekiq initializer then we can register our middleware that ensures the user has been authenticated. Now if we accidentally disabled our proxy, hitting the Sidekiq dashboard URL would fail with an error that the user isn't authenticated.
The idea here though is of course more generic. It allows great flexibility for developers to customise a third party request handler. Our middleware can handle our custom needs without needing any support from third party libraries.
Is this something that would be feasible for GraphQL Pro? Something like:
Beta Was this translation helpful? Give feedback.
All reactions