Skip to content
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

feat(ansible): optionally set basic auth on admin #643

Merged
merged 5 commits into from
Aug 13, 2024
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
6 changes: 6 additions & 0 deletions deployment/ansible/conf/nginx-judgels-server-admin.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ server {
proxy_http_version 1.1;
proxy_buffering off;
client_max_body_size 512M;

{% if domain.auth_basic_user != '' %}
# HTTP basic authentication
auth_basic "Authorized users only";
auth_basic_user_file /etc/nginx/passwords/{{ domain.name }};
{% endif %}
}

location ^~ /.well-known/acme-challenge/ {
Expand Down
10 changes: 6 additions & 4 deletions deployment/ansible/env-example/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ app_footer: © Ikatan Alumni TOKI
nginx_domain_judgels_client: judgels.com
nginx_domain_judgels_server_api: api.judgels.com
nginx_domain_judgels_server_admin: admin.judgels.com
# nginx_domain_judgels_server_admin_auth_basic_user: user # <-- CHANGE THIS !!!
# nginx_domain_judgels_server_admin_auth_basic_pass: pass # <-- CHANGE THIS !!!
nginx_certbot_email: [email protected]

# java_opts_judgels_server: -Xmx1g
# java_opts_judgels_grader: -Xmx1g

db_root_password: pass # <-------------------------- CHANGE THIS !!!
db_root_password: pass # <------------------------------------- CHANGE THIS !!!
db_username: judgels
db_password: pass # <------------------------------- CHANGE THIS !!!
db_password: pass # <------------------------------------------ CHANGE THIS !!!

rabbitmq_username: judgels
rabbitmq_password: pass # <------------------------- CHANGE THIS !!!
rabbitmq_password: pass # <------------------------------------ CHANGE THIS !!!

jophiel_superadmin_initialPassword: superadmin # <-- CHANGE THIS !!!
jophiel_superadmin_initialPassword: superadmin # <------------- CHANGE THIS !!!
jophiel_session_maxConcurrentSessionsPerUser: -1
jophiel_session_disableLogout: false

Expand Down
2 changes: 2 additions & 0 deletions deployment/ansible/playbooks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- name: judgels-server-admin
fqdn: "{{ nginx_domain_judgels_server_admin }}"
config_template: "{{ playbook_dir }}/../conf/nginx-judgels-server-admin.conf.j2"
auth_basic_user: "{{ nginx_domain_judgels_server_admin_auth_basic_user | default('') }}"
auth_basic_pass: "{{ nginx_domain_judgels_server_admin_auth_basic_pass | default('') }}"
- name: judgels-client
fqdn: "{{ nginx_domain_judgels_client }}"
config_template: "{{ playbook_dir }}/../conf/nginx-judgels-client.conf.j2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
mode: 0644
when: not letsencrypt_certificate.stat.exists
notify: Reload nginx

- name: Enable nginx letsencrypt domain config
file:
src: /etc/nginx/sites-available/{{ domain.name | mandatory }}
Expand Down Expand Up @@ -41,6 +41,21 @@
when: not letsencrypt_certificate.stat.exists
notify: Reload nginx

- name: Set up basic auth
when: domain.auth_basic_user is defined and domain.auth_basic_user != ""
block:
- name: Install passlib
package:
name: python3-passlib
state: present

- name: Generate basic auth
htpasswd:
path: /etc/nginx/passwords/{{ domain.name | mandatory }}
name: "{{ domain.auth_basic_user }}"
password: "{{ domain.auth_basic_pass }}"
notify: Reload nginx

- name: Add nginx domain config
template:
src: "{{ domain.config_template | mandatory }}"
Expand Down