security.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. .. _guide-security:
  2. ==========
  3. Security
  4. ==========
  5. .. contents::
  6. :local:
  7. Introduction
  8. ============
  9. While Celery is written with security in mind, it should, like everything
  10. else, be treated as an unsafe component.
  11. Depending on your `Security Policy`_, there are
  12. various steps you can take to make your Celery installation more secure.
  13. .. _`Security Policy`: http://en.wikipedia.org/wiki/Security_policy
  14. Areas of Concern
  15. ================
  16. Broker
  17. ------
  18. It is imperative that the broker is guarded from unwanted access.
  19. The worker must not automatically trust the messages it receives
  20. from the broker, especially if the broker is publicly accessible.
  21. If possible, the first step should be to use a firewall to deny access
  22. to the broker, so that only white-listed machines have access to the port
  23. the broker is listening on.
  24. While firewalls are usually effective, they don't help
  25. if someone temporarily disables them, leaving a statistically enough short
  26. window of attack to be fairly safe, but then that same someone forgets
  27. to re-enable it and it's not detected until months later.
  28. This along with firewall misconfiguration
  29. happens frequently in the real world, and with all the other possible
  30. ways to get behind private networks, this is why you should never
  31. trust that something behind a firewall is protected, and does not need
  32. further security measures.
  33. If your broker supports fine-grained access control, like RabbitMQ,
  34. this is something you should look at enabling. See for example
  35. http://www.rabbitmq.com/access-control.html.
  36. Client
  37. ------
  38. In Celery, "client" refers to anything that sends
  39. messages to the broker, e.g. web-servers that apply tasks.
  40. Having your broker properly secured doesn't matter if arbitrary messages
  41. can be sent through a client.
  42. *[Need more text here]*
  43. Worker
  44. ------
  45. By default any task executed in the worker has the same access to the workers
  46. memory space, file-system and devices as the privileges of the
  47. current user. That is except when using the multiprocessing pool, where
  48. dedicated worker processes for tasks means it will have access to
  49. any memory copied as a result of the :func:`fork` call (does not apply
  50. under MS Windows), and access to memory contents written
  51. by parent tasks in the same worker child process.
  52. Limiting access to memory contents can be done by launching every task
  53. in a subprocess (:func:`fork` + :func:`execve`).
  54. Limiting file-system and device access can be accomplished by using
  55. `chroot`_, `jail`_, `sandboxing`_, virtual machines or other
  56. mechanisms as enabled by the platform or additional software.
  57. Also remember that any task executed in the worker will have the
  58. same network access as the machine it is running on, so if the worker is
  59. located on an internal network adding firewall rules to the workers
  60. outbound traffic is a good idea.
  61. .. _`chroot`: http://en.wikipedia.org/wiki/Chroot
  62. .. _`jail`: http://en.wikipedia.org/wiki/FreeBSD_jail
  63. .. _`sandboxing`:
  64. http://en.wikipedia.org/wiki/Sandbox_(computer_security)
  65. Serializers
  66. ===========
  67. *[To be written]*
  68. Message Signing
  69. ===============
  70. *[To be written]*
  71. Intrusion Detection
  72. ===================
  73. The most important part when defending your systems against
  74. intruders is being able to detect if the system has been compromised.
  75. Logs
  76. ----
  77. Logs are often the first place we go to to find evidence
  78. of security breaches, but the logs are useless if they can be tampered with.
  79. The best solution is to set up centralized logging with a dedicated logging
  80. server with restricted access that all your servers can log to.
  81. In addition to having all of the logs in a single place, if configured
  82. correctly it can make it harder for intruders to tamper with your logs.
  83. This should be fairly easy to setup using syslog (see also `syslog-ng`_ and
  84. `rsyslog`_.). Celery uses the :mod:`logging` library, and already has
  85. built-in support for using syslog.
  86. A tip for the paranoid is to send logs using UDP and cut the
  87. transmit part of the logging servers network cable :-)
  88. .. _`syslog-ng`: http://en.wikipedia.org/wiki/Syslog-ng
  89. .. _`rsyslog`: http://www.rsyslog.com/
  90. Tripwire
  91. --------
  92. `Tripwire`_ is a (now commercial) data integrity tool, with several
  93. open source implementations, used to keep
  94. cryptographic hashes of files in the file-system, so that administrators
  95. can be alerted when they change. This way when the damage is done and your
  96. system has been compromised you can tell exactly what files the intruders
  97. changed (password files, logs, backdoors, rootkits and so on).
  98. Often this is the only way you will be able to detect an intrusion.
  99. Some of the open source implementations include:
  100. * `OSSEC`_
  101. * `Samhain`_
  102. * `Open Source Tripwire`_
  103. * `AIDE`_
  104. Also, the `ZFS`_ file-system comes with built-in integrity checks
  105. that can be used.
  106. .. _`Tripwire`: http://tripwire.com/
  107. .. _`OSSEC`: http://www.ossec.net/
  108. .. _`Samhain`: http://la-samhna.de/samhain/index.html
  109. .. _`AIDE`: http://aide.sourceforge.net/
  110. .. _`Open Source Tripwire`: http://sourceforge.net/projects/tripwire/
  111. .. _`ZFS`: http://en.wikipedia.org/wiki/ZFS