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

pg_hba_rule does not properly verify address parameter #1372

Merged
merged 12 commits into from
Oct 11, 2022

Conversation

tuxmea
Copy link
Contributor

@tuxmea tuxmea commented Oct 7, 2022

According to PostgreSQL documentation there are only specific data possible for address:
https://www.postgresql.org/docs/current/auth-pg-hba-conf.html

  • IPV4 CIDR
  • IPV6 CIDR
  • FQDN
  • the strings 'samenet' or 'samehost'
  • a domain
  • a domain with a starting dot

fixes #1373

According to PostgreSQL documentation there are only specific data
possible for address:
https://www.postgresql.org/docs/current/auth-pg-hba-conf.html

- IPV4 CIDR
- IPV6 CIDR
- FQDN
- the strings 'samenet' or 'samehost'
- a domain
- a domain with a starting dot
@tuxmea tuxmea requested a review from a team as a code owner October 7, 2022 09:59
@puppet-community-rangefinder
Copy link

postgresql::server::pg_hba_rule is a type

Breaking changes to this file WILL impact these 14 modules (exact match):
Breaking changes to this file MAY impact these 4 modules (near match):

This module is declared in 70 of 579 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

Copy link
Collaborator

@smortex smortex left a comment

Choose a reason for hiding this comment

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

According to the link in the docstring:

You can also write all to match any IP address, samehost to match any of the server's own IP addresses, or samenet to match any address in any subnet that the server is directly connected to.

manifests/server/pg_hba_rule.pp Outdated Show resolved Hide resolved
manifests/server/pg_hba_rule.pp Outdated Show resolved Hide resolved
tuxmea and others added 3 commits October 10, 2022 09:31
Co-authored-by: Romain Tartière <romain@blogreen.org>
Co-authored-by: Romain Tartière <romain@blogreen.org>
@GSPatton
Copy link
Contributor

hey @tuxmea. The spec tests with puppet 6 and 7 have both failed. Address these failures and we can have a look! Cheers

@tuxmea
Copy link
Contributor Author

tuxmea commented Oct 11, 2022

@GSPatton I have issues identifying the error:
Both tests show the following:

Failures:

  1) postgresql::server::default_privileges valid object_type schemas on postgres < 10.0 
     Got 0 failures and 2 other errors:

     1.1) Failure/Error: result_facts.merge!(munge_facts(facts)) if self.respond_to?(:facts)

          TypeError:
            no implicit conversion of nil into Hash
          # ./vendor/bundle/ruby/2.7.0/bin/rspec:23:in `load'
          # ./vendor/bundle/ruby/2.7.0/bin/rspec:23:in `<top (required)>'
          # /opt/hostedtoolcache/Ruby/2.7.6/x64/bin/bundle:23:in `load'
          # /opt/hostedtoolcache/Ruby/2.7.6/x64/bin/bundle:23:in `<main>'

     1.2) Failure/Error: @logs.clear

          NoMethodError:
            undefined method `clear' for nil:NilClass
          # ./vendor/bundle/ruby/2.7.0/bin/rspec:23:in `load'
          # ./vendor/bundle/ruby/2.7.0/bin/rspec:23:in `<top (required)>'
          # /opt/hostedtoolcache/Ruby/2.7.6/x64/bin/bundle:23:in `load'
          # /opt/hostedtoolcache/Ruby/2.7.6/x64/bin/bundle:23:in `<main>'

Finished in 7 minutes 24 seconds (files took 1.62 seconds to load)
228 examples, 1 failure

Failed examples:

rspec ./spec/defines/server/default_privileges_spec.rb:132 # postgresql::server::default_privileges valid object_type schemas on postgres < 10.0 

Copy link
Collaborator

@smortex smortex left a comment

Choose a reason for hiding this comment

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

The last PR merged in the main branch had similar CI failures, so these failures seems unrelated to this change.

The change itself looks good to me 👍

smortex
smortex previously approved these changes Oct 11, 2022
@tuxmea
Copy link
Contributor Author

tuxmea commented Oct 11, 2022

@david22swan Can you please explain why this is backwards-incompatible?
When specifying an invalid entry, the postgresql service will not start.

@david22swan
Copy link
Member

Anything that alters what a parameter accepts in such a way as to limit it is technically backwards incompatible.
Since you are limiting it to the correct input only and anything that doesn't match it would have caused errors anyway it is debatable you can probably get it change to bugfix.
Just of the opinion that it needs discussed over first.

@ekohl
Copy link
Collaborator

ekohl commented Oct 11, 2022

Anything that alters what a parameter accepts in such a way as to limit it is technically backwards incompatible.

I think I agree with @tuxmea here. Where previously it would be invalid and fail at runtime (starting the service would fail), now it will fail at catalog compilation. I think it could be an enhancement instead of backwards incompatible change.

@bastelfreak
Copy link
Collaborator

I agree with @ekohl and @tuxmea here. I think this is a good enhancement but not a breaking change.

@david22swan
Copy link
Member

Not that I'm caving to peer pressure, but yeh. Your explanation sounds good so gonna go with feature.
Like the type change to, just need the rubocop errors fixed and I'd be happy to merge.

@tuxmea
Copy link
Contributor Author

tuxmea commented Oct 11, 2022

@david22swan lint fixes have been added.

Copy link
Member

@david22swan david22swan left a comment

Choose a reason for hiding this comment

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

LGTM

Gonna do a squash merge since there's a dozen commits, but otherwise this is all good. Thanks for getting back on it so fast.

@david22swan david22swan merged commit 766508d into puppetlabs:main Oct 11, 2022
@tuxmea tuxmea deleted the validate_pg_hab_rule_address branch October 12, 2022 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pg_hab_rule allows any kind of data for address parameter
7 participants