# Unified Request System Deploy


## Installation

Tested on Fedora 42 + Chrome browser
[Fedora Virtualisation guide](https://docs.fedoraproject.org/en-US/quick-docs/virtualization-getting-started/)

### Requirements

- Linux or knowledge of the used concepts in other operating systems (e.g. manual write to the /etc/hosts, virtualisation, containerisation, etc.)
- [SSH key](https://www.ssh.com/academy/ssh/keygen)
- [Vagrant](https://developer.hashicorp.com/vagrant/install)
- [Libvirt](https://libvirt.org/compiling.html) (it is advisable to look for libvirt package in the distribution repositories instead of compiling from the source code)
- [Vagrant Libvirt](https://vagrant-libvirt.github.io/vagrant-libvirt/installation.html)
- [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)

### Steps

1. Open terminal in the root folder of this project and run `vagrant up --provider=libvirt`. See [Possible Issues with libvirt](#possible-issues-with-libvirt) if Vagrant gets stuck on IP address assignment.
2. While waiting for Vagrant to finish, go to `/etc/hosts` on the host machine and add the following line and save
    ```
    192.168.56.10 rt-test.svc.csirt.muni.cz keycloak
    ```
3. After, the Vagrant finishes, run in the same terminal as before: 
   ```
   vagrant --provider=libvirt ssh
   ```
   and then 
   ```
   cd /docker_deploy
   ```
4. Go to http://keycloak:8080/admin/master/console/#/RT-TEST/realm-settings/keys and log in using admin credentials (username: admin - password: admin). Copy the value of RS256 public key.
5. In the same terminal with open ssh connection edit file `compose.yaml` and paste the key into the service `netbox` -> `environment` -> `SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY` (line 236).
6. Navigate to http://192.168.56.10:3000 and log in using one of the test Keycloak users (e.g. username: 100100100 - password: password123) click on the username (bottom left) -> Preferences -> API & Apps -> click `+ New API key...` -> fill out the name -> Create -> copy.
7. In the same terminal with open ssh connection edit file `compose.yaml` and paste the copied Outline token into the `self-service-backend` -> `environment` -> `CSIRTMU_SELF_SERVICE_BACKEND_OUTLINE_TOKEN` (line 23).
8. In the same terminal with open ssh connection run `sudo docker compose up -d` (NetBox takes a few minutes to startup, meanwhile other services are already ready to test)

#### Post Init Steps
- Upload JSON file with Perun users as described in the [Trigger the Sync section](#trigger-the-sync).

### Possible Issues with libvirt
#### Waiting for domain to get an ip address
If the Vagrant gets stuck while waiting for domain to get an ip address, it might help to update the following field in the libvirt config:
```
/etc/libvirt/network.conf
```
Add line:
```
firewall_backend = "iptables"
```

### Exposed Services and Ports

Exposed services:
- self-service interface: http://192.168.56.10:8000
- MinIO S3: http://192.168.56.10:9000
- Keycloak: http://keycloak:8080 http://192.168.56.10:8080
- NetBox: http://192.168.56.10:8081
- Outline: http://192.168.56.10:3000
- Temporal UI: http://192.168.56.10:8082

Vagrant VM:
- RT: https://rt-test.svc.csirt.muni.cz https://192.168.56.10
- NATS API: nats://192.168.56.10:4222

### Keycloak Users
All of the Keycloak testing user credentials are located in the `rtir-deploy/ansible/ansible-deploy-conf.yml` file in the keycloak_fixtures section.

## Usage

### Perun Sync
Perun sync worker listens for new file uploads in the configured MinIO bucket. Once triggered it parses through the file and loads its contents into the database which is then accessible through the REST API.\
**This is necessary for RT Email Parser to work correctly (to correctly link users with their aliases).**

#### Trigger the Sync
Before triggering the synchronisation of users, you can try to send email from alias email address (test_mails/*-alias-mail.mbox) as is described in the [Email Ticket Submission section](#email-ticket-submission) and observe what will happen in RT. Try logging into RT via sender account (username: 100100100 or 200200200 or 300300300 - password: password123) and via root (username: root - password: password).

1. Navigate to the [MinIO](http://192.168.56.10:9000), log in using credentials (username: minio - password: password) -> `perun_sync-1` -> `facility-123456` -> Upload the file `perun-0123456789.json` located in the project root (if any part of the path is missing, simply create it with identical names).
2. Watch the workflow finish in the [Temporal UI](http://192.168.56.10:8082) (Should finish as `Continued as New` and new workflow should be `Running`)

### Self Service Ticket Submission

1. Navigate to the http://192.168.56.10:8000, log in using Keycloak user credentials (e.g. username: 100100100 - password: password123).
2. Explore Self-Service and submit the form.
3. Visit [RT](https://rt-test.svc.csirt.muni.cz) directly (`Sign in with Authentik` -> username: 100100100 - password: password123) or navigate to the `Tickets` page and view tickets connected to the logged account.

### Email Ticket Submission

1. Connect to the Vagrant VM `vagrant --provider=libvirt ssh`
2. Run `sendmail -t rt@rt-test.svc.csirt.muni.cz` (press enter), copy one of the prepared messages (located in `test_mails/`) or write the message (written message will be sent under logged user e.g. `vagrant`) and press ctrl+d (eof) to send.
3. Visit [RT](https://rt-test.svc.csirt.muni.cz) (`Sign in with Authentik` -> username: 100100100 - password: password123 for 'John Kirby' test email or other account for other emails).

### Search NetBox Assets

1. Log into [NetBox](http://192.168.56.10:8081) via admin account (username: admin - password: admin) and create assets for the search (i.e. IP addresses, prefixes or tenants).
2. In the [self-service interface](http://192.168.56.10:8000) select one of the top-level steps: `IP Address Search`, `Prefix Search` or `Tenant Search`.
3. Write the keyword you want search by, click search and see the results.

### Search Outline Documents
In the Outline there are some introductory documents that can be used for search present on startup. Optionally, create own documents by navigating to [Outline](http//192.168.56.10:3000) and logging with Keycloak test user (user: 100100100 - password: password123).

1. In the [self-service interface](http://192.168.56.10:8000) select the top-level step: `Outline Document Search`.
2. Write a keyword that you want to search by (e.g. "editor"), click search and see the results.


## Cleanup

1. In the project root run
```
vagrant --provider=libvirt destroy
```

2. Remove added entries from the `/etc/hosts` file.

