Skip to content

chore: Add workspace proxy enterprise cli commands #7176

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 21 commits into from
Apr 20, 2023

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Apr 17, 2023

What this does

Makes a cli command to spin up external workspace proxies!

coder proxy create # ....
coder proxy server # ....

This is just the start to get an external workspace proxy up for manual testing/verification. All commands are hidden right now by default.

Future work

  • Exchange app key over api route, not flags.
  • Better way to make proxy only options?
  • Workspace proxy implementations (healthz, apis, etc)
  • /terminal endpoint requires static files.

Testing/Development

This gives develop.sh an option --use-proxy which will spin up the devserver with an external workspace proxy. This should allow easier manual validation.

develop.sh --use-proxy -- --experiments="*,moons" 

Features added to make this work

  • Cli command to delete workspace proxies.
  • clibase.Optionset filter to filter out options that do not pertain to the workspace proxy.
  • Ability to hard code app-security-key

Logs

Run ./develop.sh --use-proxy

====================================================================
==                                                                ==
==            Coder is now running in development mode.           ==
==                  API:    http://localhost:3000                 ==
==                  API:    http://127.0.0.1:3000                 ==
==                  API:    http://192.168.1.17:3000              ==
==                  API:    http://192.168.1.18:3000              ==
==                  API:    http://172.25.0.1:3000                ==
==                  Web UI: http://localhost:8080                 ==
==                  Web UI: http://127.0.0.1:8080                 ==
==                  Web UI: http://192.168.1.17:8080              ==
==                  Web UI: http://192.168.1.18:8080              ==
==                  Web UI: http://172.25.0.1:8080                ==
==                  Proxy:  http://localhost:3010                 ==
==                  Proxy:  http://127.0.0.1:3010                 ==
==                  Proxy:  http://192.168.1.17:3010              ==
==                  Proxy:  http://192.168.1.18:3010              ==
==                  Proxy:  http://172.25.0.1:3010                ==
==                                                                ==
==      Use ./scripts/coder-dev.sh to talk to this instance!      ==
==       alias cdr=/home/steven/go/src/github.com/cdr/coder/scripts/coder-dev.sh              ==
====================================================================

Video

Peek.2023-04-18.10-02.webm

Emyrk added 2 commits April 17, 2023 15:12
Add primary access url

Include app security key

Add output formats for registering a proxy

Fix formats

Add cli cmd to get app security key

Add deleting proxies

feat: Allow workspace proxy spawn in develop.sh

Make gen

Import ordeR

Quote shell var

Imports

Fix lint

Tabs vs spaces

remove unused command

Fix compile and make gen

Fix slim cmd to include extra proxy cmds

Import order

Import order

Fix comment

Fix compile with name
@Emyrk Emyrk marked this pull request as ready for review April 18, 2023 13:58
cli/server.go Outdated
Comment on lines 624 to 633
if cfg.Dangerous.DevAppSecurityKey.Value() != "" {
_, err := workspaceapps.KeyFromString(cfg.Dangerous.DevAppSecurityKey.Value())
if err != nil {
return xerrors.Errorf("invalid dev app security key: %w", err)
}
err = tx.UpsertAppSecurityKey(ctx, cfg.Dangerous.DevAppSecurityKey.Value())
if err != nil {
return xerrors.Errorf("Insert dev app security key: %w", err)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This will be removed when we do this over an authenticated api

Comment on lines 60 to 101
opts.Add(
// Options only for external workspace proxies

clibase.Option{
Name: "Proxy Session Token",
Description: "Authentication token for the workspace proxy to communicate with coderd.",
Flag: "proxy-session-token",
Env: "CODER_PROXY_SESSION_TOKEN",
YAML: "proxySessionToken",
Default: "",
Value: &proxySessionToken,
Group: &externalProxyOptionGroup,
Hidden: false,
},

clibase.Option{
Name: "Coderd (Primary) Access URL",
Description: "URL to communicate with coderd. This should match the access URL of the Coder deployment.",
Flag: "primary-access-url",
Env: "CODER_PRIMARY_ACCESS_URL",
YAML: "primaryAccessURL",
Default: "",
Value: &primaryAccessURL,
Group: &externalProxyOptionGroup,
Hidden: false,
},

// TODO: Make sure this is kept secret. Idk if a flag is the best option
clibase.Option{
Name: "App Security Key",
Description: "App security key used for decrypting/verifying app tokens sent from coderd.",
Flag: "app-security-key",
Env: "CODER_APP_SECURITY_KEY",
YAML: "appSecurityKey",
Default: "",
Value: &appSecuritYKey,
Group: &externalProxyOptionGroup,
Hidden: false,
Annotations: clibase.Annotations{}.Mark("secret", "true"),
},
)

Copy link
Member Author

Choose a reason for hiding this comment

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

Until we have a better way, this is how I add options that are only for workspace proxies.

@Emyrk Emyrk requested a review from deansheather April 18, 2023 14:54
@Emyrk Emyrk requested a review from kylecarbs April 18, 2023 15:03
r.InitClient(client),
),
Handler: func(inv *clibase.Invocation) error {
if !(primaryAccessURL.Scheme == "http" || primaryAccessURL.Scheme == "https") {
Copy link
Member

Choose a reason for hiding this comment

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

it'd be nice if deployment options can be validated in the option definition but alas

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting idea... @ammario ? Is a "Validate" func field on an option reasonable?

Copy link
Member

Choose a reason for hiding this comment

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

I like that idea

Comment on lines +149 to +153
clibase.Option{
Flag: "only-token",
Description: "Only print the token. This is useful for scripting.",
Value: clibase.BoolOf(&onlyToken),
},
Copy link
Member

Choose a reason for hiding this comment

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

Honestly seems unnecessary given you support JSON output.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is so easy:

proxy_session_token=$(coder proxy create --only-token)

Otherwise I need to chain with jq. This is just nice imo.

Copy link
Collaborator

@sreya sreya left a comment

Choose a reason for hiding this comment

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

Honestly LGTM 👍

@Emyrk Emyrk merged commit a5a5c4d into main Apr 20, 2023
@Emyrk Emyrk deleted the dreamteam/external_proxy_cli_cmd_rebased branch April 20, 2023 14:48
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 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