Fix logging without root in container (#966)

* Catch IOError issues (i.e. permission issues) with writing to log files
    * Related to #844
* Logs now have a sys.stdout handler
* Update Dockerfile to create and chown/chmod the folders used by `docker-compose` to store files/logs (`/var/log/CTFd`, `/var/uploads`)
selenium-screenshot-testing
Kevin Chung 2019-04-22 22:22:54 -04:00 committed by GitHub
parent ad5df80979
commit 367498fd72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 10 deletions

View File

@ -35,6 +35,7 @@ from sqlalchemy.exc import InvalidRequestError, IntegrityError
import datetime
import logging
import os
import sys
def init_template_filters(app):
@ -85,6 +86,7 @@ def init_logs(app):
'registrations': os.path.join(log_dir, 'registrations.log')
}
try:
for log in logs.values():
if not os.path.exists(log):
open(log, 'a').close()
@ -102,6 +104,20 @@ def init_logs(app):
logger_registrations.addHandler(
registration_log
)
except IOError:
pass
stdout = logging.StreamHandler(stream=sys.stdout)
logger_submissions.addHandler(
stdout
)
logger_logins.addHandler(
stdout
)
logger_registrations.addHandler(
stdout
)
logger_submissions.propagate = 0
logger_logins.propagate = 0

View File

@ -4,7 +4,7 @@ RUN apk update && \
RUN adduser -D -u 1001 -s /bin/bash ctfd
WORKDIR /opt/CTFd
RUN mkdir -p /opt/CTFd
RUN mkdir -p /opt/CTFd /var/log/CTFd /var/uploads
COPY requirements.txt .
@ -20,6 +20,7 @@ RUN for d in CTFd/plugins/*; do \
RUN chmod +x /opt/CTFd/docker-entrypoint.sh
RUN chown -R 1001:1001 /opt/CTFd
RUN chown -R 1001:1001 /var/log/CTFd /var/uploads
USER 1001
EXPOSE 8000