Skip to content

Allow empty string value for config entries #1603

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

antaflos
Copy link
Contributor

@antaflos antaflos commented Jul 5, 2024

Summary

PostgreSQL supports and allows config entries, such as those in postgresql.conf, to be set to the empty string. The postgresql::server::config_entry defined type, however, requires String[1] when supplying string values. This doesn't allow for the empty string.

This change relaxes the allowed data types for the value parameter of postgresql::server::config_entry to String from String[1] and adds a spec test to support the change.

Related Issues (if any)

#1602

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

@antaflos
Copy link
Contributor Author

antaflos commented Jul 5, 2024

I don't think I can do anything about the failing tests (labeller and mend). The rest looks good.

@bastelfreak
Copy link
Collaborator

@antaflos can you please document in the spec test some examples of options where this makes sense? And please rebase after #1599 got merged.

@antaflos
Copy link
Contributor Author

@bastelfreak Will do. Our use case for empty strings here is that we have applications that use transaction-bound session variables, as in SET LOCAL awsome_app.auth_user_id = 123456 and SET LOCAL awesome_app.tenant_id = 893745. This pertains to auditability and row-level security.

PostgreSQL 13 (and possibly newer versions also) requires such session variables to be defined beforehand and initialised with a default value, such as the empty string, in postgresql.conf.

@antaflos antaflos force-pushed the config_allow_empty_values branch from 263eaab to 6cb0f1f Compare August 14, 2024 09:57
bastelfreak
bastelfreak previously approved these changes Aug 14, 2024
deric
deric previously approved these changes Aug 14, 2024
@antaflos
Copy link
Contributor Author

So this has been open for a long while now. Any chance to get it merged?

@antaflos antaflos force-pushed the config_allow_empty_values branch from 6cb0f1f to 34fc7a7 Compare January 20, 2025 17:13
@antaflos
Copy link
Contributor Author

This is still open, even though approvals were given. What do I need to do to get this merged?

Some acceptance tests are failing, but apparently not because of my changes.

@antaflos antaflos dismissed stale reviews from deric and bastelfreak via b1dd0c5 April 22, 2025 00:01
@antaflos antaflos force-pushed the config_allow_empty_values branch from 34fc7a7 to b1dd0c5 Compare April 22, 2025 00:01
Copy link
Collaborator

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

I wondered about purging empty entries, but that's done with Undef:

$config_entries.each |$entry, $value| {
postgresql::server::config_entry { $entry:
ensure => bool2str($value =~ Undef, 'absent', 'present'),
value => $value,
}
}

@@ -10,7 +10,7 @@
define postgresql::server::config_entry (
Enum['present', 'absent'] $ensure = 'present',
String[1] $key = $name,
Optional[Variant[String[1], Numeric, Array[String[1]]]] $value = undef,
Optional[Variant[String, Numeric, Array[String[1]]]] $value = undef,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the array also allow empty strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not aware of a use-case where an array would contain empty string values.

But I am not even sure if array values make sense for Postgres config entries, because it seems to use just (quoted) strings, integers, floats and booleans (https://www.postgresql.org/docs/current/config-setting.html#CONFIG-SETTING-NAMES-VALUES). And from quickly looking at the postgresql_conf provider I don't immediately see where/how it even handles array values? But in any case, I don't think we need to touch this part of the functionality here. Just support for single, empty string values would be nice :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

That may actually be a regression introduced in 179472b. It was added in 36674b3 but contain any description. #1434 does point to listen_addresses and now I wonder if that functionality actually works now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it seems the accepted data types of $value were changed to include Array[String[1]], and the "parsed" provider was replaced by a "ruby" provider, but there doesn't seem to have been any code added to actually handle such array values. The parsed provider had something like h[:value].join(', ') when h[:value] was an array, but I see no equivalent in the ruby provider.

But I suppose this discussion is best moved elsewhere, probably to its own bug report?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, it seems the accepted data types of $value were changed to include Array[String[1]], and the "parsed" provider was replaced by a "ruby" provider, but there doesn't seem to have been any code added to actually handle such array values. The parsed provider had something like h[:value].join(', ') when h[:value] was an array, but I see no equivalent in the ruby provider.

If the implementation is h[:value].join(', ') then an empty array should result in an empty string and allowing empty strings within the array doesn't make sense. It'd result in , which is probably never valid. In other words, consider my comments addressed.

But I suppose this discussion is best moved elsewhere, probably to its own bug report?

Yes, agreed.

PostgreSQL supports and allows config entries, such as those in
postgresql.conf, to be set to the empty string. The
`postgresql::server::config_entry` defined type, however, requires
String[1] when supplying string values. This doesn't allow for the empty
string.

This change relaxes the allowed data types for the `value` parameter of
`postgresql::server::config_entry` to `String` from `String[1]` and adds
a spec test to support the change.

Fixes puppetlabs#1602
@antaflos antaflos force-pushed the config_allow_empty_values branch from b1dd0c5 to e859b1f Compare April 22, 2025 11:33
@antaflos
Copy link
Contributor Author

@ekohl Thank you for taking the time to look at and review this!

@ekohl
Copy link
Collaborator

ekohl commented Apr 22, 2025

CI is busted because Perforce is still using ubuntu-20.04. I think we should wait until they fix that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants