Skip to content

Aws fastpath deploy #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
45823f1
Create machine for fastpath
LDiazN May 5, 2025
4abaeca
Merge branch 'main' into aws-fastpath-deploy
LDiazN May 5, 2025
19e6da1
Add domain name for fastpath
LDiazN May 5, 2025
5a4d72c
Add domain for fastpath
LDiazN May 5, 2025
865ab47
Fixed bad ingress rules
LDiazN May 6, 2025
3084833
Add roles for fastpath
LDiazN May 6, 2025
86fdc2c
Install docker in the fastpath machine; Clone repo
LDiazN May 6, 2025
4f3d66c
Set up docker in fastpath machine; Install fastpath
LDiazN May 6, 2025
4d5ed92
Deploy fastpath to an EC2 instance with docker
LDiazN May 6, 2025
3264fb4
Increase capacity of fastpath machine
LDiazN May 6, 2025
96094a6
Allow traffic on fastpath port 8472
LDiazN May 6, 2025
abbe35a
Add Ubuntu as part of the docker users
LDiazN May 7, 2025
4ba80b5
Upgrade the fastpath machine, it was running out of memory by staying up
LDiazN May 7, 2025
228b356
Remove unnecessary parameter
LDiazN May 8, 2025
4b148c6
Merge branch 'main' into aws-fastpath-deploy
LDiazN Jun 11, 2025
9117c89
Add docker builder module and fastpath builder
LDiazN Jun 30, 2025
a830f2f
Fix docker build setup
LDiazN Jun 30, 2025
ba0790d
Add parameter to set up disk size of EC2 machines
LDiazN Jul 1, 2025
82ae981
run fastpath with docker image
LDiazN Jul 1, 2025
bacae24
increase disk size of fastpath machine
LDiazN Jul 1, 2025
7806d93
add instance public ip to outputs variables
LDiazN Jul 2, 2025
b096592
Add clickhouse DB url parameter (readonly for now)
LDiazN Jul 2, 2025
29bb922
Add docker collection for managing containers
LDiazN Jul 2, 2025
6f4a747
Rewrite rule for running container
LDiazN Jul 2, 2025
f263b95
Ensure /var/lib/ooniapi exists
LDiazN Jul 2, 2025
c02a957
Setting up measurement uploader in EC2 fastpath
LDiazN Jul 2, 2025
d6d1a4b
Add measurement-uploader files
LDiazN Jul 2, 2025
3b2e79b
Install measurement uploader dependencies
LDiazN Jul 3, 2025
39ce30b
Make uploader script executable
LDiazN Jul 3, 2025
d85aa84
Installing api uploader script
LDiazN Jul 3, 2025
a1b92b5
Install clickhouse proxy dependency for api uploader
LDiazN Jul 3, 2025
f8fbb77
Add host_vars for dev
LDiazN Jul 3, 2025
3dd8f83
Add host var for fastpath dev
LDiazN Jul 3, 2025
078cf81
Change fastpath clickhouse credentials
LDiazN Jul 3, 2025
6bf270d
Fix bad clickhouse url
LDiazN Jul 3, 2025
4f4f264
Change collector_id so it's different from backend-hel
LDiazN Jul 3, 2025
31461bc
Remove unused port 5000
LDiazN Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ansible/deploy-fastpath.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Deploy fastpath
hosts:
- fastpath.dev.ooni.io
become: true
roles:
- role: bootstrap
- role: dehydrated
vars:
ssl_domains:
- "{{ inventory_hostname }}"
tls_cert_dir: /var/lib/dehydrated/certs
- role: prometheus_node_exporter
vars:
node_exporter_port: 9100
node_exporter_host: "0.0.0.0"
prometheus_nginx_proxy_config:
- location: /metrics/node_exporter
proxy_pass: http://127.0.0.1:9100/metrics
- role: geerlingguy.docker
docker_users:
- fastpath
- ubuntu
docker_package_state: latest
- role: fastpath
4 changes: 4 additions & 0 deletions ansible/host_vars/fastpath.dev.ooni.io/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
s3_ooni_open_data_access_key: "{{ vault_s3_ooni_open_data_access_key }}"
clickhouse_url: "clickhouse://write:{{ lookup('amazon.aws.aws_ssm', '/oonidevops/secrets/clickhouse_write_password', profile='oonidevops_user_prod') }}@clickhouseproxy.dev.ooni.io/oonitest"
bucket_name: "ooni-data-eu-fra-test"
collector_id: "3"
9 changes: 9 additions & 0 deletions ansible/host_vars/fastpath.dev.ooni.io/vault
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$ANSIBLE_VAULT;1.1;AES256
30333638353938613934613439396236613334333437623332653266353065616332323461343537
6363393434393664626432373738393239346366336236630a653764373339663739393434666162
37666566306164643738356138363232623461316233396233653030633031303634356233666631
3863336634343932330a356232343735313033396365383161666666646335333033656639623135
64366564306163343738316538663539326631653435343232383464666330333765643132363264
61386432316330383366363665323237663634656630393933303430633034313634633937633337
36373164353238326265643232626536303165613135396137656566653131393033643062656435
38303563333835313965
4 changes: 4 additions & 0 deletions ansible/inventory
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ monitoringproxy.prod.ooni.io
[openvpn]
openvpn1.htz-fsn.prod.ooni.nu
openvpn2.htz-fsn.prod.ooni.nu

[aws-backend]
fastpath.dev.ooni.io
# fastpath.prod.ooni.io
36 changes: 21 additions & 15 deletions ansible/requirements/ansible-galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
- src: willshersystems.sshd
version: v0.25.0
- src: nginxinc.nginx
version: 0.24.3
- src: geerlingguy.certbot
version: 5.2.0
- src: artis3n.tailscale
version: v4.5.0
- src: https://github.com/idealista/clickhouse_role
scm: git
version: 3.5.1
name: idealista.clickhouse_role
- src: https://github.com/ooni/airflow-role.git
scm: git
name: ooni.airflow_role
roles:
- src: willshersystems.sshd
version: v0.25.0
- src: nginxinc.nginx
version: 0.24.3
- src: geerlingguy.certbot
version: 5.2.0
- src: artis3n.tailscale
version: v4.5.0
- src: https://github.com/idealista/clickhouse_role
scm: git
version: 3.5.1
name: idealista.clickhouse_role
- src: https://github.com/ooni/airflow-role.git
scm: git
name: ooni.airflow_role
- src: geerlingguy.docker # installs docker
version: 7.4.7
collections:
- name: community.docker # manages containers
version: 4.6.1
9 changes: 9 additions & 0 deletions ansible/roles/fastpath/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tls_cert_dir: /var/lib/dehydrated/certs

# Fastpath user
fastpath_user: fastpath
fastpath_home: "/opt/{{ fastpath_user }}"

# Fastpath settings
# TODO Update this to the actual clickhouse host when we have migrated it
clickhouse_url: "clickhouse://default:default@clickhouse-server:9000"
27 changes: 27 additions & 0 deletions ansible/roles/fastpath/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- name: test nginx config
command: /usr/sbin/nginx -t -c /etc/nginx/nginx.conf
listen:
- restart nginx
- reload nginx

- name: restart nginx
service:
name: nginx
state: restarted

- name: reload nginx
service:
name: nginx
state: reloaded

- name: reload nftables
tags: nftables
ansible.builtin.systemd_service:
name: nftables
state: reloaded

- name: restart docker
tags: docker
ansible.builtin.systemd_service:
name: docker
state: restarted
183 changes: 183 additions & 0 deletions ansible/roles/fastpath/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
---
# For prometheus scrape requests
- name: Flush all handlers
meta: flush_handlers

- name: Allow traffic on port 9100
become: true
tags: prometheus-proxy
blockinfile:
path: /etc/ooni/nftables/tcp/9100.nft
create: yes
block: |
add rule inet filter input tcp dport 9100 counter accept comment "node exporter"
notify:
- reload nftables

# For incoming fastpath traffic
- name: Allow traffic on port 8472
become: true
tags: fastpath
blockinfile:
path: /etc/ooni/nftables/tcp/8472.nft
create: yes
block: |
add rule inet filter input tcp dport 8472 counter accept comment "fastpath"
notify:
- reload nftables

# Docker seems to have problems with nftables, so this command will translate all iptables
# commands to nftables commands
- name: Update alternatives for iptables
tags: docker
become: yes
ansible.builtin.command: "update-alternatives --set iptables /usr/sbin/iptables-nft"
notify:
- restart docker

- name: Update alternatives for iptables
tags: docker
become: yes
ansible.builtin.command: "update-alternatives --set ip6tables /usr/sbin/ip6tables-nft"
notify:
- restart docker

- name: Flush all handlers # Required to apply iptables settings before docker runs
meta: flush_handlers

### Create fastpath user
- name: Ensure the fastpath group exists
ansible.builtin.group:
name: "{{ fastpath_user }}"
state: present
become: yes
- name: Create the fastpath user
ansible.builtin.user:
name: "{{ fastpath_user }}"
home: "{{ fastpath_home }}"
shell: "/bin/bash"
group: "{{ fastpath_user }}"
create_home: yes
system: yes
become: yes
- name: Set ownership of the fastpath directory
ansible.builtin.file:
path: "{{ fastpath_home }}"
owner: "{{ fastpath_user }}"
group: "{{ fastpath_user }}"
state: directory
mode: '0755'
become: yes

### Run fastpath
- name: Make sure that the fastpath configuration directory exists
ansible.builtin.file:
path: /opt/{{fastpath_user}}/backend/fastpath/
state: directory
mode: '0700'
owner: "{{fastpath_user}}"
group: "{{fastpath_user}}"

- name: Create configuration file
tags: fastpath
template:
src: templates/fastpath.conf
dest: "/opt/{{fastpath_user}}/backend/fastpath/fastpath.conf"
mode: 0444
owner: "{{fastpath_user}}"
become: yes

- name: Ensure ooniapi directory existence
ansible.builtin.file:
path: /var/lib/ooniapi
state: directory
mode: '0700'
owner: "{{fastpath_user}}"
group: "{{fastpath_user}}"

- name: Ensure fastpath is running
community.docker.docker_container:
name: fastpath
image: ooni/fastpath:latest
state: started
published_ports:
- "8472:8472"
volumes:
- /opt/{{fastpath_user}}/backend/fastpath/fastpath.conf:/etc/ooni/fastpath.conf
- /var/lib/ooniapi:/var/lib/ooniapi

### API Uploader set up
- name: configure api uploader using s3 bucket
tags: uploader
template:
src: templates/api-uploader.conf
dest: /etc/ooni/api-uploader.conf

- name: Install measurement uploader script
tags: uploader
template:
src: templates/ooni_api_uploader.py
dest: /usr/bin/ooni_api_uploader.py
owner: "{{fastpath_user}}"
group: "{{fastpath_user}}"
mode: "0755"

- name: Install clickhouse driver (uploader dep)
tags: uploader
become: true
apt:
name: python3-clickhouse-driver
state: present
update_cache: true

- name: Install ujson (uploader dep)
tags: uploader
become: true
apt:
name: python3-ujson
state: present
update_cache: true

- name: Install Systemd
tags: uploader
apt:
name: python3-systemd
state: present
update_cache: true

- name: Install boto3
tags: uploader
apt:
name: python3-boto3
state: present
update_cache: true

- name: Install Statsd
tags: uploader
apt:
name: python3-statsd
state: present
update_cache: true

- name: Install uploder service
tags: uploader
template:
src: templates/ooni-api-uploader.service
dest: /etc/systemd/system/ooni-api-uploader.service
mode: 0644
owner: root

- name: Install uploader timer
tags: uploader
template:
src: templates/ooni-api-uploader.timer
dest: /etc/systemd/system/ooni-api-uploader.timer
mode: 0644
owner: root

- name: Ensure uploader timer runs
tags: uploader
systemd:
name: ooni-api-uploader.timer
state: started
enabled: yes
10 changes: 10 additions & 0 deletions ansible/roles/fastpath/templates/api-uploader.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# OONI API measurement uploader - Python ini format
# Deployed by ansible, see roles/ooni-backend/templates/api-uploader.conf
[DEFAULT]
# arn:aws:iam::676739448697:user/ooni-pipeline, AWS: OONI Open Data
aws_access_key_id = AKIAJURD7T4DTN5JMJ5Q
aws_secret_access_key = {{ s3_ooni_open_data_access_key }}
bucket_name = {{ bucket_name }}
msmt_spool_dir = /var/lib/ooniapi/measurements
collector_id = {{ collector_id }}
db_uri = {{ clickhouse_url }}
19 changes: 19 additions & 0 deletions ansible/roles/fastpath/templates/fastpath.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[DEFAULT]
# Collector hostnames, comma separated
collectors = localhost


{% if psql_uri is defined %}
# The password is already made public
db_uri = {{ psql_uri }}
{% else %}
db_uri =
{% endif %}

# S3 access credentials
# Currently unused
s3_access_key =
s3_secret_key =


clickhouse_url = {{clickhouse_url}}
11 changes: 11 additions & 0 deletions ansible/roles/fastpath/templates/ooni-api-uploader.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Upload raw OONI measurements to S3
Wants=ooni-api-uploader.timer

[Service]
Type=oneshot
ExecStart=/usr/bin/ooni_api_uploader.py

[Install]
WantedBy=multi-user.target

12 changes: 12 additions & 0 deletions ansible/roles/fastpath/templates/ooni-api-uploader.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Upload raw OONI measurements to S3
Requires=ooni-api-uploader.service

[Timer]
Unit=ooni-api-uploader.service
# run every hour at 10 minutes past the hour
OnCalendar=*-*-* *:10
#OnCalendar=*-*-* *:00/5

[Install]
WantedBy=timers.target
Loading
Loading