You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,7 @@ CHANGELOG
59
59
-`intelmq.bots.outputs.smtp_batch.output`: Added a bot to gathering the events and sending them by e-mails at a stroke as CSV files (PR#2253 by Edvard Rejthar)
60
60
61
61
### Documentation
62
+
- API: update API installation to be aligned with the rewritten API, and clarify some missing steps.
62
63
63
64
### Tests
64
65
- New decorator `skip_installation` and environment variable `INTELMQ_TEST_INSTALLATION` to skip tests requiring an IntelMQ installation on the test host by default (PR#2370 by Sebastian Wagner, fixes #2369)
`intelmq-api` is a `hug <http://hug.rest>`_ based API for the `IntelMQ <https://github.com/certtools/intelmq/>`_ project.
9
+
`intelmq-api` is a `FastAPI <https://fastapi.tiangolo.com/>`_ based API for the `IntelMQ <https://github.com/certtools/intelmq/>`_ project.
10
10
11
11
.. contents::
12
12
@@ -23,51 +23,140 @@ For the list of supported distributions, please see the intelmq :doc:`installati
23
23
Our repository page gives `installation instructions for various operating systems <https://software.opensuse.org/download.html?project=home:sebix:intelmq&package=intelmq-api>`_.
24
24
No additional set-up steps are needed if you use these packages.
25
25
26
-
The `intelmq-api` provides the route ``/api`` for managing the IntelMQ installation.
26
+
The `intelmq-api` provides the route ``/v1/api`` for managing the IntelMQ installation.
27
27
28
-
For development purposes and testing you can also run `intelmq-api` directly using ``hug``:
28
+
For development purposes and testing, you can also run `intelmq-api` using development script
29
+
from this `repository <https://github.com/certtools/intelmq-api>`_:
29
30
30
31
.. code-block:: bash
31
32
32
-
hug -m intelmq_api.serve
33
+
./scripts/run_dev.sh
34
+
35
+
The API is then served on ``127.0.0.1:8000/v1/api``, and the interactive documentation on ``127.0.0.1:8000/docs``.
36
+
Please refer to the repository README for more development tips.
33
37
34
38
Installation using pip
35
39
^^^^^^^^^^^^^^^^^^^^^^
36
40
37
-
The `intelmq-api` packages ship a configuration file in ``${PREFIX}/etc/intelmq/api-config.json``, a positions configuration for the manager in ``{PREFIX}/etc/intelmq/manager/positions.conf``, a virtualhost configuration file for Apache 2 in ``${PREFIX}/etc/intelmq/api-apache.conf`` and a sudoers configuration file in ``${PREFIX}/etc/intelmq/api-sudoers.conf``.
41
+
.. note::
42
+
43
+
Native system packages (DEB, RPM) should automatically prepare steps described in this section. If
44
+
you wish to base on package from pip, you may need to do them manually, as described below.
45
+
46
+
To configure your system to serve the API for not-development purposes, you need to prepare a
47
+
configuration for IntelMQ API, a position config for the IntelMQ Manager as well as a web application
48
+
server and a (reverse)proxy. For all those steps we have prepared example configuration, intended
49
+
to work with `Gunicorn <https://gunicorn.org/>`_ as the web server and `Apache 2 <https://httpd.apache.org/>`_
50
+
as the proxy.
51
+
52
+
The `intelmq-api` package ships the following example files:
53
+
- ``${PREFIX}/etc/intelmq/api-config.json`` - the API configuration,
54
+
- ``${PREFIX}/etc/intelmq/manager/positions.conf`` - positions configuration for the manager,
55
+
- ``${PREFIX}/etc/intelmq/api-apache.conf`` - a virtualhost configuration file for Apache 2,
56
+
- ``${PREFIX}/etc/intelmq/api-sudoers.conf`` - a sudoers configuration file,
57
+
- ``${PREFIX}/etc/intelmq/intelmq-api.service`` - a systemd service unit configuration for Gunicorn,
58
+
- ``${PREFIX}/etc/intelmq/intelmq-api.socket`` - a systemd socket unit configuration.
59
+
38
60
The value of ``${PREFIX}`` depends on your environment and is something like ``/usr/local/lib/pythonX.Y/dist-packages/`` (where ``X.Y`` is your Python version).
39
61
62
+
.. note::
63
+
64
+
All configuration files have example paths to the IntelMQ API package. During the installation
65
+
please ensure to update them with the right value, as the ``${PREFIX}``.
66
+
67
+
Installing packages
68
+
~~~~~~~~~~~~~~~~~~~
69
+
70
+
Let's start with installing the IntelMQ API package:
71
+
72
+
.. code-block:: bash
73
+
74
+
pip install intelmq-api
75
+
76
+
You need to install Gunicorn and Apache2 on your own, e.g., using apt:
77
+
78
+
.. code-block:: bash
79
+
80
+
apt install gunicorn apache2
81
+
82
+
Then, if you didn't use it before, ensure to enable the ``proxy_http`` module for Apache:
83
+
84
+
.. code-block:: bash
85
+
86
+
a2enmod proxy_http
87
+
88
+
Configuring Apache
89
+
~~~~~~~~~~~~~~~~~~
90
+
40
91
The file ``${PREFIX}/etc/intelmq/api-apache.conf`` needs to be placed in the correct place for your Apache 2 installation.
41
92
- On Debian and Ubuntu, move the file to ``/etc/apache2/conf-available.d/api-apache.conf`` and then execute ``a2enconf api-apache``.
42
93
- On CentOS, RHEL and Fedora, move the file to ``/etc/httpd/conf.d/``.
43
94
- On openSUSE, move the file to ``/etc/apache2/conf.d/``.
44
-
Don't forget to reload your webserver afterwards.
95
+
96
+
Don't forget to reload the Apache2 afterwards.
97
+
98
+
Configuring Systemd services
99
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100
+
101
+
.. note::
102
+
103
+
This step could be also done by calling the script:
104
+
105
+
.. code-block:: bash
106
+
107
+
intelmq-api-setup-systemd
108
+
109
+
The systemd configuration files (``intelmq-api.service`` and ``intelmq-api.socket``) are responsible
110
+
for instructing systemd daemon to start and keep running Gunicorn (that serves the API), and
111
+
forwarding requests between proxy and the Gunicorn instance.
112
+
113
+
- Files ``${PREFIX}/etc/intelmq/intelmq-api.service`` and ``${PREFIX}/etc/intelmq/intelmq-api.socket``
114
+
should be placed in ``/lib/systemd/system/`` directory. Then adapt the webserver username in
115
+
``intelmq-api.service``.
116
+
117
+
After moving files, you can enable the service by executing ``systemctl enable intelmq-api`` to
118
+
start it on the system startup.
119
+
120
+
Setup API configuration files
121
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45
122
46
123
- The file ``${PREFIX}/etc/intelmq/api-config.json`` needs to be moved to ``/etc/intelmq/api-config.json``.
47
124
- The file ``${PREFIX}/etc/intelmq/manager/positions.conf`` needs to be moved to ``/etc/intelmq/manager/positions.conf``.
48
-
- Last but not least move the file ``${PREFIX}/etc/intelmq/api-sudoers.conf`` to ``/etc/sudoers.d/01_intelmq-api`` and adapt the webserver user name in this file. Set the file permissions to ``0o440``.
125
+
- Last but not least move the file ``${PREFIX}/etc/intelmq/api-sudoers.conf`` to ``/etc/sudoers.d/01_intelmq-api`` and adapt the webserver username in this file. Set the file permissions to ``0o440``.
126
+
127
+
Afterwards, continue with the section Permissions below. When you finish the configuration,
128
+
you can start the service using ``systemctl start intelmq-api``. You may need to restart the service
129
+
after any configuration change.
49
130
50
-
Afterwards continue with the section Permissions below.
131
+
Next steps
132
+
~~~~~~~~~~
51
133
52
-
IntelMQ 2.3.1 comes with a tool ``intelmqsetup`` which performs these set-up steps automatically.
53
-
Please note that the tool is very new and may not detect all situations correctly. Please report us any bugs you are observing.
54
-
The tools is idempotent, you can execute it multiple times.
134
+
The example Apache2 and Gunicorn configurations serve the IntelMQ API under ``/intelmq`` prefix,
135
+
what means that at this moment you should be able to get, e.g., the API documentation under
136
+
``/intelmq/docs`` etc.
137
+
138
+
Now, you should continue with the API configuration and creating users. If you didn't do it before,
139
+
it's also time to configure IntelMQ itself.
140
+
141
+
IntelMQ 2.3.1 comes with a tool ``intelmqsetup`` which helps with performing some steps automatically.
142
+
Please note that the tool is still under development and may not detect all situations correctly.
143
+
Please report us any bugs you are observing. The tool is idempotent, you can execute it multiple times.
55
144
56
145
***********************
57
146
Configuring intelmq-api
58
147
***********************
59
148
60
-
Depending on your setup you might have to install ``sudo`` to make it possible for the ``intelmq-api`` to run the ``intelmq`` command as the user-account usually used to run ``intelmq`` (which is also often called ``intelmq``).
149
+
Depending on your setup, you might have to install ``sudo`` to make it possible for the ``intelmq-api`` to run the ``intelmq`` command as the user-account usually used to run ``intelmq`` (which is also often called ``intelmq``).
61
150
62
151
``intelmq-api`` is configured using a configuration file in ``json`` format.
63
152
``intelmq-api`` tries to load the configuration file from ``/etc/intelmq/api-config.json`` and ``${PREFIX}/etc/intelmq/api-config.json``, but you can override the path setting the environment variable ``INTELMQ_API_CONFIG``.
64
-
(When using Apache, you can do this by modifying the Apache configuration file shipped with ``intelmq-api``, the file contains an example)
153
+
(When using Gunicorn and systemd service, you can do this by modifying the ``intelmq-api.service`` configuration file shipped with ``intelmq-api``, the file contains an example)
65
154
66
-
When running the API using ``hug``, you can set the environment variable like this:
155
+
When running the API using development mode, you can set the environment variable like this:
The default configuration which is shipped with the packages is also listed here for reference:
@@ -83,7 +172,7 @@ The default configuration which is shipped with the packages is also listed here
83
172
}
84
173
85
174
86
-
On Debian based systems, the default path for the ``session_store`` is ``/var/lib/dbconfig-common/sqlite3/intelmq-api/intelmqapi``, because the Debian package uses the Debian packaging tools to manage the database file.
175
+
On Debian based systems, the default path for the ``session_store`` is ``/var/lib/dbconfig-common/sqlite3/intelmq-api/intelmqapi`` because the Debian package uses the Debian packaging tools to manage the database file.
87
176
88
177
The following configuration options are available:
89
178
@@ -92,14 +181,14 @@ The following configuration options are available:
92
181
This means that if the command you want to use needs parameters, they have to be separate strings.
93
182
* ``allowed_path``: intelmq-api can grant **read-only** access to specific files - this setting defines the path those files can reside in.
94
183
* ``session_store``: this is an optional path to a sqlite database, which is used for session storage and authentication. If it is not set (which is the default), no authentication is used!
95
-
* ``session_duration``: the maximal duration of a session, its 86400 seconds by default
184
+
* ``session_duration``: the maximal duration of a session, it's 86400 seconds by default
96
185
* ``allow_origins``: a list of origins the responses of the API can be shared with. Allows every origin by default.
97
186
98
187
Permissions
99
188
^^^^^^^^^^^
100
189
101
190
``intelmq-api`` tries to write a couple of configuration files in the ``${PREFIX}/etc/intelmq`` directory - this is only possible if you set the permissions accordingly, given that ``intelmq-api`` runs under a different user.
102
-
The user the API run as also needs write access to the folder the ``session_store`` is located in, otherwise there will be an error accessing the session data.
191
+
The user the API run as also needs write access to the folder the ``session_store`` is located in; otherwise there will be an error accessing the session data.
103
192
If you're using the default Apache 2 setup, you might want to set the group of the files to ``www-data`` and give it write permissions (``chmod -R g+w <directoryname>``).
104
193
In addition to that, the ``intelmq-manager`` tries to store the bot positions via the API into the file ``${PREFIX}/etc/intelmq/manager/positions.conf``.
105
194
You should therefore create the folder ``${PREFIX}/etc/intelmq/manager`` and the file ``positions.conf`` in it.
@@ -138,7 +227,7 @@ To do so, first send a POST-Request with JSON-formatted data to http://localhost
138
227
139
228
{
140
229
"username": "$your_username",
141
-
"password: "$your_password"
230
+
"password": "$your_password"
142
231
}
143
232
144
233
With valid credentials, the JSON-formatted response contains the ``login_token``.
If you see the IntelMQ Manager interface and menu, but the API calls to the back-end querying configuration and status of IntelMQ fail with "Access Denied" or "Authentication Required: Please provide valid Token verification credentials" errors, you are maybe not logged in while the API requires authentication.
190
279
191
-
By default, the API requires authentication. Create user accounts and login with them or - if you have other protection means in place - deactivate the authentication requirement by removing or renaming the `session_store` parameter in the configuration.
280
+
By default, the API requires authentication. Create user accounts and login with them, or - if you have other protection means in place - deactivate the authentication requirement by removing or renaming the `session_store` parameter in the configuration.
192
281
193
282
Internal Server Error
194
283
^^^^^^^^^^^^^^^^^^^^^
195
284
196
-
There can be various reasons for internal server errors. You need to look at the error log of your web server, for example ``/var/log/apache2/error.log`` or ``/var/log/httpd/error_log`` for Apache 2. It could be that the sudo-setup is not functional, the configuration file or session database file can not be read or written or other errors in regards to the execution of the API program.
285
+
There can be various reasons for internal server errors. You need to look at the error log of your web server, for example ``/var/log/apache2/error.log`` or ``/var/log/httpd/error_log`` for Apache 2. It could be that the sudo-setup is not functional, the configuration file or session database file can not be read or written or other errors in regard to the execution of the API program.
197
286
198
287
Can I just install it from the deb/rpm packages while installing IntelMQ from a different source?
@@ -202,15 +291,44 @@ Yes, you can install the API and the Manager from the deb/rpm repositories, and
202
291
However, knowledge about Python and system administration experience is recommended if you do so.
203
292
204
293
The packages install IntelMQ to ``/usr/lib/python3*/site-packages/intelmq/``.
205
-
Installing with ``pip`` results in ``/usr/local/lib/python3*/site-packages/intelmq/`` (and some other accompaning resources) which overrides the installation in ``/usr/lib/``.
294
+
Installing with ``pip`` results in ``/usr/local/lib/python3*/site-packages/intelmq/`` (and some other accompanying resources) which overrides the installation in ``/usr/lib/``.
206
295
You probably need to adapt the configuration parameter ``intelmq_ctl_cmd`` to the ``/usr/local/bin/intelmqctl`` executable and some other tweaks.
207
296
208
297
sqlite3.OperationalError: attempt to write a readonly database
SQLite does not only need write access to the database itself, but also the folder the database file is located in. Please check that the webserver has write permissions to the folder
300
+
SQLite does not only need write access to the database itself, but also the folder the database file is located in. Please check that the webserver has `write` permissions to the folder
212
301
the session file is located in.
213
302
303
+
sqlite3.OperationalError: unable to open database file
0 commit comments