-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Teleport Connect Kube gateway POC #27287
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import ( | |
|
|
||
| "github.com/gravitational/trace" | ||
|
|
||
| "github.com/gravitational/teleport/lib/teleterm/api/uri" | ||
| "github.com/gravitational/teleport/lib/teleterm/gateway" | ||
| "github.com/gravitational/teleport/lib/tlsca" | ||
| ) | ||
|
|
@@ -42,6 +43,21 @@ type CreateGatewayParams struct { | |
|
|
||
| // CreateGateway creates a gateway | ||
| func (c *Cluster) CreateGateway(ctx context.Context, params CreateGatewayParams) (*gateway.Gateway, error) { | ||
| switch { | ||
| case uri.IsDB(params.TargetURI): | ||
| gw, err := c.createDatabaseGateway(ctx, params) | ||
| return gw, trace.Wrap(err) | ||
|
|
||
| case uri.IsKube(params.TargetURI): | ||
| gw, err := c.createKubeGateway(ctx, params) | ||
| return gw, trace.Wrap(err) | ||
|
|
||
| default: | ||
| return nil, trace.NotImplemented("gateway not supported for %v", params.TargetURI) | ||
| } | ||
| } | ||
|
ravicious marked this conversation as resolved.
|
||
|
|
||
| func (c *Cluster) createDatabaseGateway(ctx context.Context, params CreateGatewayParams) (*gateway.Gateway, error) { | ||
| db, err := c.GetDatabase(ctx, params.TargetURI) | ||
| if err != nil { | ||
| return nil, trace.Wrap(err) | ||
|
|
@@ -67,6 +83,7 @@ func (c *Cluster) CreateGateway(ctx context.Context, params CreateGatewayParams) | |
| KeyPath: c.status.KeyPath(), | ||
| CertPath: c.status.DatabaseCertPathForCluster(c.clusterClient.SiteName, db.GetName()), | ||
| Insecure: c.clusterClient.InsecureSkipVerify, | ||
| ClusterName: c.Name, | ||
| WebProxyAddr: c.clusterClient.WebProxyAddr, | ||
| Log: c.Log, | ||
| CLICommandProvider: params.CLICommandProvider, | ||
|
|
@@ -82,3 +99,34 @@ func (c *Cluster) CreateGateway(ctx context.Context, params CreateGatewayParams) | |
|
|
||
| return gw, nil | ||
| } | ||
|
|
||
| func (c *Cluster) createKubeGateway(ctx context.Context, params CreateGatewayParams) (*gateway.Gateway, error) { | ||
| kubeCluster := uri.New(params.TargetURI).GetKubeName() | ||
| if kubeCluster == "" { | ||
| return nil, trace.BadParameter("invalid TargetURI %v for Kube gateway", params.TargetURI) | ||
| } | ||
|
Comment on lines
+104
to
+107
Member
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. A side note, I have an issue open (#15953) to cast strings to URIs on the gRPC handler level instead of "poisoning" the rest of the app with parsing URIs, what I don't have is the time to do this as it'd require some bigger changes throughout lib/teleterm. 😶🌫️ |
||
|
|
||
| if err := c.ReissueKubeCerts(ctx, kubeCluster); err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
|
|
||
| // TODO support TargetUser (--as), TargetGroups (--as-groups), TargetSubresourceName (--kube-namespace) | ||
| gw, err := gateway.New(gateway.Config{ | ||
| LocalPort: params.LocalPort, | ||
| TargetURI: params.TargetURI, | ||
| TargetName: kubeCluster, | ||
| KeyPath: c.status.KeyPath(), | ||
| CertPath: c.status.KubeCertPath(kubeCluster), | ||
| Insecure: c.clusterClient.InsecureSkipVerify, | ||
| ClusterName: c.Name, | ||
| WebProxyAddr: c.clusterClient.WebProxyAddr, | ||
| Log: c.Log, | ||
| CLICommandProvider: params.CLICommandProvider, | ||
| TCPPortAllocator: params.TCPPortAllocator, | ||
| OnExpiredCert: params.OnExpiredCert, | ||
| Clock: c.clock, | ||
| TLSRoutingConnUpgradeRequired: c.clusterClient.TLSRoutingConnUpgradeRequired, | ||
| RootClusterCACertPoolFunc: c.clusterClient.RootClusterCACertPool, | ||
| }) | ||
| return gw, trace.Wrap(err) | ||
| } | ||
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,34 @@ | ||
| // Copyright 2023 Gravitational, Inc | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package clusters | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os/exec" | ||
|
|
||
| "github.com/gravitational/teleport" | ||
| "github.com/gravitational/teleport/lib/teleterm/gateway" | ||
| ) | ||
|
|
||
| // TODO | ||
| type KubeCLICommandProvider struct { | ||
| } | ||
|
|
||
| func (p KubeCLICommandProvider) GetCommand(gateway *gateway.Gateway) (*exec.Cmd, error) { | ||
| // Use kubectl version as placeholders. Only env should be used. | ||
| cmd := exec.Command("kubectl", "version") | ||
| cmd.Env = []string{fmt.Sprintf("%v=%v", teleport.EnvKubeConfig, gateway.KubeconfigPath())} | ||
| return cmd, nil | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have time to look into this closely, but why do kube proxies need a separate
*WithRandomPortfunction whereas db proxies do not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db has a single ALPN local proxy, which should serve the port user specified.
kube (and other HTTP proxies like aws/azure/gcp) has two local proxies, one HTTPS_PROXY (in code it's called forward proxy) and the ALPN local proxy. Client connects through HTTPS_PROXY so it should use the port user specified. The HTTPS_PROXY forwards to the ALPN local proxy where it can use a random port.
The preivous
NewKubeListenercreates the tcp listener within itself. But gateway code needs to pass in a tcp listener.