README.md 2.81 KB
Newer Older
Trishna Saeharaseelan's avatar
Trishna Saeharaseelan committed
1 2
# Communications Backbone

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Communications Backbone by C2 Team (NOC)

## DJ prototype 

I did this in freedom-fire-day so it doesn't currently follow the flask template. 

It's also a bit weird because it writes to a local ignored `clients.json` file 
instead of using a database. I did this as a placeholder because we've not yet 
decided what the infrastructure looks like.

### Data flow 

- Client A sends to `client-a-outbox` (or POSTs to API /send - not yet implemented)
- Messages are forwarded from `client-a-outbox` to `soar-publish` 
- Messages are published from `soar-publish` with the given topic read from the message 
- Subscribers listen to for messages 
- Subscription is delivered to `client-b-inbox` 
- Client B reads from `client-b-inbox (or GETs from API /receive)

There is a parallel flow when a client sends to `client-a-notify` in which case the 
messages are delivered through the broadcast exchange to all clients `client-x-inbox`.

25 26 27 28 29 30 31 32 33
### Auth placeholder 

As a proxy for proper authentication, when you post a client a random secret is 
returned in the response. To send to / receive from the bus you then call the API
with the client_id and secret and it checks they match. The client_id determines 
which queues it reads from. 

Subsequent requests to the client endpoint return the client_id but not the secret.

34 35 36
### Setup 

```
37
pipenv install  
38 39 40 41 42 43 44 45 46 47 48
```

### Running 

#### RabbitMQ 

`docker run --rm -p 5672:5672 -d --hostname rmq --name rmq rabbitmq:management`

#### API 

```
49
pipenv run python api.py 
50 51 52 53 54 55 56 57 58
```

#### Create some clients 

`POST` to `http://localhost:3000/clients` 

#### Event bus 

``` 
59
pipenv run python soar_bus.py
60 61 62 63 64 65
```

#### Send / Receive directly 

```
# Send a message 
66
pipenv run python client_send.py noc-c2-outbox 'soar.noc.slocum.something' from noc-c2
67 68 69 70
```

```
# Receive messages  
71
pipenv run python client_read.py noc-sfmc-inbox
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
```

#### Receive via API

As a placeholder for proper authentication you post the `client_id` and 
`secret` and it checks that a client with that id exists and that the 
secret matches before allowing the request. 

This should be replaced with a proper auth layer. 

`GET http://localhost:5000/receive?client_id=[client_id]&secret=[secret]`

### Components 

- `soar_bus.py` - Run all the components threaded based on existing clients  
- `soar_forward.py` - Listen for messages on queue A and forward messages to queue B 
- `soar_publish.py` - Listen for messages on queue A and publish on exchange B 
- `soar_broadcast.py` - Listen for messages on queue A and broadcast on exchange B 
- `soar_subscribe.py` - Create subscriptions to both the publish and broadcast exchange - deliver to queue A
  (I think this should probably be 2 separate functions to keep things nice and simple)
- `soar_push.py` - Not yet implemented - Listen for messages on queue A and POST to the client's webhook URL