infobyte / faraday

Open Source Vulnerability Management Platform
https://www.faradaysec.com
GNU General Public License v3.0
4.96k stars 908 forks source link

docker-compose up failing with latest image #487

Closed jotamjr closed 4 months ago

jotamjr commented 6 months ago

Faraday version

5.2.0

Component Name

Docker image (faradaysec/faraday)

docker images --digests
REPOSITORY                            TAG             DIGEST                                                                    IMAGE ID       CREATED        SIZE
faradaysec/faraday                    latest          sha256:7d4ca614af952f917b790c55e3bf83527d2a86c9534c4eff43caa384eb3ff5b3   24a4aa3a1a3c   5 days ago     782MB

Steps to reproduce

wget https://github.com/infobyte/faraday/raw/master/docker-compose.yaml
docker-compose up
app_1    | Wed Mar 20 01:47:02 UTC 2024 Creating server.ini
app_1    | Waiting for postgres on db
app_1    | Wed Mar 20 01:47:03 UTC 2024 Creating tables on database faraday...
app_1    | Traceback (most recent call last):
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
app_1    |     self.dialect.do_execute(
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
app_1    |     cursor.execute(statement, parameters)
app_1    | psycopg2.errors.UndefinedTable: relation "agent" does not exist
app_1    | LINE 2: FROM agent
app_1    |              ^
app_1    |
app_1    |
app_1    | The above exception was the direct cause of the following exception:
app_1    |
app_1    | Traceback (most recent call last):
app_1    |   File "/usr/local/bin/faraday-manage", line 5, in <module>
app_1    |     from faraday.manage import cli
app_1    |   File "/usr/local/lib/python3.8/site-packages/faraday/manage.py", line 62, in <module>
app_1    |     app = get_app(register_extensions_flag=False)
app_1    |   File "/usr/local/lib/python3.8/site-packages/faraday/server/app.py", line 539, in get_app
app_1    |     FARADAY_APP = create_app(db_connection_string=db_connection_string,
app_1    |   File "/usr/local/lib/python3.8/site-packages/faraday/server/app.py", line 526, in create_app
app_1    |     remove_sid()
app_1    |   File "/usr/local/lib/python3.8/site-packages/faraday/server/websockets/dispatcher.py", line 53, in remove_sid
app_1    |     agents = Agent.query.filter(Agent.sid!=None).all()  # noqa E711
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3373, in all
app_1    |     return list(self)
app_1    |   File "/usr/local/lib/python3.8/site-packages/nplusone/ext/sqlalchemy.py", line 99, in query_iter
app_1    |     ret, clone = itertools.tee(original_query_iter(self))
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3535, in __iter__
app_1    |     return self._execute_and_instances(context)
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
app_1    |     result = conn.execute(querycontext.statement, self._params)
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
app_1    |     return meth(self, multiparams, params)
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
app_1    |     return connection._execute_clauseelement(self, multiparams, params)
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
app_1    |     ret = self._execute_context(
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
app_1    |     self._handle_dbapi_exception(
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
app_1    |     util.raise_(
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
app_1    |     raise exception
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
app_1    |     self.dialect.do_execute(
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
app_1    |     cursor.execute(statement, parameters)
app_1    | sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "agent" does not exist
app_1    | LINE 2: FROM agent
app_1    |              ^
app_1    |
app_1    | [SQL: SELECT agent.create_date AS agent_create_date, agent.update_date AS agent_update_date, agent.id AS agent_id, agent.token AS agent_token, agent.name AS agent_name, agent.active AS agent_active, agent.sid AS agent_sid, agent.creator_id AS agent_creator_id, agent.update_user_id AS agent_update_user_id
app_1    | FROM agent
app_1    | WHERE agent.sid IS NOT NULL]
app_1    | (Background on this error at: http://sqlalche.me/e/13/f405)
app_1    | Wed Mar 20 01:47:05 UTC 2024 Using existing server.ini
app_1    | Update swagger...
app_1    | Traceback (most recent call last):
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
app_1    |     self.dialect.do_execute(
app_1    |   File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
app_1    |     cursor.execute(statement, parameters)
app_1    | psycopg2.errors.UndefinedTable: relation "agent" does not exist
app_1    | LINE 2: FROM agent
javierjeronimo commented 6 months ago

I have the same error

ezk06eer commented 6 months ago

@jotamjr Hi, we are aware of the issue, and it will be corrected shortly.

Lax-Asuna commented 5 months ago

I hava the same error:

docker logs faraday_db 2>&1 | grep ERROR

2024-04-19 02:55:55.941 UTC [56] ERROR: relation "agent" does not exist at character 307 2024-04-19 02:56:00.048 UTC [57] ERROR: relation "agent" does not exist at character 307 2024-04-19 02:56:00.142 UTC [57] ERROR: relation "vulnerability" does not exist 2024-04-19 02:56:06.005 UTC [58] ERROR: relation "agent" does not exist at character 307 2024-04-19 02:56:10.110 UTC [59] ERROR: relation "agent" does not exist at character 307 2024-04-19 02:56:10.148 UTC [59] ERROR: relation "vulnerability" does not exist 2024-04-19 02:56:16.132 UTC [60] ERROR: relation "agent" does not exist at character 307 2024-04-19 02:56:20.549 UTC [61] ERROR: relation "agent" does not exist at character 307

ruthlezs commented 4 months ago

It seems like the table "alembic_version" will always be found during the database initialization at line:425-428 in initdb.py even though the metadata tables have not been created yet. This resulted in the function returning and skipping the "create_all" function that will create all required tables, and then the migration failed.

Here is my work-around solution:

  1. Edit initdb.py (should be located in /usr/local/lib/python3.8/site-packages/faraday/server/commands/initdb.py) by removing the return statement at line:432

  2. Run the command "faraday-manage create-tables" in faraday-app's docker Exec console to create all required tables

  3. Now, you should be able to access the Faraday application

  4. Run the command "faraday-manage create-superuser" in faraday-app's docker Exec console

Hope this helps!

ezk06eer commented 4 months ago

@jotamjr please do a pull for the community version (5.3.0), delete the $HOME/.faraday folder and do a docker-compose up.

check you dont have volumes persistent in docker, and delete the images you have in docker about faraday.

Cheers!