Skip to content

Commit

Permalink
feat(app): improve logging, database pool, and auto update shema
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-ssd committed Oct 25, 2024
1 parent ce67c94 commit c14269d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ FROM python:$BASE_IMAGE_TAG
ARG PI_HOME
LABEL maintainer="Sida Say <sida@kheek.com>"
ENV PI_SKIP_BOOTSTRAP=false \
PI_AUTO_UPDATE=false \
PI_DB_VENDOR=sqlite \
PI_DATA_DIR=/data/privacyidea \
PI_CFG_DIR=/etc/privacyidea \
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ The kheeklab privacyIDEA container can create a default admin user by setting th
| `PI_SECRET_KEY` | This is used to encrypt the auth_token | |
| `PI_SUPERUSER_REALM` | The realm, where users are allowed to login as administrators in comma separated value | administrator |
| `PI_SKIP_BOOTSTRAP` | Set this to true to prevent the container to run setup again | false |
| `PI_AUTO_UPDATE` | Set this to true to automatically update privacyIDEA. Only effect when `PI_SKIP_BOOTSTRAP` is set to **true** | false |

> [!WARNING]
> Be careful and setting `PI_SKIP_BOOTSTRAP` to **true** after first initialization. This will prevent the container to run setup again or your data such as admin credentials, secret keys, etc will be overwritten.
> `PI_AUTO_UPDATE` set to **true** will update privacyIDEA to the latest version. Make sure you have backup your data before setting `PI_AUTO_UPDATE` to **true**.
### gunicorn environment variables

Expand Down
32 changes: 16 additions & 16 deletions rootfs/opt/privacyidea/gunicorn_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@


# For debugging and testing
log_data = {
"loglevel": loglevel,
"workers": workers,
"bind": bind,
"graceful_timeout": graceful_timeout,
"timeout": timeout,
"keepalive": keepalive,
"errorlog": errorlog,
"accesslog": accesslog,
# Additional, non-gunicorn variables
"workers_per_core": workers_per_core,
"use_max_workers": use_max_workers,
"host": host,
"port": port,
}
print(json.dumps(log_data))
# log_data = {
# "loglevel": loglevel,
# "workers": workers,
# "bind": bind,
# "graceful_timeout": graceful_timeout,
# "timeout": timeout,
# "keepalive": keepalive,
# "errorlog": errorlog,
# "accesslog": accesslog,
# # Additional, non-gunicorn variables
# "workers_per_core": workers_per_core,
# "use_max_workers": use_max_workers,
# "host": host,
# "port": port,
# }
# print(json.dumps(log_data))
20 changes: 20 additions & 0 deletions rootfs/opt/privacyidea/pi-logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
formatters:
detail:
class: privacyidea.lib.log.SecureFormatter
format: '[%(asctime)s][%(process)d][%(thread)d][%(levelname)s][%(name)s:%(lineno)d] %(message)s'

handlers:
console:
class: logging.StreamHandler
level: INFO
formatter: detail

loggers:
privacyidea:
level: INFO
handlers: [console]

root:
level: WARNING
handlers: [console]
4 changes: 4 additions & 0 deletions rootfs/opt/templates/pi-config.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if PI_PEPPER is None:
SUPERUSER_REALM = os.environ.get('PI_SUPERUSER_REALM','administrator').split(',')

SQLALCHEMY_DATABASE_URI = "$SQLALCHEMY_DATABASE_URI"
SQLALCHEMY_ENGINE_OPTIONS = {"pool_pre_ping": True, "pool_recycle": 3600, "pool_size":10, "pool_timeout": 30, "max_overflow": 20}

This comment has been minimized.

Copy link
@cparkins

cparkins Dec 13, 2024

@mr-ssd When running against SQLite3 adding the options "pool_size", "pool_timeout" and "max_overflow" causes an Exception during startup.

This comment has been minimized.

Copy link
@mr-ssd

mr-ssd Dec 16, 2024

Author Contributor

I create issue #179 for this

PI_ENCFILE = os.environ.get("PI_ENCFILE", "/data/privacyidea/keys/encfile")
PI_HSM = os.environ.get("PI_HSM", "default")
PI_AUDIT_NO_SIGN = os.environ.get("PI_AUDIT_NO_SIGN", "False").lower() == "true"
Expand All @@ -24,6 +25,9 @@ PI_AUDIT_MODULE = os.environ.get("", "privacyidea.lib.auditmodules.sqlaudit")
PI_AUDIT_KEY_PRIVATE = os.environ.get("PI_AUDIT_KEY_PRIVATE_PATH", "/data/privacyidea/keys/private.pem")
# PI_AUDIT_KEY_PUBLIC will be used only when PI_AUDIT_NO_SIGN is True
PI_AUDIT_KEY_PUBLIC = os.environ.get("PI_AUDIT_KEY_PUBLIC_PATH", "/data/privacyidea/keys/public.pem")
PI_AUDIT_POOL_SIZE = os.environ.get("PI_AUDIT_POOL_SIZE", 5)
PI_AUDIT_POOL_RECYCLE = os.environ.get("PI_AUDIT_POOL_RECYCLE", 3600)
PI_LOGCONFIG= os.environ.get("PI_LOGCONFIG", "/opt/privacyidea/pi-logging.yml")
PI_LOGFILE = os.environ.get("PI_LOGFILE", "/dev/stdout")
PI_LOGLEVEL = logging.getLevelName(os.environ.get("PI_LOGLEVEL", 20))
PI_NODE = os.environ.get("HOSTNAME", "localnode")
Expand Down
6 changes: 6 additions & 0 deletions rootfs/usr/local/bin/configure_privacyidea.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ function prestart_privacyidea {
echo "[INFO] Skipping key generation, table creation, and admin user creation."
echo ""
fi

if [ "${PI_SKIP_BOOTSTRAP}" = true ] && [ "${PI_AUTO_UPDATE}" = true ] ; then
echo "Auto updating privacyIDEA..."
privacyidea-schema-upgrade /opt/privacyidea/lib/privacyidea/migrations
echo "privacyIDEA successfully updated."
fi
}

main

0 comments on commit c14269d

Please sign in to comment.