V-73007

Severity: Medium

Generated

2019-05-20 15:48:11.984914

Status

Passed

Unused database components, PostgreSQL software, and database objects must be removed.

NIST 800-53

STIG # Description Result
CM-7 CM-7: Least Functionality passed

Guidance

Information systems are capable of providing a wide variety of functions and services. Some of the functions and services, provided by default, may not be necessary to support essential organizational operations (e.g., key missions, functions).

It is detrimental for software products to provide, or install by default, functionality exceeding requirements or mission objectives.

PostgreSQLs must adhere to the principles of least functionality by providing only essential capabilities.

Check

To get a list of all extensions installed, use the following commands: $ sudo su - postgres $ psql -c “select * from pg_extension where extname != ‘plpgsql’;“”

If any extensions exist that are not approved, this is a finding.

Fix

To remove extensions, use the following commands: $ sudo su - postgres $ psql -c “DROP EXTENSION

Note: it is recommended that plpgsql not be removed.

Test Results

  Result
PostgreSQL query: SELECT extname from pg_extension WHERE extname NOT IN ('address_standardizer','address_standardizer_data_us','adminpack','amcheck','autoinc','bloom','btree_gin','btree_gist','chkpass','citext','cube','dblink','dict_int','dict_xsyn','earthdistance','file_fdw','fuzzystrmatch','hstore','hstore_plperl','insert_username','intagg','intarray','isn','lo','ltree','moddatetime','pageinspect','pgaudit','pg_buffercache','pgcrypto','pg_freespacemap','pg_prewarm','pgrowlocks','pg_stat_statements','pgstattuple','pg_trgm','pg_visibility','postgis','postgis_tiger_geocoder','postgis_topology','postgres_fdw','redis_fdw','refint','seg','set_user','sslinfo','tablefunc','tcn','timetravel','tsm_system_rows','tsm_system_time','unaccent','uuid-ossp','xml2','plpgsql','plperl','plr'); output should eq "" passed
PostgreSQL query with errors: SELECT extname from pg_extension WHERE extname NOT IN ('address_standardizer','address_standardizer_data_us','adminpack','amcheck','autoinc','bloom','btree_gin','btree_gist','chkpass','citext','cube','dblink','dict_int','dict_xsyn','earthdistance','file_fdw','fuzzystrmatch','hstore','hstore_plperl','insert_username','intagg','intarray','isn','lo','ltree','moddatetime','pageinspect','pgaudit','pg_buffercache','pgcrypto','pg_freespacemap','pg_prewarm','pgrowlocks','pg_stat_statements','pgstattuple','pg_trgm','pg_visibility','postgis','postgis_tiger_geocoder','postgis_topology','postgres_fdw','redis_fdw','refint','seg','set_user','sslinfo','tablefunc','tcn','timetravel','tsm_system_rows','tsm_system_time','unaccent','uuid-ossp','xml2','plpgsql','plperl','plr'); output should match /FATAL:\s+database "template0" is not currently accepting connections/ passed
PostgreSQL query: SELECT extname from pg_extension WHERE extname NOT IN ('address_standardizer','address_standardizer_data_us','adminpack','amcheck','autoinc','bloom','btree_gin','btree_gist','chkpass','citext','cube','dblink','dict_int','dict_xsyn','earthdistance','file_fdw','fuzzystrmatch','hstore','hstore_plperl','insert_username','intagg','intarray','isn','lo','ltree','moddatetime','pageinspect','pgaudit','pg_buffercache','pgcrypto','pg_freespacemap','pg_prewarm','pgrowlocks','pg_stat_statements','pgstattuple','pg_trgm','pg_visibility','postgis','postgis_tiger_geocoder','postgis_topology','postgres_fdw','redis_fdw','refint','seg','set_user','sslinfo','tablefunc','tcn','timetravel','tsm_system_rows','tsm_system_time','unaccent','uuid-ossp','xml2','plpgsql','plperl','plr'); output should eq "" passed
PostgreSQL query: SELECT extname from pg_extension WHERE extname NOT IN ('address_standardizer','address_standardizer_data_us','adminpack','amcheck','autoinc','bloom','btree_gin','btree_gist','chkpass','citext','cube','dblink','dict_int','dict_xsyn','earthdistance','file_fdw','fuzzystrmatch','hstore','hstore_plperl','insert_username','intagg','intarray','isn','lo','ltree','moddatetime','pageinspect','pgaudit','pg_buffercache','pgcrypto','pg_freespacemap','pg_prewarm','pgrowlocks','pg_stat_statements','pgstattuple','pg_trgm','pg_visibility','postgis','postgis_tiger_geocoder','postgis_topology','postgres_fdw','redis_fdw','refint','seg','set_user','sslinfo','tablefunc','tcn','timetravel','tsm_system_rows','tsm_system_time','unaccent','uuid-ossp','xml2','plpgsql','plperl','plr'); output should eq "" passed
PostgreSQL query: SELECT extname from pg_extension WHERE extname NOT IN ('address_standardizer','address_standardizer_data_us','adminpack','amcheck','autoinc','bloom','btree_gin','btree_gist','chkpass','citext','cube','dblink','dict_int','dict_xsyn','earthdistance','file_fdw','fuzzystrmatch','hstore','hstore_plperl','insert_username','intagg','intarray','isn','lo','ltree','moddatetime','pageinspect','pgaudit','pg_buffercache','pgcrypto','pg_freespacemap','pg_prewarm','pgrowlocks','pg_stat_statements','pgstattuple','pg_trgm','pg_visibility','postgis','postgis_tiger_geocoder','postgis_topology','postgres_fdw','redis_fdw','refint','seg','set_user','sslinfo','tablefunc','tcn','timetravel','tsm_system_rows','tsm_system_time','unaccent','uuid-ossp','xml2','plpgsql','plperl','plr'); output should eq "" passed
PostgreSQL query: SELECT extname from pg_extension WHERE extname NOT IN ('address_standardizer','address_standardizer_data_us','adminpack','amcheck','autoinc','bloom','btree_gin','btree_gist','chkpass','citext','cube','dblink','dict_int','dict_xsyn','earthdistance','file_fdw','fuzzystrmatch','hstore','hstore_plperl','insert_username','intagg','intarray','isn','lo','ltree','moddatetime','pageinspect','pgaudit','pg_buffercache','pgcrypto','pg_freespacemap','pg_prewarm','pgrowlocks','pg_stat_statements','pgstattuple','pg_trgm','pg_visibility','postgis','postgis_tiger_geocoder','postgis_topology','postgres_fdw','redis_fdw','refint','seg','set_user','sslinfo','tablefunc','tcn','timetravel','tsm_system_rows','tsm_system_time','unaccent','uuid-ossp','xml2','plpgsql','plperl','plr'); output should eq "" passed
PostgreSQL query: SELECT extname from pg_extension WHERE extname NOT IN ('address_standardizer','address_standardizer_data_us','adminpack','amcheck','autoinc','bloom','btree_gin','btree_gist','chkpass','citext','cube','dblink','dict_int','dict_xsyn','earthdistance','file_fdw','fuzzystrmatch','hstore','hstore_plperl','insert_username','intagg','intarray','isn','lo','ltree','moddatetime','pageinspect','pgaudit','pg_buffercache','pgcrypto','pg_freespacemap','pg_prewarm','pgrowlocks','pg_stat_statements','pgstattuple','pg_trgm','pg_visibility','postgis','postgis_tiger_geocoder','postgis_topology','postgres_fdw','redis_fdw','refint','seg','set_user','sslinfo','tablefunc','tcn','timetravel','tsm_system_rows','tsm_system_time','unaccent','uuid-ossp','xml2','plpgsql','plperl','plr'); output should eq "" passed
PostgreSQL query: SELECT extname from pg_extension WHERE extname NOT IN ('address_standardizer','address_standardizer_data_us','adminpack','amcheck','autoinc','bloom','btree_gin','btree_gist','chkpass','citext','cube','dblink','dict_int','dict_xsyn','earthdistance','file_fdw','fuzzystrmatch','hstore','hstore_plperl','insert_username','intagg','intarray','isn','lo','ltree','moddatetime','pageinspect','pgaudit','pg_buffercache','pgcrypto','pg_freespacemap','pg_prewarm','pgrowlocks','pg_stat_statements','pgstattuple','pg_trgm','pg_visibility','postgis','postgis_tiger_geocoder','postgis_topology','postgres_fdw','redis_fdw','refint','seg','set_user','sslinfo','tablefunc','tcn','timetravel','tsm_system_rows','tsm_system_time','unaccent','uuid-ossp','xml2','plpgsql','plperl','plr'); output should eq "" passed

Code

control "V-73007" do
  title "Unused database components, PostgreSQL software, and database objects must be removed."
  desc  "Information systems are capable of providing a wide variety of functions
  and services. Some of the functions and services, provided by default, may not be
  necessary to support essential organizational operations (e.g., key missions,
  functions).

  It is detrimental for software products to provide, or install by default,
  functionality exceeding requirements or mission objectives.

  PostgreSQLs must adhere to the principles of least functionality by providing only
  essential capabilities."

  impact 0.5
  tag "severity": "medium"
  tag "gtitle": "SRG-APP-000141-DB-000091"
  tag "gid": "V-73007"
  tag "rid": "SV-87659r1_rule"
  tag "stig_id": "PGS9-00-008900"
  tag "cci": "CCI-000381"
  tag "nist": ["CM-7 a", "Rev_4"]
  tag "check": "To get a list of all extensions installed, use the following commands:
  $ sudo su - postgres
  $ psql -c \"select * from pg_extension where extname != 'plpgsql';\"\"

  If any extensions exist that are not approved, this is a finding."

  tag "fix": "To remove extensions, use the following commands:
  $ sudo su - postgres
  $ psql -c \"DROP EXTENSION <extension_name>\"

  Note: it is recommended that plpgsql not be removed."

  extensions = PG_APPROVED_EXTENSIONS + PG_TRUSTED_LANGUAGES
  extensions_sql = "SELECT extname from pg_extension "\
    "WHERE extname NOT IN (#{extensions.map { |e| "'#{e}'" }.join(',')});"
  sql = postgres_session(PG_DBA, PG_DBA_PASSWORD, PG_HOST)

  databases_sql = 'SELECT datname FROM pg_catalog.pg_database;'
  databases_query = sql.query(databases_sql, [PG_DB])
  databases = databases_query.lines

  databases.each do |database|
    connection_error = "FATAL:\\s+database \"#{database}\" is not currently "\
      "accepting connections"
    connection_error_regex = Regexp.new(connection_error)

    describe.one do
      describe sql.query(extensions_sql, [database]) do
        its('output') { should eq '' }
      end

      describe sql.query(extensions_sql, [database]) do
        its('output') { should eq 'plpgsql' }
      end

      describe sql.query(extensions_sql, [database]) do
        it { should match connection_error_regex }
      end
    end
  end
end