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

enable GIN mTLS support #7

Merged
merged 10 commits into from
May 18, 2022
Merged

Conversation

alvinlee001
Copy link
Contributor

pull request for #6

@malwaredllc
Copy link
Collaborator

@alvinlee001 nice! can we make the client_auth option more general, so it applies to all TLS (not just client side auth)?

@alvinlee001
Copy link
Contributor Author

Hi @malwaredllc, are u saying that you just want it to be https disabled or enabled? If https enabled, implies opting for mTLS? What about opting for TLS but not mTLS? It totally depends on you, but right now TLS is mandatory, while mTLS is optional.

@malwaredllc
Copy link
Collaborator

@alvinlee001 Basically TLS should be optional. The problem I want to solve is that right now, if a server's hostname or IP does not appear in this TLS certificate config file here, then it will be unable to communicate with other servers.

This means that unless all of your servers are in the same subdomain that you can use a wildcard for (i.e. *.example.com), then if you want to add a new server, you must add its hostname/IP to that config file and run the ./gen.sh script to regenerate the TLS certificates, which is not ideal.

For example, if I want to add cacheserver4 to my docker-compose.yml to spin up an extra server in a container, I will need to add DNS:cacheserver4 to the certs/server-ext.cnf and regenerate the certificates first.

One way around this is to simply not use TLS (make it optional) to not have to worry about this, so the cluster size can dynamically change without issue. Alternatively, I need to figure out a more flexible way of doing TLS.

@alvinlee001
Copy link
Contributor Author

alvinlee001 commented May 17, 2022

I see, @malwaredllc can we have an additional property called https-enabled and this will control whether we want to enable or disable HTTPS? So we can do it as separate from forcing mTLS, is that okay? If not, I could just remove my previous commit of making mTLS an option, and just have this new property, this will work too.

@malwaredllc
Copy link
Collaborator

@alvinlee001 Yeah I think https-enabled sounds great

@alvinlee001
Copy link
Contributor Author

Hi @malwaredllc, i have implemented it. There will be a flag in CLI and json to specify if https should be enabled, it is enabled by default unless specified otherwise. I have pushed the new commit, kindly have a look.

@malwaredllc
Copy link
Collaborator

malwaredllc commented May 17, 2022

@alvinlee001 thanks for your help with this, looks like the build is failing though (see build tests ran on this PR), can you take a look?

@alvinlee001
Copy link
Contributor Author

Ok wait

@alvinlee001
Copy link
Contributor Author

Hi @malwaredllc , sorry I have force pushed again, missed some changes previously. Now the tests are passing.

@malwaredllc
Copy link
Collaborator

@alvinlee001 Looks good! Last thing will be to add a test to make sure that HTTP without TLS works properly (you can basically copy/paste this test in main_test.go but tweak the params to not use HTTPS. Note you may need to modify this function to accept the https_enabled flag to do this.

@alvinlee001
Copy link
Contributor Author

Alright, sure @malwaredllc

@alvinlee001
Copy link
Contributor Author

hi @malwaredllc , added test and it is passing, previously has been testing the HTTP rest locally as well, it is working

main_test.go Outdated Show resolved Hide resolved
@@ -59,7 +61,7 @@ func HashId(key string) uint32 {
// Load nodes config file
func LoadNodesConfig(config_file string) NodesConfig {
file, _ := ioutil.ReadFile(config_file)
nodes_config := NodesConfig{}
nodes_config := NodesConfig{EnableClientAuth: true, EnableHttps: true}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Quick question, why are EnableClientAuth and EnableHttps hard coded to true here? Shouldn't these values come from the config file or command line flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @malwaredllc, if unspecified, these will be the default values, meaning if the config have the fields to be absent, it will have https and mTLS as enabled by default

@malwaredllc
Copy link
Collaborator

@alvinlee001 looks awesome thanks for doing that! I left a couple of comments on small things to address above but besides that it looks ready to go

@alvinlee001
Copy link
Contributor Author

Hi @malwaredllc , I resolved the 2 comments just now, and pushed changes. pls have a look

RELATIVE_CONFIG_PATH = "configs/nodes-local.json"
RELATIVE_CLIENT_CERT_DIR = "certs"
RELATIVE_CONFIG_PATH = "configs/nodes-local.json"
RELATIVE_CONFIG_PATH_HTTP = "configs/nodes-local-insecure.json"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add this file to the commit

@malwaredllc
Copy link
Collaborator

@alvinlee001 after further investigation, it appears the integration tests are passing but they shouldn't be (see here: https://github.com/malwaredllc/minicache/runs/6465112038?check_suite_focus=true#step:8:33) - it is unable to connect to any nodes now, it visits them all then loops forever because it is skipping visited nodes - we can fix this test but still the main issue is that the connections to the server are failing

@malwaredllc
Copy link
Collaborator

I am fixing the issue causing the test to appear to pass here and will merge it momentarily

@malwaredllc
Copy link
Collaborator

@alvinlee001 ok I fixed the issue causing the test to appear to pass when it should fail. You can merge in the latest changes from the main branch

@alvinlee001
Copy link
Contributor Author

Hi @malwaredllc , sorry for the late reply, I was busy with my day job. I tried to find the issue with my code, which I think there are a few, and fixed them... but the tests still fail. However, if I run each of the tests individually by commenting out the others, all tests pass... I am not sure why though.

@malwaredllc
Copy link
Collaborator

malwaredllc commented May 17, 2022

@alvinlee001 No worries, if you look at the test output here you'lll see the test failing is Test10kConcurrentRestApiPutsInsecure and the error message is:

2022/05/17 17:00:22 GetLeader failed rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: tls: first record does not look like a TLS handshake"...

So this indicates either the client or server is still trying to use TLS, but one side isn't.

I think it is may be because the config file you are trying to use configs/nodes-local-insecure.json doesn't exist?

@malwaredllc
Copy link
Collaborator

I added a print statement which revealed "enable_https" and "enable_client_auth" are both set to true in the test Test10kConcurrentRestApiPutsInsecure, which should not be the case.

2022/05/17 11:17:34 enable https: %!b(bool=true), insecure: %!b(bool=true), client_auth: %!b(bool=true)

@malwaredllc
Copy link
Collaborator

I figured out the problem, the StartClusterConfigWatcher goroutine has no shutdown mechanism, so the goroutine from the first test was interferring with the 2nd test. That is why if you run the 2nd test individually it works, but all tests won't work.

I am fixing it now and will push changes to your branch here.

@malwaredllc
Copy link
Collaborator

@alvinlee001 I'm not able to modify your PR directly so I made a PR with your changes + the fix I added: #9

Either you can copy over the changes to your branch and we can merge it (so you get credit for your contribution), or we can merge that PR.

@alvinlee001
Copy link
Contributor Author

Hi @malwaredllc , I have patched my changes with yours. U may merge this PR. Thanks

@@ -257,7 +276,7 @@ func (c *ClientWrapper) Put(key string, value string) error {
// check response
res, err := new(http.Client).Do(req)
defer res.Body.Close()
Copy link
Collaborator

@malwaredllc malwaredllc May 18, 2022

Choose a reason for hiding this comment

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

@alvinlee001 I think this line is causing the test to fail with a segfault. The error check needs to go before using the res object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wokay, done pushing the fix.

@malwaredllc malwaredllc merged commit 91bb0bc into danielvegamyhre:main May 18, 2022
@malwaredllc
Copy link
Collaborator

Merged! Thanks for the contribution, feel free to add any ideas for other features or improvements

@malwaredllc
Copy link
Collaborator

I also just updated the setup/usage information in the readme to include these new changes: https://github.com/malwaredllc/minicache#set-up-and-usage

This was referenced May 18, 2022
danielvegamyhre pushed a commit that referenced this pull request Jul 8, 2024
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