Skip to content

Commit 8bb0db0

Browse files
committed
Use a dedicated database encryption key
The `manage.py setclusters ...` needs to be called after this change. Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
1 parent 7d581ca commit 8bb0db0

File tree

8 files changed

+19
-1
lines changed

8 files changed

+19
-1
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
DB_HOST = "localhost"
5353
DB_PORT = 5432
5454
SECRET_KEY = "$(uuidgen)"
55+
DATABASE_KEY = "$(uuidgen)"
5556
EOF
5657
5758
- name: Run tests

setup/collections/ansible_collections/ansible/containerized_installer/roles/automationdashboard/tasks/facts.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
ansible.builtin.set_fact:
3535
_common_secrets:
3636
- 'dashboard_secret_key,target=/etc/dashboard/SECRET_KEY,mode=0400,uid={{ ansible_user_uid }}'
37+
- 'dashboard_database_key,target=/etc/dashboard/DATABASE_KEY,mode=0400,uid={{ ansible_user_uid }}'
3738
# - 'dashboard_channels,target=/etc/tower/conf.d/channels.py,mode=0400,uid={{ ansible_user_uid }}'
3839
- 'dashboard_postgres,target=/etc/dashboard/conf.d/postgres.py,mode=0400,uid={{ ansible_user_uid }}'
3940
_common_volumes:

setup/collections/ansible_collections/ansible/containerized_installer/roles/automationdashboard/tasks/secrets.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,15 @@
2020
# - Restart dashboard rsyslog
2121
- Restart dashboard task
2222
- Restart dashboard web
23+
24+
- name: Create the dashboard DATABASE_KEY secret
25+
containers.podman.podman_secret:
26+
name: dashboard_database_key
27+
data: '{{ dashboard_database_key | default(lookup("ansible.builtin.password", "/dev/null length=50")) }}'
28+
force: '{{ dashboard_update_database_key | bool }}'
29+
skip_existing: '{{ not dashboard_update_database_key | bool }}'
30+
notify:
31+
# - Restart dashboard rsyslog
32+
- Restart dashboard task
33+
- Restart dashboard web
2334
...

setup/collections/ansible_collections/ansible/containerized_installer/roles/automationdashboard/tasks/uninstall.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- dashboard_channels
4949
- dashboard_postgres
5050
- dashboard_secret_key
51+
- dashboard_database_key
5152

5253
- name: Delete the directories/files
5354
ansible.builtin.file:

setup/collections/ansible_collections/ansible/containerized_installer/roles/automationdashboard/templates/django_dashboard_conf.py.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
with open("/etc/dashboard/SECRET_KEY") as fin:
22
SECRET_KEY = fin.read()
3+
with open("/etc/dashboard/DATABASE_KEY") as fin:
4+
DATABASE_KEY = fin.read()
35

46
ALLOWED_HOSTS=["*"]
57
CORS_ALLOWED_ORIGINS = [

src/backend/apps/clusters/encryption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, key: bytes | str):
2525

2626
def get_encryption_key() -> bytes:
2727
h = hashlib.sha512()
28-
h.update(smart_bytes(settings.SECRET_KEY))
28+
h.update(smart_bytes(settings.DATABASE_KEY))
2929
return base64.urlsafe_b64encode(h.digest())
3030

3131

src/backend/django_config/local_settings.example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
}
1818

1919
SECRET_KEY = 'django-insecure-cu=@gv*8$8+rr2-^-8^g00!ib_9-utgu!26#q#@)!y%3#wt^1#'
20+
DATABASE_KEY = 'insecure-database-encryption-key-cu=@gv*8$8+rr2-^-8^g00!ib_9-utgu!26#q#@)!y%3#wt^1#'
2021

2122
AAP_AUTH_PROVIDER = {
2223
"name": "Ansible Automation Platform",

src/backend/django_config/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
# SECURITY WARNING: keep the secret key used in production secret!
2929
# SECRET_KEY = ...
30+
# DATABASE_KEY - ...
3031

3132
# SECURITY WARNING: don't run with debug turned on in production!
3233
DEBUG = False

0 commit comments

Comments
 (0)