Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YvJ8T-00077J-7U for pgsql-hackers@arkaria.postgresql.org; Thu, 21 May 2015 05:35:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YvJ8S-00047x-B8 for pgsql-hackers@arkaria.postgresql.org; Thu, 21 May 2015 05:35:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YvJ8Q-000470-LM for pgsql-hackers@postgresql.org; Thu, 21 May 2015 05:35:10 +0000 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YvJ8M-0004IN-KK for pgsql-hackers@postgresql.org; Thu, 21 May 2015 05:35:09 +0000 Received: by padbw4 with SMTP id bw4so93110339pad.0 for ; Wed, 20 May 2015 22:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=3WAhHGIDgh2pkpmAXWdIBldwpEwynYCF5q4xBzGG1XQ=; b=C8dPXdn2wuXZL9B1SdbKVFSFneyhCCw3d2vcUWCQZXOF4oSguCV5S2ORzLjLAIDd0h l49cs0EtvZoAGIoqF+uO1J2TA0Z3w9+gWgrSpofGG3GXv+FVzgK3JeGA9JQZUajGhNyB ZT3QSIcWoLonNmOleHBin63zRaAgNFrjQR9jo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=3WAhHGIDgh2pkpmAXWdIBldwpEwynYCF5q4xBzGG1XQ=; b=FeYwP2PpAH7PuQnEKsZSy6mU0cl9fb1lVkpzYa3YGpVcYh+ZZUFj9vEXQ1cCi7Yv9m PUVincmYxuEJb4+Hg0T7TwuGzpBzC36a860NovXnVEwpnxrLO9jzf4LdL1HSEft7rPzS LV0/3WD5nGWBAZjMedFUQsF2CHKL11wWMMnX+DpF3NiKkm98H3dkmD2QHgG2MjtPQ+c6 CSnlV/6V+wQL8XrtFLbZBTpNeEwv5XR17wpxyo4okML+y8171BPEQA9JSUfm1uPOCQ22 qg+TGzzF0ZcogJiKrqsDf2sbPDfklN0HH3wLU3C5h7ka6LJ+9D+Wq2u7GaopqLFXK4fH gn9w== X-Gm-Message-State: ALoCoQlkBBc15XHBy5Cjmoqo5ewc5w9L3QlF/rqfLD5MmUkNcsq8OmtpKS7bZd339XFG9NCxzIAq X-Received: by 10.66.197.231 with SMTP id ix7mr2142962pac.9.1432186503467; Wed, 20 May 2015 22:35:03 -0700 (PDT) Received: from tornado.leadboat.com (c-98-248-47-228.hsd1.ca.comcast.net. [98.248.47.228]) by mx.google.com with ESMTPSA id ym6sm17955451pac.32.2015.05.20.22.35.01 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 20 May 2015 22:35:02 -0700 (PDT) Date: Thu, 21 May 2015 01:35:00 -0400 From: Noah Misch To: Stephen Frost , Tom Lane Cc: pgsql-hackers@postgreSQL.org Subject: Re: [COMMITTERS] pgsql: Add pg_audit, an auditing extension Message-ID: <20150521053500.GB3934913@tornado.leadboat.com> References: <20150514154619.GY30322@tamriel.snowman.net> <21368.1431618712@sss.pgh.pa.us> <20150514161032.GA30322@tamriel.snowman.net> <4844.1431621244@sss.pgh.pa.us> <20150514163551.GB30322@tamriel.snowman.net> <5043.1431621669@sss.pgh.pa.us> <20150514164330.GD30322@tamriel.snowman.net> <5654.1431623278@sss.pgh.pa.us> <20150514171101.GG30322@tamriel.snowman.net> <6454.1431625129@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6454.1431625129@sss.pgh.pa.us> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On Thu, May 14, 2015 at 01:38:49PM -0400, Tom Lane wrote: > * The comments in the code betray utter ignorance of how logging actually > works, in particular this: > > * Administrators can choose which log level the audit log is to be logged > * at. The default level is LOG, which goes into the server log but does > * not go to the client. Set to NOTICE in the regression tests. > > All the user has to do is change client_min_messages and he'll see all the > reports, which means if you think that letting the user see the audit > reports is a security problem then you have a hole a mile wide. That indicates the patch's general readiness: > + /* These are DDL, unless they are ROLE */ > + case LOGSTMT_DDL: > + className = CLASS_DDL; > + class = LOG_DDL; > + > + /* Identify role statements */ > + switch (stackItem->auditEvent.commandTag) > + { > + /* We know these are all role statements */ > + case T_GrantStmt: > + case T_GrantRoleStmt: > + case T_CreateRoleStmt: > + case T_DropRoleStmt: > + case T_AlterRoleStmt: > + case T_AlterRoleSetStmt: > + className = CLASS_ROLE; > + class = LOG_ROLE; > + break; Not T_AlterDefaultPrivilegesStmt? > +static void > +pg_audit_ProcessUtility_hook(Node *parsetree, > + const char *queryString, > + ProcessUtilityContext context, > + ParamListInfo params, > + DestReceiver *dest, > + char *completionTag) > +{ > + AuditEventStackItem *stackItem = NULL; > + int64 stackId = 0; > + > + /* > + * Don't audit substatements. All the substatements we care about should > + * be covered by the event triggers. > + */ > + if (context <= PROCESS_UTILITY_QUERY && !IsAbortedTransactionBlockState()) They aren't covered. A GRANT inside CREATE SCHEMA escapes auditing: create extension pg_audit; SET pg_audit.log = 'role'; SET pg_audit.log_catalog = OFF; SET pg_audit.log_level = 'warning'; SET pg_audit.log_parameter = on; SET pg_audit.log_relation = on; SET pg_audit.role = auditor; SET pg_audit.log_statement_once = ON; create table t (); create role alice; grant select on t to alice; revoke select on t from alice; \z t create schema foo grant select on public.t to alice; \z t I'm wary of the ease of forgetting to run CREATE EXTENSION. One gets much auditing from GUCs alone; for example, we audit "CREATE TABLE t ()" with or without the extension, but only with the extension do we audit the inner CREATE TABLE of "CREATE SCHEMA s CREATE TABLE t ()". A user that creates a database without creating the extension might look at the audit messages and mistakenly think the database is all set. > + /* Return objects affected by the (non drop) DDL statement */ > + query = "SELECT UPPER(object_type), object_identity\n" > + " FROM pg_event_trigger_ddl_commands()"; This SPI query neglects to schema-qualify its function calls. > + DefineCustomStringVariable( > + "pg_audit.log", > + > + "Specifies which classes of statements will be logged by session audit " > + "logging. Multiple classes can be provided using a comma-separated " > + "list and classes can be subtracted by prefacing the class with a " > + "- sign.", > + > + NULL, The short_desc is several lines long, while long_desc is NULL. > --- /dev/null > +++ b/contrib/pg_audit/sql/pg_audit.sql I do applaud the breadth of test coverage. > +-- Set pg_audit parameters for the current (super)user. > +ALTER ROLE :current_user SET pg_audit.log = 'Role'; > +ALTER ROLE :current_user SET pg_audit.log_level = 'notice'; Do not ALTER the initial login role in a regression test. In the installcheck case, the role belongs to the test operator; it is not ours to modify. > +CREATE USER user1; > +ALTER ROLE user1 SET pg_audit.log = 'ddl, ROLE'; > +ALTER ROLE user1 SET pg_audit.log_level = 'notice'; > + > +-- > +-- Create, select, drop (select will not be audited) > +\connect - user1 Adding new CREATE USER statements, as opposed to CREATE ROLE, to regression tests is almost always wrong. During "make check" on Windows, such users cannot connect. "REGRESS_OPTS = --create-role=user1" fixes that problem but does not help installcheck to pass under MD5 authentication (which it did as of commit c82725e). Skip past these challenges by using SET statements instead of ALTER ROLE + \connect. > + > + Settings can be specified globally (in > + postgresql.conf or using > + ALTER SYSTEM ... SET), at the database level (using > + ALTER DATABASE ... SET), or at the role level (using > + ALTER ROLE ... SET). Note that settings are not > + inherited through normal role inheritance and SET ROLE will > + not alter a user's pg_audit settings. This is a limitation > + of the roles system and not inherent to pg_audit. > + This paragraph applies equally to every SUSET GUC in PostgreSQL. > + > + The pg_audit extension must be loaded in > + . Otherwise, an error > + will be raised at load time and no audit logging will occur. > + The test suite is a counterexample to that. > + > + Object audit logging logs statements that affect a particular relation. > + Only SELECT, INSERT, UPDATE and > + DELETE commands are supported. TRUNCATE is not > + included because there is no specific privilege for it. > + PostgreSQL has a TRUNCATE privilege: GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER } [, ...] | ALL [ PRIVILEGES ] } ON { [ TABLE ] table_name [, ...] | ALL TABLES IN SCHEMA schema_name [, ...] } TO role_specification [, ...] [ WITH GRANT OPTION ] > + > + Object-level audit logging is implemented via the roles system. The > + setting defines the role that > + will be used for audit logging. A relation (TABLE, > + VIEW, etc.) will be audit logged when the audit role has > + permissions for the command executed or inherits the permissions from > + another role. This allows you to effectively have multiple audit roles > + even though there is a single master role in any context. > + This is clever, but it means that any user can add to the list of audited objects by granting individual object permissions, or the role itself, to the audit role. Crowding the audit log is one thing, but object owners can also use REVOKE to stop auditing an object. Perhaps the answer is to put all important objects under trusted owners, but that's a heavy restriction. Do other RDBMS auditing features behave this way? Stephen, please revert this feature. Most pg_audit bugs will create security vulnerabilities, so incremental development in the PostgreSQL tree is the wrong approach. The feature needs substantial hacking, then an additional committer's thorough review. (The above sampling of defects and weak areas was not a thorough review.) nm -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers