Skip to content

Commit

Permalink
containers_web: switch to apache proxy
Browse files Browse the repository at this point in the history
* replaces nginx container
* gitea uses http/1.1 only, due to go-gitea/gitea#19265
* vaultwarden admin uses oidc sso
  • Loading branch information
chrisx8 committed Jan 2, 2023
1 parent 393d0e6 commit d41d22a
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 236 deletions.
4 changes: 2 additions & 2 deletions roles/containers_web/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Ansible Role: `containers_web`

This role provides role variables for `containers` role and installs containerized web apps, including:
This role provides role variables for `containers` role, installs an Apache web server, and installs containerized web apps, including:

- [cloudflared](https://github.com/cloudflare/cloudflared)
- [Gitea](https://gitea.io/)
- [Keycloak](https://www.keycloak.org/)
- [Nginx](https://nginx.org/)
- [Vaultwarden](https://github.com/dani-garcia/vaultwarden)

Required facts: `distribution`, `virtualization_type`
Expand All @@ -14,5 +13,6 @@ Required role vars:

- `cloudflared_token`: Cloudflare Tunnel token.
- `containers_web_cron_ping_url`: Webhook URL for cron job.
- `vaultwarden_oidc`: OIDC client credentials, requires `client_id` and `client_secret`.

Supported OS: RHEL-like systems, version 8 or newer
File renamed without changes.
2 changes: 2 additions & 0 deletions roles/containers_web/files/httpd/conf.d/1_proxy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 10.88.0.0/24
25 changes: 25 additions & 0 deletions roles/containers_web/files/httpd/conf.d/gitea.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<VirtualHost *:443>
ServerName gitea.chrisx.xyz
SSLEngine on
SSLCertificateFile /etc/ssl/chrisx.xyz/fullchain.pem
SSLCertificateKeyFile /etc/ssl/chrisx.xyz/privkey.pem
Protocols http/1.1

Header always set Referrer-Policy "no-referrer"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Robots-Tag "none"
Header always set X-XSS-Protection "1; mode=block"

AllowEncodedSlashes NoDecode

ProxyPass /robots.txt !
ProxyPass / http://127.0.0.1:53000/
ProxyPassReverse / http://127.0.0.1:53000/
ProxyPreserveHost On
ProxyRequests off
RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}

ErrorLog /var/log/httpd/gitea_error_log
CustomLog /var/log/httpd/gitea_access_log combined
</VirtualHost>
22 changes: 22 additions & 0 deletions roles/containers_web/files/httpd/conf.d/sso.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<VirtualHost *:443>
ServerName sso.chrisx.xyz
SSLEngine on
SSLCertificateFile /etc/ssl/chrisx.xyz/fullchain.pem
SSLCertificateKeyFile /etc/ssl/chrisx.xyz/privkey.pem
Protocols h2 http/1.1

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"

AliasMatch "^/resources/.+/login/keycloak/img/favicon.ico$" /var/www/html/favicon.ico
RedirectMatch 404 "^/$"

ProxyPassMatch "^/$" !
ProxyPassMatch "^/resources/.+/login/keycloak/img/favicon.ico$" !
ProxyPass / http://127.0.0.1:58080/
ProxyPassReverse / http://127.0.0.1:58080/
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}

ErrorLog /var/log/httpd/sso_error_log
CustomLog /var/log/httpd/sso_access_log combined
</VirtualHost>
14 changes: 0 additions & 14 deletions roles/containers_web/files/nginx/conf.d/1-default.conf

This file was deleted.

25 changes: 0 additions & 25 deletions roles/containers_web/files/nginx/conf.d/gitea.conf

This file was deleted.

32 changes: 0 additions & 32 deletions roles/containers_web/files/nginx/conf.d/sso.conf

This file was deleted.

35 changes: 0 additions & 35 deletions roles/containers_web/files/nginx/conf.d/vaultwarden.conf

This file was deleted.

47 changes: 0 additions & 47 deletions roles/containers_web/files/nginx/nginx.conf

This file was deleted.

2 changes: 0 additions & 2 deletions roles/containers_web/files/nginx/www/robots.txt

This file was deleted.

35 changes: 35 additions & 0 deletions roles/containers_web/tasks/apache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
- name: Copy favicon
ansible.builtin.copy:
src: favicon.ico
dest: /var/www/html
mode: 0644

- name: Generate new OIDC crypto password
ansible.builtin.set_fact:
oidc_crypto: "{{ lookup('password', '/dev/null length=64') }}"
- name: Copy vaultwarden site config
ansible.builtin.template:
src: vaultwarden.conf.j2
dest: /etc/httpd/conf.d/vaultwarden.conf
mode: 0640
- name: Copy Apache site config
ansible.builtin.copy:
src: httpd/conf.d
dest: /etc/httpd
mode: 0640

- name: Copy chrisx ssl certs
ansible.builtin.import_role:
name: sslcert
tasks_from: chrisx.yml

- name: Configure SELinux httpd_can_network_connect
ansible.posix.seboolean:
name: httpd_can_network_connect
persistent: true
state: true

- name: Restart httpd
ansible.builtin.systemd:
name: httpd
state: restarted
22 changes: 5 additions & 17 deletions roles/containers_web/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
- name: Load secret vars
ansible.builtin.include_vars: secrets.yml

- name: Create containers directory
ansible.builtin.file:
path: ~/containers
state: directory
mode: 0700
register: _containers_dir

- name: Configure Nginx
ansible.builtin.import_tasks: nginx.yml
- name: Copy helper scripts
ansible.builtin.import_tasks: scripts.yml

- name: Set up Postgres DBs
ansible.builtin.import_tasks: postgres_db.yml
become_user: postgres
delegate_to: postgres

- name: Create container network
containers.podman.podman_network:
name: ct
state: present

- name: Launch containers
ansible.builtin.import_role:
name: containers

- name: Configure Apache sites
ansible.builtin.import_tasks: apache.yml
- name: Copy helper scripts
ansible.builtin.import_tasks: scripts.yml
17 changes: 0 additions & 17 deletions roles/containers_web/tasks/nginx.yml

This file was deleted.

14 changes: 0 additions & 14 deletions roles/containers_web/tasks/scripts.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
- name: Copy logrotate config
ansible.builtin.template:
src: logrotate.conf.j2
dest: "{{ _containers_dir.path }}/log/logrotate.conf"
mode: 0644
- name: Set up logrotate cron job
ansible.builtin.cron:
name: container logrotate
# yamllint disable-line rule:line-length
job: "/usr/sbin/logrotate -s {{ _containers_dir.path }}/log/logrotate.state {{ _containers_dir.path }}/log/logrotate.conf"
hour: 2
minute: 0
state: present

- name: Copy backup script
ansible.builtin.template:
src: backup.sh
Expand Down
13 changes: 0 additions & 13 deletions roles/containers_web/templates/logrotate.conf.j2

This file was deleted.

0 comments on commit d41d22a

Please sign in to comment.