Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 11, 2025

  • Add automatic SCRAM-SHA-256 password escaping and comprehensive documentation
  • Address code scanning alerts for incomplete string escaping
  • Use nil_or_empty? function for password validation check as suggested in code review
  • Fix backslash escaping in SCRAM-SHA-256 password handling
  • Fix markdownlint issues in SCRAM-SHA-256 documentation

Changes

This PR addresses the SCRAM-SHA-256 password handling issue where $ characters in password hashes were being mangled during SQL execution, causing authentication failures.

Key improvements:

  • Automatic Detection: The cookbook detects passwords starting with SCRAM-SHA-256
  • Transparent Escaping: $ characters are automatically escaped as \$ to prevent shell interpretation
  • Proper Backslash Escaping: Fixed excessive backslash escaping from \\\\\\\\ to proper \\\\ for SQL safety
  • Backward Compatible: Only affects SCRAM-SHA-256 passwords; all other formats remain unchanged
  • Code Quality: Used existing nil_or_empty? utility function for cleaner password validation
  • Documentation Quality: Fixed all markdownlint issues for proper documentation formatting

Solution

Users can now simply write:

postgresql_role 'user1' do
  encrypted_password 'SCRAM-SHA-256$4096:salt$key:server'
  action [:create, :update]
end

The cookbook automatically escapes the password for safe SQL execution.

Testing

Verified that:

  • SCRAM-SHA-256 passwords are properly escaped (both $ and \ characters)
  • All existing password formats (MD5, plain text, etc.) remain unchanged
  • Integration test successfully creates users with SCRAM-SHA-256 passwords
  • Backslash escaping uses proper SQL escaping (not excessive escaping)
  • Documentation passes all markdownlint checks

Fixes #703.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] SCRAM-SHA-256 documentation Add automatic SCRAM-SHA-256 password escaping and comprehensive documentation Sep 11, 2025
Copilot AI requested a review from damacus September 11, 2025 23:18
Copilot finished work on behalf of damacus September 11, 2025 23:18
@damacus damacus marked this pull request as ready for review September 14, 2025 16:16
@damacus damacus requested a review from a team as a code owner September 14, 2025 16:16
Copilot AI requested a review from bmhughes September 14, 2025 17:26
Copilot finished work on behalf of bmhughes September 14, 2025 17:26
bmhughes
bmhughes previously approved these changes Sep 14, 2025
@bmhughes bmhughes added Bug Something isn't working Release: Patch Release to Chef Supermarket as a version patch when merged labels Sep 14, 2025
Copilot AI requested a review from bmhughes September 14, 2025 17:40
Copilot finished work on behalf of bmhughes September 14, 2025 17:40
Copilot finished work on behalf of bmhughes September 14, 2025 17:44
@damacus
Copy link
Member

damacus commented Sep 15, 2025

This is ready to release. But I'm going to move it over to the new release workflow before releasing.

@damacus damacus changed the title Add automatic SCRAM-SHA-256 password escaping and comprehensive documentation fix(role): Add automatic SCRAM-SHA-256 password escaping and docs Oct 15, 2025
@github-actions
Copy link

Slowest examples

Top 10 slowest examples (0.02 seconds, 53.28% of total time)
Example Description Time in seconds
spec/libraries/helpers_spec.rb:19 PostgreSQL::Cookbook::Helpers#data_dir(version) with rhel family and Postgres 11 from repo returns the correct path 0.01336
spec/libraries/role_spec.rb:70 PostgreSQL::Cookbook::SqlHelpers::Role #escape_password_for_sql with edge cases handles nil passwords 0.00286
spec/libraries/helpers_spec.rb:27 PostgreSQL::Cookbook::Helpers#data_dir(version) with rhel family and Postgres 11 from os returns the correct path 0.00097
spec/libraries/helpers_spec.rb:35 PostgreSQL::Cookbook::Helpers#data_dir(version) with debian family and Postgres 11 from repo returns the correct path 0.00066
spec/libraries/helpers_spec.rb:43 PostgreSQL::Cookbook::Helpers#data_dir(version) with debian family and Postgres 11 from os returns the correct path 0.00055
spec/libraries/helpers_spec.rb:73 PostgreSQL::Cookbook::Helpers#conf_dir(version) with debian family and Postgres 11 from repo returns the correct path 0.00047
spec/libraries/helpers_spec.rb:57 PostgreSQL::Cookbook::Helpers#conf_dir(version) with rhel family and Postgres 11 from repo returns the correct path 0.00047
spec/libraries/helpers_spec.rb:65 PostgreSQL::Cookbook::Helpers#conf_dir(version) with rhel family and Postgres 11 from os returns the correct path 0.00041
spec/libraries/helpers_spec.rb:119 PostgreSQL::Cookbook::Helpers#default_platform_service_name(version) with debian family and Postgres 11 from os returns the correct service name 0.0004
spec/libraries/helpers_spec.rb:95 PostgreSQL::Cookbook::Helpers#default_platform_service_name(version) with rhel family and Postgres 15 from repo returns the correct service name 0.00039

Copilot AI and others added 6 commits October 21, 2025 21:12
…ng or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ng or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Changed from excessive \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ (8 backslashes) to proper \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ (4 backslashes) for SQL escaping.
Each backslash in the original password is now correctly escaped as \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ (2 backslashes) in the result.

Co-authored-by: bmhughes <[email protected]>
@github-actions
Copy link

Slowest examples

Top 10 slowest examples (0.01 seconds, 49.31% of total time)
Example Description Time in seconds
spec/libraries/helpers_spec.rb:19 PostgreSQL::Cookbook::Helpers#data_dir(version) with rhel family and Postgres 11 from repo returns the correct path 0.0124
spec/libraries/role_spec.rb:70 PostgreSQL::Cookbook::SqlHelpers::Role #escape_password_for_sql with edge cases handles nil passwords 0.00302
spec/libraries/helpers_spec.rb:27 PostgreSQL::Cookbook::Helpers#data_dir(version) with rhel family and Postgres 15 from os returns the correct path 0.00046
spec/libraries/helpers_spec.rb:111 PostgreSQL::Cookbook::Helpers#default_platform_service_name(version) with debian family and Postgres 11 from repo returns the correct service name 0.00039
spec/libraries/helpers_spec.rb:119 PostgreSQL::Cookbook::Helpers#default_platform_service_name(version) with debian family and Postgres 12 from os returns the correct service name 0.00038
spec/libraries/helpers_spec.rb:19 PostgreSQL::Cookbook::Helpers#data_dir(version) with rhel family and Postgres 15 from repo returns the correct path 0.00038
spec/libraries/helpers_spec.rb:57 PostgreSQL::Cookbook::Helpers#conf_dir(version) with rhel family and Postgres 13 from repo returns the correct path 0.00038
spec/libraries/helpers_spec.rb:27 PostgreSQL::Cookbook::Helpers#data_dir(version) with rhel family and Postgres 11 from os returns the correct path 0.00037
spec/libraries/helpers_spec.rb:103 PostgreSQL::Cookbook::Helpers#default_platform_service_name(version) with rhel family and Postgres 14 from os returns the correct service name 0.00037
spec/libraries/helpers_spec.rb:35 PostgreSQL::Cookbook::Helpers#data_dir(version) with debian family and Postgres 13 from repo returns the correct path 0.00037

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

Labels

Bug Something isn't working Release: Patch Release to Chef Supermarket as a version patch when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCRAM-SHA-256 documentation

4 participants