|
| 1 | + |
| 2 | +.. _manual-out-smtp-auth: |
| 3 | + |
| 4 | +SMTP authentication and TLS |
| 5 | +=========================== |
| 6 | + |
| 7 | +.. versionadded:: 4.1.0 |
| 8 | + |
| 9 | +Starting with OSSEC 4.1.0, ``ossec-maild`` and ``ossec-monitord`` can send email through SMTP servers |
| 10 | +that require authentication and TLS. This requires OSSEC to be built with libcurl (``USE_CURL=yes``). |
| 11 | +The installer sets this automatically when you enable SMTP authentication, secure SMTP, a custom port, |
| 12 | +or disable TLS certificate verification during ``install.sh``. |
| 13 | + |
| 14 | +All options are configured in the ``<global>`` section of ``ossec.conf``. See :ref:`ossec_config.global` |
| 15 | +for the full syntax reference. |
| 16 | + |
| 17 | +Build requirements |
| 18 | +------------------ |
| 19 | + |
| 20 | +Install libcurl development packages on the build host before compiling: |
| 21 | + |
| 22 | +Red Hat family: |
| 23 | + |
| 24 | +.. code-block:: console |
| 25 | +
|
| 26 | + yum install libcurl-devel |
| 27 | +
|
| 28 | +Debian / Ubuntu: |
| 29 | + |
| 30 | +.. code-block:: console |
| 31 | +
|
| 32 | + apt-get install libcurl4-openssl-dev |
| 33 | +
|
| 34 | +If you build manually without ``install.sh``, pass ``USE_CURL=yes`` to ``make``: |
| 35 | + |
| 36 | +.. code-block:: console |
| 37 | +
|
| 38 | + cd ossec-hids-* |
| 39 | + make USE_CURL=yes |
| 40 | + ./install.sh |
| 41 | +
|
| 42 | +Submission port with STARTTLS (port 587) |
| 43 | +---------------------------------------- |
| 44 | + |
| 45 | +Typical configuration for providers that use authenticated submission with STARTTLS |
| 46 | +(``auth_smtp=yes``, ``secure_smtp=no``): |
| 47 | + |
| 48 | +.. code-block:: xml |
| 49 | +
|
| 50 | + <ossec_config> |
| 51 | + <global> |
| 52 | + <email_notification>yes</email_notification> |
| 53 | + <email_to>alerts@example.com</email_to> |
| 54 | + <email_from>ossec@example.com</email_from> |
| 55 | + <smtp_server>smtp.example.com</smtp_server> |
| 56 | + <auth_smtp>yes</auth_smtp> |
| 57 | + <secure_smtp>no</secure_smtp> |
| 58 | + <smtp_port>587</smtp_port> |
| 59 | + <smtp_user>ossec@example.com</smtp_user> |
| 60 | + <smtp_password>your-secret-here</smtp_password> |
| 61 | + <smtp_tls_verify>yes</smtp_tls_verify> |
| 62 | + </global> |
| 63 | + <alerts> |
| 64 | + <email_alert_level>7</email_alert_level> |
| 65 | + </alerts> |
| 66 | + </ossec_config> |
| 67 | +
|
| 68 | +If ``smtp_port`` is omitted and ``auth_smtp`` is ``yes``, port **587** is used automatically. |
| 69 | + |
| 70 | +SMTPS (implicit TLS, port 465) |
| 71 | +------------------------------ |
| 72 | + |
| 73 | +Use ``secure_smtp=yes`` when the server expects TLS from the first byte (SMTPS): |
| 74 | + |
| 75 | +.. code-block:: xml |
| 76 | +
|
| 77 | + <ossec_config> |
| 78 | + <global> |
| 79 | + <email_notification>yes</email_notification> |
| 80 | + <email_to>alerts@example.com</email_to> |
| 81 | + <email_from>ossec@example.com</email_from> |
| 82 | + <smtp_server>smtp.example.com</smtp_server> |
| 83 | + <secure_smtp>yes</secure_smtp> |
| 84 | + <smtp_port>465</smtp_port> |
| 85 | + <smtp_user>ossec@example.com</smtp_user> |
| 86 | + <smtp_password>your-secret-here</smtp_password> |
| 87 | + </global> |
| 88 | + </ossec_config> |
| 89 | +
|
| 90 | +If ``smtp_port`` is omitted and ``secure_smtp`` is ``yes``, port **465** is used automatically. |
| 91 | + |
| 92 | +Plain SMTP (port 25) |
| 93 | +-------------------- |
| 94 | + |
| 95 | +Legacy servers without authentication continue to work as before. Do not set ``auth_smtp`` or |
| 96 | +``secure_smtp`` unless the server requires them: |
| 97 | + |
| 98 | +.. code-block:: xml |
| 99 | +
|
| 100 | + <ossec_config> |
| 101 | + <global> |
| 102 | + <email_notification>yes</email_notification> |
| 103 | + <email_to>alerts@example.com</email_to> |
| 104 | + <smtp_server>192.168.1.10</smtp_server> |
| 105 | + </global> |
| 106 | + </ossec_config> |
| 107 | +
|
| 108 | +Testing and restarting |
| 109 | +---------------------- |
| 110 | + |
| 111 | +Test the configuration without sending mail: |
| 112 | + |
| 113 | +.. code-block:: console |
| 114 | +
|
| 115 | + # /var/ossec/bin/ossec-maild -t |
| 116 | +
|
| 117 | +Restart OSSEC after changing mail settings: |
| 118 | + |
| 119 | +.. code-block:: console |
| 120 | +
|
| 121 | + # /var/ossec/bin/ossec-control restart |
| 122 | +
|
| 123 | +Unattended installation |
| 124 | +----------------------- |
| 125 | + |
| 126 | +For unattended installs, set the following in ``etc/preloaded-vars.conf`` in addition to |
| 127 | +``USER_ENABLE_EMAIL``, ``USER_EMAIL_ADDRESS``, and ``USER_EMAIL_SMTP``: |
| 128 | + |
| 129 | +.. code-block:: console |
| 130 | +
|
| 131 | + USER_SMTP_AUTH="y" |
| 132 | + USER_SMTP_USER="user@example.com" |
| 133 | + USER_SMTP_PASS="secret" |
| 134 | + USER_SMTP_SECURE="n" |
| 135 | + USER_SMTP_PORT="587" |
| 136 | + USER_SMTP_TLS_VERIFY="y" |
| 137 | +
|
| 138 | +See :ref:`install_source_unattended` for the full preloaded-vars example. |
| 139 | + |
| 140 | +Security notes |
| 141 | +-------------- |
| 142 | + |
| 143 | +- Restrict permissions on ``ossec.conf`` because ``smtp_password`` is stored in plain text. |
| 144 | +- Avoid ``smtp_tls_verify=no`` in production; it disables certificate and hostname verification. |
| 145 | +- If ``smtp_server`` is a hostname, ensure name resolution works from ``/var/ossec/etc`` (copy |
| 146 | + ``/etc/resolv.conf`` when needed). |
0 commit comments