dfir-iris / iris-web

Collaborative Incident Response platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] iriswebapp_app fails to start - psycopg2.errors.UndefinedFunction: function gen_random_uuid() does not exist

vector1one opened this issue · comments

on v2.4.5 everything builds ok but on docker-compose up I get a couple errors.

iriswebapp_nginx | 2024/02/22 15:17:26 [error] 10#10: *48815 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: iris.app.dev, request: "GET / HTTP/1.1", upstream: "http://172.22.0.2:8000/", host: "127.0.0.1"
iriswebapp_nginx | 127.0.0.1 - - [22/Feb/2024:15:17:26 +0000] "GET / HTTP/1.1" 502 497 "-" "curl/7.64.0" "-"
iriswebapp_nginx | 2024/02/22 15:17:26 [info] 10#10: *48815 client 127.0.0.1 closed keepalive connection

which causes

iriswebapp_worker | IRISwebapp is unavailable - sleeping

when I check the webapp and db this is the error

iriswebapp_db | 2024-02-21 03:13:05.561 UTC [30] ERROR: function gen_random_uuid() does not exist at character 77
iriswebapp_db | 2024-02-21 03:13:05.561 UTC [30] HINT: No function matches the given name and argument types. You might need to add explicit type casts.
iriswebapp_db | 2024-02-21 03:13:05.561 UTC [30] STATEMENT:
iriswebapp_db | CREATE TABLE contact (
iriswebapp_db | id BIGSERIAL NOT NULL,
iriswebapp_db | contact_uuid UUID DEFAULT gen_random_uuid() NOT NULL,
iriswebapp_db | contact_name TEXT,
iriswebapp_db | contact_email TEXT,
iriswebapp_db | contact_role TEXT,
iriswebapp_db | contact_note TEXT,
iriswebapp_db | contact_work_phone TEXT,
iriswebapp_db | contact_mobile_phone TEXT,
iriswebapp_db | custom_attributes JSON,
iriswebapp_db | client_id BIGINT,
iriswebapp_db | PRIMARY KEY (id),
iriswebapp_db | FOREIGN KEY(client_id) REFERENCES client (client_id)
iriswebapp_db | )
iriswebapp_db |
iriswebapp_db |
iriswebapp_app | 2024-02-21 03:13:05 :: ERROR :: views :: :: Post init failed. IRIS not started
iriswebapp_app | Traceback (most recent call last):
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1969, in _exec_single_context
iriswebapp_app | self.dialect.do_execute(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 922, in do_execute
iriswebapp_app | cursor.execute(statement, parameters)
iriswebapp_app | psycopg2.errors.UndefinedFunction: function gen_random_uuid() does not exist
iriswebapp_app | LINE 4: contact_uuid UUID DEFAULT gen_random_uuid() NOT NULL,
iriswebapp_app | ^
iriswebapp_app | HINT: No function matches the given name and argument types. You might need to add explicit type casts.
iriswebapp_app |
iriswebapp_app |
iriswebapp_app | The above exception was the direct cause of the following exception:
iriswebapp_app |
iriswebapp_app | Traceback (most recent call last):
iriswebapp_app | File "/iriswebapp/app/views.py", line 116, in
iriswebapp_app | run_post_init(development=app.config["DEVELOPMENT"])
iriswebapp_app | File "/iriswebapp/app/post_init.py", line 145, in run_post_init
iriswebapp_app | db.create_all(bind_key=None)
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/flask_sqlalchemy/extension.py", line 868, in create_all
iriswebapp_app | self._call_for_binds(bind_key, "create_all")
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/flask_sqlalchemy/extension.py", line 849, in _call_for_binds
iriswebapp_app | getattr(metadata, op_name)(bind=engine)
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 5832, in create_all
iriswebapp_app | bind._run_ddl_visitor(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3244, in _run_ddl_visitor
iriswebapp_app | conn._run_ddl_visitor(visitorcallable, element, **kwargs)
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2448, in _run_ddl_visitor
iriswebapp_app | visitorcallable(self.dialect, self, **kwargs).traverse_single(element)
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/sql/visitors.py", line 671, in traverse_single
iriswebapp_app | return meth(obj, **kw)
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 919, in visit_metadata
iriswebapp_app | self.traverse_single(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/sql/visitors.py", line 671, in traverse_single
iriswebapp_app | return meth(obj, **kw)
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 952, in visit_table
iriswebapp_app | CreateTable(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 315, in _invoke_with
iriswebapp_app | return bind.execute(self)
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1416, in execute
iriswebapp_app | return meth(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 181, in _execute_on_connection
iriswebapp_app | return connection._execute_ddl(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1528, in _execute_ddl
iriswebapp_app | ret = self._execute_context(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1848, in _execute_context
iriswebapp_app | return self._exec_single_context(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1988, in _exec_single_context
iriswebapp_app | self._handle_dbapi_exception(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2344, in _handle_dbapi_exception
iriswebapp_app | raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1969, in _exec_single_context
iriswebapp_app | self.dialect.do_execute(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 922, in do_execute
iriswebapp_app | cursor.execute(statement, parameters)
iriswebapp_app | sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) function gen_random_uuid() does not exist
iriswebapp_app | LINE 4: contact_uuid UUID DEFAULT gen_random_uuid() NOT NULL,
iriswebapp_app | ^
iriswebapp_app | HINT: No function matches the given name and argument types. You might need to add explicit type casts.
iriswebapp_app |
iriswebapp_app | [SQL:
iriswebapp_app | CREATE TABLE contact (
iriswebapp_app | id BIGSERIAL NOT NULL,
iriswebapp_app | contact_uuid UUID DEFAULT gen_random_uuid() NOT NULL,
iriswebapp_app | contact_name TEXT,
iriswebapp_app | contact_email TEXT,
iriswebapp_app | contact_role TEXT,
iriswebapp_app | contact_note TEXT,
iriswebapp_app | contact_work_phone TEXT,
iriswebapp_app | contact_mobile_phone TEXT,
iriswebapp_app | custom_attributes JSON,
iriswebapp_app | client_id BIGINT,
iriswebapp_app | PRIMARY KEY (id),
iriswebapp_app | FOREIGN KEY(client_id) REFERENCES client (client_id)
iriswebapp_app | )
iriswebapp_app |
iriswebapp_app | ]
iriswebapp_app | (Background on this error at: https://sqlalche.me/e/20/f405)
iriswebapp_app | [2024-02-21 03:13:05 +0000] [11] [ERROR] Exception in worker process
iriswebapp_app | Traceback (most recent call last):
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1969, in _exec_single_context
iriswebapp_app | self.dialect.do_execute(
iriswebapp_app | File "/opt/venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 922, in do_execute
iriswebapp_app | cursor.execute(statement, parameters)
iriswebapp_app | psycopg2.errors.UndefinedFunction: function gen_random_uuid() does not exist
iriswebapp_app | LINE 4: contact_uuid UUID DEFAULT gen_random_uuid() NOT NULL,
iriswebapp_app | ^
iriswebapp_app | HINT: No function matches the given name and argument types. You might need to add explicit type casts.

So in my case this is not a bug in iris at all.
It's because I made some changes to my posgres-management.

Added the extention 'pgcrypto' to the database fixed the issue.
Some ansible code for you here:

- name: "Add pgcrypt-extension to the database"
  postgresql_ext:
    login_port: "{{ postgres_port }}"
    login_host: "{{ postgres_host}}"
    login_user: "{{ postgres_secrets.postgres_user }}"
    login_password: "{{ postgres_secrets.postgres_password }}"
    name: "pgcrypto"                                                                                                           
    db: "{{ iris.postgres.db_name }}"
    state: present

It might be enough to run this SQL when connected to your DB using psql:

CREATE EXTENSION pgcrypto;

Could be a good idea to catch this exception and hint to the user that they might have to fix their backend?