Skip to content

Limit logging on mitogen

Limit the logging of mitogen function. For file operations it logs the full file content:

2024-07-12 07:14:56,259 DEBUG    inmanta.agent.agent.longevity-2024.2.1.ii.inmanta.com resource fs::File[longevity-2024.2.1.ii.inmanta.com,path=/var/lib/pgsql/13/data/pg_hba.conf],v=1572562033: Calling function <function read_binary at 0x7f932db68c20> in context longevity-2024.2.1.ii.inmanta.com.: b'# PostgreSQL Client Authentication Configuration File\n# ===================================================\n#\n# Refer to the "Client Authentication" section in the PostgreSQL\n# documentation for a complete description of this file.  A short\n# synopsis follows.\n#\n# This file controls: which hosts are allowed to connect, how clients\n# are authenticated, which PostgreSQL user names they can use, which\n# databases they can access.  Records take one of these forms:\n#\n# local      DATABASE  USER  METHOD  [OPTIONS]\n# host       DATABASE  USER  ADDRESS  METHOD  [OPTIONS]\n# hostssl    DATABASE  USER  ADDRESS  METHOD  [OPTIONS]\n# hostnossl  DATABASE  USER  ADDRESS  METHOD  [OPTIONS]\n#\n# (The uppercase items must be replaced by actual values.)\n#\n# The first field is the connection type: "local" is a Unix-domain\n# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,\n# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a\n# plain TCP/IP socket.\n#\n# DATABASE can be "all", "sameuser", "samerole", "replication", a\n# database name, or a comma-separated list thereof. The "all"\n# keyword does not match "replication". Access to replication\n# must be enabled in a separate record (see example below).\n#\n# USER can be "all", a user name, a group name prefixed with "+", or a\n# comma-separated list thereof.  In both the DATABASE and USER fields\n# you can also write a file name prefixed with "@" to include names\n# from a separate file.\n#\n# ADDRESS specifies the set of hosts the record matches.  It can be a\n# host name, or it is made up of an IP address and a CIDR mask that is\n# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that\n# specifies the number of significant bits in the mask.  A host name\n# that starts with a dot (.) matches a suffix of the actual host name.\n# Alternatively, you can write an IP address and netmask in separate\n# columns to specify the set of hosts.  Instead of a CIDR-address, you\n# can write "samehost" to match any of the server\'s own IP addresses,\n# or "samenet" to match any address in any subnet that the server is\n# directly connected to.\n#\n# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",\n# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".\n# Note that "password" sends passwords in clear text; "md5" or\n# "scram-sha-256" are preferred since they send encrypted passwords.\n#\n# OPTIONS are a set of options for the authentication in the format\n# NAME=VALUE.  The available options depend on the different\n# authentication methods -- refer to the "Client Authentication"\n# section in the documentation for a list of which options are\n# available for which authentication methods.\n#\n# Database and user names containing spaces, commas, quotes and other\n# special characters must be quoted.  Quoting one of the keywords\n# "all", "sameuser", "samerole" or "replication" makes the name lose\n# its special character, and just match a database or username with\n# that name.\n#\n# This file is read on server startup and when the server receives a\n# SIGHUP signal.  If you edit the file on a running system, you have to\n# SIGHUP the server for the changes to take effect, run "pg_ctl reload",\n# or execute "SELECT pg_reload_conf()".\n#\n# Put your actual configuration here\n# ----------------------------------\n#\n# If you want to allow non-local connections, you need to add more\n# "host" records.  In that case you will also need to make PostgreSQL\n# listen on a non-local interface via the listen_addresses\n# configuration parameter, or via the -i or -h command line switches.\n\n# CAUTION: Configuring the system for local "trust" authentication\n# allows any local user to connect as any PostgreSQL user, including\n# the database superuser.  If you do not trust all your local users,\n# use another authentication method.\n\n\n# TYPE  DATABASE        USER            ADDRESS                 METHOD\n\n# "local" is for Unix domain socket connections only\nlocal   all             all                                     peer\n# IPv4 local connections:\nhost    all             all             127.0.0.1/32            md5\n# IPv6 local connections:\nhost    all             all             ::1/128                 md5\n# Allow replication connections from localhost, by a user with the\n# replication privilege.\nlocal   replication     all                                     peer\nhost    replication     all             127.0.0.1/32            ident\nhost    replication     all             ::1/128                 ident\n\n\nhost    inmanta     inmanta             127.0.0.1/32            md5\n\nhost    inmanta     inmanta             ::1/128            md5\n\nhost    inmanta     inmanta             192.168.2.53/32            md5\n'

This might blow up the logs and it might actually log secrets it should not log.


https://inmanta.slack.com/archives/C01QH7140NT/p1721024431823609

  1. By default only log the function and not the arguments
  2. Introduce an env var that allows you to enable argument logging but with a limit on the length.
Edited by Guillaume Everarts de Velp