Skip to content

Commit

Permalink
Fix #20. Making basic http authentication credenctials configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ricsanfre committed Dec 11, 2021
1 parent dae52d1 commit 434b9be
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ansible/roles/traefik/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ k3s_traefik_namespace: traefik-system

# Endpoint Service DNS name
traefik_dashboard_dns: traefik.picluster.ricsanfre.com


# Basic auth user/passwd
traefik_basic_auth_user: admin
traefik_basic_auth_passwd: s1cret0

traefik_auth_htpasswd_pair: KKYWRtaW46JGFwcjEkWkRkMWIvNC4kUG9RR244RW5Gc0lWUUFDS3p3VHJrLgoK
18 changes: 18 additions & 0 deletions ansible/roles/traefik/tasks/create_basic_auth_credentials.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---

- name: Ensure htpasswd utility is installed
package:
name: 'apache2-utils'
state: 'present'
update_cache: true
become: true

- name: htpasswd utility
shell:
cmd: >-
htpasswd -nb {{ traefik_basic_auth_user }} {{ traefik_basic_auth_passwd }} | base64
register: htpasswd

- name: Set htpasswd pair
set_fact:
traefik_auth_htpasswd_pair: "{{ htpasswd.stdout }}"
3 changes: 3 additions & 0 deletions ansible/roles/traefik/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
kind: Namespace
state: present

- name: Create Basic authentication credentials
include_tasks: create_basic_auth_credentials.yml

- name: Configura Traefik
kubernetes.core.k8s:
definition: "{{ lookup('template', 'templates/' + item ) }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
namespace: {{ k3s_traefik_namespace }}
data:
users: |2
b3NzOiRhcHIxJDNlZTVURy83JFpmY1NRQlV6SFpIMFZTak9NZGJ5UDANCg0K
{{ traefik_auth_htpasswd_pair }}

---
# Basic-auth middleware
Expand Down

0 comments on commit 434b9be

Please sign in to comment.