Skip to content

feat(tls): support inline PEM content for TLS configuration#1381

Merged
kongfei605 merged 1 commit into
flashcatcloud:mainfrom
kongfei605:tls_feat
Dec 24, 2025
Merged

feat(tls): support inline PEM content for TLS configuration#1381
kongfei605 merged 1 commit into
flashcatcloud:mainfrom
kongfei605:tls_feat

Conversation

@kongfei605

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings December 24, 2025 08:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the TLS configuration functionality to support inline PEM content in addition to file paths. Users can now provide certificate and key data directly as strings containing PEM-encoded content, rather than being limited to file system paths.

Key Changes

  • Added a new readPEM helper function that detects whether input is inline PEM content or a file path
  • Modified makeCertPool and loadCertificate functions to use the new readPEM helper
  • Removed deprecated BuildNameToCertificate() call

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/tls/config.go
Comment thread pkg/tls/config.go
Comment on lines +219 to +225
func readPEM(input string) ([]byte, error) {
if strings.Contains(input, "-----BEGIN") {
return []byte(input), nil
}

return os.ReadFile(input)
}

Copilot AI Dec 24, 2025

Copy link

Choose a reason for hiding this comment

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

The new readPEM function and the modified behavior of makeCertPool and loadCertificate functions lack documentation. Since these functions now accept either file paths or inline PEM content, this dual behavior should be documented with comments explaining the expected input formats and how the function distinguishes between them.

Copilot uses AI. Check for mistakes.
Comment thread pkg/tls/config.go
Comment on lines +167 to +172
preview := input
if len(preview) > 20 {
preview = preview[:20] + "..."
}
return nil, fmt.Errorf(
"could not parse any PEM certificates %q: %v", certFile, err)
"could not parse any PEM certificates from %q: %v", preview, err)

Copilot AI Dec 24, 2025

Copy link

Choose a reason for hiding this comment

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

The error message may expose sensitive PEM content (private keys or certificates) in logs when the preview is displayed. When inline PEM content fails to parse, the preview could contain parts of sensitive cryptographic material. Consider sanitizing the preview to avoid logging sensitive data, or use a generic message that doesn't include the actual content.

Copilot uses AI. Check for mistakes.
Comment thread pkg/tls/config.go
Comment thread pkg/tls/config.go
}
return nil, fmt.Errorf(
"could not parse any PEM certificates %q: %v", certFile, err)
"could not parse any PEM certificates from %q: %v", preview, err)

Copilot AI Dec 24, 2025

Copy link

Choose a reason for hiding this comment

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

The variable err is nil at this point. When AppendCertsFromPEM returns false, it doesn't set an error - it simply indicates that no certificates were successfully parsed. Including %v with a nil err in the error message will print <nil>, which is misleading and unhelpful to users.

Suggested change
"could not parse any PEM certificates from %q: %v", preview, err)
"could not parse any PEM certificates from %q", preview)

Copilot uses AI. Check for mistakes.
Comment thread pkg/tls/config.go
@kongfei605 kongfei605 merged commit 890693d into flashcatcloud:main Dec 24, 2025
9 checks passed
@kongfei605 kongfei605 deleted the tls_feat branch December 24, 2025 08:59
laiwei pushed a commit to laiwei/categraf that referenced this pull request Mar 3, 2026
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.

2 participants