Fix PEM line ending normalization for JWT OAuth2 private key, TLS certs and keys#1673
Fix PEM line ending normalization for JWT OAuth2 private key, TLS certs and keys#1673Copilot wants to merge 7 commits into
Conversation
Agent-Logs-Url: https://github.com/grafana/grafana-infinity-datasource/sessions/a0087b4d-3709-4f6a-8135-5069955cb845 Co-authored-by: yesoreyeram <153843+yesoreyeram@users.noreply.github.com>
Agent-Logs-Url: https://github.com/grafana/grafana-infinity-datasource/sessions/a0087b4d-3709-4f6a-8135-5069955cb845 Co-authored-by: yesoreyeram <153843+yesoreyeram@users.noreply.github.com>
Agent-Logs-Url: https://github.com/grafana/grafana-infinity-datasource/sessions/a0087b4d-3709-4f6a-8135-5069955cb845 Co-authored-by: yesoreyeram <153843+yesoreyeram@users.noreply.github.com>
|
TruffleHog Scan Results Summary: Found 1 potential secrets (0 verified, 1 unverified)
Review: Check if unverified secrets are false positives. Ignoring False Positives: This works for files that support line numbers (most source files). After adding the comment, push your changes and the scan will re-run. |
|
@copilot - Address the review comment. Also add required changeset files. |
Agent-Logs-Url: https://github.com/grafana/grafana-infinity-datasource/sessions/bdadc3f7-bade-4e52-a7f0-ce39cd4f67c5 Co-authored-by: yesoreyeram <153843+yesoreyeram@users.noreply.github.com>
Added the changeset file in commit |
|
@copilot - Identify and apply the fix in other places if applicable. (example: TLS certs and keys) |
…MContent Agent-Logs-Url: https://github.com/grafana/grafana-infinity-datasource/sessions/ab2122bf-f948-4123-ba1c-d8886c85f64b Co-authored-by: yesoreyeram <153843+yesoreyeram@users.noreply.github.com>
Done in commit |
|
@copilot - sanitise these while parsing the settings/config rather at runtime / consumers. |
Agent-Logs-Url: https://github.com/grafana/grafana-infinity-datasource/sessions/785a83cd-d90d-4385-9fe2-2ced837a2d8f Co-authored-by: yesoreyeram <153843+yesoreyeram@users.noreply.github.com>
Done in commit |
JWT OAuth2 authentication fails when the private key contains escaped CRLF sequences (
\r\nliteral chars), common in Google Service Account JSON files and Windows-generated keys. The previous code only replaced escaped\nwith actual newlines, leaving literal\rcharacters that corrupt the PEM header, causingpem.Decode()to returnniland subsequent parsing to fail.The same issue applies to TLS client certificates, TLS client keys, and TLS CA certificates, which are also PEM-encoded and may be stored with the same line-ending variants.
Changes
pkg/models/pem.go: AddednormalizePEMContent()to themodelspackage. It handles all common line-ending formats in priority order:\r\nliteral) → LF\nliteral) → LF\rliteral) → strippkg/models/settings.go: AppliednormalizePEMContent()inLoadSettingsat the point each PEM field is read fromDecryptedSecureJSONData—oauth2JWTPrivateKey,tlsCACert,tlsClientCert, andtlsClientKey. Normalization now happens once at config-parse time rather than in each runtime consumer.pkg/models/pem_test.go: Unit tests covering all line-ending variants, plus PEM-parseability tests that verify the normalized output is accepted bypem.Decode()andx509.ParsePKCS1PrivateKey()for each input format.