data-govt-nz / ckanext-security

A CKAN extension to hold various security improvements for CKAN
GNU Affero General Public License v3.0
25 stars 32 forks source link

Each ckan requests give key error for 'content-type' #20

Closed skumlk closed 5 years ago

skumlk commented 5 years ago

I installed ckanext-secuirty using the guidelines in here https://github.com/data-govt-nz/ckanext-security, my ckan version is 2.8 and ubuntu version is 16.04. But now for every request I get the following two errors, I get first error several times for a page request and the second error once for every page request, if you can please help if there is any misconfiguration or a bug in extension

Exception happened during processing of request from ('127.0.0.1', 58688) Traceback (most recent call last): File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/httpserver.py", line 1068, in process_request_in_thread self.finish_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.7/SocketServer.py", line 652, in init self.handle() File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/httpserver.py", line 442, in handle BaseHTTPRequestHandler.handle(self) File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle self.handle_one_request() File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/httpserver.py", line 437, in handle_one_request self.wsgi_execute() File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/httpserver.py", line 289, in wsgi_execute for chunk in result: File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/registry.py", line 409, in streaming_iter for item in self.application(environ, start_response): File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/beaker/middleware.py", line 156, in call return self.wrap_app(environ, session_start_response) File "/usr/lib/ckan/default/src/ckanext-security/ckanext/security/middleware.py", line 55, in call if 'text/html' in resp.headers['Content-type']: File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/webob/headers.py", line 16, in getitem raise KeyError(key) KeyError: 'content-type'


File "/usr/lib/ckan/default/lib/python2.7/site-packages/repoze/who/middleware.py", line 75, in call api.authenticate() # identity saved in environ File "/usr/lib/ckan/default/lib/python2.7/site-packages/repoze/who/api.py", line 129, in authenticate ids = self._identify() File "/usr/lib/ckan/default/lib/python2.7/site-packages/repoze/who/api.py", line 308, in _identify identity = plugin.identify(self.environ) File "/usr/lib/ckan/default/lib/python2.7/site-packages/repoze.who_use_beaker-0.4-py2.7.egg/repoze/who/plugins/use_beaker.py", line 37, in identify s = self._get_beaker(environ) File "/usr/lib/ckan/default/lib/python2.7/site-packages/repoze.who_use_beaker-0.4-py2.7.egg/repoze/who/plugins/use_beaker.py", line 92, in _get_beaker self.session_name) ValueError: No Beaker session (beaker.session) in environment

My configuration are as following,

development.ini

beaker.session.key = ckan beaker.session.secret = ya6CWNIY3iFOd5+ofUjtKtqPU beaker.session.data_serializer = json beaker.session.secure = true beaker.session.timeout = 3600 beaker.session.save_accessed_time = true beaker.session.type = ext:memcached beaker.session.url = 127.0.0.1:11211 beaker.session.memcache_module = pylibmc beaker.session.cookie_expires = true beaker.session.cookie_domain = http://localhost:5000

ckan.plugins = stats resource_proxy geo_view image_view security ckan.site_url = http://localhost:5000

ckanext.security.memcached = 127.0.0.1:11211 ckanext.security.domain = http://localhost:5000 ckanext.security.lock_timeout = 900
ckanext.security.login_max_count = 10

who.ini

[plugin:use_beaker] use = repoze.who.plugins.use_beaker:make_plugin key_name = ckan_session delete_on_logout = True

[plugin:local_plugin] use = ckanext.local_plugin.plugin:local_plugin

[plugin:auth_tkt] use = ckan.lib.auth_tkt:make_plugin

[plugin:friendlyform] use = repoze.who.plugins.friendlyform:FriendlyFormPlugin login_form_url= /user/login login_handler_path = /login_generic logout_handler_path = /user/logout rememberer_name = auth_tkt post_login_url = /user/logged_in post_logout_url = /user/logged_out charset = utf-8 rememberer_name = use_beaker

[general] request_classifier = repoze.who.classifiers:default_request_classifier challenge_decider = repoze.who.classifiers:default_challenge_decider

[identifiers] plugins = friendlyform;browser auth_tkt use_beaker

[authenticators] plugins = auth_tkt ckan.lib.authenticator:UsernamePasswordAuthenticator local_plugin ckanext.security.authenticator:CKANLoginThrottle ckanext.security.authenticator:BeakerMemcachedAuth

[challengers] plugins = friendlyform;browser

pylons_app.py


app = PluggableAuthenticationMiddleware(
        app,
      xxxxxxxxxxxxxxxxxxxxx
    )

try:
        from ckanext.security.middleware import CSRFMiddleware
        app = CSRFMiddleware(app, config)
    except ImportError:
        pass

    app = SessionMiddleware(app, config)
    app = RegistryManager(app, streaming=True)

    if asbool(static_files):

My memcache instance is also running.

skumlk commented 5 years ago

I noticed something interesting, I have no idea how this happens, but I get the first error for every page requests from Firefox. But for chrome I never get the first error, only the second error.

camfindlay commented 5 years ago

There is a PR in progress which adds support for CKAN 2.7 up (master as it sits will work for 2.6 down)... you may want to test out that branch (note you need to dump memcache and replace with redis for your sessions). We haven't explicitly tested with 2.8 so would be keen to hear how you get on. We're looking at tidying up the PR and merging shortly so we can tag a proper release.

ebuckley commented 5 years ago

HI @skumlk , I've noticed a similar issue with ckan2.8 and ckanext-security.

I've create this PR to fix it https://github.com/data-govt-nz/ckanext-security/pull/21

camfindlay commented 5 years ago

Should be fixed in #21 please reopen or re-raise issue if you are still having issues.