oAuth calls failing with 404 not found
Describe the bug We are running the oryd/hydra:v0.11.12-alpine and want to update to the latest 1.0 rc6 version. We cloned our system and migrated the database to 1.0 rc6. After migration on the test system we noticed that every second or so call will fail. It happens for normal consent flows, refresh token calls or introspection calls.
The consent or refresh token call will fail because hydra says it doesn't know the used client. A second call with the same client will work.
In the log you can see right on the top that we make a call with a client called mailservice and it fails. After that the call is retried and works
time="2019-01-31T15:56:47Z" level=info msg="started handling request" method=GET remote="172.19.0.1:54500" request="/oauth2/auth?state=e8fff5fe-9b37-4492-83bd-4bd7c21df488&response_type=code&client_id=mailservice&redirect_uri=http%3A%2F%2Flocalhost%3A4445%2Fcallback&scope=offline"
time="2019-01-31T15:56:47Z" level=error msg="An error occurred" description="Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method)" error=invalid_client hint="The requested OAuth 2.0 Client does not exist."
time="2019-01-31T15:56:47Z" level=debug msg="Stack trace: \ngithub.com/ory/fosite.(*Fosite).NewAuthorizeRequest\n\t/go/pkg/mod/github.com/ory/[email protected]/authorize_request_handler.go:231\ngithub.com/ory/hydra/oauth2.(*Handler).AuthHandler\n\t/go/src/github.com/ory/hydra/oauth2/handler.go:603\ngithub.com/ory/hydra/oauth2.(*Handler).AuthHandler-fm\n\t/go/src/github.com/ory/hydra/oauth2/handler.go:173\ngithub.com/julienschmidt/httprouter.(*Router).ServeHTTP\n\t/go/pkg/mod/github.com/julienschmidt/[email protected]/router.go:334\ngithub.com/urfave/negroni.Wrap.func1\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:46\ngithub.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:29\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.middleware.ServeHTTP-fm\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1964\ngithub.com/ory/hydra/cmd/server.(*Handler).RejectInsecureRequests\n\t/go/src/github.com/ory/hydra/cmd/server/handler.go:292\ngithub.com/ory/hydra/cmd/server.(*Handler).RejectInsecureRequests-fm\n\t/go/src/github.com/ory/hydra/cmd/server/handler.go:62\ngithub.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:29\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.middleware.ServeHTTP-fm\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/ory/x/metricsx.(*MetricsManager).ServeHTTP\n\t/go/pkg/mod/github.com/ory/[email protected]/metricsx/middleware.go:207\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.middleware.ServeHTTP-fm\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/ory/hydra/metrics/prometheus.(*MetricsManager).ServeHTTP\n\t/go/src/github.com/ory/hydra/metrics/prometheus/middleware.go:26\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.middleware.ServeHTTP-fm\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/meatballhat/negroni-logrus.(*Middleware).ServeHTTP\n\t/go/pkg/mod/github.com/meatballhat/[email protected]/middleware.go:136\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.(*Negroni).ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:96\ngithub.com/gorilla/context.ClearHandler.func1\n\t/go/pkg/mod/github.com/gorilla/[email protected]/context.go:141\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1964\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2741\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:1847\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1333"
time="2019-01-31T15:56:47Z" level=info msg="completed handling request" measure#https://192.168.162.168:9001/.latency=12387700 method=GET remote="172.19.0.1:54500" request="/oauth2/auth?state=e8fff5fe-9b37-4492-83bd-4bd7c21df488&response_type=code&client_id=mailservice&redirect_uri=http%3A%2F%2Flocalhost%3A4445%2Fcallback&scope=offline" status=302 text_status=Found took=12.3877ms
time="2019-01-31T15:57:11Z" level=info msg="started handling request" method=GET remote="172.19.0.1:54530" request="/oauth2/auth?state=62a250a9-640f-4780-8ff8-86e8cdf3c248&response_type=code&client_id=mailservice&redirect_uri=http%3A%2F%2Flocalhost%3A4445%2Fcallback&scope=offline"
time="2019-01-31T15:57:11Z" level=info msg="completed handling request" measure#https://192.168.162.168:9001/.latency=58533600 method=GET remote="172.19.0.1:54530" request="/oauth2/auth?state=62a250a9-640f-4780-8ff8-86e8cdf3c248&response_type=code&client_id=mailservice&redirect_uri=http%3A%2F%2Flocalhost%3A4445%2Fcallback&scope=offline" status=302 text_status=Found took=58.5336ms
Same for the introspection call
time="2019-01-31T16:01:07Z" level=info msg="started handling request" method=POST remote="172.19.0.1:35884" request=/oauth2/introspect
time="2019-01-31T16:01:07Z" level=error msg="An error occurred" debug=": not_found" description="The request could not be authorized" error=request_unauthorized hint="Check that you provided valid credentials in the right format."
time="2019-01-31T16:01:07Z" level=debug msg="Stack trace: \ngithub.com/ory/fosite.(*Fosite).IntrospectToken\n\t/go/pkg/mod/github.com/ory/[email protected]/introspect.go:69\ngithub.com/ory/hydra/oauth2.(*Handler).IntrospectHandler\n\t/go/src/github.com/ory/hydra/oauth2/handler.go:419\ngithub.com/ory/hydra/oauth2.(*Handler).IntrospectHandler-fm\n\t/go/src/github.com/ory/hydra/oauth2/handler.go:186\ngithub.com/julienschmidt/httprouter.(*Router).ServeHTTP\n\t/go/pkg/mod/github.com/julienschmidt/[email protected]/router.go:334\ngithub.com/urfave/negroni.Wrap.func1\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:46\ngithub.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:29\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.middleware.ServeHTTP-fm\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1964\ngithub.com/ory/hydra/cmd/server.(*Handler).RejectInsecureRequests\n\t/go/src/github.com/ory/hydra/cmd/server/handler.go:292\ngithub.com/ory/hydra/cmd/server.(*Handler).RejectInsecureRequests-fm\n\t/go/src/github.com/ory/hydra/cmd/server/handler.go:62\ngithub.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:29\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.middleware.ServeHTTP-fm\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/ory/x/metricsx.(*MetricsManager).ServeHTTP\n\t/go/pkg/mod/github.com/ory/[email protected]/metricsx/middleware.go:207\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.middleware.ServeHTTP-fm\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/ory/hydra/metrics/prometheus.(*MetricsManager).ServeHTTP\n\t/go/src/github.com/ory/hydra/metrics/prometheus/middleware.go:26\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.middleware.ServeHTTP-fm\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/meatballhat/negroni-logrus.(*Middleware).ServeHTTP\n\t/go/pkg/mod/github.com/meatballhat/[email protected]/middleware.go:136\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:38\ngithub.com/urfave/negroni.(*Negroni).ServeHTTP\n\t/go/pkg/mod/github.com/urfave/[email protected]/negroni.go:96\ngithub.com/gorilla/context.ClearHandler.func1\n\t/go/pkg/mod/github.com/gorilla/[email protected]/context.go:141\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:1964\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2741\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:1847\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1333"
time="2019-01-31T16:01:07Z" level=info msg="completed handling request" measure#https://192.168.162.168:9001/.latency=4754100 method=POST remote="172.19.0.1:35884" request=/oauth2/introspect status=200 text_status=OK took=4.7541ms
time="2019-01-31T16:01:07Z" level=info msg="started handling request" method=POST remote="172.19.0.1:35884" request=/oauth2/introspect
time="2019-01-31T16:01:07Z" level=info msg="completed handling request" measure#https://192.168.162.168:9001/.latency=5671100 method=POST remote="172.19.0.1:35884" request=/oauth2/introspect status=200 text_status=OK took=5.6711ms
hydra.log
To Reproduce On our system it is enough to make consecutive calls with the same client_id and client_secret and some will work some wont.
Expected behavior Expected is a consistent behevior to a call.
Version:
- Environment: Docker on Red Hat Linux and OSx
- Version: 1.0 rc6
Additional context As mentioned above we migrated from 0.11.12 to 1.0.0rc6.
If you look in the clients table, does it have mailservice? Can you also check your database logs for e.g. dropped connections? What does your DB config string look like (filter out credentials).
Yes, the client is there, you can see that se second call is working. I don't see any errors in the database logs. This ist the db config string. postgres://user:[email protected]:5432/hydra?sslmode=disable"
Strange - do you have features like tracing enabled? Maybe try playing around with different configuration settings (e.g. setting max lifetime): https://www.ory.sh/docs/hydra/dependencies-environment#configuration
If you run SELECT * FROM hydra_clients WHERE client_id=mailservice a bunch of times, does that return empty rows?
Also, is the network dislocated? So e.g. PostgreSQL running on AWS and you're running hydra locally?
Both, hydra and Postgres are running as docker containers on my machine. (I could supply both and a small Java project triggering the error if you like) Running "SELECT * FROM hydra_client WHERE id='mailservice'" through pgAdmin docker container is always returning the one expected row.
Yeah, that might be really useful!
Any update on this @alien0matic ?
I'm sorry, I caught a pretty severe cold and am back at the office today, I just started to create your minimal example.
No worries!
I'm closing this for the time being as this is not reproducible in other environments and it seems to no longer be relevant