Git Product home page Git Product logo

kombu-fernet-serializers's Introduction

Kombu Fernet Serializers

This library registers a set of Kombu serializers which take those built into Kombu and symmetrically encrypts them using Fernet.

The encryption key is accessed via the KOMBU_FERNET_KEY environment variable. To set the encryption key:

import os
from cryptography.fernet import Fernet

key = Fernet.generate_key()
os.environ['KOMBU_FERNET_KEY'] = key

To try it out, start a redis server and from the example directory, run:

pip install celery redis
celery -A tasks worker

Then from another shell:

python -c "from tasks import add; add.delay(1, 2)"

kombu-fernet-serializers's People

Contributors

alex avatar alouie-sfdc avatar dgouldin avatar iamjem avatar istapletoncordascosfdc avatar lambacck avatar rhyselsmore avatar svc-scm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kombu-fernet-serializers's Issues

TypeError raised in Python 3

The cryptography package expects an instance of bytes to be sent to its Fernet.encrypt method: https://github.com/pyca/cryptography/blob/master/cryptography/fernet.py#L63

Since json.dumps is being used to serialize the data before encryption, a string is being passed to the cryptography package. In Python 2 strings are also bytes. In Python 3 they are not, so an explicit translation is required.

It appears that doing something like message.encode('utf-8') (if the Python version is 3.x) would make the cryptography package happy.

Lazy-load KOMBU_FERNET_KEY

I've just started recently using this package as part of a Django + Celery setup, and I'm finding having to set KOMBU_FERNET_KEY even when I'm doing something quite unrelated to Kombu (e.g. making Django database migrations) a real pain.

#12 by @diwu1989 looks like it'll solve the issue and looks good to me, but it's been sitting there for over four years with no feedback.

Is there a reason it hasn't been merged in? Can it be?

Release of 0.1.0 on PyPI?

@iamjem @lambacck @dgouldin could you please push version 0.1.0 to pypi?

(To rephrase @pcraciunoiu from issue #16.)

The current version of kombu-fernet-serializers on pypi is 0.0.5 and has a couple of issues solved by the 0.1.0 release. And most importantly: 0.0.5 does not support Python 3, while 0.1.0 does.

Python 3 NameError: name 'unicode' is not defined

Hi,

I'm getting an error while runnign a flask app in python 3.6.4 with the following config:

    from kombu_fernet.serializers.pickle import MIMETYPE
    CELERY_TASK_SERIALIZER = 'fernet_pickle'
    CELERY_RESULT_SERIALIZER = 'fernet_pickle'
    CELERY_ACCEPT_CONTENT = [MIMETYPE]

Below is the erorr, its looking for unicode which isn't global in python3. Chaning the line to

if isinstance(encoded_message, str):

Solved the issue.

Full error:

11:17:56 web.1   |  [2018-05-25 11:17:56,027: INFO/MainProcess] Received task: car_listing_flask_app.blueprints.general_info.views.wait_and_add_background_task[d8c098d6-3881-4dce-9348-8e898a39464e]  
11:17:56 web.1   |  [2018-05-25 11:17:56,045: ERROR/MainProcess] Pool callback raised exception: DecodeError(NameError("name 'unicode' is not defined",),)
11:17:56 web.1   |  Traceback (most recent call last):
11:17:56 web.1   |    File "/Users/V/Documents/Python/Car_Listing_Project/venv_car_listing_project/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
11:17:56 web.1   |      return obj.__dict__[self.__name__]
11:17:56 web.1   |  KeyError: 'chord'
11:17:56 web.1   |  During handling of the above exception, another exception occurred:
11:17:56 web.1   |  Traceback (most recent call last):
11:17:56 web.1   |    File "/Users/V/Documents/Python/Car_Listing_Project/venv_car_listing_project/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
11:17:56 web.1   |      return obj.__dict__[self.__name__]
11:17:56 web.1   |  KeyError: '_payload'
11:17:56 web.1   |  During handling of the above exception, another exception occurred:
11:17:56 web.1   |  Traceback (most recent call last):
11:17:56 web.1   |    File "/Users/V/Documents/Python/Car_Listing_Project/venv_car_listing_project/lib/python3.6/site-packages/kombu/serialization.py", line 50, in _reraise_errors
11:17:56 web.1   |      yield
11:17:56 web.1   |    File "/Users/V/Documents/Python/Car_Listing_Project/venv_car_listing_project/lib/python3.6/site-packages/kombu/serialization.py", line 263, in loads
11:17:56 web.1   |      return decode(data)
11:17:56 web.1   |    File "/Users/V/Documents/Python/Car_Listing_Project/venv_car_listing_project/lib/python3.6/site-packages/kombu_fernet/serializers/__init__.py", line 16, in inner
11:17:56 web.1   |      if isinstance(encoded_message, unicode):
11:17:56 web.1   |  NameError: name 'unicode' is not defined

Allow for Key Rotation

Say that you have a queue which is constantly receiving new jobs. You don't have the opportunity to force a quiescence, yet need to rotate the encryption keys. Rotating the key with jobs in the queue would possibly lead to some tasks being lost.

I am proposing that we make use of an environmental var such as KOMBU_FERNET_KEY_PREVIOUS. In the case that a key needs to be rotated you can then do it like so:

  1. Set the value of KOMBU_FERNET_KEY_PREVIOUS to the current value of KOMBU_FERNET_KEY
  2. Set the value of KOMBU_FERNET_KEY to the value of the new fernet encryption key.

Within the code, you could try the KOMBU_FERNET_KEY value, and if that raises an exception, try KOMBU_FERNET_KEY_PREVIOUS if it is set.

The name for 'KOMBU_FERNET_KEY_PREVIOUS' can be anything, just named it here to make it obvious. Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.