Skip to content

Commit b0b025b

Browse files
authored
Merge pull request #24 from OS2iot/stage
Merge stage prior to release v.1.1.0
2 parents 6bce29a + de1fd8d commit b0b025b

File tree

12 files changed

+153
-16
lines changed

12 files changed

+153
-16
lines changed

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Sphinx==3.3.1
2-
sphinx-rtd-theme==0.5.0
3-
sphinx-autobuild==2020.9.1
1+
Sphinx==4.3.2
2+
sphinx-rtd-theme==1.0.0
3+
sphinx-autobuild==2021.3.14

source/contents.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
external-interface-design/external-interface-design.rst
1414
software-architecture/software-architecture.rst
1515
payload-decoders/payload-decoders.rst
16+
multicast/multicast.rst
1617
iot-data-handling/iot-data-handling.rst
1718
downlink-helpers/downlink-helpers.rst
1819
kombit-adgangsstyring/kombit-adgangsstyring.rst
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
API key access
2+
----------------
3+
4+
OS2IoT supports API key authentification. This allows external clients to use the system without the need of a browser or a user.
5+
6+
Configuration
7+
^^^^^^^^^^^^^
8+
9+
In order to use this type of authentication, an administrator must create an API key with one or more user groups.
10+
This can be done on the portal through the API key management pages. It can be accessed through the menu.
11+
12+
13+
Usage
14+
^^^^^
15+
With an API key, you can fetch and manage data in your OS2IoT system just as well as if you were a user on the browser.
16+
What you can access and manage is limited by the user group (-s) tied to the API key.
17+
18+
With that in mind, let's dive into using an API key. Let's make a few assumptions:
19+
20+
- We have an API key with the value :code:`00000000-abcd-ef00-0000-012345678901`
21+
- This API key is tied to a user group with Read priviliges to an organization and all its applications
22+
- There exists a :code:`GET` endpoint for fetching applications. The route ends with :code:`/application`
23+
24+
There's a broad variety of applications, terminals etc. which can perform HTTP requests. To authenticate this request
25+
with the API key, you must provide it as the header "x-api-key". Below, a screenshot is shown of how this is done in Postman.
26+
27+
|api-key-usage|
28+
29+
The bottom half of the screenshot is the response. The request was limited to 2 applications using the :code:`limit` query parameter.
30+
As seen, the backend responded with 2 (collapsed) applications.
31+
32+
33+
Limitations
34+
^^^^^^^^^^^
35+
While most of the system is accessible using API key authentication, there are some security limitations, however:
36+
37+
- You cannot manage your API key or someone else's
38+
- You cannot manage users nor user groups
39+
- You cannot manage organizations
40+
41+
Currently, there's no expiration date on an API key. It will not expire unless an administrator revokes it on the key management page.
42+
43+
.. |api-key-usage| image:: ./media/api-key-usage.jpg

source/internal-interface-design/internal-interface-design.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ There is four levels of permissions in OS2IoT:
7676

7777
The permissions are hieratical, meaning that you implicitly have all lesser permissions than the ones you have explicitly.
7878
For instance, if a user is an Organization Admin for an Organization, then that user also have the Write and Read permissions.
79+
80+
.. include:: api-key-access.rst
Loading

source/kombit-adgangsstyring/kombit-adgangsstyring.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Steps:
3131
a. Edit the file with a suiteable text editor, such as: VSCode, SublimeText or notepad++.
3232
b. Replace all instances of :code:`{YOUR_BASE_URL}` with your actual base url, i.e. :code:`test.os2iot.dk`.
3333
c. Replace all instances of :code:`{YOUR_PUBLIC_KEY_AS_BASE64}` with the base64 encoded part of the certificate (without newlines), i.e. :code:`<X509Certificate>MIIGJDCCBQygAwIBAgIEXd/ZTjANBgkqhkiG9w0BAQsFADBAMQswCQYDVQQGEwJESzESMBAGA1UECgwJVFJVU1QyNDA...=</X509Certificate>`
34-
(Tip: `{YOUR_PUBLIC_KEY_AS_BASE64}` is the extracted certificate)
34+
35+
(Tip: `{YOUR_PUBLIC_KEY_AS_BASE64}` is the extracted certificate)
3536

3637

3738
3. Create an IT-system in KOMBIT adgangsstrying:

source/maintenance-guide/maintenance-guide.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,37 @@ More information can be found at https://www.chirpstack.io/application-server/in
178178

179179
For installation configuration of Chirpstack see: https://www.chirpstack.io/application-server/install/config/
180180

181+
Migrations
182+
-----------
183+
184+
This project is using TypeORM migrations when changes are applied to the database. This is recommended by TypeORM when the project is used for production.
185+
186+
Generate migrations
187+
~~~~~~~~~~~~~~~~~~~
188+
189+
If you modify or adds an entity (or more than one entity) and/or relationships you then need to generate a migration. In the console you write: :code:`npm run generate-migration <your name of the migration>`. Then a migration file
190+
will be created in a migration folder. The folder path is specified in :code:`ormconfig.json`. A timestamp will be added to the name to indicate when the migration has been generated. If no changes have been made to the entity classes, no migrations are generated.
191+
192+
Run migrations
193+
~~~~~~~~~~~~~~~~
194+
When the project is starting, a new command will be called automatically. This happens every time you run the program because of a prestart script.
195+
The command is :code:`run-migrations` which runs all the pending generated migrations in the Migrations folder, starting from the oldest migration.
196+
In the pending migrations, the :code:`up` block will be executed.
197+
If there are no pending migrations then no migrations will be run.
198+
199+
It will happen in both debug and prod mode.
200+
201+
Revert migration
202+
~~~~~~~~~~~~~~~~~~
203+
If you want to revert a migration later, you can write :code:`npm run typeorm migration:revert`. Then the latest executed migration will be reverted. What happens is that the :code:`down` block in the latest executed migration will be run.
204+
You can continue to do this until you reach the desired migration.
205+
The generated migrations will not be deleted when you are reverting so when you run the project again, the migrations will be run with the :code:`up` block unless you manually deletes them.
206+
207+
Show migration
208+
~~~~~~~~~~~~~~~~
209+
If you are in doubt which migrations has been run, then you have the possibility to write :code:`npm run typeorm migration:show` in the console. Then the migrations will be shown in the console,
210+
and if [X] is marked at a migration it means that it has been run. Otherwise it will be an empty [] which means that is has NOT been run.
211+
181212
Maintaining the docs
182213
--------------------
183214

source/multicast/media/image1.png

48.3 KB
Loading

source/multicast/multicast.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Multicast
2+
======================
3+
4+
This chapter describes the multicast-groups.
5+
6+
What can multicast-groups do?
7+
---------------------------------------------
8+
Multicast-groups make it possible to send a single downlink payload to a group of devices.
9+
10+
A multicast-group consist of some different properties like multicast-address, session-keys and frame counter. All these properties makes it possible to send only one downlink payload to a group
11+
of devices instead of sending many downlink payloads to devices one by one.
12+
13+
Multicast-groups does not support Class-A devices, and at this moment, multicast-groups only supports LoRaWAN devices.
14+
15+
Creation in OS2IoT
16+
-------------------
17+
If you want to make a multicast-group in OS2IoT you have to go into a specific application and then create the multicast-group from there.
18+
19+
You have to fill out all the required forms, and in the end you can add some devices. It's required that the devices share the same service profile, which is set when you create a LoRaWAN device.
20+
The multicast-address has to be an 8-character hexadecimal (hex) value, and the network and application session key has to be a 32-character hex value.
21+
22+
If these requirements are not met, then the multicast-group will not be created.
23+
24+
When you have added the devices that have the same service profile, and have filled out the other forms, then a multicast-group will be created in the database and in Chirpstack.
25+
26+
This sequence diagram describes the flow from the user to the Chirpstack Application Server:
27+
|image1|
28+
29+
Sending downlink payload
30+
-------------------------
31+
32+
When the multicast-group is created it's possible to send a downlink payload to the group of devices. This is done by navigating to the details page of the multicast-group, and from here you have to choose a specific port and a payload that you wish to send to the devices in the Multicast-group.
33+
34+
The downlink payload is sent using Chirpstack which also has the multicast-group with the devices from OS2IoT.
35+
36+
Explanation of properties
37+
--------------------------
38+
39+
A very short explanation of some of the properties that needs to be fulfilled when creating a multicast-group:
40+
41+
**Multicast address:** An address that defines the multicast-group. Has to be an 8-character hex value.
42+
43+
**Application Session Key:** An application session key used to encrypt the payloads that are send to the multicast-group. Has to be a 32-character hex value.
44+
45+
**Network Session Key:** A network session key is used to compute the message integrity check field of the packets sent to the group. Has to be a 32-character hex value.
46+
47+
----------
48+
49+
.. |image1| image:: ./media/image1.png

source/software-architecture/software-architecture.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ Process perspective
5151
Receive IoT device data
5252
~~~~~~~~~~~~~~~~~~~~~~~
5353

54-
See the seperate page: `IoT Data management <../iot-data-handling/iot-data-handling.html`_.
54+
See the separate page: `IoT Data management`_.
55+
56+
.. _`IoT Data management`: ../iot-data-handling/iot-data-handling.html
5557

5658
Implementation perspective
5759
--------------------------
@@ -280,9 +282,15 @@ OS2iot REST API security
280282

281283
In order to use the REST API exposed by OS2iot, the user must be authenticated.
282284

283-
Authentication is done using the JWT gained from the :code:`/api/v1/auth/login` endpoint.
285+
There are two methods of authentication. The first method is done by using the JWT gained from the :code:`/api/v1/auth/login` endpoint.
284286
The JWT is inserted as a Bearer token in the :code:`Authorization` header of the type :code:`Bearer` as described in RFC 6750, section 2.1.
285287

288+
The second method of authentication involves using an API key generated on the :code:`/api/v1/api-key` endpoint.
289+
An API key is tied to one or more user groups so the access level reflects what each user group is permitted.
290+
It can be created by users with an organization administrator role or higher.
291+
292+
The API key is inserted as text in the :code:`X-API-KEY` header. Note that if a valid JWT token is provided, then API key authentication is skipped.
293+
286294
Device security
287295
~~~~~~~~~~~~~~~
288296

0 commit comments

Comments
 (0)