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

machine registration connectivity rework - part I #140

Merged
merged 4 commits into from
Aug 31, 2022
Merged

Conversation

fgiudici
Copy link
Member

@fgiudici fgiudici commented Aug 18, 2022

Till now the TPM package was in charge to upgrade the HTTP connection and manage the websocket one.
This PR moves the connection management (server side) to the server package to split the connection management from TPM authentication.
This will allow us later (part II) to make it easier to pass the smbios data and the labels through the websocket channel instead of abusing HTTP headers.
This PR doesn't introduce any functional change, so doesn't change (nor break) current websocket communication pattern.
Related to #5
Partially fixes #130

@fgiudici fgiudici requested a review from a team August 19, 2022 15:52
@github-actions github-actions bot added area/operator operator related changes area/register register related changes labels Aug 22, 2022
@fgiudici
Copy link
Member Author

rebased on main

@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2022

Codecov Report

Merging #140 (9e36eff) into main (f0bd8f4) will decrease coverage by 3.51%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #140      +/-   ##
==========================================
- Coverage   33.77%   30.26%   -3.52%     
==========================================
  Files           5        5              
  Lines         379      423      +44     
==========================================
  Hits          128      128              
- Misses        246      290      +44     
  Partials        5        5              
Impacted Files Coverage Δ
pkg/server/register.go 19.42% <0.00%> (-4.56%) ⬇️
pkg/server/server.go 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@davidcassany davidcassany left a comment

Choose a reason for hiding this comment

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

Looks good to me, even I am not deeply familiar with the former issue of using https headers to pass data.

In any case it seams like a good move to me setting the websocket apart from the tpm authentication.

I am not sure the e2e tests are covering this (I don't think so), if not I am wondering that probably this is the right time to add some. It could be done in a follow up PR/card after the three parts are in though.

// get the machine registration relevant to this request
registration, err := i.getMachineRegistration(req)
if err != nil {
http.Error(resp, err.Error(), http.StatusNotFound)
return
}

// attempt to authenticate the machine, if the machine is nil, authentication has failed
inventory, w, err := i.authMachine(resp, req, registration.Namespace)
if !websocket.IsWebSocketUpgrade(req) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how does this works? we run the auth after this part? Not sure I understand it correctly

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically, in order to switch a plan HTTP connection to a websocket one, it is the client that must add an "Upgrade" header in the HTTP GET request first (the gorilla/websocket library Dial() function does this automatically for the client, so it is hidden in the code). The idea here is, as soon as we receive an HTTP GET, let's check if it contains the UPGRADE header to upgrade to a websocket connection. If so, it should be a register client, otherwise is just a request to download the registration yaml to feed the elemental-register cli (via curl or any plain HTTP client).

Copy link
Contributor

@Itxaka Itxaka left a comment

Choose a reason for hiding this comment

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

only a question, looks good to me

If the websocket upgrade header is missing, the client is likely a plain
HTTP one, so let's return immediately the unauthenticated reply.

Add a couple of debug logs to semplify debugging when needed.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
we already log the same error in the calling function
(writeMachineInventoryCloudConfig)

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
Till now the TPM package was in charge to upgrade the HTTP connection
and manage the websocket one.
Move the connection management to the server package to split connection
management from TPM authentication.
This will allow us later to pass the smbios data and the labels through
the channel instead of abusing HTTP headers.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
Error: cyclomatic complexity 16 of func `(*InventoryServer).ServeHTTP` is high (> 15) (gocyclo)

Move code to update labels from headers to subfunction

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
@fgiudici fgiudici merged commit 52410aa into main Aug 31, 2022
@fgiudici fgiudici deleted the websocket_reg01 branch August 31, 2022 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/operator operator related changes area/register register related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve debug logging in the operator
4 participants