mirror of
https://github.com/openziti/zrok.git
synced 2025-06-26 12:42:18 +02:00
Merge branch 'main' into overview_agent_enrollment
This commit is contained in:
commit
8daa97ea46
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
CHANGE: The `/overview` endpoint has been adjusted to include a new `remoteAgent` `boolean` on the `environment` instances, indicating whether or not the environment has an enrolled remote agent (https://github.com/openziti/zrok/issues/977)
|
CHANGE: The `/overview` endpoint has been adjusted to include a new `remoteAgent` `boolean` on the `environment` instances, indicating whether or not the environment has an enrolled remote agent (https://github.com/openziti/zrok/issues/977)
|
||||||
|
|
||||||
|
CHANGE: Adjusted core framework entry points to support changing zrokdir, and host interrogation functions to better support embedded zrok functionality (https://github.com/openziti/zrok/issues/976)
|
||||||
|
|
||||||
## v1.0.5
|
## v1.0.5
|
||||||
|
|
||||||
FEATURE: Initial support for zrok Agent remoting; new `zrok agent enroll` and `zrok agent unenroll` commands that establish opt-in remote Agent management facilities on a per-environment basis. The central API has been augmented to allow for remote control (creating shares and private access instances) of these agents; see the [remoting guide](https://docs.zrok.io/docs/guides/agent/remoting) for details (https://github.com/openziti/zrok/issues/967)
|
FEATURE: Initial support for zrok Agent remoting; new `zrok agent enroll` and `zrok agent unenroll` commands that establish opt-in remote Agent management facilities on a per-environment basis. The central API has been augmented to allow for remote control (creating shares and private access instances) of these agents; see the [remoting guide](https://docs.zrok.io/docs/guides/agent/remoting) for details (https://github.com/openziti/zrok/issues/967)
|
||||||
|
@ -2,6 +2,10 @@ package agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||||
"github.com/openziti/zrok/agent/agentGrpc"
|
"github.com/openziti/zrok/agent/agentGrpc"
|
||||||
"github.com/openziti/zrok/agent/agentUi"
|
"github.com/openziti/zrok/agent/agentUi"
|
||||||
@ -13,9 +17,6 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
@ -66,7 +67,9 @@ func (a *Agent) Run() error {
|
|||||||
a.agentSocket = agentSocket
|
a.agentSocket = agentSocket
|
||||||
|
|
||||||
go a.manager()
|
go a.manager()
|
||||||
|
if a.cfg.ConsoleEnabled {
|
||||||
go a.gateway()
|
go a.gateway()
|
||||||
|
}
|
||||||
go a.remoteAgent()
|
go a.remoteAgent()
|
||||||
|
|
||||||
a.persistRegistry = false
|
a.persistRegistry = false
|
||||||
|
@ -4,6 +4,7 @@ type AgentConfig struct {
|
|||||||
ConsoleAddress string
|
ConsoleAddress string
|
||||||
ConsoleStartPort uint16
|
ConsoleStartPort uint16
|
||||||
ConsoleEndPort uint16
|
ConsoleEndPort uint16
|
||||||
|
ConsoleEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfig() *AgentConfig {
|
func DefaultConfig() *AgentConfig {
|
||||||
@ -11,5 +12,6 @@ func DefaultConfig() *AgentConfig {
|
|||||||
ConsoleAddress: "127.0.0.1",
|
ConsoleAddress: "127.0.0.1",
|
||||||
ConsoleStartPort: 8080,
|
ConsoleStartPort: 8080,
|
||||||
ConsoleEndPort: 8181,
|
ConsoleEndPort: 8181,
|
||||||
|
ConsoleEnabled: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/openziti/zrok/agent"
|
"github.com/openziti/zrok/agent"
|
||||||
"github.com/openziti/zrok/environment"
|
"github.com/openziti/zrok/environment"
|
||||||
"github.com/openziti/zrok/tui"
|
"github.com/openziti/zrok/tui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -54,7 +55,7 @@ func (cmd *agentStartCommand) run(_ *cobra.Command, _ []string) {
|
|||||||
tui.Error("error creating agent", err)
|
tui.Error("error creating agent", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c := make(chan os.Signal)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
|
@ -2,6 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/spinner"
|
"github.com/charmbracelet/bubbles/spinner"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
httptransport "github.com/go-openapi/runtime/client"
|
httptransport "github.com/go-openapi/runtime/client"
|
||||||
@ -9,12 +12,9 @@ import (
|
|||||||
"github.com/openziti/zrok/environment/env_core"
|
"github.com/openziti/zrok/environment/env_core"
|
||||||
restEnvironment "github.com/openziti/zrok/rest_client_zrok/environment"
|
restEnvironment "github.com/openziti/zrok/rest_client_zrok/environment"
|
||||||
"github.com/openziti/zrok/tui"
|
"github.com/openziti/zrok/tui"
|
||||||
"github.com/shirou/gopsutil/v3/host"
|
"github.com/openziti/zrok/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
|
||||||
user2 "os/user"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -51,26 +51,12 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
|
|||||||
tui.Error(fmt.Sprintf("you already have an enabled environment, %v first before you %v", tui.Code.Render("zrok disable"), tui.Code.Render("zrok enable")), nil)
|
tui.Error(fmt.Sprintf("you already have an enabled environment, %v first before you %v", tui.Code.Render("zrok disable"), tui.Code.Render("zrok enable")), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostName, hostDetail, err := getHost()
|
hostName, hostDetail, username, err := util.GetHostDetails()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
var username string
|
hostDetail, cmd.description = util.FormatHostDetailsWithUser(username, hostName, hostDetail, cmd.description)
|
||||||
userObj, err := user2.Current()
|
|
||||||
if err == nil && userObj.Username != "" {
|
|
||||||
username = userObj.Username
|
|
||||||
} else {
|
|
||||||
username = os.Getenv("USER")
|
|
||||||
if username == "" {
|
|
||||||
euid := os.Geteuid()
|
|
||||||
username = fmt.Sprintf("user-%d", euid)
|
|
||||||
logrus.Warnf("unable to determine the current user, using effective UID: %v", euid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hostDetail = fmt.Sprintf("%v; %v", username, hostDetail)
|
|
||||||
if cmd.description == "<user>@<hostname>" {
|
|
||||||
cmd.description = fmt.Sprintf("%v@%v", username, hostName)
|
|
||||||
}
|
|
||||||
zrok, err := env.Client()
|
zrok, err := env.Client()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.endpointError(env.ApiEndpoint())
|
cmd.endpointError(env.ApiEndpoint())
|
||||||
@ -169,16 +155,6 @@ func (cmd *enableCommand) endpointError(apiEndpoint, _ string) {
|
|||||||
fmt.Printf("(where newEndpoint is something like: %v)\n\n", tui.Code.Render("https://some.zrok.io"))
|
fmt.Printf("(where newEndpoint is something like: %v)\n\n", tui.Code.Render("https://some.zrok.io"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHost() (string, string, error) {
|
|
||||||
info, err := host.Info()
|
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
thisHost := fmt.Sprintf("%v; %v; %v; %v; %v; %v; %v",
|
|
||||||
info.Hostname, info.OS, info.Platform, info.PlatformFamily, info.PlatformVersion, info.KernelVersion, info.KernelArch)
|
|
||||||
return info.Hostname, thisHost, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type enableTuiModel struct {
|
type enableTuiModel struct {
|
||||||
spinner spinner.Model
|
spinner spinner.Model
|
||||||
msg string
|
msg string
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/openziti/sdk-golang/ziti"
|
"github.com/openziti/sdk-golang/ziti"
|
||||||
"github.com/openziti/zrok/cmd/zrok/endpointUi"
|
"github.com/openziti/zrok/cmd/zrok/endpointUi"
|
||||||
"github.com/openziti/zrok/tui"
|
"github.com/openziti/zrok/tui"
|
||||||
|
"github.com/openziti/zrok/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -200,7 +201,7 @@ func newEndpointData(r *http.Request) *endpointData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ed *endpointData) getHostInfo() {
|
func (ed *endpointData) getHostInfo() {
|
||||||
host, hostDetail, err := getHost()
|
host, hostDetail, _, err := util.GetHostDetails()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error getting host detail: %v", err)
|
logrus.Errorf("error getting host detail: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,12 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SetRootDirName allows setting a custom name for the root directory.
|
||||||
|
// This should be called before any other environment operations.
|
||||||
|
func SetRootDirName(name string) {
|
||||||
|
env_v0_4.SetRootDirName(name)
|
||||||
|
}
|
||||||
|
|
||||||
func LoadRoot() (env_core.Root, error) {
|
func LoadRoot() (env_core.Root, error) {
|
||||||
if assert, err := env_v0_4.Assert(); assert && err == nil {
|
if assert, err := env_v0_4.Assert(); assert && err == nil {
|
||||||
return env_v0_4.Load()
|
return env_v0_4.Load()
|
||||||
|
@ -6,12 +6,18 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var rootDirName = ".zrok"
|
||||||
|
|
||||||
|
func SetRootDirName(name string) {
|
||||||
|
rootDirName = name
|
||||||
|
}
|
||||||
|
|
||||||
func rootDir() (string, error) {
|
func rootDir() (string, error) {
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return filepath.Join(home, ".zrok"), nil
|
return filepath.Join(home, rootDirName), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func metadataFile() (string, error) {
|
func metadataFile() (string, error) {
|
||||||
|
51
util/host.go
Normal file
51
util/host.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/shirou/gopsutil/v3/host"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetHostDetails returns the hostname, detailed host information, and username.
|
||||||
|
// The detailed host information includes OS, platform, kernel details, and username.
|
||||||
|
func GetHostDetails() (hostname string, hostDetail string, username string, err error) {
|
||||||
|
info, err := host.Info()
|
||||||
|
if err != nil {
|
||||||
|
return "", "", "", err
|
||||||
|
}
|
||||||
|
hostname = info.Hostname
|
||||||
|
|
||||||
|
userObj, err := user.Current()
|
||||||
|
if err == nil && userObj.Username != "" {
|
||||||
|
username = userObj.Username
|
||||||
|
} else {
|
||||||
|
username = os.Getenv("USER")
|
||||||
|
if username == "" {
|
||||||
|
euid := os.Geteuid()
|
||||||
|
username = fmt.Sprintf("user-%d", euid)
|
||||||
|
logrus.Warnf("unable to determine the current user, using effective UID: %v", euid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hostDetail = fmt.Sprintf("%v; %v; %v; %v; %v; %v; %v",
|
||||||
|
info.Hostname, info.OS, info.Platform, info.PlatformFamily,
|
||||||
|
info.PlatformVersion, info.KernelVersion, info.KernelArch)
|
||||||
|
|
||||||
|
return hostname, hostDetail, username, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormatHostDetailsWithUser combines the username and host details into a single string.
|
||||||
|
// It also returns a formatted description string if the input description is the default "<user>@<hostname>".
|
||||||
|
func FormatHostDetailsWithUser(username, hostname, hostDetail, description string) (formattedHostDetail, formattedDescription string) {
|
||||||
|
formattedHostDetail = fmt.Sprintf("%v; %v", username, hostDetail)
|
||||||
|
|
||||||
|
if description == "<user>@<hostname>" {
|
||||||
|
formattedDescription = fmt.Sprintf("%v@%v", username, hostname)
|
||||||
|
} else {
|
||||||
|
formattedDescription = description
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedHostDetail, formattedDescription
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user