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(mTLS): adds mTLS support to dataplane api-server #280

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

EandrewJones
Copy link
Contributor

@EandrewJones EandrewJones commented Sep 8, 2024

Closes #50.

Questions

I am not sure how best to add tests for this. Unit testing the config trivially tests the behavior of Opt which we know works. Unit testing setup_tls forces me to mock read_to_string in the absence of an actual file to read in and all the ways I've read about doing that in rust feel really kludgie / dirty up the code with dependency injections, etc.

  1. Is this all we need to add mTLS support for the api-server?
  2. Is there some sort of API contract we need to maintain for this such that I can write a conformance or integration test?
  3. What documentation would we like to see for this?

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 8, 2024
@shaneutt shaneutt self-requested a review September 9, 2024 13:00
@shaneutt shaneutt self-assigned this Sep 12, 2024
@aryan9600
Copy link
Member

Unit testing setup_tls forces me to mock read_to_string in the absence of an actual file to read in

how about generating certs during the test, writing them to temp files and then passing those to setup_tls?

  1. Is this all we need to add mTLS support for the api-server?

this looks good. we can test it using https://github.com/islishude/grpc-mtls-example/blob/main/cmd/client/main.go.

  1. Is there some sort of API contract we need to maintain for this such that I can write a conformance or integration test?

we don't have an integration test for the current grpc server. i guess an integration test for the api server would involve spinning up the server and calling each method from an independent client? for testing mTLS specifically, i think we can just get away with only testing one method, since the thing we want to test is actually the TLS connection. something, like the answer to your first question, but coded in a script.

  1. What documentation would we like to see for this?

we don't really have any docs apart from code comments. i think code comments for now is fine. documentation is an entirely separate conversation that we need to have soon.

dataplane/api-server/src/config.rs Outdated Show resolved Hide resolved
dataplane/api-server/src/config.rs Outdated Show resolved Hide resolved
dataplane/api-server/src/lib.rs Outdated Show resolved Hide resolved
dataplane/api-server/src/config.rs Outdated Show resolved Hide resolved
dataplane/api-server/src/config.rs Outdated Show resolved Hide resolved
dataplane/loader/src/main.rs Outdated Show resolved Hide resolved
dataplane/api-server/src/config.rs Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 17, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: EandrewJones
Once this PR has been reviewed and has the lgtm label, please ask for approval from aryan9600. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 22, 2024
@EandrewJones
Copy link
Contributor Author

EandrewJones commented Sep 22, 2024

@aryan9600 All comments addressed apart from the one issue flagged below.

  1. Is this all we need to add mTLS support for the api-server?

this looks good. we can test it using https://github.com/islishude/grpc-mtls-example/blob/main/cmd/client/main.go.

If we're not treating this as an integration test, where should we add this so it runs in our pipeline? We need the dataplane server running so we can mimic the client, so it seems like it should go into the integration test pipeline (tests/integration). However, the makefile states these tests are deprecated, so should I really be adding new tests to the suite?

dataplane/api-server/src/config.rs Outdated Show resolved Hide resolved
dataplane/api-server/src/config.rs Outdated Show resolved Hide resolved
dataplane/api-server/src/config.rs Outdated Show resolved Hide resolved
@shaneutt shaneutt added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 15, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 18, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2024
@EandrewJones
Copy link
Contributor Author

EandrewJones commented Oct 23, 2024

I pushed up a go test that creates certs, spins up the dataplane, and dials the grpc w/ mTLS from a client. The test passes, but I suspect it's a false positive because the dataplane exits almost immediately on my machine due to an error:

Error: map error: failed to create map `AYA_LOGS` with code -1

Caused by:
    0: failed to create map `AYA_LOGS` with code -1
    1: Operation not permitted (os error 1)
Error: map error: failed to create map `GATEWAY_INDEXES` with code -1

Caused by:
    0: failed to create map `GATEWAY_INDEXES` with code -1
    1: Operation not permitted (os error 1)

I only care about having a valid test at this point and adding it to our CI.

My guess is I need to deploy the dataplane into KTF to get a proper environment for testing. Is that correct @shaneutt ?

@EandrewJones
Copy link
Contributor Author

EandrewJones commented Oct 23, 2024 via email

@shaneutt
Copy link
Member

Does the golang controlplane archival have any impact on this? Or do I just need to stand up KTF before I run these tests?

The archival shouldn't have an impact: there's a make build.cluster target that sends the right flags (and will automatically install ktf for you). The Golang integration tests actually were left in main despite removing all the other Go code (since the tests in still have value and help us validate our Rust changes until we replace them with Rust tests).

@EandrewJones
Copy link
Contributor Author

@shaneutt @aryan9600 This should be ready for final review. I finally have passing tests. Upon lgtm, I'll squash my commits.

@shaneutt
Copy link
Member

shaneutt commented Dec 2, 2024

Woops I still owe you a review! If you wouldn't mind doing a rebase to main I'll have some time this week to start a review (I was out the last couple weeks sorry for the lag ^_^)

@EandrewJones
Copy link
Contributor Author

EandrewJones commented Dec 2, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

mTLS for dataplane API
4 participants