Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ s3_bucket: "octobot-sync-dev"
s3_region: "garage"
octobot_sync_port: 3000
nginx_port: 80
nginx_ssl_port: 443
garage_replication_factor: 1

# Map vault → app vars
Expand All @@ -28,6 +29,7 @@ evm_contract_base: "{{ vault_evm_contract_base | default('') }}"
firewall_allowed_tcp_ports:
- "22"
- "80"
- "443"
# Port 3901 (Garage RPC) restricted to peer IPs only — see sync_nodes group vars

# Docker (geerlingguy.docker)
Expand Down
2 changes: 1 addition & 1 deletion infra/sync/ansible/roles/stack/tasks/healthcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
status_code: [200]
register: garage_health
until: garage_health.status == 200
retries: 10
retries: 30
delay: 5

- name: Wait for OctoBot sync health
Expand Down
26 changes: 26 additions & 0 deletions infra/sync/ansible/roles/stack/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
---
- name: Check if Docker iptables chains are present
ansible.builtin.command: iptables -L DOCKER-USER -n
register: docker_chains
changed_when: false
failed_when: false

- name: Restart Docker to rebuild iptables chains after firewall changes
ansible.builtin.service:
name: docker
state: restarted
when: docker_chains.rc != 0

- name: Create deploy directory
ansible.builtin.file:
Expand Down Expand Up @@ -40,6 +47,25 @@
mode: "0644"
notify: restart garage

- name: Render ssl.conf
ansible.builtin.template:
src: ssl.conf.j2
dest: "{{ stack_deploy_dir }}/ssl.conf"
owner: deploy
group: deploy
mode: "0644"
notify: restart nginx

- name: Generate self-signed TLS certificate
ansible.builtin.command:
cmd: >-
openssl req -x509 -nodes -newkey rsa:2048 -days 3650
-keyout {{ stack_deploy_dir }}/origin.key
-out {{ stack_deploy_dir }}/origin.crt
-subj "/CN={{ inventory_hostname }}"
creates: "{{ stack_deploy_dir }}/origin.crt"
notify: restart nginx

- name: Copy collections.json
ansible.builtin.copy:
src: collections.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ services:
image: {{ nginx_image }}
ports:
- "{{ nginx_port }}:80"
- "{{ nginx_ssl_port }}:443"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
- ./ssl.conf:/etc/nginx/conf.d/ssl.conf:ro
- ./origin.crt:/etc/nginx/certs/origin.crt:ro
- ./origin.key:/etc/nginx/certs/origin.key:ro
depends_on:
octobot-sync:
condition: service_healthy
Expand Down
46 changes: 46 additions & 0 deletions infra/sync/ansible/roles/stack/templates/ssl.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
server {
listen {{ nginx_ssl_port }} ssl;
server_name _;

ssl_certificate /etc/nginx/certs/origin.crt;
ssl_certificate_key /etc/nginx/certs/origin.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;

client_max_body_size 10m;

# Health (no cache, no rate limit)
location = /health {
proxy_pass http://octobot_sync;
}

# Push endpoints (strict rate limit)
location ~* ^/v1/push/ {
proxy_pass http://octobot_sync;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
limit_req zone=sync_strict burst=25 nodelay;
}

# Pull endpoints (general rate limit + cache)
location ~* ^/v1/pull/ {
proxy_pass http://octobot_sync;
proxy_cache sync_cache;
proxy_cache_valid 200 1h;
proxy_cache_use_stale error timeout updating;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
limit_req zone=sync_global burst=50 nodelay;
}

# Reject anything outside /v1 and /health
location / {
return 404;
}
}
Loading