Skip to content

Compare actual sensitive values when testing #1405

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

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

smortex
Copy link
Collaborator

@smortex smortex commented Feb 24, 2023

When testing, sensitive values can be compared to the String Sensitive [value redacted], but if we want to check that the redacted content is the one we expect, we should compare with another Sensitive wrapper.

This allows us to spot errors in the test suite (see #1404) more easily.

No functional change in this PR.

'sensitive' => 'true',
'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
'port' => '5432')
end
it 'has alter role for "test" user with password as ****' do
is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
.with('command' => 'Sensitive [value redacted]',
.with('command' => sensitive(%(ALTER ROLE "test" ENCRYPTED PASSWORD 'Sensitive [value redacted]')),
# FIXME: This is obviously wrong ^^^^^^^^^^^^^^^^^^^^^^^^^^
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any idea what's needed to fix this? Or is it actually a bug?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a bug?? What harm would there be if sensitive values were unwrapped on these lines?

$pw_command = "ALTER ROLE \"${username}\" ENCRYPTED PASSWORD '${pwd_hash_sql}'"
$unless_pw_command = "SELECT 1 FROM pg_shadow WHERE usename = '${username}' AND passwd = '${pwd_hash_sql}'"

(given the use of Sensitive on these?
command => Sensitive($pw_command),
unless => Sensitive($unless_pw_command),
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, the sensitive values definitely need unwrapping before interpolating into another string.

$secret = Sensitive('SECRET')

exec { 'test':
  command => Sensitive("/bin/echo My secret is ${secret} > /tmp/test_secret"),
}
cat /tmp/test_secret
My secret is Sensitive [value redacted]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Given the minimum supported version in the metadata is 6.24.0 it should be fine to just throw some unwraps in there without even checking if the value is Sensitive first.

See puppetlabs/puppet@41991b2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it is a bug. I opened this PR in order to make it easier to diagnose the issues and fix it. For that reason I do not change the tested value in this PR so that it can hopefully be merged quickly because it does not change the current (bad) behavior. Yet, adding a comment for the obvious does not hurt.

The bug itself is tracked in #1404.

@smortex

This comment was marked as resolved.

@smortex smortex force-pushed the unwrap-sensitive-values-for-testing branch 2 times, most recently from 6045a37 to ccae023 Compare April 25, 2023 08:14
@smortex smortex changed the title Unwrap sensitive values for testing Compare actual sensitive values when testing Apr 25, 2023
@smortex smortex force-pushed the unwrap-sensitive-values-for-testing branch from ccae023 to 0be3db2 Compare April 28, 2023 05:56
@smortex smortex force-pushed the unwrap-sensitive-values-for-testing branch from 0be3db2 to 38da528 Compare June 29, 2023 22:55
@smortex smortex force-pushed the unwrap-sensitive-values-for-testing branch from 38da528 to 26349e0 Compare June 30, 2023 16:44
@SimonHoenscheid
Copy link
Collaborator

@smortex is this ready to go after a rebase?

When testing, sensitive values can be compared to the String `Sensitive
[value redacted]`, but if we want to check that the redacted content is
the one we expect, we should compare with another Sensitive wrapper.
@smortex smortex force-pushed the unwrap-sensitive-values-for-testing branch from 26349e0 to df215b2 Compare July 10, 2023 16:57
@smortex
Copy link
Collaborator Author

smortex commented Jul 10, 2023

@SimonHoenscheid this is ready to go! I rebased the PR, I will merge it when CI has passed.

@smortex smortex merged commit 2bab88a into main Jul 10, 2023
@smortex smortex deleted the unwrap-sensitive-values-for-testing branch July 10, 2023 17:33
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.

8 participants