-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add app gateways to Connect #36393
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
Add app gateways to Connect #36393
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f148a97
Allow creating app gateways in tshd
gzdunek ec0e702
Add UI for document gateway app
gzdunek cac1df3
Show apps in connections
gzdunek 5f11764
Capture app protocol
gzdunek 9309d99
Start app proxy when clicking on 'Connect' in app
gzdunek 6d8a902
Remove `removeAppGateway`
gzdunek 5b1151a
`appUri` -> `targetUri`
gzdunek 2a0d899
Add TCP and HTTP constants
gzdunek 2906658
Add CLI command for HTTP apps
gzdunek 6f37ce9
Add `makeAppGateway`
gzdunek dcc2978
Specify `handleChangePort` dependencies correctly
gzdunek 0277365
Remove `doc.gateway_app` and `connection.app`, instead differentiate …
gzdunek 6a2e4eb
Correctly report protocol usage
gzdunek c77829b
Mention that AWS apps are supported in tsh
gzdunek 7b75f23
Rename constants and add godoc
gzdunek b8bdfe5
Add a TODO comment about dialogs for connecting to unsupported apps
gzdunek 97eab28
`onRun` -> `onButtonClick`, `runButtonText` -> `buttonText`
gzdunek 4f73619
Show a notification after copying to clipboard
gzdunek 7905dfe
Make the message about unsupported gateways more precise
gzdunek 133b12f
Revert mistakenly removed `document.targetUri` from `getResourceUri`
gzdunek 10514ee
Remove 'Local app proxy' header
gzdunek aa4cb24
Merge branch 'master' into gzdunek/app-gateways
gzdunek 79718bf
Post-merge fixes
gzdunek 5977ef1
Use proper component for the 'offline gateway' state
gzdunek 718b688
Support all gateway types in relogin UI
ravicious 4ef4504
Fix JSdoc comment
gzdunek e17c6a5
Add a TODO comment about the docs link
gzdunek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -17,7 +17,16 @@ | |||
| package clusters | ||||
|
|
||||
| import ( | ||||
| "context" | ||||
| "crypto/tls" | ||||
| "fmt" | ||||
|
|
||||
| "github.com/gravitational/trace" | ||||
|
|
||||
| "github.com/gravitational/teleport/api/client/proto" | ||||
| "github.com/gravitational/teleport/api/types" | ||||
| "github.com/gravitational/teleport/lib/client" | ||||
| libclient "github.com/gravitational/teleport/lib/client" | ||||
| "github.com/gravitational/teleport/lib/teleterm/api/uri" | ||||
| ) | ||||
|
|
||||
|
|
@@ -36,3 +45,91 @@ type SAMLIdPServiceProvider struct { | |||
|
|
||||
| Provider types.SAMLIdPServiceProvider | ||||
| } | ||||
|
|
||||
| func (c *Cluster) getApp(ctx context.Context, appName string) (types.Application, error) { | ||||
| var app types.Application | ||||
| err := AddMetadataToRetryableError(ctx, func() error { | ||||
| apps, err := c.clusterClient.ListApps(ctx, &proto.ListResourcesRequest{ | ||||
| Namespace: c.clusterClient.Namespace, | ||||
| ResourceType: types.KindAppServer, | ||||
| PredicateExpression: fmt.Sprintf(`name == "%s"`, appName), | ||||
| }) | ||||
| if err != nil { | ||||
| return trace.Wrap(err) | ||||
| } | ||||
|
|
||||
| if len(apps) == 0 { | ||||
| return trace.NotFound("app %q not found", appName) | ||||
| } | ||||
|
|
||||
| app = apps[0] | ||||
| return nil | ||||
| }) | ||||
|
|
||||
| return app, trace.Wrap(err) | ||||
| } | ||||
|
|
||||
| // reissueAppCert issue new certificates for the app and saves them to disk. | ||||
| func (c *Cluster) reissueAppCert(ctx context.Context, app types.Application) (tls.Certificate, error) { | ||||
| if app.IsAWSConsole() || app.IsGCP() || app.IsAzureCloud() { | ||||
| return tls.Certificate{}, trace.BadParameter("cloud applications are not supported") | ||||
| } | ||||
| // Refresh the certs to account for clusterClient.SiteName pointing at a leaf cluster. | ||||
| err := c.clusterClient.ReissueUserCerts(ctx, client.CertCacheKeep, client.ReissueParams{ | ||||
| RouteToCluster: c.clusterClient.SiteName, | ||||
| AccessRequests: c.status.ActiveRequests.AccessRequests, | ||||
| }) | ||||
| if err != nil { | ||||
| return tls.Certificate{}, trace.Wrap(err) | ||||
| } | ||||
|
|
||||
| proxyClient, err := c.clusterClient.ConnectToProxy(ctx) | ||||
| if err != nil { | ||||
| return tls.Certificate{}, trace.Wrap(err) | ||||
| } | ||||
| defer proxyClient.Close() | ||||
|
|
||||
| request := types.CreateAppSessionRequest{ | ||||
| Username: c.status.Username, | ||||
| PublicAddr: app.GetPublicAddr(), | ||||
| ClusterName: c.clusterClient.SiteName, | ||||
| AWSRoleARN: "", | ||||
| AzureIdentity: "", | ||||
| GCPServiceAccount: "", | ||||
| } | ||||
|
|
||||
| ws, err := proxyClient.CreateAppSession(ctx, request) | ||||
| if err != nil { | ||||
| return tls.Certificate{}, trace.Wrap(err) | ||||
| } | ||||
|
|
||||
| err = proxyClient.ReissueUserCerts(ctx, client.CertCacheKeep, client.ReissueParams{ | ||||
| RouteToCluster: c.clusterClient.SiteName, | ||||
| RouteToApp: proto.RouteToApp{ | ||||
| Name: app.GetName(), | ||||
| SessionID: ws.GetName(), | ||||
| PublicAddr: app.GetPublicAddr(), | ||||
| ClusterName: c.clusterClient.SiteName, | ||||
| AWSRoleARN: "", | ||||
| AzureIdentity: "", | ||||
| GCPServiceAccount: "", | ||||
| }, | ||||
| AccessRequests: c.status.ActiveRequests.AccessRequests, | ||||
| }) | ||||
| if err != nil { | ||||
| return tls.Certificate{}, trace.Wrap(err) | ||||
| } | ||||
|
|
||||
| key, err := c.clusterClient.LocalAgent().GetKey(c.clusterClient.SiteName, libclient.WithAppCerts{}) | ||||
| if err != nil { | ||||
| return tls.Certificate{}, trace.Wrap(err) | ||||
| } | ||||
|
|
||||
| cert, ok := key.AppTLSCerts[app.GetName()] | ||||
| if !ok { | ||||
| return tls.Certificate{}, trace.NotFound("the user is not logged in into the application %v", app.GetName()) | ||||
| } | ||||
|
|
||||
| tlsCert, err := key.TLSCertificate(cert) | ||||
| return tlsCert, trace.Wrap(err) | ||||
|
Comment on lines
101
to
134
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI I took this from teleport/tool/tsh/common/proxy.go Line 555 in 39af8d3
|
||||
| } | ||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "os/exec" | ||
|
|
||
| "github.com/gravitational/trace" | ||
|
|
||
| "github.com/gravitational/teleport/api/types" | ||
| "github.com/gravitational/teleport/lib/teleterm/gateway" | ||
| ) | ||
|
|
||
| // NewAppCLICommand creates CLI commands for app gateways. | ||
| func NewAppCLICommand(g gateway.Gateway) (*exec.Cmd, error) { | ||
| app, err := gateway.AsApp(g) | ||
| if err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
|
|
||
| if g.Protocol() == types.ApplicationProtocolTCP { | ||
| return exec.Command(""), nil | ||
| } | ||
|
|
||
| cmd := exec.Command("curl", app.LocalProxyURL()) | ||
| return cmd, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Teleport | ||
| * Copyright (C) 2024 Gravitational, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/gravitational/teleport/api/types" | ||
| "github.com/gravitational/teleport/lib/teleterm/gateway" | ||
| ) | ||
|
|
||
| type fakeAppGateway struct { | ||
| gateway.App | ||
| protocol string | ||
| generatedUrl string | ||
| } | ||
|
|
||
| func (m fakeAppGateway) Protocol() string { return m.protocol } | ||
| func (m fakeAppGateway) LocalProxyURL() string { return m.generatedUrl } | ||
|
|
||
| func TestNewAppCLICommand(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| protocol string | ||
| generatedUrl string | ||
| output string | ||
| }{ | ||
| { | ||
| name: "TCP app", | ||
| protocol: types.ApplicationProtocolTCP, | ||
| generatedUrl: "tcp://localhost:8888", | ||
| output: "", | ||
| }, | ||
| { | ||
| name: "HTTP app", | ||
| protocol: types.ApplicationProtocolHTTP, | ||
| generatedUrl: "http://localhost:8888", | ||
| output: "curl http://localhost:8888", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
|
|
||
| mockGateway := fakeAppGateway{ | ||
| protocol: tc.protocol, | ||
| generatedUrl: tc.generatedUrl, | ||
| } | ||
|
|
||
| command, err := NewAppCLICommand(mockGateway) | ||
|
|
||
| require.NoError(t, err) | ||
| cmdString := strings.TrimSpace( | ||
| fmt.Sprintf("%s %s", | ||
| strings.Join(command.Env, " "), | ||
| strings.Join(command.Args, " "))) | ||
|
|
||
| require.Equal(t, cmdString, tc.output) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.