-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(inputs.x509_cert): Add support for JKS and PKCS#12 keystores #16508
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
@paulojmdias please check the linter issues. You can reproduce them locally using |
Signed-off-by: Paulo Dias <[email protected]>
Fixed 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution @paulojmdias! This is very much appreciated! I do have some comments in the code...
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulojmdias some more comments...
|
||
_, cert, caCerts, err := pkcs12.DecodeChain(data, passwordStr) | ||
if err != nil { | ||
_, cert, caCerts, err = pkcs12.DecodeChain(data, "") // Retry without password |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this required? The user can specify an empty password if he needs to, so don't try to be smart here as this usually calls for trouble. ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense to set the default password as ""
in Init()
instead of the user explicitly adding it to the configuration? Or by default is ""
if is not set?
err = jks.Store(output, []byte("test-password")) | ||
require.NoError(t, err) | ||
|
||
return "jks://" + jksPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work on Windows, you should do
return "jks://" + jksPath | |
jksPath = filepath.ToSlash(jksPath) | |
if !strings.HasPrefix(jksPath, "/") { | |
jksPath = "/" + jksPath | |
} | |
return "jks://" + jksPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed also pkcs12Path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still seems to be not working on Windows. The code below will not make it work using absolute paths?
absPath, err := filepath.Abs(jksPath)
require.NoError(t, err)
return "jks://" + absPath
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Signed-off-by: Paulo Dias <[email protected]>
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
Summary
I initially thought about creating a separate input plugin for JKS & PKCS12 key stores but decided to integrate it into x509_cert since the changes were minimal. This update allows x509_cert to automatically detect and parse JKS & PKCS12 files while maintaining the existing certificate validation and metric collection logic. I also added tests to ensure everything works smoothly without overcomplicating the code.
Please evaluate if make sense and let me know what changes you feel are needed to accommodate this feature.
Checklist
Related issues
resolves #7013