Skip to content

chore: add workspace proxies to the backend #7032

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

Merged
merged 51 commits into from
Apr 17, 2023
Merged

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Apr 6, 2023

What this does

This is the initial implementation of workspace proxies. It is missing functionality, and not complete. Stuff that's remaining is listed at the bottom.

This initial implementation implements the basic interface contracts that allow workspace proxies to communicate with coderd. It enables basic workspace proxying! The unit tests are setup and all passing. Token smuggling is implemented, hostname validation is implemented.

This feature is experiment flag gated and not able to be used in any production environment. Currently only unit tests can leverage this code since there's no CLI yet.

More PRs will add functionality. This is the core, and makes PRs more "bite sized".... Ok it is a big bite.

Future Work

@deansheather deansheather self-assigned this Apr 6, 2023
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

I know this is in draft, but wanted to take a peek! Feel free to take my comments or leave em', all just naming stuff.

@Emyrk Emyrk changed the title draft: External Workspace Proxies chore: External workspace proxies available in testing. Apr 12, 2023
@deansheather deansheather requested a review from kylecarbs April 17, 2023 17:00
Comment on lines +372 to +373
// Same as the first but it's optional.
apiKeyMiddlewareOptional := httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{
Copy link
Member

Choose a reason for hiding this comment

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

Would it be cleaner if we allowed Optional as a separate argument to this function? Then they could share configs.

Copy link
Member

Choose a reason for hiding this comment

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

There are a few values that change between the 3 instances of ExtractAPIKeyMW we have like Optional, RedirectToLogin, etc. Do you propose we add all of these as bool params? Seems janky IMO

Comment on lines +65 to +72
-- Validate that the @hostname has been sanitized and is not empty. This
-- doesn't prevent SQL injection (already prevented by using prepared
-- queries), but it does prevent carefully crafted hostnames from matching
-- when they shouldn't.
--
-- Periods don't need to be escaped because they're not special characters
-- in SQL matches unlike regular expressions.
@hostname :: text SIMILAR TO '[a-zA-Z0-9.-]+' AND
Copy link
Member

Choose a reason for hiding this comment

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

It seems weird to me that we need to do this, and could cause some odd bugs. Why can't we do an exact match for the hostname?

Copy link
Member

Choose a reason for hiding this comment

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

You can't do exact match because app--agent--workspace--username.dev.coder.com is not an exact match for dev.coder.com or *.dev.coder.com.

The specific lines you commented on is to avoid regex escapes in hostnames. It's a preventative measure to make the match more consistent and to avoid security issues.

Comment on lines +24 to +26
// The format of an external proxy token is:
// <proxy id>:<proxy secret>
//
Copy link
Member

Choose a reason for hiding this comment

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

I don't disagree with the ease of telling a difference, it just seems weird to maintain multiple types of secret keys when we already have a standard in the product.

If we need to bump the security of our keys, we'll now have multiple places for that to be done, even though they share the same purpose.

And under this format, it's not explicit when it's a proxy key... we just know it is because of the :, right?

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

All of my comments were just naming, nothing daunting.

@deansheather feel free to merge once we reconcile the naming stuff!

🥳🥳🥳

@kylecarbs
Copy link
Member

@deansheather before merge lets rename the title to something like feat: add workspace proxies to the backend or something

@deansheather deansheather changed the title chore: External workspace proxies main code chore: add workspace proxies to the backend Apr 17, 2023
@deansheather
Copy link
Member

Keeping it as chore so it doesn't show up in changelog (it's not usable by users yet)

@deansheather deansheather enabled auto-merge (squash) April 17, 2023 19:54
@deansheather deansheather merged commit 658246d into main Apr 17, 2023
@deansheather deansheather deleted the dreamteam/external_proxy branch April 17, 2023 19:57
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants