Phantom v2: dual-mode architecture, security hardening, deployment management

- Dual-mode operation: standalone + c2itall integrated (env var detection)
- SSH keys moved to ~/.ssh/c2deploy_ph-{id} with per-deployment known_hosts
- Ansible output streaming with filtered console + full log capture
- Deployment management menu: discover, SSH, teardown existing deployments
- Cert setup script (setup-cert.sh) deployed to servers for post-DNS LE certs
- Matrix hardening: unique secrets, SSRF protection, rate limits, nginx security headers
- Base hardening: fail2ban systemd backend (Debian 12), SSH limits, nginx jails
- Add-matrix-user helper script deployed to all Matrix servers
- .env support for standalone credential storage
- Config key rename: deploy_id → deployment_id (with backward compat)
- Provider cleanup playbooks for teardown
- Test suite with 50 tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
n0mad1k
2026-03-09 15:45:24 -04:00
parent 973cede31f
commit 7484a0e034
44 changed files with 3167 additions and 381 deletions
+26 -6
View File
@@ -1,11 +1,31 @@
---
# Media deployment — Coming soon
# This is a stub playbook. Full implementation planned.
# Jellyfin media server deployment (native package from official repo)
- name: Deploy Media Server
- name: Deploy Jellyfin Media Server
hosts: all
become: true
vars:
jellyfin_domain: "{{ domain }}"
jellyfin_library: "{{ media_library_path | default('/srv/media') }}"
target_host: "{{ target_host | default('localhost') }}"
tasks:
- name: Placeholder
debug:
msg: "Media playbook not yet implemented. Check phantom/README.md for status."
- name: Include Jellyfin installation
include_tasks: tasks/install.yml
- name: Include Jellyfin configuration
include_tasks: tasks/configure.yml
- name: Include Jellyfin nginx reverse proxy
include_tasks: tasks/nginx.yml
handlers:
- name: reload nginx
service:
name: nginx
state: reloaded
- name: restart jellyfin
service:
name: jellyfin
state: restarted
@@ -0,0 +1,33 @@
---
# Jellyfin service configuration
- name: Create media library directory
file:
path: "{{ jellyfin_library }}"
state: directory
owner: jellyfin
group: jellyfin
mode: "0755"
- name: Ensure Jellyfin binds to localhost only
lineinfile:
path: /etc/jellyfin/network.xml
regexp: '<LocalNetworkAddresses>'
line: ' <LocalNetworkAddresses><string>127.0.0.1</string></LocalNetworkAddresses>'
create: true
mode: "0644"
notify: restart jellyfin
failed_when: false
- name: Enable and start Jellyfin service
service:
name: jellyfin
state: started
enabled: true
- name: Wait for Jellyfin to be ready
wait_for:
port: 8096
host: 127.0.0.1
delay: 5
timeout: 60
+41
View File
@@ -0,0 +1,41 @@
---
# Jellyfin installation from official apt repository
- name: Install prerequisites
apt:
name:
- curl
- gnupg
- ca-certificates
- nginx
- certbot
- python3-certbot-nginx
state: present
update_cache: true
- name: Add Jellyfin GPG signing key
ansible.builtin.get_url:
url: https://repo.jellyfin.org/jellyfin_team.gpg.key
dest: /usr/share/keyrings/jellyfin-archive-keyring.asc
mode: "0644"
- name: Add Jellyfin apt repository
apt_repository:
repo: "deb [signed-by=/usr/share/keyrings/jellyfin-archive-keyring.asc] https://repo.jellyfin.org/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} main"
state: present
filename: jellyfin
- name: Install Jellyfin
apt:
name: jellyfin
state: present
update_cache: true
- name: Allow HTTP/HTTPS through UFW
ufw:
rule: allow
port: "{{ item }}"
proto: tcp
loop:
- "80"
- "443"
+91
View File
@@ -0,0 +1,91 @@
---
# Nginx reverse proxy for Jellyfin
- name: Create certbot webroot
file:
path: /var/www/certbot
state: directory
owner: www-data
group: www-data
mode: "0755"
- name: Deploy HTTP-only nginx config (for certbot)
copy:
dest: /etc/nginx/sites-available/jellyfin
content: |
server {
listen 80;
server_name {{ jellyfin_domain }};
location /.well-known/acme-challenge/ { root /var/www/certbot; }
location / { return 200 'phantom setup in progress'; add_header Content-Type text/plain; }
}
mode: "0644"
notify: reload nginx
- name: Enable Jellyfin nginx site
file:
src: /etc/nginx/sites-available/jellyfin
dest: /etc/nginx/sites-enabled/jellyfin
state: link
notify: reload nginx
- name: Flush handlers to apply HTTP config
meta: flush_handlers
- name: Setup TLS (certbot with self-signed fallback)
include_tasks: ../../common/tls_setup.yml
vars:
_tls_domain: "{{ jellyfin_domain }}"
- name: Deploy SSL nginx config
copy:
dest: /etc/nginx/sites-available/jellyfin
content: |
server {
listen 80;
server_name {{ jellyfin_domain }};
location /.well-known/acme-challenge/ { root /var/www/certbot; }
location / { return 301 https://$host$request_uri; }
}
server {
listen 443 ssl http2;
server_name {{ jellyfin_domain }};
ssl_certificate {{ _ssl_cert }};
ssl_certificate_key {{ _ssl_key }};
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
server_tokens off;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
client_max_body_size 100m;
location / {
proxy_pass http://127.0.0.1:8096;
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 $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /socket {
proxy_pass http://127.0.0.1:8096;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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 $scheme;
}
}
mode: "0644"
notify: reload nginx