Added WIP pleroma OTP role.
authorLuke Hoersten <luke@hoersten.org>
Sun, 19 Jan 2020 13:41:08 -0600
changeset 84 d0c40727e6ff
parent 83 ccd5604f5b69
child 85 dcfd23308c32
Added WIP pleroma OTP role.
roles/pleroma-otp/defaults/main.yaml
roles/pleroma-otp/files/[email protected]
roles/pleroma-otp/handlers/main.yaml
roles/pleroma-otp/tasks/main.yaml
roles/pleroma-otp/templates/config.exs.j2
roles/pleroma-otp/templates/pleroma.cloudflare.nginx.conf.j2
roles/pleroma-otp/templates/pleroma.nginx.conf.j2
roles/pleroma-otp/templates/setup_db.psql.j2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/pleroma-otp/defaults/main.yaml	Sun Jan 19 13:41:08 2020 -0600
@@ -0,0 +1,30 @@
+---
+
+pleroma_host: "localhost"
+pleroma_port: 4000
+pleroma_scheme: "http"
+
+pleroma_proxy_pass: "{{pleroma_scheme}}://{{pleroma_host}}:{{pleroma_port}}"
+
+pleroma_link_host: "localhost"
+pleroma_link_port: "443"
+pleroma_link_scheme: "https"
+
+pleroma_instance_name: "{{pleroma_link_host}}"
+pleroma_desc: "A Pleroma fediverse instance."
+pleroma_admin_email: "[email protected]{{pleroma_link_host}}"
+pleroma_char_limit: 5000
+pleroma_signup_open: "true"
+pleroma_db_host: "localhost"
+pleroma_db_superuser: "postgres"
+
+pleroma_apt_packages:
+  - "curl"
+  - "unzip"
+
+pleroma_branch: "stable"
+pleroma_flavor: "arm"
+
+pleroma_db: "{{pleroma_instance}}"
+pleroma_db_user: "{{pleroma_instance}}"
+pleroma_data_dir: "/var/lib/pleroma/instance_data"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/pleroma-otp/files/[email protected]	Sun Jan 19 13:41:08 2020 -0600
@@ -0,0 +1,33 @@
+[Unit]
+Description=Pleroma social network instance %I
+After=network.target postgresql.service
+
+[Service]
+User=pleroma
+WorkingDirectory=/opt/pleroma
+
+Environment="HOME=/opt/pleroma"
+Environment="PLEROMA_CONFIG_PATH=/etc/pleroma/%i.config.exs"
+Environment="PLUG_TMPDIR=/tmp/%i"
+
+ExecStart=/opt/pleroma/bin/pleroma daemon
+ExecReload=/opt/pleroma/bin/pleroma stop
+KillMode=process
+Restart=on-failure
+
+; Some security directives.
+; Use private /tmp and /var/tmp folders inside a new file system namespace, which are discarded after the process stops.
+PrivateTmp=true
+; The /home, /root, and /run/user folders can not be accessed by this service anymore. If your Pleroma user has its home folder in one of the restricted places, or use one of these folders as its working directory, you have to set this to false.
+ProtectHome=false
+; Mount /usr, /boot, and /etc as read-only for processes invoked by this service.
+ProtectSystem=full
+; Sets up a new /dev mount for the process and only adds API pseudo devices like /dev/null, /dev/zero or /dev/random but not physical devices. Disabled by default because it may not work on devices like the Raspberry Pi.
+PrivateDevices=false
+; Ensures that the service process and all its children can never gain new privileges through execve().
+NoNewPrivileges=true
+; Drops the sysadmin capability from the daemon.
+CapabilityBoundingSet=~CAP_SYS_ADMIN
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/pleroma-otp/handlers/main.yaml	Sun Jan 19 13:41:08 2020 -0600
@@ -0,0 +1,5 @@
+---
+
+- name: "restart pleroma {{pleroma_instance}} instance"
+  become: yes
+  systemd: name="[email protected]{{pleroma_instance}}" state="restarted" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/pleroma-otp/tasks/main.yaml	Sun Jan 19 13:41:08 2020 -0600
@@ -0,0 +1,113 @@
+---
+
+- name: install pleroma apt packages
+  become: yes
+  apt: name="{{pleroma_apt_packages}}"
+
+- name: add users
+  become: yes
+  user: name="pleroma" shell="/bin/false" home="/opt/pleroma" system="yes"
+
+- name: create config and data directory
+  become: yes
+  file:
+    path: "{{item}}"
+    state: "directory"
+    mode: "0755"
+  with_items:
+    - "{{pleroma_data_dir}}"
+    - "/etc/pleroma"
+
+- name: install pleroma config
+  template:
+    src: "config.exs.j2"
+    dest: "/etc/pleroma/{{pleroma_instance}}.config.exs"
+    mode: "0700"
+  become: yes
+  notify: "restart pleroma {{pleroma_instance}} instance"
+
+- name: create instance data directory
+  become: yes
+  file:
+    path: "{{item}}"
+    state: "directory"
+    owner: "pleroma"
+    group: "pleroma"
+    mode: "0755"
+  with_items:
+    - "{{pleroma_data_dir}}/{{pleroma_instance}}"
+    - "{{pleroma_data_dir}}/{{pleroma_instance}}/uploads"
+    - "{{pleroma_data_dir}}/{{pleroma_instance}}/static"
+    - "{{pleroma_data_dir}}/{{pleroma_instance}}/static/emoji"
+
+# Set config path in systemd: PLEROMA_CONFIG_PATH
+
+# - name: install pleroma db schema file
+#   template:
+#     src: "setup_db.psql.j2"
+#     dest: "/tmp/setup_db.psql"
+#     owner: "{{pleroma_db_superuser}}"
+#     group: "{{pleroma_db_superuser}}"
+#     mode: "0700"
+#   become: yes
+
+# - name: install pleroma psql
+#   become: yes
+#   become_user: "{{pleroma_db_superuser}}"
+#   command: "psql -f /tmp/setup_db.psql"
+#   notify: restart pleroma
+
+
+
+
+
+# MIGERATION
+# mv ~pleroma/uploads/* /var/lib/pleroma/uploads
+# mv ~pleroma/instance/static /var/lib/pleroma/static
+# mv ~pleroma/priv/static/emoji /var/lib/pleroma/static/emoji
+# mv ~pleroma/config/prod.secret.exs /etc/pleroma/config.exs
+# Change `use Mix.Config` at the top to `import Config`
+# rm -r ~pleroma/*
+
+
+- name: download and unarchive pleroma release
+  become: yes
+  unarchive:
+    src: "https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/{{pleroma_branch}}/download?job={{pleroma_flavor}}"
+    dest: "/tmp/"
+    remote_src: yes
+    creates: "/tmp/release"
+  notify: "restart pleroma {{pleroma_instance}} instance"
+
+- name: install pleroma release
+  become: yes
+  copy: remote_src="True" src="/tmp/release/" dest="/opt/pleroma/"
+
+# - name: Remove old files foo
+#   file: path="/path/to/foo" state="absent"
+
+# ***
+# mv /tmp/release/* ~pleroma/
+
+
+# Copy the service into a proper directory
+# cp ~pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
+
+# - name: "configure pleroma systemd service"
+#   become: yes
+#   copy:
+#     src: "[email protected]"
+#     dest: "/lib/systemd/system/[email protected]"
+#   notify: "restart pleroma {{pleroma_instance}} instance"
+
+# - name: "ensure pleroma {{pleroma_instance}} instance is enabled and started"
+#   become: yes
+#   systemd: name="[email protected]{{pleroma_instance}}" enabled="yes" state="started"
+
+# - name: migrate db
+#   become: yes
+#   become_user: "pleroma"
+#   command: "/opt/pleroma/bin/pleroma_ctl migrate"
+#   args:
+#     chdir: "/opt/pleroma/"
+#   notify: restart pleroma
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/pleroma-otp/templates/config.exs.j2	Sun Jan 19 13:41:08 2020 -0600
@@ -0,0 +1,43 @@
+use Mix.Config
+
+config :pleroma, Pleroma.Web.Endpoint,
+  url: [host: "{{pleroma_link_host}}", scheme: "{{pleroma_link_scheme}}", port: {{pleroma_link_port}}],
+  http: [port: {{pleroma_port}}, ip: {127, 0, 0, 1}],
+  secret_key_base: "{{pleroma_secret_key}}",
+  secure_cookie_flag: true
+
+config :pleroma, :http_security,
+  enabled: true,
+  sts: true,
+  referrer_policy: "same-origin"
+
+config :pleroma, :instance,
+  name: "{{pleroma_instance_name}}",
+  description: "{{pleroma_desc}}",
+  email: "{{pleroma_admin_email}}",
+  limit: {{pleroma_char_limit}},
+  registrations_open: {{pleroma_signup_open}},
+  invites_enabled: {{pleroma_invites_enabled}}
+
+config :pleroma, Pleroma.Upload,
+  uploader: Pleroma.Uploaders.Local,
+  filters: [Pleroma.Upload.Filter.Dedupe]
+
+config :pleroma, Pleroma.Uploaders.Local,
+  uploads: "{{pleroma_data_dir}}/{{pleroma_instance}}/"
+
+config :pleroma, :media_proxy,
+  enabled: false,
+  redirect_on_failure: true
+  #base_url: "https://cache.pleroma.social"
+
+# Configure your database
+config :pleroma, Pleroma.Repo,
+  adapter: Ecto.Adapters.Postgres,
+  username: "{{pleroma_db_user}}",
+  password: "{{pleroma_db_passwd}}",
+  database: "{{pleroma_db}}",
+  hostname: "{{pleroma_db_host}}",
+  pool_size: 10,
+  timeout: 60000,
+  pool_timeout: 60000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/pleroma-otp/templates/pleroma.cloudflare.nginx.conf.j2	Sun Jan 19 13:41:08 2020 -0600
@@ -0,0 +1,74 @@
+# default nginx site config for Pleroma
+#
+# Simple installation instructions:
+# 1. Install your TLS certificate, possibly using Let's Encrypt.
+# 2. Replace 'example.tld' with your instance's domain wherever it appears.
+# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
+#    in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
+
+proxy_cache_path /tmp/{{pleroma_instance}}-pleroma-media-cache levels=1:2 keys_zone={{pleroma_instance}}-pleroma_media_cache:10m max_size=10g
+                 inactive=720m use_temp_path=off;
+
+server {
+    listen {{nginx_port}};
+    # listen [::]:{{nginx_port}};
+    server_name _;
+    return 301 https://$host$request_uri;
+}
+
+# Enable SSL session caching for improved performance
+ssl_session_cache shared:ssl_session_cache:10m;
+
+server {
+    listen {{nginx_ssl_port}} ssl http2;
+    # listen [::]:{{nginx_ssl_port}} ssl ipv6only=on;
+    server_name _;
+
+    ssl_certificate {{nginx_ssl_cert}};
+    ssl_certificate_key {{nginx_ssl_privkey}};
+    include /etc/letsencrypt/options-ssl-nginx.conf;
+    # ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
+
+    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
+    ssl_stapling on;
+    ssl_stapling_verify on;
+
+    add_header Strict-Transport-Security "max-age=31536000" always;
+
+    gzip_vary on;
+    gzip_proxied any;
+    gzip_comp_level 6;
+    gzip_buffers 16 8k;
+    gzip_http_version 1.1;
+    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
+
+    # the nginx default is 1m, not enough for large media uploads
+    client_max_body_size 16m;
+
+    location / {
+        add_header X-XSS-Protection "1; mode=block";
+        add_header X-Permitted-Cross-Domain-Policies none;
+        add_header X-Frame-Options DENY;
+        add_header X-Content-Type-Options nosniff;
+        add_header Referrer-Policy same-origin;
+        add_header X-Download-Options noopen;
+
+        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
+
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "upgrade";
+        proxy_set_header Host $http_host;
+
+        proxy_pass {{pleroma_proxy_pass}};
+
+        client_max_body_size 16m;
+    }
+
+    location /proxy {
+        proxy_cache {{pleroma_instance}}-pleroma_media_cache;
+        proxy_cache_lock on;
+        proxy_ignore_client_abort on;
+        proxy_pass {{pleroma_proxy_pass}};
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/pleroma-otp/templates/pleroma.nginx.conf.j2	Sun Jan 19 13:41:08 2020 -0600
@@ -0,0 +1,95 @@
+# default nginx site config for Pleroma
+#
+# Simple installation instructions:
+# 1. Install your TLS certificate, possibly using Let's Encrypt.
+# 2. Replace 'example.tld' with your instance's domain wherever it appears.
+# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
+#    in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
+
+proxy_cache_path /tmp/{{pleroma_instance}}-pleroma-media-cache levels=1:2 keys_zone={{pleroma_instance}}-pleroma_media_cache:10m max_size=10g
+                 inactive=720m use_temp_path=off;
+
+server {
+    listen {{nginx_port}};
+    # listen [::]:{{nginx_port}};
+    server_name {{nginx_server_name}};
+    return 301 https://$server_name$request_uri;
+
+    # Uncomment this if you need to use the 'webroot' method with certbot. Make sure
+    # that you also create the .well-known/acme-challenge directory structure in pleroma/priv/static and
+    # that is is accessible by the webserver. You may need to load this file with the ssl
+    # server block commented out, run certbot to get the certificate, and then uncomment it.
+    #
+    # location ~ /\.well-known/acme-challenge {
+    #     root <path to install>/pleroma/priv/static/;
+    # }
+}
+
+# Enable SSL session caching for improved performance
+ssl_session_cache shared:ssl_session_cache:10m;
+
+server {
+    listen {{nginx_ssl_port}} ssl http2;
+    # listen [::]:{{nginx_ssl_port}} ssl ipv6only=on;
+    server_name {{nginx_server_name}};
+
+    ssl_certificate {{nginx_ssl_cert}};
+    ssl_certificate_key {{nginx_ssl_privkey}};
+    include /etc/letsencrypt/options-ssl-nginx.conf;
+    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
+
+    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
+    ssl_stapling on;
+    ssl_stapling_verify on;
+
+    add_header Strict-Transport-Security "max-age=31536000" always;
+
+    gzip_vary on;
+    gzip_proxied any;
+    gzip_comp_level 6;
+    gzip_buffers 16 8k;
+    gzip_http_version 1.1;
+    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
+
+    # the nginx default is 1m, not enough for large media uploads
+    client_max_body_size 16m;
+
+    location / {
+        # if you do not want remote frontends to be able to access your Pleroma backend
+        # server, remove these lines.
+        # add_header 'Access-Control-Allow-Origin' '*' always;
+        # add_header 'Access-Control-Allow-Methods' 'POST, PUT, DELETE, GET, PATCH, OPTIONS' always;
+        # add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Idempotency-Key' always;
+        # add_header 'Access-Control-Expose-Headers' 'Link, X-RateLimit-Reset, X-RateLimit-Limit, X-RateLimit-Remaining, X-Request-Id' always;
+        # if ($request_method = OPTIONS) {
+        #     return 204;
+        # }
+        # stop removing lines here.
+
+        add_header X-XSS-Protection "1; mode=block";
+        add_header X-Permitted-Cross-Domain-Policies none;
+        add_header X-Frame-Options DENY;
+        add_header X-Content-Type-Options nosniff;
+        add_header Referrer-Policy same-origin;
+        add_header X-Download-Options noopen;
+
+        # Uncomment this only after you get HTTPS working.
+        # add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
+
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "upgrade";
+        proxy_set_header Host $http_host;
+
+        proxy_pass {{pleroma_proxy_pass}};
+
+        client_max_body_size 16m;
+    }
+
+    location /proxy {
+        proxy_cache {{pleroma_instance}}-pleroma_media_cache;
+        proxy_cache_lock on;
+        proxy_ignore_client_abort on;
+        proxy_pass {{pleroma_proxy_pass}};
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/pleroma-otp/templates/setup_db.psql.j2	Sun Jan 19 13:41:08 2020 -0600
@@ -0,0 +1,7 @@
+CREATE USER {{pleroma_db_user}} WITH ENCRYPTED PASSWORD '{{pleroma_db_passwd}}';
+CREATE DATABASE {{pleroma_db}} WITH OWNER {{pleroma_db_user}};
+\c {{pleroma_db}};
+--Extensions made by ecto.migrate that need superuser access
+CREATE EXTENSION IF NOT EXISTS citext;
+CREATE EXTENSION IF NOT EXISTS pg_trgm;
+CREATE EXTENSION IF NOT EXISTS "uuid-ossp";