The service can be configured by setting various environment variables.
The following environment variables set directly the Django setting with the same name:
-
ALLOWED_HOSTS
. Default is empty list. -
CSRF_COOKIE_NAME
. Default is to use the Django default. -
CSRF_COOKIE_PATH
. Default is to use the Django default. -
CSRF_COOKIE_SECURE
. Default is to use the Django default. -
CSRF_TRUSTED_ORIGINS
. Default is empty list. -
DEBUG
. Default isTrue
. -
DEFAULT_FROM_EMAIL
. Default is "no-reply@hel.fi". See also the other email settings. -
FORCE_SCRIPT_NAME
. Default is to use the Django default. -
MEDIA_URL
. Default is "/media/". -
SECRET_KEY
. IfDEBUG
isTrue
, default is "xxx", otherwise empty string (which prevents Django from starting, so you need to set this). -
SESSION_COOKIE_NAME
. Default is to use the Django default. -
SESSION_COOKIE_PATH
. Default is to use the Django default. -
SESSION_COOKIE_SECURE
. Default is to use the Django default. -
STATIC_URL
. Default is "/static/". -
USE_X_FORWARDED_HOST
. Default is to use the Django default.
The following environment variables can be used to affect some standard Django settings, but somewhat indirectly:
-
CACHE_URL
: Configures the "default" cache using Django-environ. Default is "locmemcache://". -
DATABASE_URL
: Configures the "default" database connection using Django-environ. Default is "postgres://open_city_profile:open_city_profile@localhost/open_city_profile". -
EMAIL_URL
: Configures email for Django using Django-environ. Default is "consolemail://". -
VAR_ROOT
: Provides a base path for theMEDIA_ROOT
andSTATIC_ROOT
Django settings.MEDIA_ROOT
will be set to${VAR_ROOT}/media
andSTATIC_ROOT
to${VAR_ROOT}/static
. If run with Docker (determined by checking that the project is in an/app
directory),VAR_ROOT
defaults to/var
. Otherwise it defaults to a path calledvar
under the project directory.
This project uses Django-helusers for doing authentication. The following environment variables correspond directly to Django-helusers settings:
-
TOKEN_AUTH_ACCEPTED_AUDIENCE
: Corresponds toOIDC_API_TOKEN_AUTH.AUDIENCE
. Default is empty. -
TOKEN_AUTH_ACCEPTED_SCOPE_PREFIX
: Corresponds toOIDC_API_TOKEN_AUTH. API_SCOPE_PREFIX
. Default is empty. -
TOKEN_AUTH_REQUIRE_SCOPE
: Corresponds toOIDC_API_TOKEN_AUTH. REQUIRE_API_SCOPE_FOR_AUTHENTICATION
. Default isFalse
.
The following environment variables configure authentication or authorization in other ways:
-
TOKEN_AUTH_AUTHSERVER_URL
: Sets the "main" authentication server’s URL. The URL needs to be exactly what the authentication server reports as itsissuer
value. Default is empty. -
ADDITIONAL_AUTHSERVER_URLS
: Sets additional authentication server URLs as a list of strings. JWTs signed by these servers are accepted for authentication. The URLs need to be exactly what the authentication servers report as theirissuer
value. Default is empty list. -
VERIFIED_PERSONAL_INFORMATION_ACCESS_AMR_LIST
: Can be used to limit staff users access to verified personal information fields for only those that have authenticated using certain authentication method (Denoted by the "amr" claim in the authentication token). If empty, access is not limited. Default is empty list.
It’s possible to configure open-city-profile to communicate with a Keycloak instance. User data gets synchronised into the Keycloak instance. The Keycloak instance can simultaneously act as an authentication server but it doesn’t have to. All the following settings are needed — if any are missing, then the communication with Keycloak feature is disabled.
-
KEYCLOAK_BASE_URL
: The base URL of the Keycloak server, including any configured context path. -
KEYCLOAK_REALM
: The name of the Keycloak realm to use. -
KEYCLOAK_CLIENT_ID
: Authentication to the Keycloak instance happens using a service account. This is the client id. -
KEYCLOAK_CLIENT_SECRET
: …and this is the client secret.
Application logs are output to stderr.
-
OPEN_CITY_PROFILE_LOG_LEVEL
: sets logging level. Use any string representation of a Python logging level. Default is "DEBUG" if Django’sDEBUG
setting is on, otherwise it’s "INFO".
Profile data access produces audit events. Audit events may be output to multiple destinations. The destinations can be enabled individually. By default all outputs are disabled.
-
AUDIT_LOG_TO_DB_ENABLED
: enable audit logging to database by setting toTrue
. Default isFalse
.
Output as JSON using the Python logging module.
-
AUDIT_LOG_TO_LOGGER_ENABLED
: enable audit logging to logger by setting toTrue
. Default isFalse
. -
AUDIT_LOG_LOGGER_FILENAME
: by default logger output is sent tostdout
. It’s possible to send the output to a file instead, by giving a filename with this setting. The filename may be randomized by including capital "X" characters in it. The "X"s get replaced by random characters.
Django-searchable-encrypted-fields library is used to encrypt some data in the database. Read that library’s documentation to learn what needs to be considered when handling these encryption keys and other values.
-
FIELD_ENCRYPTION_KEYS
: Used to encrypt/decrypt some data in the database. Corresponds directly to the setting with same name in django-searchable-encrypted-fields. Must be set to a valid value. -
SALT_NATIONAL_IDENTIFICATION_NUMBER
: Used as additional salt in calculating search keys for the national identification number field in Profile. Given as thehash_key
argument to django-searchable-encrypted-fields’sSearchField
instance. If not given andDEBUG
isTrue
, defaults to "DEBUG_SALT".
GDPR API functionality needs to communicate with an authentication server. The implementation can use Tunnistamo and/or Keycloak depending on the connected services.
The following settings are required when there are services that are connected to Tunnistamo:
-
TOKEN_AUTH_AUTHSERVER_URL
: The authentication server. Needs to point to the correct Tunnistamo instance. -
OIDC_CLIENT_ID
: Client id to use in the authorization code flow -
OIDC_CLIENT_SECRET
: Client secret to use in the authorization code flow -
TUNNISTAMO_API_TOKENS_URL
: Tunnistamo URL from which the backend will fetch API tokens for GDPR API use
Required environment variables when there are services that are connected only to Keycloak:
-
KEYCLOAK_BASE_URL
andKEYCLOAK_REALM
: Described above -
KEYCLOAK_GDPR_CLIENT_ID
: Client id to use in the authorization code flow. -
KEYCLOAK_GDPR_CLIENT_SECRET
: Client secret to use in the authorization code flow.
Common environment variable that is required in either case:
-
GDPR_AUTH_CALLBACK_URL
: Callback URL should be the same which is used by the UI for fetching OAuth/OIDC authorization token for using the GDPR API.
-
ENABLE_GRAPHIQL
: Enables GraphiQL testing user interface. IfDEBUG
isTrue
, this setting has no effect and GraphiQL is always enabled. Default isFalse
. -
ENABLE_GRAPHQL_INTROSPECTION
: Enables GraphQL introspection queries. IfDEBUG
isTrue
, this setting has no effect and introspection queries are always enabled. Default isFalse
. -
USE_X_FORWARDED_FOR
: Affects the way how a requester’s IP address is figured out. If set toTrue
, theX-Forwarded-For
HTTP header is used as one option. Default isFalse
.
It’s possible to report errors to Sentry.
-
SENTRY_DSN
: Sets the Sentry DSN. If this is not set, nothing is sent to Sentry. -
SENTRY_ENVIRONMENT
: Sets the Sentry environment. Default is "development". -
COMMIT_HASH
: Sets the Sentry release. SeeCOMMIT_HASH
in Miscellaneous. IfCOMMIT_HASH
is not set, set module version instead.