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

Check and disallow a relative path for sqlite #22530

Merged
merged 1 commit into from
Mar 25, 2022
Merged
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
10 changes: 10 additions & 0 deletions airflow/www/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
from flask_appbuilder import SQLA
from flask_caching import Cache
from flask_wtf.csrf import CSRFProtect
from sqlalchemy.engine.url import make_url

from airflow import settings
from airflow.configuration import conf
from airflow.exceptions import AirflowConfigException
from airflow.logging_config import configure_logging
from airflow.utils.json import AirflowJsonEncoder
from airflow.www.extensions.init_appbuilder import init_appbuilder
Expand Down Expand Up @@ -76,6 +78,14 @@ def create_app(config=None, testing=False):
flask_app.config['APP_NAME'] = conf.get(section="webserver", key="instance_name", fallback="Airflow")
flask_app.config['TESTING'] = testing
flask_app.config['SQLALCHEMY_DATABASE_URI'] = conf.get('core', 'SQL_ALCHEMY_CONN')

url = make_url(flask_app.config['SQLALCHEMY_DATABASE_URI'])
if url.drivername == 'sqlite' and url.database and not url.database.startswith('/'):
raise AirflowConfigException(
f'Cannot use relative path: `{conf.get("core", "SQL_ALCHEMY_CONN")}` to connect to sqlite. '
'Please use absolute path such as `sqlite:////tmp/airflow.db`.'
)

flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

flask_app.config['SESSION_COOKIE_HTTPONLY'] = True
Expand Down