Skip to content
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

Add support for signed tasks. #73

Closed
wants to merge 9 commits into from

Conversation

hooverdc
Copy link

No description provided.

Copy link
Owner

@RealOrangeOne RealOrangeOne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this feature! It's something we spoke of during the DEP process, but ended up working around with opt-in task functions. However, I do think it'd be a nice feature to add.

Along with my comments, it'd be great if you could add some tests for this new functionality!

@@ -63,7 +63,7 @@ class DBTaskResult(GenericBase[P, T], models.Model):
max_length=max(len(value) for value in ResultStatus.values),
)

enqueued_at = models.DateTimeField(auto_now_add=True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What's the reason for this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enqueued_at was getting set at insert rather than at model creation time. We would have to do an insert and an update to set the signature. Now whether or not enqueued_at should represented the time .enqueue was called or the time the record was inserted, I'm not sure about.


def _task_to_db_task(
self, task: Task[P, T], args: P.args, kwargs: P.kwargs
) -> "DBTaskResult":
from .models import DBTaskResult

return DBTaskResult(
db_task_result: DBTaskResult = DBTaskResult(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The explicit type shouldn't be necessary here

Suggested change
db_task_result: DBTaskResult = DBTaskResult(
db_task_result = DBTaskResult(

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy yelled about it, it really should be able to infer that.

"""
Get canonical form
"""
return {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Because TaskResult is a dataclass, you can call asdict on it to get it as a dict natively, and then massage the types into something JSON-serializable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved .canonical inside the base task result, but for task I only wanted to include invariant values. I don't think status, started_at, or finished_at should form part of the signature.

@hooverdc
Copy link
Author

Thanks, I'll get working on those.

Remove supports_signed_task property from backend.
Get SIGN_TASKS setting from backend options.
Add salt field to DB task result model.
@RealOrangeOne RealOrangeOne marked this pull request as draft August 2, 2024 15:45
@hooverdc
Copy link
Author

@RealOrangeOne Added tests and made updates based on your suggestions.

@RealOrangeOne
Copy link
Owner

CI is still failing. However, on reflection, I'm not sure the added complexity is worthwhile.

Because task functions must be explicitly allowed, there's no ability to gain remote-code execution inside Django (at least not in ways which can be controlled by django-tasks). Whilst it's possible to potentially modify data, if an attacker already has access to the database they can do that anyway, not to mention that they probably have access to other parts of your infrastructure too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants