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

Remove feature flag for VNet launch daemon #44923

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/img/use-teleport/vnet-starting@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions docs/pages/connect-your-client/vnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ have `tcp://` as the protocol in their addresses.
Click "Connect" next to the TCP app. This starts VNet if it's not already running. Alternatively,
you can start VNet through the connection list in the top left.

VNet needs to set up a network device and configure DNS on your device, so it'll ask for admin
permissions. For now your password is needed each time you start VNet, but we're working on showing
the prompt only once.
During the first launch, macOS will prompt you to enable a background item for tsh.app. VNet needs
this background item in order to configure DNS on your device. To enable the background item, either
interact with the system notification or go to System Settings > General > Logit Items and look for
ravicious marked this conversation as resolved.
Show resolved Hide resolved
tsh.app under "Allow in the Background".

![VNet starting up](../../img/use-teleport/vnet-starting@2x.png)

Expand Down
80 changes: 43 additions & 37 deletions gen/proto/go/teleport/lib/teleterm/vnet/v1/vnet_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions lib/teleterm/vnet/service_daemon_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ package vnet

import (
"context"
"os"

"github.com/gravitational/trace"

api "github.com/gravitational/teleport/gen/proto/go/teleport/lib/teleterm/vnet/v1"
"github.com/gravitational/teleport/lib/vnet"
vnetdaemon "github.com/gravitational/teleport/lib/vnet/daemon"
)

func (s *Service) GetBackgroundItemStatus(ctx context.Context, req *api.GetBackgroundItemStatusRequest) (*api.GetBackgroundItemStatusResponse, error) {
if os.Getenv(vnet.EnvFeatureFlag) != "yes" {
return nil, trace.NotImplemented("tsh was built with VNet daemon support, but the feature flag is not enabled")
}

status, err := vnetdaemon.DaemonStatus()
if err != nil {
return nil, trace.Wrap(err)
Expand All @@ -55,6 +49,8 @@ func backgroundItemStatusFromServiceStatus(status vnetdaemon.ServiceStatus) api.
return api.BackgroundItemStatus_BACKGROUND_ITEM_STATUS_REQUIRES_APPROVAL
case vnetdaemon.ServiceStatusNotFound:
return api.BackgroundItemStatus_BACKGROUND_ITEM_STATUS_NOT_FOUND
case vnetdaemon.ServiceStatusNotSupported:
return api.BackgroundItemStatus_BACKGROUND_ITEM_STATUS_NOT_SUPPORTED
default:
return api.BackgroundItemStatus_BACKGROUND_ITEM_STATUS_UNSPECIFIED
}
Expand Down
4 changes: 4 additions & 0 deletions lib/vnet/daemon/client_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ const (
ServiceStatusEnabled ServiceStatus = 1
ServiceStatusRequiresApproval ServiceStatus = 2
ServiceStatusNotFound ServiceStatus = 3
// ServiceStatusNotSupported is returned by us when macOS version is < 13.0.
ServiceStatusNotSupported ServiceStatus = -1
)

func (s ServiceStatus) String() string {
Expand All @@ -212,6 +214,8 @@ func (s ServiceStatus) String() string {
return "requires approval"
case ServiceStatusNotFound:
return "not found"
case ServiceStatusNotSupported:
return "not supported"
default:
return strconv.Itoa(int(s))
}
Expand Down
10 changes: 1 addition & 9 deletions lib/vnet/setup_daemon_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@ package vnet

import (
"context"
"os"

"github.com/gravitational/trace"

"github.com/gravitational/teleport/lib/vnet/daemon"
)

const EnvFeatureFlag = "VNETDAEMON"

func execAdminProcess(ctx context.Context, config daemon.Config) error {
// TODO(ravicious): Remove the feature env var after the daemon gets implemented.
if os.Getenv(EnvFeatureFlag) == "yes" {
return trace.Wrap(daemon.RegisterAndCall(ctx, config))
}

return trace.Wrap(execAdminSubcommand(ctx, config))
return trace.Wrap(daemon.RegisterAndCall(ctx, config))
}

func DaemonSubcommand(ctx context.Context) error {
Expand Down
1 change: 1 addition & 0 deletions proto/teleport/lib/teleterm/vnet/v1/vnet_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ enum BackgroundItemStatus {
BACKGROUND_ITEM_STATUS_ENABLED = 2;
BACKGROUND_ITEM_STATUS_REQUIRES_APPROVAL = 3;
BACKGROUND_ITEM_STATUS_NOT_FOUND = 4;
BACKGROUND_ITEM_STATUS_NOT_SUPPORTED = 5;
Copy link
Member Author

Choose a reason for hiding this comment

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

Negative values for enum are supported but not recommended, so I just used 5 instead. On top of that, BackgroundItemStatus in protos already doesn't map 1:1 to the actual status returned by macOS, because 0 returned by macOS means "not registered", whereas in protos 0 should be reserved "unspecified".

}
43 changes: 43 additions & 0 deletions tool/tsh/common/vnet_daemon_darwin.go
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/>.

//go:build vnetdaemon
// +build vnetdaemon

package common

import (
"log/slog"

"github.com/gravitational/trace"

"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/vnet"
)

func (c *vnetDaemonCommand) run(cf *CLIConf) error {
if cf.Debug {
utils.InitLogger(utils.LoggingForDaemon, slog.LevelDebug)
} else {
utils.InitLogger(utils.LoggingForDaemon, slog.LevelInfo)
}

return trace.Wrap(vnet.DaemonSubcommand(cf.Context))
}

func (c *vnetAdminSetupCommand) run(cf *CLIConf) error {
return trace.NotImplemented("tsh was built with support for VNet daemon, use %s instead", vnetDaemonSubCommand)
}
41 changes: 3 additions & 38 deletions tool/tsh/common/vnet_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ package common

import (
"fmt"
"log/slog"
"os"

"github.com/alecthomas/kingpin/v2"
"github.com/gravitational/trace"

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/vnet"
"github.com/gravitational/teleport/lib/vnet/daemon"
)

type vnetCommand struct {
Expand Down Expand Up @@ -100,28 +95,6 @@ func newVnetAdminSetupCommand(app *kingpin.Application) *vnetAdminSetupCommand {
return cmd
}

func (c *vnetAdminSetupCommand) run(cf *CLIConf) error {
homePath := os.Getenv(types.HomeEnvVar)
if homePath == "" {
// This runs as root so we need to be configured with the user's home path.
return trace.BadParameter("%s must be set", types.HomeEnvVar)
}

config := daemon.Config{
SocketPath: c.socketPath,
IPv6Prefix: c.ipv6Prefix,
DNSAddr: c.dnsAddr,
HomePath: homePath,
ClientCred: daemon.ClientCred{
Valid: true,
Egid: c.egid,
Euid: c.euid,
},
}

return trace.Wrap(vnet.AdminSetup(cf.Context, config))
}

type vnetDaemonCommand struct {
*kingpin.CmdClause
// Launch daemons added through SMAppService are launched from a static .plist file, hence
Expand All @@ -131,17 +104,9 @@ type vnetDaemonCommand struct {

func newVnetDaemonCommand(app *kingpin.Application) *vnetDaemonCommand {
return &vnetDaemonCommand{
// The command must match the command provided in the .plist file.
CmdClause: app.Command("vnet-daemon", "Start the VNet daemon").Hidden(),
CmdClause: app.Command(vnetDaemonSubCommand, "Start the VNet daemon").Hidden(),
}
}

func (c *vnetDaemonCommand) run(cf *CLIConf) error {
if cf.Debug {
utils.InitLogger(utils.LoggingForDaemon, slog.LevelDebug)
} else {
utils.InitLogger(utils.LoggingForDaemon, slog.LevelInfo)
}

return trace.Wrap(vnet.DaemonSubcommand(cf.Context))
}
// The command must match the command provided in the .plist file.
const vnetDaemonSubCommand = "vnet-daemon"
56 changes: 56 additions & 0 deletions tool/tsh/common/vnet_nodaemon_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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/>.

//go:build !vnetdaemon
// +build !vnetdaemon

package common

import (
"os"

"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/vnet"
"github.com/gravitational/teleport/lib/vnet/daemon"
)

func (c *vnetDaemonCommand) run(cf *CLIConf) error {
return trace.NotImplemented("tsh was built without support for VNet daemon")
}

func (c *vnetAdminSetupCommand) run(cf *CLIConf) error {
homePath := os.Getenv(types.HomeEnvVar)
if homePath == "" {
// This runs as root so we need to be configured with the user's home path.
return trace.BadParameter("%s must be set", types.HomeEnvVar)
}

config := daemon.Config{
SocketPath: c.socketPath,
IPv6Prefix: c.ipv6Prefix,
DNSAddr: c.dnsAddr,
HomePath: homePath,
ClientCred: daemon.ClientCred{
Valid: true,
Egid: c.egid,
Euid: c.euid,
},
}

return trace.Wrap(vnet.AdminSetup(cf.Context, config))
}
3 changes: 0 additions & 3 deletions web/packages/teleterm/src/mainProcess/mainProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ export default class MainProcess {
env: {
...process.env,
TELEPORT_HOME: homeDir,
VNETDAEMON: this.configService.get('feature.vnetDaemon').value
? 'yes'
: undefined,
},
}
);
Expand Down
Loading
Loading