Skip to content

Commit

Permalink
Merge pull request #10248 from gem/suppress_403_warnings
Browse files Browse the repository at this point in the history
Add a SUPPRESS_PERMISSION_DENIED_WARNINGS flag to the webui settings
  • Loading branch information
ptormene authored Jan 8, 2025
2 parents aa8351e + 77ec451 commit e18e194
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
16 changes: 12 additions & 4 deletions openquake/server/local_settings.py.aelo_aristotle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ DISABLE_VERSION_WARNING = True

ARISTOTLE_DEFAULT_USGS_ID = ''

# # Static Folder
# STATIC_ROOT = ''
# By default it is 'openquake'
# WEBUI_USER =

# Folder STATIC_ROOT is the full, absolute path to your static files folder.
# Furthermore, the user WEBUI_USER must own that directory.
STATIC_ROOT = '/var/www/webui'

# Configure the directory to store the server user access log
# Furthermore, the user WEBUI_USER must own that directory.
WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# WEBUI config uncomment and set properly if needed
# WEBUIURL = 'http://localhost:8800/'
Expand Down Expand Up @@ -37,8 +45,6 @@ SERVER_NAME = <localhost>
# values
USE_REVERSE_PROXY = <True|False>

WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
Expand All @@ -48,3 +54,5 @@ WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'
# TIME_ZONE =

DEBUG = False

SUPPRESS_PERMISSION_DENIED_WARNINGS = True
14 changes: 11 additions & 3 deletions openquake/server/local_settings.py.pam
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ AUTHENTICATION_BACKENDS += (
'django_pam.auth.backends.PAMBackend',
)

#Static Folder
# By default it is 'openquake'
# WEBUI_USER =

# Folder STATIC_ROOT is the full, absolute path to your static files folder.
# Furthermore, the user WEBUI_USER must own that directory.
STATIC_ROOT = '/var/www/webui'

# Configure the directory to store the server user access log
# Furthermore, the user WEBUI_USER must own that directory.
WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# WEBUI config uncomment and set properly if needed
# WEBUIURL = 'http://localhost:8800/'

Expand All @@ -29,8 +37,6 @@ STATIC_ROOT = '/var/www/webui'
# enable WEBUI_PATHPREFIX to place webui pages below a specific path
# WEBUI_PATHPREFIX='/path/prefix'

WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
Expand All @@ -40,3 +46,5 @@ WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# This is reasonable in an internal installation, otherwise set it to False
DEBUG = True

SUPPRESS_PERMISSION_DENIED_WARNINGS = True
15 changes: 10 additions & 5 deletions openquake/server/local_settings.py.server
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ APPLICATION_MODE = 'RESTRICTED'
# Disable sharing of results across users
ACL_ON = True

# By default it is 'openquake'
# WEBUI_USER =

# Folder STATIC_ROOT is the full, absolute path to your static files folder.
# Furthermore, the user `openquake` must own that directory.
# Furthermore, the user WEBUI_USER must own that directory.
STATIC_ROOT = '/var/www/webui'

# Configure the directory to store the server user access log
# Furthermore, the user WEBUI_USER must own that directory.
WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# WEBUI config uncomment and set properly if needed
# WEBUIURL = 'http://localhost:8800/'

Expand All @@ -17,10 +24,6 @@ STATIC_ROOT = '/var/www/webui'
# the path must start with ``/`` and ending without it (e.g. ``'/path/prefix'``)
# WEBUI_PATHPREFIX='/path/prefix'

# Configure the directory to store the server user access log
# Furthermore, the user `openquake` must own that directory.
WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
Expand All @@ -29,3 +32,5 @@ WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'
# TIME_ZONE =

DEBUG = False

SUPPRESS_PERMISSION_DENIED_WARNINGS = True
14 changes: 11 additions & 3 deletions openquake/server/local_settings.py.tools
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ APPLICATION_MODE = 'TOOLS_ONLY'
# Disable sharing of results across users (default True)
# ACL_ON = True

#Static Folder
# By default it is 'openquake'
# WEBUI_USER =

# Folder STATIC_ROOT is the full, absolute path to your static files folder.
# Furthermore, the user WEBUI_USER must own that directory.
STATIC_ROOT = '/var/www/webui'

# Configure the directory to store the server user access log
# Furthermore, the user WEBUI_USER must own that directory.
WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# WEBUI config uncomment and set properly if needed
# WEBUIURL = 'http://localhost:8800/'

Expand All @@ -17,8 +25,6 @@ STATIC_ROOT = '/var/www/webui'
# enable WEBUI_PATHPREFIX to place webui pages below a specific path
# WEBUI_PATHPREFIX='/path/prefix'

WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
Expand All @@ -28,3 +34,5 @@ WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'

# Set debug if the installation is dev mode
DEBUG = os.environ.get('TOOLS_DEV', False) == 'True'

SUPPRESS_PERMISSION_DENIED_WARNINGS = True
21 changes: 20 additions & 1 deletion openquake/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import socket
import getpass
import tempfile
import logging

from openquake.baselib import config
from openquake.commonlib import datastore
Expand All @@ -32,6 +33,7 @@
STANDALONE_APPS = ()

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
WEBUI_USER = 'openquake'

TEST = 'test' in sys.argv

Expand Down Expand Up @@ -193,6 +195,8 @@
},
}

SUPPRESS_PERMISSION_DENIED_WARNINGS = False

FILE_UPLOAD_MAX_MEMORY_SIZE = 1
FILE_UPLOAD_TEMP_DIR = config.directory.custom_tmp or tempfile.gettempdir()

Expand Down Expand Up @@ -264,6 +268,21 @@
# settings in this file only will be used
pass

if SUPPRESS_PERMISSION_DENIED_WARNINGS:
class SuppressPermissionDeniedWarnings(logging.Filter):
def filter(self, record):
if 'Forbidden' in record.getMessage():
# Avoid warnings like "WARNING Forbidden: /v1/calc/list"
return False
return True

LOGGING['filters'] = {
'suppress_403_warnings': {
'()': SuppressPermissionDeniedWarnings,
},
}
LOGGING['handlers']['console']['filters'] = ['suppress_403_warnings']

# NOTE: the OQ_APPLICATION_MODE environment variable, if defined, overrides
# both the default setting and the one specified in the local settings
APPLICATION_MODE = os.environ.get('OQ_APPLICATION_MODE', APPLICATION_MODE)
Expand Down Expand Up @@ -307,7 +326,7 @@
SERVER_PORT = 443

# do not log to file unless running through the webui
if getpass.getuser() == 'openquake': # the user that runs the webui
if getpass.getuser() == WEBUI_USER:
try:
log_filename = os.path.join(WEBUI_ACCESS_LOG_DIR, # NOQA
'webui-access.log')
Expand Down

0 comments on commit e18e194

Please sign in to comment.