Search code examples
postgresqlazureazure-postgresql

Is it a kind of Microsoft Azure bug for adding pgaudit Azure postgresql?


I am trying to setup pgaudit structure in Azure PostgreSql for pgaudit log I fallowed instuction of microsoft by using below link.

https://learn.microsoft.com/en-us/azure/postgresql/concepts-audit. But I can not see anything when I run

AzureDiagnostics
| where ResourceProvider =="MICROSOFT.DBFORPOSTGRESQL" 
| where Category == "PostgreSQLLogs"
| where Message contains "AUDIT:" 


When I read some article ;

It needs that In Azure Database for PostgreSQL, pgaudit.log cannot be set using a - (minus) sign shortcut as described in the pgAudit documentation. All required statement classes (READ, WRITE etc) should be individually specified.But in Azure PostGre, You need to be superuser make pgaudit got permission with READ,WRITE.

But ;

Now when i try to create SUPERUSER , by giving the command CREATE USER TESTER SUPERUSER; ---> it gives me error saying must be superuser to create superuser

THat's the point? How can I give pgAudit rights and how can I see audit logs in Azure.I applied above instructions but I can not see audilts log in Kusto queries results? Why?

By default, when a server is created we have the following 3 roles defined, which you can also see when you run SELECT rolname FROM pg_roles;

  1. azure_pg_admin
  2. azure_superuser
  3. server admin login – the admin login the user created the server with – which by default is a member of azure_pg_admin.

My roles in Azure :


                                          List of roles
    Role name    |                         Attributes                         |    Member of
-----------------+------------------------------------------------------------+------------------
 azure_pg_admin  | Cannot login                                               | {}
 azure_superuser | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 my_admin        | Create role, Create DB                                     | {azure_pg_admin}
 my_db           | Create role, Create DB                                     | {azure_pg_admin}

Solution

  • You can configure pgaudit.log using Azure CLI with the command az postgres server configuration set -g {resource group} -s {server name} -n "pgaudit.log" --value "read, write" this will log all reads and writes.