kong.request.get_header - header length issue
mpromny opened this issue · 2 comments
mpromny commented
Summary
- Env: K8s
- Deployment via Helm
- Kong version (
2.4
) - customized - Kong-python-pdk - 0.25
- each plugin as a microservice approach
- Issue:
- Python server is unable to get headers larger than 1024 characters
Additional Details & Logs
- Error:
[info] 30#0: *17 [py:32] DEBG - [16:51:56] rpc: #32 return: {'Data': {'Method': 'kong.request.get_header', 'Args': ('x-test-header',)}, 'EventId': 5}, context: ngx.timer
[error] 30#0: *124 recv() failed (104: Connection reset by peer), client: 100.97.23.0, server: kong, request: "GET /foo HTTP/1.1", host: "kong-test.example.com"
-
Error description:
- It seems that python plugin server restarts/fails while it has to read headers longer than 1024 characters.
- If an error occurs, Kong processes the request without involving Kong python server
-
Assumptions:
I could be wrong but maybe it's somehow connected with listener definition:
https://github.com/Kong/kong-python-pdk/blob/master/kong_pdk/listener.py
Steps To Reproduce
- Load plugin as configmap via helm or add directly to the docker image
Plugin:
#!/usr/bin/python3
import os
import time
import kong_pdk.pdk.kong as kong
Schema = (
{"message": {"type": "string"}}
)
version = '0.1.0'
priority = 0
class Plugin(object):
def __init__(self, config):
self.config = config
def access(self, kong: kong):
message = "hello"
if 'message' in self.config:
message = self.config['message']
# Get Authorization Header from the request
try:
header_auth, err_auth = kong.request.get_header("x-test-header")
if err_auth:
kong.log.err(err_auth)
except Exception as e:
kong.log.err(e)
kong.response.exit(403,"Too long header")
# Authorization header is empty
try:
kong.service.request.set_header("x-new-header", str(header_auth))
except Exception as e:
kong.log.err(e)
kong.response.exit(403,str(e))
# add below section to allow this plugin optionally be running in a dedicated process
if __name__ == "__main__":
from kong_pdk.cli import start_dedicated_server
start_dedicated_server("py-hello", Plugin, version, priority)
2.Modify Kong configuration:
log_level: debug
plugins: bundled, py-hello
pluginserver_names: py
pluginserver_py_socket: /usr/local/kong/py_hello.sock
pluginserver_py_start_cmd: /opt/test/py-hello.py -vvv
pluginserver_py_query_cmd: /opt/test/py-hello.py -dump
- Load plugin
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: py-hello
annotations:
kubernetes.io/ingress.class: kong
labels:
global: "true"
plugin: py-hello
- Execute:
curl -L -X GET https://kong-test.example.com/foo \ -H 'x-test-header: mNYEQap544A9KEsILt6sv8WHICsXkVKIFdtDxIKdRkwKqOcvjWQCAVDNfjncendb3uSEXCoxBfCVsvbIldYghKd5koonnlTCGLr0PkDQO3hHOSnI0u0usAFtyxiywZ4ezDUsJ9iLTWXUcMN8QTyfgkRRGYX7EN4DEKp061B6PT6YzSXfR2iHfsimmoWewcS8XvCy6DqcG7Im0c4486lCgT8q4jySL7z08iP40plGVgpqCN5PxEOrmbjXFdO32Lin70zPBgUq1unjzLQY50kycR4kal07FmuiaBFJQAeGKg4xkHQOcgzbmUZ9Ibe0n2p2Os2FiApPAlvtyt4bNofI7l2REgzSLPaXia3zyQeJL7MurePa5EbQKxL4qxvY21F2JbisiwyYCAqnyUpuK6eHRsqL2ISntdsd4A97s2HoSfTNtO3npJKinclYQNvlqJ54HK40OB1gJKg27e8qh2r0Ljr7DsFpG8aCyYjofnQH7NyyE5qvjnmRbQiARHn5jmcr3UDmZsVLZrPsUmOOVNBMtpRwaXOQlbHxDW5ctMQnafn4zcS4r2SZAnvWPLa3Apwv3UxU7z6ihO4JvT6QNswmeHfmC1Iw474OILsef2AquZfGCaxtfuucOidYAXwRhe53wX8xhcGZoUlGoi17CelEj8HoLZtQQF6bWwnTneq85PyBqm3Gfeg7ygnoLAPLjtCN8sBo6YbTSP4gstu9VvZVxCsBjitxAljDWJ3B2mzeGCxvxHV4q1Xdno9tYqcZho0EbqENEwERdCRftcSYdAoZzKpU77o5Ybgg3H6wb6pKrnT0t8xkIlR9s3j72DqcGRFOFsS9jQp0TlVLfdO45xdFTuKbRVrMzbAZLeuAQqPVP3iyAMFFYACqySQHJNBqmbtpUt8jSX18IYDCcuNwJ1NuXzuAxfx36VSzyeUmFzs0cFKz5yno1F3ZaSb7QEH2UNB5SgDfDPfX1RqRcMlagt1qgvim3k1zsFmMjHIwRwh2AgYdS'