Skip to content

pgwire: add password policy observability metrics#170106

Merged
trunk-io[bot] merged 2 commits into
cockroachdb:masterfrom
souravcrl:add-password-policy-metrics
May 16, 2026
Merged

pgwire: add password policy observability metrics#170106
trunk-io[bot] merged 2 commits into
cockroachdb:masterfrom
souravcrl:add-password-policy-metrics

Conversation

@souravcrl
Copy link
Copy Markdown
Contributor

@souravcrl souravcrl commented May 11, 2026

Summary

  • Adds two new functional gauges for password policy observability:
    • auth.password_encryption.is_scram — reports whether server.user_login.password_encryption is set to scram-sha-256 (1) or crdb-bcrypt (0)
    • auth.min_password_length — reports the current value of server.user_login.min_password_length
  • These gauges read their respective cluster settings on each metric scrape, providing real-time visibility into password policy configuration without instrumenting auth callsites.
  • Enables compliance alerting: operators can alert if SCRAM is disabled or if minimum password length drops below organizational requirements.
  • Includes unit tests that verify both gauges track cluster setting changes dynamically.

Release note (security change): Two new metrics are added for password
policy observability. auth.password_encryption.is_scram reports whether
password encryption is configured to use SCRAM-SHA-256 (1) or crdb-bcrypt
(0), enabling operators to verify password hashing policy across the
cluster. auth.min_password_length reports the configured minimum
password length, enabling alerts when the value drops below organizational
security requirements.

Informs: #167911
Epic: none

🤖 Generated with Claude Code

@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented May 11, 2026

😎 Merged successfully - details.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@souravcrl souravcrl force-pushed the add-password-policy-metrics branch from 8b589e4 to ef00d2b Compare May 11, 2026 10:39
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 11, 2026

Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link)

@souravcrl souravcrl force-pushed the add-password-policy-metrics branch 2 times, most recently from b19ad7e to 32e480d Compare May 13, 2026 05:22
@souravcrl souravcrl requested a review from sanchit-CRL May 13, 2026 05:32
@souravcrl souravcrl changed the title pgwire: add functional gauge for password encryption method pgwire: add password policy observability metrics May 13, 2026
@souravcrl souravcrl marked this pull request as ready for review May 13, 2026 05:35
@souravcrl souravcrl requested a review from a team as a code owner May 13, 2026 05:35
Copy link
Copy Markdown
Collaborator

@sanchit-CRL sanchit-CRL left a comment

Choose a reason for hiding this comment

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

the metrics share file, struct, plumbing, and test pattern. Commit 1 changes the newTenantSpecificMetrics signature (4 call sites) but the metrics.yaml regen lives entirely in commit 2 (covers both metrics due to alphabetical ordering). This makes commit 1 not independently consistent

Comment thread pkg/sql/pgwire/server.go
@@ -479,6 +508,17 @@ func newTenantSpecificMetrics(
getHistogramOptionsForIOLatency(AuthLDAPConnLatencyInternal, histogramWindow)),
AuthCertSANConnTotal: metric.NewCounter(AuthCertSANConnTotal),
AuthCertSANConnSuccess: metric.NewCounter(AuthCertSANConnSuccess),
PasswordEncryptionIsSCRAM: metric.NewFunctionalGauge(
MetaPasswordEncryptionIsSCRAM, func() int64 {
if security.GetConfiguredPasswordHashMethod(sv) == password.HashSCRAMSHA256 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tighten the closure to explicitly check HashBCrypt, or add a regression test that pins behavior across all defined HashMethod values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We only want to check for SCRAM passwords as bcrypt is the older format and SCRAM is the newer mandated newer one. These are the only 2 supported hashes in pkg/security/password.go#L102-L105. If a newer hash type comes up, we want to track that as a metric separate from SCRAM, so as far this closure is concerned functionally, adding this won't make sense as this is meant to track SCRAM enablement.

For the test part, I am checking for brcypt in the test TestPasswordEncryptionIsSCRAMGauge. I can add a type which is not SCRAM or bcrypt but it just be an empty validation as this metric gauge won't be updated.

souravcrl and others added 2 commits May 14, 2026 18:38
Add a functional gauge `auth.password_encryption.is_scram` that reports
whether `server.user_login.password_encryption` is set to `scram-sha-256`
(1) or `crdb-bcrypt` (0). This provides observability into password
encryption policy adoption across clusters and orgs.

The gauge reads the cluster setting on each metric scrape, so it always
reflects the current configuration without requiring instrumentation at
each auth callsite.

Informs: cockroachdb#167911

Release note (security change): A new metric
`auth.password_encryption.is_scram` reports whether password encryption
is configured to use SCRAM-SHA-256 (1) or crdb-bcrypt (0). This enables
operators to verify and alert on password hashing policy across the
cluster, supporting security compliance requirements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a functional gauge `auth.min_password_length` that reports the
current value of `server.user_login.min_password_length`. This provides
immediate visibility into password length policy configuration and
enables compliance alerting if the value drops below organizational
requirements.

Informs: cockroachdb#167911

Release note (security change): A new metric `auth.min_password_length`
reports the configured minimum password length for the cluster. This
enables operators to monitor and alert on password length policy,
ensuring compliance with organizational security requirements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@souravcrl souravcrl force-pushed the add-password-policy-metrics branch from 32e480d to bac7950 Compare May 14, 2026 13:10
@souravcrl
Copy link
Copy Markdown
Contributor Author

the metrics share file, struct, plumbing, and test pattern. Commit 1 changes the newTenantSpecificMetrics signature (4 call sites) but the metrics.yaml regen lives entirely in commit 2 (covers both metrics due to alphabetical ordering). This makes commit 1 not independently consistent

Both the commits get rolled before the merge into the master branch. So there is never a case for metrics.yaml to not exist for the commit 1. But to ensure both commits pass CI I have generated the first commit.

@souravcrl souravcrl requested a review from sanchit-CRL May 14, 2026 13:13
Copy link
Copy Markdown
Collaborator

@sanchit-CRL sanchit-CRL left a comment

Choose a reason for hiding this comment

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

LGTM

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 15, 2026

Metrics change detected

This PR adds or updates one or more CRDB metrics. If you want these metrics to be exported by CRDB Cloud clusters to Internal CRL Datadog and/or included in the customer metric export integration (Essential metrics for standard deployment, and Essential metrics for advanced deployment), refer to this Installation and Usage guide of a CLI tool that syncs the metric mappings in managed-service. Run this CLI tool after your CRDB PR is merged.

  • The CLI opens a PR in managed-service with the required config changes.
  • Please track that PR and ensure it merges so your metrics become available to CRDB Cloud clusters.

Note: Your metric will appear in Internal CRL Datadog only after the managed-service PR merges and the new OTel configuration rolls out to at least one cluster running a CRDB build that includes this metric.

Docs: cockroach-metric-sync

Questions: reach out to @obs-india-prs

@souravcrl
Copy link
Copy Markdown
Contributor Author

TFTR!

/trunk merge

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 15, 2026

Detected infrastructure failure on trunk-merge branch (matched: self-hosted runner lost communication with the server). Automatically resubmitting to merge queue (attempt 1 of 2). (run link)

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 15, 2026

/trunk merge

@souravcrl
Copy link
Copy Markdown
Contributor Author

roachtest is failing in the trunk merge pipeline. retrying as it seems like a flake.

/trunk merge

@trunk-io trunk-io Bot merged commit b73593d into cockroachdb:master May 16, 2026
26 checks passed
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.

3 participants