Skip to content

Fix passing deferred password - #1651

Open
deric wants to merge 5 commits into
puppetlabs:mainfrom
deric:pw_role
Open

Fix passing deferred password#1651
deric wants to merge 5 commits into
puppetlabs:mainfrom
deric:pw_role

Conversation

@deric

@deric deric commented Nov 25, 2025

Copy link
Copy Markdown
Collaborator

Summary

I'm getting a strange error when passing Deferred object to password_hash or password:

parameter 'password_hash' expects a value of type Boolean, String, or Sensitive[String], got Sensitive

Changes done in #1611 weren't enough.

Additional Context

Tested on Puppet 8.10.0, I'm unable to compile catalog with Deferred secret returned from a function.

I have a function that returns Deferred object

function vault::kv(String $key, Hash $opts = {}) >> Deferred {
  Deferred(
    'vault_lookup::lookup',
    ["kv/data/${key}", $_opts]
  )
}

Since it's not possible to specify type for Deferred object, like Deferred[String] or Deferred[Sensitive[String]] to only workaround remains relaxing Sensitive[String] to Sensitive

    postgresql::server::db { 'mydb':
      user     => 'dbuser',
      password => vault::kv('db/password'),
    }

Related Issues (if any)

Checklist

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

@deric
deric marked this pull request as draft November 26, 2025 09:34
@deric
deric marked this pull request as ready for review November 26, 2025 16:18
@deric

deric commented Nov 26, 2025

Copy link
Copy Markdown
Collaborator Author

Test failures seems to be unrelated. Upstream fixtures modules doesn't seem to support Puppet 7 anymore.

@jiayuchen888

Copy link
Copy Markdown

Maybe you can define your password type Sensitive[String] ?

@deric

deric commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator Author

@jiayuchen888 Password is defined as Sensitive[String], yet it doesn't work. As you can see currently there is no test for passing Sensitive[String].

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates password parameter types to support deferred secrets resolving to Sensitive.

Changes:

  • Broadens database and role password types.
  • Updates deferred-password acceptance coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
manifests/server/db.pp Accepts generic sensitive passwords.
manifests/server/role.pp Broadens role password-hash input type.
spec/acceptance/db_deferred_spec.rb Tests a deferred sensitive password.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread spec/acceptance/db_deferred_spec.rb Outdated
Comment thread manifests/server/role.pp
deric and others added 2 commits August 23, 2026 14:18
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@deric
deric requested a balanced review from Copilot August 23, 2026 20:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread lib/puppet/functions/postgresql/prepend_sql_password.rb Outdated
@deric
deric requested a balanced review from Copilot August 24, 2026 08:13
@deric

deric commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

@jst-cyr could you have a look at this, please?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (1)

lib/puppet/functions/postgresql/prepend_sql_password.rb:13

  • Doubling apostrophes is not sufficient when PostgreSQL runs with standard_conforming_strings = off: a password such as \'; SUPERUSER; -- can use the backslash to escape the first doubled quote and terminate the literal at the second. Build the literal with the existing dollar-quoting postgresql::postgresql_escape function (handling the currently supported empty string explicitly), or use an E'' literal and escape both backslashes and apostrophes; add a backslash-plus-quote regression case.
    "ENCRYPTED PASSWORD '#{password.gsub("'", "''")}'"

@jst-cyr

jst-cyr commented Aug 24, 2026

Copy link
Copy Markdown
Member

Running CI tests for this PR here: #1699

@jst-cyr

jst-cyr commented Aug 24, 2026

Copy link
Copy Markdown
Member

@deric : Engineering will need to review when it comes up in the priority queue, but I'm happy to kick off some acceptance tests so that we can get some feedback and see how it runs on the different platforms.

@jst-cyr

jst-cyr commented Aug 24, 2026

Copy link
Copy Markdown
Member

**Acceptance test results: ** https://github.com/puppetlabs/puppetlabs-postgresql/actions/runs/32730002205?pr=1699

All failures (Debian-13, CentOS-7, Scientific-7, OracleLinux-7, SLES-12) match pre-existing failures already on main. Mostly a systemd/D-Bus environment issue unrelated to this change. No new regressions introduced. All other platforms passed.

So this PR doesn't seem to be introducing new issues, but this still requires an engineering review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants