-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impl: signature in periodic task #361
Open
SunnyCapt
wants to merge
21
commits into
celery:main
Choose a base branch
from
SunnyCapt:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+376
−26
Open
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ebe6975
feature: PeriodicTask by signature
SunnyCapt 0b91eca
feature: Sign field
SunnyCapt 967f200
Bugfix: id_rsa.pubpermissions & key files creating
SunnyCapt 93431fb
Feature: callback in periodic task (support for option)
SunnyCapt f8e3f17
Fix: sign hash of serialized task signature
SunnyCapt 6388db4
added tests of periodic tasks with task signatures
SunnyCapt 7b02ec0
refactor of keys loading
SunnyCapt 1d96917
Fix deprication warnings in tests and refactor key generating & loading
SunnyCapt 834a432
Update authors file
SunnyCapt 18b0290
Merge branch 'master' into master
SunnyCapt 89cb908
fix imports
SunnyCapt e7fdac4
useless commit
SunnyCapt 9b0c91e
Merge remote-tracking branch 'celery/master' into master
SunnyCapt 7c9479c
call some functions before calling real apply_async
SunnyCapt 28d6391
added comments about app.conf.call_before_run_periodic_task
SunnyCapt c85b77d
django_celery_beat.schedulers.DatabaseScheduler.apply_async refactoring
SunnyCapt bd74d99
Merge branch 'master' of https://github.com/celery/django-celery-beat
SunnyCapt 7bfca12
fix schedulers.py imports
SunnyCapt 02778de
fix performing an action before starting a periodic task
SunnyCapt 2604ab9
fix tests
SunnyCapt f2ec316
added readable info about serialized task
SunnyCapt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,3 +92,4 @@ Wes Winham <[email protected]> | |
Williams Mendez <[email protected]> | ||
WoLpH <[email protected]> | ||
dongweiming <[email protected]> | ||
SunnyCapt <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
django_celery_beat/migrations/0015_periodictask_task_signature.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 2.2.16 on 2020-09-01 10:17 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('django_celery_beat', '0014_remove_clockedschedule_enabled'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='periodictask', | ||
name='task_signature', | ||
field=models.BinaryField(help_text="Serialized `celery.canvas.Signature` type's object of task (or chain, group, etc.) got by https://pypi.org/project/dill/", null=True), | ||
), | ||
migrations.AddField( | ||
model_name='periodictask', | ||
name='task_signature_sign', | ||
field=models.CharField(help_text="Signature (in hex) of serialized `celery.canvas.Signature` type's object (see task_signature field)", max_length=1028, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 2.2.16 on 2020-09-03 13:56 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('django_celery_beat', '0015_periodictask_task_signature'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='periodictask', | ||
name='callback_signature', | ||
field=models.BinaryField(help_text="Serialized `celery.canvas.Signature` type's callback task got by https://pypi.org/project/dill/ (use as link arg in `.apply_async` method)", null=True), | ||
), | ||
migrations.AddField( | ||
model_name='periodictask', | ||
name='callback_signature_sign', | ||
field=models.CharField(help_text="Signature (in hex) of serialized `celery.canvas.Signature` type's callback task (see callback_signature field)", max_length=1028, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
django-timezone-field>=4.0,<5.0 | ||
python-crontab>=2.3.4 | ||
dill | ||
pycrypto | ||
django-appconf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
celery>=4.4,<6.0 | ||
Django>=2.2 | ||
celery>=4.4.7,<6.0 | ||
Django>=2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
from unittest import TestCase | ||
|
||
import dill | ||
from celery.canvas import Signature | ||
|
||
from django_celery_beat.utils import sign_task_signature, verify_task_signature, generate_keys | ||
|
||
|
||
class UtilsTests(TestCase): | ||
test_private_key_path = './test_id_rsa' | ||
test_public_key_path = './test_id_rsa.pub' | ||
|
||
@classmethod | ||
def setUpClass(cls) -> None: | ||
super(UtilsTests, cls).setUpClass() | ||
|
||
os.environ.update({ | ||
'DJANGO_CELERY_BEAT_PRIVATE_KEY_PATH': cls.test_private_key_path, | ||
'DJANGO_CELERY_BEAT_PUBLIC_KEY_PATH': cls.test_public_key_path, | ||
}) | ||
|
||
generate_keys( | ||
private_key_path=cls.test_private_key_path, | ||
public_key_path=cls.test_public_key_path | ||
) | ||
|
||
def test_sign_verify_task_signature(self): | ||
empty_task_signature = Signature() | ||
|
||
serialized_empty_task = dill.dumps(empty_task_signature) | ||
s = sign_task_signature(serialized_empty_task) | ||
|
||
is_valid = verify_task_signature(serialized_empty_task, s) | ||
|
||
self.assertTrue(is_valid) | ||
|
||
@classmethod | ||
def tearDownClass(cls) -> None: | ||
super(UtilsTests, cls).tearDownClass() | ||
|
||
if os.path.exists(cls.test_private_key_path): | ||
os.remove(cls.test_private_key_path) | ||
|
||
if os.path.exists(cls.test_public_key_path): | ||
os.remove(cls.test_public_key_path) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why we need rsa key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's need to sign serialized objects so as not to execute any python code that may appear in the database (execute only signed serilized code which can be signed and added only by main proc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://davidhamann.de/2020/04/05/exploiting-python-pickle/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why noy json serializer? it's default in celery
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON serializer should be the default task serializer in the integration packages as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I'll rewrite (I used dill because it was faster and easier to implement)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dill is ok for pickle, but pickle is not the default serializer. so rewriting this with json would be great