tpotce/cloud/ansible/README.md

258 lines
11 KiB
Markdown
Raw Normal View History

2019-06-30 12:36:59 +00:00
# T-Pot Ansible
2019-04-17 15:09:52 +00:00
Here you can find a ready-to-use solution for your automated T-Pot deployment using [Ansible](https://www.ansible.com/).
2019-06-30 12:36:59 +00:00
It consists of an Ansible Playbook with multiple roles, which is reusable for all [OpenStack](https://www.openstack.org/) based clouds (e.g. Open Telekom Cloud, Orange Cloud, Telefonica Open Cloud, OVH) out of the box.
2021-02-13 14:04:50 +00:00
Apart from that you can easily adapt the deploy role to use other [cloud providers](https://docs.ansible.com/ansible/latest/scenario_guides/cloud_guides.html). Check out [Ansible Galaxy](https://galaxy.ansible.com/search?keywords=&order_by=-relevance&page=1&deprecated=false&type=collection&tags=cloud) for more cloud collections.
2019-06-30 12:36:59 +00:00
2021-02-13 19:39:32 +00:00
The Playbook first creates all resources (security group, network, subnet, router), deploys one (or more) new servers and then installs and configures T-Pot on them.
2019-06-30 12:36:59 +00:00
This example showcases the deployment on our own OpenStack based Public Cloud Offering [Open Telekom Cloud](https://open-telekom-cloud.com/en).
2019-04-17 15:09:52 +00:00
# Table of contents
2019-06-30 13:18:44 +00:00
- [Preparation of Ansible Master](#ansible-master)
- [Ansible Installation](#ansible)
2021-02-13 17:20:01 +00:00
- [OpenStack Collection Installation](#collection)
2019-04-17 15:09:52 +00:00
- [Agent Forwarding](#agent-forwarding)
- [Preparations in Open Telekom Cloud Console](#preparation)
- [Create new project](#project)
- [Create API user](#api-user)
- [Import Key Pair](#key-pair)
- [Clone Git Repository](#clone-git)
- [Settings and recommended values](#settings)
2021-02-13 19:39:32 +00:00
- [clouds.yaml](#clouds-yaml)
2019-06-30 22:57:42 +00:00
- [Ansible remote user](#remote-user)
2021-02-13 19:39:32 +00:00
- [Number of instances to deploy](#number)
2019-06-30 22:57:42 +00:00
- [Instance settings](#instance-settings)
- [User password](#user-password)
2019-04-17 15:09:52 +00:00
- [Configure `tpot.conf.dist`](#tpot-conf)
2019-06-30 23:27:48 +00:00
- [Optional: Custom `ews.cfg`](#ews-cfg)
- [Optional: Custom HPFEEDS](#hpfeeds)
2019-04-17 21:45:19 +00:00
- [Deploying a T-Pot](#deploy)
- [Further documentation](#documentation)
2019-04-17 15:09:52 +00:00
2019-06-30 13:18:44 +00:00
<a name="ansible-master"></a>
# Preparation of Ansible Master
2019-07-01 00:24:32 +00:00
You can either run the Ansible Playbook locally on your Linux or macOS machine or you can use an ECS (Elastic Cloud Server) on Open Telekom Cloud, which I did.
2019-04-17 15:09:52 +00:00
I used Ubuntu 18.04 for my Ansible Master Server, but other OSes are fine too.
2019-06-29 16:32:45 +00:00
Ansible works over the SSH Port, so you don't have to add any special rules to your Security Group.
2019-04-17 15:09:52 +00:00
2019-06-30 13:18:44 +00:00
<a name="ansible"></a>
## Ansible Installation
:warning: Ansible 2.10 or newer is required!
2019-07-01 00:15:14 +00:00
Example for Ubuntu 18.04:
2019-08-08 05:48:40 +00:00
At first we update the system:
`sudo apt update`
`sudo apt dist-upgrade`
Then we need to add the repository and install Ansible:
2019-04-17 15:09:52 +00:00
`sudo apt-add-repository --yes --update ppa:ansible/ansible`
`sudo apt install ansible`
2019-07-01 00:15:14 +00:00
For other OSes and Distros have a look at the official [Ansible Documentation](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html).
If your OS does not offer a recent version of Ansible (>= 2.10) you should consider [installing Ansible with pip](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-with-pip).
In short (if you already have Python3/pip3 installed):
```
pip3 install ansible
```
2021-02-13 17:20:01 +00:00
<a name="collection"></a>
## OpenStack Collection Installation
For interacting with OpenStack resources in Ansible, you need to install the collection from Ansible Galaxy:
`ansible-galaxy collection install openstack.cloud`
2019-04-17 15:09:52 +00:00
<a name="agent-forwarding"></a>
## Agent Forwarding
2019-10-25 10:37:16 +00:00
If you run the Ansible Playbook remotely on your Ansible Master Server, Agent Forwarding must be enabled in order to let Ansible connect to newly created machines.
2019-06-30 23:44:43 +00:00
- On Linux or macOS:
2019-04-17 15:09:52 +00:00
- Create or edit `~/.ssh/config`
```
Host ANSIBLE_MASTER_IP
ForwardAgent yes
```
2019-10-25 10:38:05 +00:00
- On Windows using Putty:
2019-04-17 19:51:37 +00:00
![Putty Agent Forwarding](doc/putty_agent_forwarding.png)
2019-04-17 15:09:52 +00:00
<a name="preparation"></a>
# Preparations in Open Telekom Cloud Console
2019-08-13 12:59:05 +00:00
(You can skip this if you have already set up a project and an API account with key pair)
(Just make sure you know the naming for everything, as you need to configure the Ansible variables.)
2019-04-18 09:27:12 +00:00
2019-06-30 13:18:44 +00:00
Before we can start deploying, we have to prepare the Open Telekom Cloud tenant.
2019-04-17 20:52:40 +00:00
For that, go to the [Web Console](https://auth.otc.t-systems.com/authui/login) and log in with an admin user.
2019-04-17 15:09:52 +00:00
<a name="project"></a>
## Create new project
2019-06-30 13:18:44 +00:00
I strongly advise you to create a separate project for the T-Pots in your tenant.
2019-04-17 15:09:52 +00:00
In my case I named it `tpot`.
2019-04-18 23:39:58 +00:00
![Create new project](doc/otc_1_project.gif)
2019-04-17 15:09:52 +00:00
<a name="api-user"></a>
## Create API user
The next step is to create a new user account, which is restricted to the project.
This ensures that the API access is limited to that project.
2019-04-18 23:39:58 +00:00
![Create API user](doc/otc_2_user.gif)
2019-04-17 15:09:52 +00:00
<a name="key-pair"></a>
## Import Key Pair
2019-06-30 13:18:44 +00:00
:warning: Now log in with the newly created API user account and select your project.
2019-04-18 23:39:58 +00:00
![Login as API user](doc/otc_3_login.gif)
2019-04-18 22:35:07 +00:00
Import your SSH public key.
2019-04-17 15:09:52 +00:00
2019-04-18 23:39:58 +00:00
![Import SSH Public Key](doc/otc_4_import_key.gif)
2019-04-17 15:09:52 +00:00
<a name="clone-git"></a>
# Clone Git Repository
Clone the `tpotce` repository to your Ansible Master:
2020-09-04 13:01:21 +00:00
`git clone https://github.com/telekom-security/tpotce.git`
2020-03-22 01:29:50 +00:00
All Ansible related files are located in the [`cloud/ansible/openstack`](openstack) folder.
2019-04-17 15:09:52 +00:00
<a name="settings"></a>
# Settings and recommended values
2020-03-22 01:29:50 +00:00
You can configure all aspects of your Elastic Cloud Server and T-Pot before using the Playbook:
2019-04-17 15:09:52 +00:00
2020-03-22 01:29:50 +00:00
<a name="clouds-yaml"></a>
2021-02-13 19:39:32 +00:00
## clouds.yaml
2020-03-22 01:29:50 +00:00
Located at [`openstack/clouds.yaml`](openstack/clouds.yaml).
2019-06-30 13:18:44 +00:00
Enter your Open Telekom Cloud API user credentials here (username, password, project name, user domain name):
2019-04-17 15:09:52 +00:00
```
2020-03-22 01:29:50 +00:00
clouds:
open-telekom-cloud:
profile: otc
auth:
project_name: eu-de_your_project
username: your_api_user
password: your_password
user_domain_name: OTC-EU-DE-000000000010000XXXXX
2019-04-17 15:09:52 +00:00
```
2020-03-22 01:29:50 +00:00
You can also perform different authentication methods like sourcing OpenStack OS_* environment variables or providing an inline dictionary.
2021-02-13 18:03:56 +00:00
For more information have a look in the [openstack.cloud.server](https://docs.ansible.com/ansible/latest/collections/openstack/cloud/server_module.html) Ansible module documentation.
If you already have your own `clouds.yaml` file or have multiple clouds in there, you can specify which one to use in the `openstack/my_os_cloud.yaml` file:
```
# Enter the name of your cloud to use from clouds.yaml
cloud: open-telekom-cloud
```
2019-04-17 15:09:52 +00:00
2019-06-30 22:57:42 +00:00
<a name="remote-user"></a>
## Ansible remote user
You may have to adjust the `remote_user` in the Ansible Playbook under [`openstack/deploy_tpot.yaml`](openstack/deploy_tpot.yaml) depending on your Debian base image (e.g. on Open Telekom Cloud the default Debian user is `linux`).
2021-02-13 19:39:32 +00:00
<a name="number"></a>
## Number of instances to deploy
You can adjust the number of VMs/T-Pots that you want to create in [`openstack/deploy_tpot.yaml`](openstack/deploy_tpot.yaml):
```
loop: "{{ range(0, 1) }}"
```
One instance is set as the default, increase to your liking.
2019-06-30 22:57:42 +00:00
<a name="instance-settings"></a>
## Instance settings
2021-02-13 17:20:01 +00:00
Located at [`openstack/roles/create_vm/vars/main.yaml`](openstack/roles/create_vm/vars/main.yaml).
2019-06-30 22:57:42 +00:00
Here you can customize your virtual machine specifications:
2019-06-30 23:44:43 +00:00
- Choose an availability zone. For Open Telekom Cloud reference see [here](https://docs.otc.t-systems.com/en-us/endpoint/index.html).
2019-11-13 16:17:14 +00:00
- Change the OS image (For T-Pot we need Debian)
2019-06-30 22:57:42 +00:00
- (Optional) Change the volume size
2019-08-13 12:59:05 +00:00
- Specify your key pair (:warning: Mandatory)
2019-06-30 22:57:42 +00:00
- (Optional) Change the instance type (flavor)
2021-02-13 17:20:01 +00:00
`s3.medium.8` corresponds to 1 vCPU and 8GB of RAM and is the minimum required flavor.
2020-03-22 01:29:50 +00:00
A full list of Open Telekom Cloud flavors can be found [here](https://docs.otc.t-systems.com/en-us/usermanual/ecs/en-us_topic_0177512565.html).
2019-04-17 15:09:52 +00:00
```
2019-06-30 22:57:42 +00:00
availability_zone: eu-de-03
2019-11-13 16:17:14 +00:00
image: Standard_Debian_10_latest
2019-06-30 22:57:42 +00:00
volume_size: 128
key_name: your-KeyPair
2021-02-13 17:20:01 +00:00
flavor: s3.medium.8
2019-06-30 22:57:42 +00:00
```
<a name="user-password"></a>
## User password
Located at [`openstack/roles/install/vars/main.yaml`](openstack/roles/install/vars/main.yaml).
Here you can set the password for your Debian user (**you should definitely change that**).
```
user_password: LiNuXuSeRPaSs#
2019-04-17 15:09:52 +00:00
```
<a name="tpot-conf"></a>
## Configure `tpot.conf.dist`
2020-03-22 01:29:50 +00:00
The file is located in [`iso/installer/tpot.conf.dist`](/iso/installer/tpot.conf.dist).
2019-04-17 20:52:40 +00:00
Here you can choose:
- between the various T-Pot editions
- a username for the web interface
- a password for the web interface (**you should definitely change that**)
2019-06-30 23:27:48 +00:00
<a name="ews-cfg"></a>
## Optional: Custom `ews.cfg`
Enable this by uncommenting the role in the [deploy_tpot.yaml](openstack/deploy_tpot.yaml) playbook.
```
# - custom_ews
```
2019-04-17 20:52:40 +00:00
2019-05-16 16:29:48 +00:00
You can use a custom config file for `ewsposter`.
2019-04-17 20:52:40 +00:00
e.g. when you have your own credentials for delivering data to our [Sicherheitstacho](https://sicherheitstacho.eu/start/main).
2019-06-30 23:27:48 +00:00
You can find the `ews.cfg` template file here: [`openstack/roles/custom_ews/templates/ews.cfg`](openstack/roles/custom_ews/templates/ews.cfg) and adapt it for your needs.
2019-04-17 20:52:40 +00:00
For setting custom credentials, these settings would be relevant for you (the rest of the file can stay as is):
```
[MAIN]
...
contact = your_email_address
...
[EWS]
...
username = your_username
token = your_token
...
```
2019-04-17 15:09:52 +00:00
2019-06-30 23:27:48 +00:00
<a name="hpfeeds"></a>
## Optional: Custom HPFEEDS
Enable this by uncommenting the role in the [deploy_tpot.yaml](openstack/deploy_tpot.yaml) playbook.
```
# - custom_hpfeeds
```
2021-02-13 17:20:01 +00:00
You can specify custom HPFEEDS in [`openstack/roles/custom_hpfeeds/files/hpfeeds.cfg`](openstack/roles/custom_hpfeeds/files/hpfeeds.cfg).
2019-06-30 23:38:16 +00:00
That file contains the defaults (turned off) and you can adapt it for your needs, e.g. for SISSDEN:
2019-04-17 21:45:19 +00:00
```
myENABLE=true
myHOST=hpfeeds.sissden.eu
myPORT=10000
myCHANNEL=t-pot.events
2019-05-16 16:29:48 +00:00
myCERT=/opt/ewsposter/sissden.pem
2019-04-17 21:45:19 +00:00
myIDENT=your_user
mySECRET=your_secret
myFORMAT=json
```
<a name="deploy"></a>
2019-04-18 23:46:50 +00:00
# Deploying a T-Pot :honey_pot::honeybee:
2019-06-30 23:33:13 +00:00
Now, after configuring everything, we can finally start deploying T-Pots!
2021-02-13 19:39:32 +00:00
2019-07-01 06:20:58 +00:00
Go to the [`openstack`](openstack) folder and run the Ansible Playbook with:
2019-06-30 23:27:48 +00:00
`ansible-playbook deploy_tpot.yaml`
2019-04-17 21:45:19 +00:00
(Yes, it is as easy as that :smile:)
2019-07-01 06:16:08 +00:00
If you are running on a machine which asks for a sudo password, you can use:
`ansible-playbook --ask-become-pass deploy_tpot.yaml`
2021-02-13 19:39:32 +00:00
The Playbook will first install required packages on the Ansible Master and then deploy one (or more) new server instances.
After that, T-Pot gets installed and configured on them, optionally custom configs are applied and finally it reboots.
2019-04-17 21:45:19 +00:00
2020-09-04 13:01:21 +00:00
Once this is done, you can proceed with connecting/logging in to the T-Pot according to the [documentation](https://github.com/telekom-security/tpotce#ssh-and-web-access).
2020-03-27 07:42:53 +00:00
2019-04-17 21:45:19 +00:00
<a name="documentation"></a>
# Further documentation
- [Ansible Documentation](https://docs.ansible.com/ansible/latest/)
2021-02-13 14:04:50 +00:00
- [openstack.cloud.server Create/Delete Compute Instances from OpenStack](https://docs.ansible.com/ansible/latest/collections/openstack/cloud/server_module.html)
2019-04-17 21:45:19 +00:00
- [Open Telekom Cloud Help Center](https://docs.otc.t-systems.com/)