security.rst 4.6 KB

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