Skip to content
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 security to edgex via openziti #2603

Merged
merged 15 commits into from
Mar 28, 2024

Conversation

dovholuknf
Copy link
Contributor

EdgexFoundry has elected to adopt OpenZiti for additional security. This is an initial attempt at what integrating github.com/openziti/ziti into ekuiper for EdgexFoundry might look like. (I tried my best to follow the commit guidelines, but I'm sure I didn't do something quite right, apologies in advance)

This PR adds functionality to ekuiper. It allows ekuiper to be removed from the underlay network if desired. In this PR the restPort is no longer available on the underlay (IP-based) network as it is exclusively accessible via OpenZiti if enabled.

Considerations/Notes:

  • Logging - OpenZiti uses pfxlog which uses the logrus.StandardLogger() and had to be adapted to in order to allow OpenZiti logging in the ekuiper logs for debugging
  • VaultSecret - edgex uses vault to deliver vault tokens to services. this vault token can be exchanged for a jwt which is then usable as authentication to the OpenZiti overlay network and other edgex services. A small VaultSecret was created to keep the vault token fresh and obtain new jwt's on a regular interval
  • http clients have been adapted to allow connecting/sending data over the OpenZiti overlay network if enabled using the environment variables EDGEX_CREDENTIALS, EDGEX_CREDENTIAL_NAME, OPENZITI_CONTROLLER. If this is not desired, I'm happy to rework it how you see fit.
  • http server ListenAndServe/ListenAndServeTLS are changed to Serve(listener)/ServeTLS(listener) respectively. http server is able to be taken off the IP-based underlay network entirely (making it unattackable by conventional IP-based attacks)

@ngjaying
Copy link
Collaborator

ngjaying commented Feb 1, 2024

@dovholuknf Thanks. Please follow the Details link in DCO check to sign the commit.

@dovholuknf
Copy link
Contributor Author

@dovholuknf Thanks. Please follow the Details link in DCO check to sign the commit.

Ahhh shoot. I forgot. Thanks

@dovholuknf
Copy link
Contributor Author

I have fixed the DCO issue. Thanks

Copy link
Collaborator

@ngjaying ngjaying left a comment

Choose a reason for hiding this comment

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

When do you expect to merge this? We may help if available.

internal/conf/logger/logger.go Outdated Show resolved Hide resolved
internal/io/http/client.go Outdated Show resolved Hide resolved
internal/server/server.go Outdated Show resolved Hide resolved
@dovholuknf
Copy link
Contributor Author

sorry i've been away from this for a long long time... i'm nearly through the edgex work... i am hoping to return to this this week or next week.

Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
@dovholuknf
Copy link
Contributor Author

This should be ready to re-review now. If you would like to see instructions on testing with edgex - just let me know and i can provide a set of docker steps here

Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
@dovholuknf
Copy link
Contributor Author

dovholuknf commented Mar 27, 2024

the linter failed to run but it looks like it was some kind of error? can you maybe rerun it? I found the errors appear to be red herrings. ran gofumpt...

also is the test case failure due to something i did? I'm surprised to see that based on what i added?


--- FAIL: TestExtensions (0.03s)
    mock_topo.go:392: Drop stream fails: ext is not found.
    mock_topo.go:392: Drop stream fails: ext2 is not found.
    plugin_rule_test.go:81: The test bucket size is 2.

i'll try to fix the 'max commit len' issue -- 58 chars at the moment? ;/

@dovholuknf dovholuknf changed the title feat: initial PR for adding security to edgex via openziti feat: add security to edgex via openziti Mar 27, 2024
Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
@ngjaying
Copy link
Collaborator

the linter failed to run but it looks like it was some kind of error? can you maybe rerun it?

also is the test case failure due to something i did? I'm surprised to see that based on what i added?


--- FAIL: TestExtensions (0.03s)
    mock_topo.go:392: Drop stream fails: ext is not found.
    mock_topo.go:392: Drop stream fails: ext2 is not found.
    plugin_rule_test.go:81: The test bucket size is 2.

i'll try to fix the 'max commit len' issue -- 58 chars at the moment? ;/

OK, we can try to fix lint and ut problems

@dovholuknf
Copy link
Contributor Author

OK, we can try to fix lint and ut problems

much appreciated. i found the linter error by looking at the raw logs. the "UI view" just showed all the errors and confused me. i ran gofumpt and hopefully appeased the linter.

Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
@dovholuknf
Copy link
Contributor Author

i think i figured out how to run gci and gofumpt and hopefully the linter will be happy this time

Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
@dovholuknf
Copy link
Contributor Author

plugin was built with a different version of package github.com/lf-edge/ekuiper/internal/conf/logger (previous failure)

I do think I somehow broke that test now that i see this. I changed this file. I'm definitely going to ask for help figuring out how to fix that. Also thanks for pushing the 'approve' button on all the linter commits. I sure hope I have them all sorted now :(

@ngjaying
Copy link
Collaborator

plugin was built with a different version of package github.com/lf-edge/ekuiper/internal/conf/logger (previous failure)

I do think I somehow broke that test now that i see this. I changed this file. I'm definitely going to ask for help figuring out how to fix that. Also thanks for pushing the 'approve' button on all the linter commits. I sure hope I have them all sorted now :(

Sure, I'll take a look later today but not now since I am busy with other things in hand. Once you have a commit merged, the checks will be run without a need of approval.

copyright should be in the beginning of each file

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
Signed-off-by: Jiyong Huang <huangjy@emqx.io>
By default, it is close. To use with EdgeX secure mode, it should be turned on.

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
@ngjaying
Copy link
Collaborator

ngjaying commented Mar 27, 2024

Build packages error

The default build has edgex tag, the build package check will run the built kuiperd to check. Then the caErr cause a panic in openziti.go AuthenicatedContext.
I guess there are some dependency services which are not existed in the test env. Is EdgeX still have secure and non-secure mode? Maybe we need to have a configuration in eKuiper to switch between secure and non-secure and default to non-secure to pass the tests. Thus, I make a commit for that to add enableOpenZiti config.

UT error

It is caused by the logger adaptor. It seems to me that the adaptor is unneccessary to apply to the logger globally. We can decorate it only when calling open ziti functions. Thus, I make a commit for that.

Now all checks are passed except the coverage is too low. Is it possible to add ut? (Looks hard to me because of external dependencies).

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

Attention: Patch coverage is 5.11811% with 241 lines in your changes are missing coverage. Please review.

Project coverage is 63.17%. Comparing base (d5bbd74) to head (ef120d3).
Report is 12 commits behind head on master.

Files Patch % Lines
internal/edgex/vault.go 0.00% 138 Missing ⚠️
internal/edgex/logger_adaptor.go 0.00% 35 Missing ⚠️
internal/edgex/openziti.go 0.00% 31 Missing ⚠️
internal/io/http/client_edgex.go 23.08% 19 Missing and 1 partial ⚠️
internal/server/server_edgex.go 18.18% 9 Missing ⚠️
internal/server/server.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2603      +/-   ##
==========================================
- Coverage   63.49%   63.17%   -0.32%     
==========================================
  Files         339      345       +6     
  Lines       38932    39283     +351     
==========================================
+ Hits        24717    24816      +99     
- Misses      12046    12295     +249     
- Partials     2169     2172       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
Signed-off-by: dovholuknf <46322585+dovholuknf@users.noreply.github.com>
@ngjaying
Copy link
Collaborator

@dovholuknf Thank you. All looks good now. Is it possible to add more unit tests? If not, I think we can merge for now. And we'll need doc updates in another PR.

@dovholuknf
Copy link
Contributor Author

@dovholuknf Thank you. All looks good now. Is it possible to add more unit tests? If not, I think we can merge for now. And we'll need doc updates in another PR.

Thank you for the help! I'd really like to say yes to adding tests but I'm really strapped trying to get this and all the other edgex work out the door. i will put it on my backlog though and maybe in the coming weeks I can add them? Unit tests aren't probably too useful here other than maybe making sure configuration is set and defaults processed since it really needs an openziti overlay -- if that makes sense? I'm happy to look at it in the future, when I can get to it. Right now it's tight. :(

@dovholuknf
Copy link
Contributor Author

dovholuknf commented Mar 28, 2024

I'll need help with what kind of doc and 'how/where' to doc. If you have any pointers on that, please let me know! Maybe make an issue and assign it to me? -- same for test now that i think about it?

@dovholuknf
Copy link
Contributor Author

and one related question - will a docker container be produced from this repo that I could reference in the edgex project? sorry for all the comments...

@ngjaying
Copy link
Collaborator

and one related question - will a docker container be produced from this repo that I could reference in the edgex project? sorry for all the comments...

Yes, we can trigger an alpha release, that would produce a docker image.

@ngjaying
Copy link
Collaborator

I'll need help with what kind of doc and 'how/where' to doc. If you have any pointers on that, please let me know! Maybe make an issue and assign it to me? -- same for test now that i think about it?

OK, I'll create an issue for that.

@ngjaying ngjaying merged commit bf3b679 into lf-edge:master Mar 28, 2024
58 of 59 checks passed
@dovholuknf
Copy link
Contributor Author

Yes, we can trigger an alpha release

that would be much appreciated. I looked but it doesn't seem like one exists yet. Should I use GH Discussions for this request? Add a new issue? or just keep commenting here? :) thanks again

@ngjaying
Copy link
Collaborator

ngjaying commented Mar 29, 2024

Yes, we can trigger an alpha release

that would be much appreciated. I looked but it doesn't seem like one exists yet. Should I use GH Discussions for this request? Add a new issue? or just keep commenting here? :) thanks again

@dovholuknf https://github.com/lf-edge/ekuiper/releases/tag/v1.14.0-alpha.2 tagged. Discussions thread is OK for me.

@dovholuknf dovholuknf deleted the add-openziti branch April 3, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 1.14 Q2
Development

Successfully merging this pull request may close these issues.

2 participants