|
1 |
| -# GHOSTS Core API Overview |
| 1 | +# Setting Up the GHOSTS API |
2 | 2 |
|
3 | 3 | ???+ info "GHOSTS Source Code"
|
4 | 4 | The [GHOSTS Source Code Repository](https://github.com/cmu-sei/GHOSTS) is hosted on GitHub.
|
5 | 5 |
|
| 6 | +*Updated on July 24, 2024* |
| 7 | + |
6 | 8 | The GHOSTS API enables the control and orchestration of non-player characters (NPCs) within a deployment. It supports logging, reporting, and managing individual, groups of, or entire deployments of client installs.
|
7 | 9 |
|
8 |
| -## Installation |
| 10 | +The GHOSTS API consists of three components: the API itself for configuring and managing characters and machines, a Postgres database for managing all the pieces, and Grafana for seeing GHOSTS activities in one convenient dashboard. Each of these three components runs in its own docker container. |
9 | 11 |
|
10 |
| -1. Install 🐳 [Docker](https://docs.docker.com/install/) :material-open-in-new: |
11 |
| -2. Install [Docker Compose](https://docs.docker.com/compose/install/) :material-open-in-new: |
12 |
| -3. Run the following commands - we'll use [this docker-compose.yml file](https://raw.githubusercontent.com/cmu-sei/GHOSTS/master/src/Ghosts.Api/docker-compose.yml) |
| 12 | +Steps to set up the GHOSTS API: |
13 | 13 |
|
14 |
| -```cmd |
15 |
| -mkdir ghosts |
16 |
| -cd ghosts |
17 |
| -curl https://raw.githubusercontent.com/cmu-sei/GHOSTS/master/src/Ghosts.Api/docker-compose.yml -o docker-compose.yml |
18 |
| -docker-compose up -d |
19 |
| -``` |
| 14 | + 1. Choose where to host the API |
| 15 | + 2. Install Docker and Docker Compose |
| 16 | + 3. Build the GHOSTS containers |
| 17 | + 4. Test the API |
20 | 18 |
|
21 |
| -The required containers will be downloaded and configured automatically. |
| 19 | +## Step 1 — Choose Where to Host the API |
22 | 20 |
|
23 |
| -Once the last command completes, if you open [http://localhost:5000/api/home](http://localhost:5000/api/home) in your browser, you should see the initial API page outlining the version of the install, and a few test machine entries. If this page renders, your API is up, running, and available. |
| 21 | +Choose the machine you'll be using to host the GHOSTS API. If you're just playing around with the GHOSTS, your local machine is fine. If you're configuring an exercise or simulation that other people might care about, consider creating a dedidicate host (server, image, or virtual server) for the API, or even using a container service such as AWS ECS. |
24 | 22 |
|
25 |
| -You will still need to set up Grafana. Beware that you must often `chown` the host location of the container as listed in the docker-compose file or the container will just continually restart in error due to insufficient permissions. |
| 23 | +## Step 2 — Installing Docker |
26 | 24 |
|
27 |
| -## Configuring the API |
| 25 | +You'll need to install Docker and Docker Compose on your API host. |
28 | 26 |
|
29 |
| -The API generally has good defaults to get you up and running quickly, but there are some considerations in the `appconfig.json` file: |
| 27 | +First, **install 🐳 [Docker](https://docs.docker.com/install/)**. |
30 | 28 |
|
31 |
| -```json |
32 |
| - "ClientSettings": { |
33 |
| - "OfflineAfterMinutes": 30, ... |
34 |
| - "MatchMachinesBy": null, |
35 |
| -``` |
| 29 | +Next, **install [Docker Compose](https://docs.docker.com/compose/install/)** which will assist with starting up multiple containers at the same time. |
36 | 30 |
|
37 |
| -Can be fqdn|host|resolvedhost|null - null tells the API to match incoming requests with machine records by the machine name. For installations where multiple domains are reporting into the same API, you probably want to use FQDN in order to avoid machines being duplicated. |
| 31 | +Before continuing, test that you have the command for Docker Compose available. |
38 | 32 |
|
| 33 | +Open your system's CMD (Linux), Terminal (Mac), or PowerShell (Windows). |
39 | 34 |
|
40 |
| -```json |
41 |
| -"QueueSyncDelayInSeconds": 10, |
42 |
| -"NotificationsQueueSyncDelayInSeconds": 10, |
| 35 | +``` |
| 36 | +$ docker-compose --version |
43 | 37 | ```
|
44 | 38 |
|
45 |
| -This is how often the synch job runs. Incoming machine requests are not real-time in order to best bundle like records together. |
| 39 | +## Step 3 — Installing the GHOSTS API |
46 | 40 |
|
47 |
| -## Configuring Grafana |
| 41 | +Once you have confirmed that Docker and Docker Compose are installed, you can build the containers required for the GHOSTS API. |
48 | 42 |
|
49 |
| -- Grafana will be running (if containerized) on port 3000, and we can access it via the same URL we use for the API. |
50 |
| -- The default login is admin/admin. |
51 |
| -- The first step is to set up a datasource named "ghosts" to the ghosts Postgres database. |
52 |
| -- Now import your choice of the [grafana json files](https://github.com/cmu-sei/GHOSTS/tree/master/configuration/grafana) in this repository. It creates the default GHOSTS dashboard. |
| 43 | +Create a directory where you want to store the build files and containers. |
53 | 44 |
|
54 |
| -## Webhooks |
| 45 | +``` |
| 46 | +$ mkdir ghosts-project |
| 47 | +$ cd ghosts-project |
| 48 | +``` |
55 | 49 |
|
56 |
| -The GHOSTS API provides webhook callbacks based on the configuration on the endpoint: `/api/webhooks`. The payload for creating a webhook is in the format: |
| 50 | +Download the docker compose file for GHOSTS. |
57 | 51 |
|
58 |
| -```json |
59 |
| -{ |
60 |
| - "status": 0, |
61 |
| - "description": "some description", |
62 |
| - "postbackUrl": "http://localhost/endpoint:port", |
63 |
| - "postbackMethod": 0, (0 == get, 1 == post) |
64 |
| - "postbackFormat": "see below" |
65 |
| -} |
| 52 | +``` |
| 53 | +$ curl https://raw.githubusercontent.com/cmu-sei/GHOSTS/master/src/Ghosts.Api/docker-compose.yml -o docker-compose.yml |
66 | 54 | ```
|
67 | 55 |
|
68 |
| -Payloads can be any format — here is a sample: |
| 56 | +Build all of the containers at once using docker-compose. |
69 | 57 |
|
70 |
| -```json |
71 |
| -{ |
72 |
| - 'machine':'[machinename]', |
73 |
| - 'created':'[datetime.utcnow]', |
74 |
| - 'type':'[messagetype]', |
75 |
| - 'payload':'[messagepayload]' |
76 |
| -} |
| 58 | +``` |
| 59 | +$ docker-compose up -d |
77 | 60 | ```
|
78 | 61 |
|
79 |
| -On send, the payload will be converted into the correct JSON format: |
| 62 | +Check for the running containers. |
80 | 63 |
|
81 |
| -```json |
82 |
| -{ |
83 |
| - "machine":"some_guid", |
84 |
| - "created":"some_datetime", |
85 |
| - "type":"some_message", |
86 |
| - "payload":"some_payload" |
87 |
| -} |
88 | 64 | ```
|
| 65 | +$ docker ps -a |
| 66 | +``` |
| 67 | + |
| 68 | +If everything succeeds you should see the three new containers for the API, Grafana, and Postgres. |
89 | 69 |
|
90 |
| -If the postback method is POST, the payload will be sent as the message body. If the postback method is GET, the payload will be sent as part of the querystring value ?message=`payload`. |
| 70 | + |
91 | 71 |
|
92 |
| -The following events are reported via webhooks: |
| 72 | +## Step 4 — Testing the API |
93 | 73 |
|
94 |
| -1. Timeline delivered (with the timeline that was delivered as payload) to a machine via API (original API posting of timeline only holds timeline in wait - the client still must check-in in order for that timeline to be delivered) |
95 |
| -2. Machine requested updates ("checked in") from API |
96 |
| -3. Machine posted results to API |
| 74 | +By default, the API is hosted on port 5000. You should be able to reach the API from [http://localhost:5000](http://localhost:5000). If you open this page in your browser, you should see the initial API page outlining the version of the install, and a few test machine entries. If this page renders, your API is up, running, and available. |
| 75 | + |
| 76 | + |
97 | 77 |
|
98 | 78 | ## Troubleshooting
|
99 | 79 |
|
100 |
| -> Is the API up and running? |
| 80 | +### Problem: The API home page has an error |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +Answer: Make sure the docker container for Postgres is running using Docker Desktop or the command `docker ps -a` |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +You can check the logs with the command `docker logs ghosts-postgres` to look for container errors. |
| 89 | + |
| 90 | +### Problem: The social graph link has an error |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +Answer: You haven't created a social network yet, this is normal. |
| 95 | + |
| 96 | +### Problem: Is the API up and running? |
101 | 97 |
|
102 | 98 | - Go to `/api/home` in the browser, it should return the current API version and the number of machines and groups under management. If it says relationship not found, restart the API application and it should create the database automatically.
|
103 | 99 | - Run `docker ps --all` and see that all containers are running normally. If one or more is not running, look at the logs for that machine via `docker logs [machine name]`.
|
104 | 100 |
|
105 | 101 | > The ClientId, ClientResults, and other Client* endpoints are failing.
|
106 | 102 |
|
107 |
| -The Client* endpoints are for the Clients to use only. There are specific header values set by the client in the request that is used to authenticate the request. If you are not using the client, you will not have these headers set, and these endpoints will fail. |
| 103 | +The Client* endpoints are for the Clients to use only. There are specific header values set by the client in the request that is used to authenticate the request. If you are not using the client, you will not have these headers set, and these endpoints will fail. |
0 commit comments