-
Notifications
You must be signed in to change notification settings - Fork 30
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: add support for Kafka secure connection with certificates X509 #70
Conversation
Amazing! I tried it on the branch and the only thing I needed to change was to add an SSL entry to my config:
Without it, there's no |
@lornajane I think you are not passing the NODE_ENV like this below setting is there in the config for production environment:
it is not set to true by default because default !== production and therefor should be flexible aka non secure for testing |
OK yes, that made it work! But then why am I specifying the server at generate time if I am going to specify at run time anyway? And must the servers be named like the sections in the configuration file? Production / development etc? Can I have a server named "Fred"? |
@lornajane you can even have a server called I think always 2 cases should be supported:
what you see in Does it make sense? |
@lornajane maybe I should add something more to readme, so code change suggestions would be highly appreciated 🙏🏼 |
@lornajane thoughts? |
I think a note in the README (maybe in the generated README?) on using the environment variable to set which server config to combine with the default would be useful. But the PR change here is definitely an improvement and should be merged when we can. Thankyou! |
@lornajane I pushed some readme updates. Need approval from another maintainer and we can merge |
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.
How difficult would it be to make the location of the certificates configurable?
Co-authored-by: Fran Méndez <fmvilas@gmail.com>
@fmvilas depends, if all would be expected in single directory, then we just need to add one more param, so the default would be |
README.md
Outdated
## How to use the template | ||
|
||
This template must be used with the AsyncAPI Generator. You can find all available options [here](https://github.com/asyncapi/generator/). | ||
|
||
In case you use X509 security and need to provide certificates, place them in the root of generated server with the following names: `ca.pem`, `service.cert`, `service.key`. Since you can have multiple different security schemes, to use the one of X509 type, you need to pass the name of the scheme like this: `-p securityScheme=SCHEME_NAME`. |
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.
As a suggestion: Could we provide the absolute path instead? I think it would be easier for the users and simplifies a lot the file handling. Most of this paragraph will be then removed.
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.
I just realized @fmvilas wrote some similar suggestion at #70 (review)
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.
option to provide custom location for the files is valid, but I don't get how will it affect this paragraph, other then extend it more 😄
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.
For me this is simplified not only in terms of documentation but improved UX.
In case you use X509 security and need to provide certificates, place them in the root of generated server with the following names: `ca.pem`, `service.cert`, `service.key`. Since you can have multiple different security schemes, to use the one of X509 type, you need to pass the name of the scheme like this: `-p securityScheme=SCHEME_NAME`. | |
In case you use X509 security and need to provide certificates, specify their location at BLA BLA. Since you can have multiple different security schemes, to use the one of X509 type, you need to pass the name of the scheme like this: `-p securityScheme=SCHEME_NAME`. |
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.
for me best DX is defaults and later config. Description updated
template/src/api/index.js
Outdated
{%- if params.securityScheme and (asyncapi.server(params.server).protocol() === 'kafka' or asyncapi.server(params.server).protocol() === 'kafka-secure') and asyncapi.components().securityScheme(params.securityScheme).type() === 'X509' %} | ||
const fs = require('fs') | ||
|
||
serverConfig.ssl.ca = fs.readFileSync('ca.pem'); |
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.
What if the file does not exist? is somehow erroring?
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.
added proper try/catch, thanks!
It's pretty common to have certificates in a system directory instead of the app directory, so they can be shared. Actually, beyond proof-of-concepts, it's not very common to find certificate files in the same dir as the code. I think having the ability to simply setup the root directory where to look for certificates would be good enough to start. |
makes sense to me, will work on it |
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.
LGTM 👏 💯 🚀
@fmvilas kind reminder 😉 |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
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.
Great stuff! 🚀
🎉 This PR is included in version 0.11.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixes #66 and adds support for Kafka security using X509 security scheme.
kafka-secure
securityScheme
parameter that one need to use to provide the name of the scheme to use for code generationHow I tested:
-p securityScheme=creds
NODE_ENV=production npm start
I assume it works, but did not really test sending any events. @lornajane could you have a look, review PR and check if it works as expected. To use my template changes, do not run
ag
against@asyncapi/nodejs-template
buthttps://github.com/derberg/nodejs-template#x509