Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New postgres_hba_conf resource #1964

Merged
merged 22 commits into from
Jul 3, 2017
Merged

Conversation

aaronlippold
Copy link
Collaborator

This is a resource for parsing and processing the pg_ident.conf file for a postgres database.

rx294 and others added 13 commits June 23, 2017 01:59
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Aaron Lippold <lippold@gmail.com>
Signed-off-by: Aaron Lippold <lippold@gmail.com>
added test and doc files

Signed-off-by: Rony Xavier <rx294@nyu.edu>
updated test files and docs

Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Rony Xavier <rx294@nyu.edu>
@aaronlippold aaronlippold changed the title Al/pg hba conf Postgres pg_hba_conf resource. Jun 25, 2017
@aaronlippold aaronlippold force-pushed the al/pg_hba_conf branch 5 times, most recently from 23b4288 to 8179e8c Compare June 25, 2017 20:26
@aaronlippold
Copy link
Collaborator Author

aaronlippold commented Jun 25, 2017

@arlimus @chris-rock Appveyor seems to be running tests on windows targets even though I have a return skip_resource 'yada yada - no ones uses windows anyway' if inspec.os.windows? in place.

@aaronlippold aaronlippold force-pushed the al/pg_hba_conf branch 5 times, most recently from bc6753f to bdbb378 Compare June 26, 2017 03:00
@aaronlippold
Copy link
Collaborator Author

See #1965 for an example of the issue we were having

Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronlippold thanks for this PR as well.

A lot of my feedback in #1963 applies to this resource so I'd like to ask you to apply the same feedback to this PR before I do a full review. Thank you!


# @todo add checks to ensure that we have data in our file
def initialize(hba_conf_path = nil)
if inspec.os.linux?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better written as:

return skip_resource "blah blah" unless inspec.os.linux?
# rest of method here

This will avoid unnecessary indenting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Adam. I have made all the corrections to both the postgres PRs.
Please review them when you get a chance.
Thank you again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rx294 I haven't seen an update to this PR but you mentioned you made corrections to both. Just wanted you to be aware in case you forgot to push up your changes. Thanks! I also left another change request on #1963 to help clean that up to get it ready. You'll likely have to make a similar change to this one in order to mock/stub the calls to the postgres resource.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @adamleff , I am sorry about that, this push contains all the corrections and the test code fix.
Please take a look when you get chance.
Thank you

# @todo add checks to ensure that we have data in our file
def initialize(hba_conf_path = nil)
if inspec.os.linux?
@conf_dir = inspec.postgres.conf_dir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this as an instance variable, and why expose it to the user via attr_reader?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't have to. Just habit really

www/Gemfile.lock Outdated
@@ -1,7 +1,7 @@
PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your change should not include any www-related changes, please. Please revert this file in your next commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we do that?

@@ -122,6 +122,7 @@ def self.validate_resource_dsl_version!(version)
require 'resources/packages'
require 'resources/parse_config'
require 'resources/passwd'
require 'resources/pg_hba_conf'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like I mentioned in #1963, I'd like to suggest this resource be named postgres_hba_conf to keep all PostgreSQL-related resourced prefixed the same. While I know the file is named pg_hba.conf in practice, it's more important for the InSpec UX to be consistent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I agree that works.

@rx294 rx294 force-pushed the al/pg_hba_conf branch 2 times, most recently from 8d1d78d to 0089b70 Compare June 26, 2017 21:11
@adamleff adamleff added the Type: New Feature Adds new functionality label Jun 27, 2017
@rx294 rx294 force-pushed the al/pg_hba_conf branch 3 times, most recently from 656de4d to 8a5f227 Compare June 28, 2017 11:07
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Rony Xavier <rx294@nyu.edu>
@rx294 rx294 force-pushed the al/pg_hba_conf branch 2 times, most recently from f9766d0 to 977d471 Compare June 28, 2017 12:05
Signed-off-by: Rony Xavier <rx294@nyu.edu>
'cmp' matcher instead of 'eq'

Signed-off-by: Rony Xavier <rx294@nyu.edu>
@adamleff adamleff changed the title Postgres pg_hba_conf resource. New postgres_hba_conf resource Jun 30, 2017
Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rx294 @aaronlippold this is a great addition. I added some comments. Once resolved, we're ready for merge.


An `postgres_hba_conf` InSpec audit resource block declares client authentication data that should be tested:

describe postgres_hba_conf.where { pg_username == 'filter_value' } do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use pg_username here? Shouldn't we use the more generic version here as you use in code?

describe postgres_hba_conf.where { type == 'local' } do
  its('auth_method') { should eq ['peer'] }
end

if raw_conf.empty? && !file.empty?
return skip_resource("Can't read the contents of \"#{@conf_file}\"")
end
@content = clean_conf_file(@conf_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a specific reason why we haven't used simpleconfig https://github.com/chef/inspec/blob/master/lib/utils/simpleconfig.rb here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a blocker for merge, but I would like us to re-use as much as possible.

@@ -0,0 +1,95 @@
# encoding: utf-8
# copyright: 2017
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove the copyright header here, since everything is Apache licensed

…ater.

Signed-off-by: Aaron Lippold <lippold@gmail.com>
Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome @rx294 @aaronlippold Thank you for your great work

@chris-rock chris-rock merged commit 224935e into inspec:master Jul 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature Adds new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants