-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vnet] install and run windows service
This commit adds a Windows service for VNet. It adds support for automatically installing and running the service when the user runs `tsh vnet`, and adds a command to manually uninstall/delete the service. The service creates the TUN interface and establishes an IPC connection with the user process over a named pipe, but for now does not actually handle any networking, the rest will come in later PRs. If you want to test this out on a Windows machine/VM, you should be able to run `tsh vnet` and see that: 1. A service TeleportVNet is installed and runs `sc.exe query state=all | grep -A3 Teleport` 2. The service writes logs to `logs.txt` in the directory where `tsh` is installed (this is temporary until I find a better place for logs). 3. A TUN interface is created `netsh interface show interface` 4. The service stops and the interface is cleaned up when the user process exits. Unfortunately this PR does not include any unit tests. Most of the functionality here needs to be able to escalate to administrator with a UAC prompt and needs to run on Windows, this is exactly the kind of unit test that is very hard to write and would never actually be able to run in CI. But, any part of this that's broken would immediately break VNet on Windows, and this should be caught in any test plan.
- Loading branch information
Showing
18 changed files
with
770 additions
and
187 deletions.
There are no files selected for viewing
This file contains 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 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 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,66 @@ | ||
// 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 vnet | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gravitational/trace" | ||
"golang.zx2c4.com/wireguard/tun" | ||
) | ||
|
||
type AdminProcessConfig struct { | ||
// TODO(nklaassen): delete these, the admin process will decide them, they | ||
// don't need to be passed from the user process. Keeping them until I | ||
// remove the references from osconfig.go. | ||
IPv6Prefix string | ||
DNSAddr string | ||
HomePath string | ||
} | ||
|
||
// RunAdminProcess must run as administrator. It creates and sets up a TUN | ||
// device and runs the VNet networking stack. | ||
// | ||
// It also handles host OS configuration, OS configuration is updated every [osConfigurationInterval]. | ||
// | ||
// The admin process will stay running until the socket at config.socketPath is | ||
// deleted or until encountering an unrecoverable error. | ||
func RunAdminProcess(ctx context.Context, cfg AdminProcessConfig) error { | ||
log.InfoContext(ctx, "Running VNet admin process", "cfg", cfg) | ||
|
||
device, err := tun.CreateTUN("TeleportVNet", mtu) | ||
if err != nil { | ||
return trace.Wrap(err, "creating TUN device") | ||
} | ||
defer device.Close() | ||
tunName, err := device.Name() | ||
if err != nil { | ||
return trace.Wrap(err, "getting TUN device name") | ||
} | ||
log.InfoContext(ctx, "Created TUN interface", "tun", tunName) | ||
|
||
// TODO(nklaassen): actually run VNet. For now, just stay alive until the | ||
// context is canceled. | ||
<-ctx.Done() | ||
return trace.Wrap(ctx.Err()) | ||
} | ||
|
||
var ( | ||
// Satisfy unused linter. | ||
// TODO(nklaassen): run os configuration loop in admin process. | ||
_ = osConfigurationLoop | ||
) |
This file contains 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 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.