{"action":"created","issue":{"url":"https://api.github.com/repos/Mashape/kong/issues/1246","repository_url":"https://api.github.com/repos/Mashape/kong","labels_url":"https://api.github.com/repos/Mashape/kong/issues/1246/labels{/name}","comments_url":"https://api.github.com/repos/Mashape/kong/issues/1246/comments","events_url":"https://api.github.com/repos/Mashape/kong/issues/1246/events","html_url":"https://github.com/Mashape/kong/issues/1246","id":156542330,"number":1246,"title":"Kong behind dockercloud/haproxy - Problem with oauth2 plugin (ngx.var.scheme:lower() fails)","user":{"login":"DonMartin76","id":7326883,"avatar_url":"https://avatars.githubusercontent.com/u/7326883?v=3","gravatar_id":"","url":"https://api.github.com/users/DonMartin76","html_url":"https://github.com/DonMartin76","followers_url":"https://api.github.com/users/DonMartin76/followers","following_url":"https://api.github.com/users/DonMartin76/following{/other_user}","gists_url":"https://api.github.com/users/DonMartin76/gists{/gist_id}","starred_url":"https://api.github.com/users/DonMartin76/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonMartin76/subscriptions","organizations_url":"https://api.github.com/users/DonMartin76/orgs","repos_url":"https://api.github.com/users/DonMartin76/repos","events_url":"https://api.github.com/users/DonMartin76/events{/privacy}","received_events_url":"https://api.github.com/users/DonMartin76/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-24T15:46:05Z","updated_at":"2016-05-24T21:23:23Z","closed_at":null,"body":"Hello,\r\n\r\nI have a strange problem with my current setup here when using the oauth2 plugin. My setup is as follows: I am using kong inside docker, running without SSL. Using docker-compose, we are terminating the SSL connection using dockercloud/haproxy, also to be able to cluster Kong inside our docker environment.\r\n\r\nNow, when using the oauth2 plugin and trying to retrieve a token from the (auto-generated) oauth2/token endpoint, Kong fails with a 500; when looking inside the `error.log`, I see the following error which puzzles me greatly:\r\n\r\n```\r\n2016/05/24 14:36:57 [error] 109#0: *45 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/kong/plugins/oauth2/access.lua:92: attempt to call method 'lower' (a nil value)\r\nstack traceback:\r\ncoroutine 0:\r\n\t/usr/local/share/lua/5.1/kong/plugins/oauth2/access.lua: in function 'is_https'\r\n\t/usr/local/share/lua/5.1/kong/plugins/oauth2/access.lua:254: in function 'issue_token'\r\n\t/usr/local/share/lua/5.1/kong/plugins/oauth2/access.lua:415: in function 'execute'\r\n\t/usr/local/share/lua/5.1/kong/plugins/oauth2/handler.lua:12: in function 'access'\r\n\t/usr/local/share/lua/5.1/kong.lua:188: in function 'access'\r\n\taccess_by_lua(nginx.conf:98):2: in function <access_by_lua(nginx.conf:98):1>, client: 93.216.233.16, server: _, request: \"POST /petstore-oauth/oauth2/token HTTP/1.1\", host: \"my-correct-server.io\", referrer: \"https://my-correct-server.io/somepath\"\r\n2016/05/24 14:37:08 [error] 109#0: *85 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/kong/plugins/oauth2/access.lua:92: attempt to call method 'lower' (a nil value)\r\n```\r\n\r\nThe code which it says fails looks very innocent, inside `plugins/oauth2/access.lua`:\r\n\r\n```lua\r\nlocal HTTPS = \"https\"\r\n\r\nlocal function is_https(conf)\r\n  local result = ngx.var.scheme:lower() == HTTPS\r\n  if not result and conf.accept_http_if_already_terminated then\r\n    local forwarded_proto_header = ngx.req.get_headers()[\"x-forwarded-proto\"]\r\n    result = forwarded_proto_header and forwarded_proto_header:lower() == HTTPS\r\n  end\r\n  return result\r\nend\r\n```\r\n\r\nDoes anybody have an idea what might wreck the oauth2 call here? If I go directly inside the docker environment and issue the same call to the oauth2/token endpoint, except directly to the `http://kong:8000/petstore-oauth/oauth2/token` endpoint, passing the `X-Forwarded-Proto` header (which normally is added by haproxy) via `-H`, the call succeeds.\r\n\r\nWhat is going wrong here? Which header might be causing Kong to be so confused when being proxied via HAproxy?\r\n\r\nBest regards,\r\nMartin"},"comment":{"url":"https://api.github.com/repos/Mashape/kong/issues/comments/221405689","html_url":"https://github.com/Mashape/kong/issues/1246#issuecomment-221405689","issue_url":"https://api.github.com/repos/Mashape/kong/issues/1246","id":221405689,"user":{"login":"Tieske","id":1077043,"avatar_url":"https://avatars.githubusercontent.com/u/1077043?v=3","gravatar_id":"","url":"https://api.github.com/users/Tieske","html_url":"https://github.com/Tieske","followers_url":"https://api.github.com/users/Tieske/followers","following_url":"https://api.github.com/users/Tieske/following{/other_user}","gists_url":"https://api.github.com/users/Tieske/gists{/gist_id}","starred_url":"https://api.github.com/users/Tieske/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tieske/subscriptions","organizations_url":"https://api.github.com/users/Tieske/orgs","repos_url":"https://api.github.com/users/Tieske/repos","events_url":"https://api.github.com/users/Tieske/events{/privacy}","received_events_url":"https://api.github.com/users/Tieske/received_events","type":"User","site_admin":false},"created_at":"2016-05-24T21:23:23Z","updated_at":"2016-05-24T21:23:23Z","body":">  attempt to call method 'lower' (a nil value)\r\n\r\nHow to reproduce this error in Lua at all?\r\n\r\n````\r\nC:\\luajit>luajit\r\nLuaJIT 2.1.0-beta2 -- Copyright (C) 2005-2016 Mike Pall. http://luajit.org/\r\nJIT: ON SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse\r\n> (nil):lower()\r\nstdin:1: attempt to index a nil value\r\nstack traceback:\r\n        stdin:1: in main chunk\r\n        [C]: at 0x00401ff0\r\n> (1):lower()\r\nstdin:1: attempt to index a number value\r\nstack traceback:\r\n        stdin:1: in main chunk\r\n        [C]: at 0x00401ff0\r\n> \r\n````\r\n\r\nThat would give us a hint as to what is causing it. It doesn't seem to be a regular Lua type.\r\n"}}
{"actor":{"display_login":"Tieske"}}