Enable secure logs ΒΆ

Deprecation notice

Support for Secure Logs in Nais has been deprecated and will be removed at the end of the year. Secure logs will not be migrated to nav-logs (OpenSearch). Migrate to Team Logs for a private logging solution.

This guide will show you how to enable shipping of secure logs for your application.

Prerequisites ΒΆ

If your Nais team has already at any point produced secure logs, you can skip this step.

If your team has never before produced secure logs, give a warning in #kibana Slack channel for the admins to open access for your team. Remember to include the name of your Nais team in the message.

Configuring secure logs ΒΆ

To enable secure logs for your application, you need to add the following configuration to your application manifest. This will send all logs produced by the application to the secure logs index in the legacy logging system.

.nais/app.yaml

yaml

Legacy secure logs configuration ΒΆ

Deprecated syntax

This part of the guide contains the now deprecated syntax for enabling secure logs and is subject to removal in the future.

Enabling secure logs manifest ΒΆ

.nais/app.yaml

yaml

Set log rotation ΒΆ

With secure logs enabled a directory /secure-logs/ will be mounted in the application container. Every *.log file in this directory will be monitored and the content transferred to the legacy Elasticsearch system. Make sure that these files are readable for the log shipper (the process runs as uid/gid 1065).

directory size limit

The /secure-logs/ directory has a size limit of 128Mb, and it's the application's responsibility to ensure that this limit is not exceeded.

If the limit is exceeded the application pod will be evicted and restarted.

Example log configuration ΒΆ

Log files should be in JSON format as the normal application logs. Here is an example configuration of JSON logging with a size based rolling file appender in Logback:

xml

Configure log shipping ΒΆ

Example configuration selecting which logs go to secure logs

logback.xml

xml

Use secure logs in application ΒΆ

Using the Logback config below you can log to secure logs by writing Kotlin-code like this:

kotlin

See doc on Logback filters and markers See Example log configuration for further configuration examples.

Non-JSON logs ΒΆ

If the logging framework used doesn't support JSON logging, it is also possible to use multiline logs in this format:

Plaintext

Files on this format must be named *.mlog.

Sending logs with HTTP ΒΆ

If you do not want to have these logs as files in the pod, it is also possible to use HTTP to write logs. POST your log entry as JSON to http://localhost:19880

bash