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

Finish HTTP proxy support in Kubernetes authenticator #2766

Merged
merged 3 commits into from
Apr 13, 2023

Conversation

micahlee
Copy link
Contributor

@micahlee micahlee commented Apr 4, 2023

Desired Outcome

The outcome of this PR is to support connecting through an HTTP proxy for all phases of the Kubernetes authenticator, including certificate injection.

Implemented Changes

Previously, the Kubernetes authenticator supported an HTTP proxy for the REST-ful API calls. For example, when checking the existence of a k8s resource. However, it failed to use the proxy server for the execute call to inject the authentication certificate. This was due to this phase using a separate websocket client that lacked proxy support.

This PR implements tests to detect the proxy implementation gap and adds support for proxies to the websocket client.

Connected Issue/Story

CyberArk internal issue ID: CNJR-230

Definition of Done

At least 1 todo must be completed in the sections below for the PR to be
merged.

Changelog

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a
    CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code
    changes, or
  • The changes in this PR do not require tests

Documentation

  • Docs (e.g. READMEs) were updated in this PR
  • A follow-up issue to update official docs has been filed here: [insert issue ID]
  • This PR does not require updating any documentation

Behavior

  • This PR changes product behavior and has been reviewed by a PO, or
  • These changes are part of a larger initiative that will be reviewed later, or
  • No behavior was changed with this PR

Security

  • Security architect has reviewed the changes in this PR,
  • These changes are part of a larger initiative with a separate security review, or
  • There are no security aspects to these changes

@micahlee micahlee force-pushed the cnjr-230-websocket-proxy branch 2 times, most recently from 15373bf to d8dfaa9 Compare April 4, 2023 18:13
This ensures we detect the issue in which a http
proxy is not correctly used with kube exec to
inject the Conjur client certificate.
@micahlee micahlee force-pushed the cnjr-230-websocket-proxy branch 2 times, most recently from 964d06e to 452a32e Compare April 11, 2023 20:55
@micahlee micahlee changed the title WIP: Add proxy support Finish HTTP proxy support in Kubernetes authenticator Apr 11, 2023
@micahlee micahlee force-pushed the cnjr-230-websocket-proxy branch 7 times, most recently from a7dfc17 to 3b48304 Compare April 12, 2023 14:20
@codeclimate
Copy link

codeclimate bot commented Apr 12, 2023

Code Climate has analyzed commit 9d54d17 and detected 5 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3
Style 2

The test coverage on the diff in this pull request is 99.2% (50% is the threshold).

This pull request will bring the total coverage in the repository to 89.9% (-1.8% change).

View more on Code Climate.

@micahlee micahlee marked this pull request as ready for review April 12, 2023 17:09
@micahlee micahlee requested a review from a team as a code owner April 12, 2023 17:09
emit(:__close)

Thread.kill(@thread) if @thread
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to ensure we can safely spawn a new thread in begin_event_loop below?

It feels a bit disjointed to have the lifecycle of a variable spread across three different classes, but without changing the interface, there's not much we can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it so much for spawning a new thread, but just to make sure we clean up the thread already created.

I started down a path of refactoring more of the event loop, but I became concerned about verifying that it hadn't regressed in the timeframe we have for code freeze, so I backed out of that. There is definitely room to decouple some of these lifecycle and thread management routines, though. It's really difficult to try to add unit tests for this class the way it's written right now. The _spec.rb file for the websocket client is really more of an integration test right now. It gets the job done, but is slower than it needs to be and doesn't really test all of the lifecycle edge cases.

Considering we've fixed 3+ bugs in this code over the past year, this wouldn't be a bad candidate for focusing on in a quality sprint at some point, to make this code easier to test and make changes to. I tried to do some of that with the OpenSSL setup and the proxy support, but the thread/event loop is still just kind of spaghetti code. CC: @adamouamani

Copy link
Contributor

@jvanderhoof jvanderhoof left a comment

Choose a reason for hiding this comment

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

Nice work on this @micahlee. I always like seeing what these protocols look like under the hood.

@micahlee micahlee merged commit 24ebb8f into master Apr 13, 2023
@micahlee micahlee deleted the cnjr-230-websocket-proxy branch April 13, 2023 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants