summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2020-12-26 11:44:31 +0000
committerPaul Buetow <git@mx.buetow.org>2020-12-26 11:44:31 +0000
commit60fa324cd5296b088c24d8db1d334a25ca955788 (patch)
tree88c14b39b66f5273cebf96307c86293b178cce40
parentab676c2b484225ed22765b23d8f0545088ecd610 (diff)
initial spartan mode support
-rw-r--r--cmd/dcat/main.go1
-rw-r--r--cmd/dgrep/main.go1
-rw-r--r--cmd/dmap/main.go1
-rw-r--r--cmd/dtail/main.go1
-rw-r--r--internal/clients/args.go1
-rw-r--r--internal/clients/baseclient.go2
-rw-r--r--internal/clients/catclient.go3
-rw-r--r--internal/clients/grepclient.go3
-rw-r--r--internal/clients/maprclient.go3
-rw-r--r--internal/clients/stats.go4
-rw-r--r--internal/clients/tailclient.go3
-rw-r--r--internal/server/handlers/serverhandler.go7
-rw-r--r--internal/user/server/user.go4
-rw-r--r--samples/dtail.json.sample9
14 files changed, 30 insertions, 13 deletions
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go
index 05e46ab..851936a 100644
--- a/cmd/dcat/main.go
+++ b/cmd/dcat/main.go
@@ -29,6 +29,7 @@ func main() {
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
+ flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
flag.IntVar(&sshPort, "port", 2222, "SSH server port")
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index 133631f..7da9082 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -31,6 +31,7 @@ func main() {
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
+ flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
flag.IntVar(&sshPort, "port", 2222, "SSH server port")
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go
index 9f9ca9d..56ac168 100644
--- a/cmd/dmap/main.go
+++ b/cmd/dmap/main.go
@@ -34,6 +34,7 @@ func main() {
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
+ flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
flag.IntVar(&sshPort, "port", 2222, "SSH server port")
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index aefaa6a..e9166df 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -42,6 +42,7 @@ func main() {
flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
+ flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
diff --git a/internal/clients/args.go b/internal/clients/args.go
index 34fcfa2..cd0f174 100644
--- a/internal/clients/args.go
+++ b/internal/clients/args.go
@@ -22,4 +22,5 @@ type Args struct {
SSHAuthMethods []gossh.AuthMethod
SSHHostKeyCallback gossh.HostKeyCallback
PrivateKeyPathFile string
+ Spartan bool
}
diff --git a/internal/clients/baseclient.go b/internal/clients/baseclient.go
index 69055a3..1e40ff2 100644
--- a/internal/clients/baseclient.go
+++ b/internal/clients/baseclient.go
@@ -70,7 +70,7 @@ func (c *baseClient) Start(ctx context.Context, statsCh <-chan string) (status i
// Periodically check for unknown hosts, and ask the user whether to trust them or not.
go c.hostKeyCallback.PromptAddHosts(ctx)
// Print client stats every time something on statsCh is recieved.
- go c.stats.Start(ctx, c.throttleCh, statsCh)
+ go c.stats.Start(ctx, c.throttleCh, statsCh, c.Args.Spartan)
// Keep count of active connections
active := make(chan struct{}, len(c.connections))
diff --git a/internal/clients/catclient.go b/internal/clients/catclient.go
index d8e9196..50a8d18 100644
--- a/internal/clients/catclient.go
+++ b/internal/clients/catclient.go
@@ -42,8 +42,9 @@ func (c CatClient) makeHandler(server string) handlers.Handler {
}
func (c CatClient) makeCommands() (commands []string) {
+ options := fmt.Sprintf("spartan=%v", c.Args.Spartan)
for _, file := range strings.Split(c.What, ",") {
- commands = append(commands, fmt.Sprintf("%s %s %s", c.Mode.String(), file, c.Regex.Serialize()))
+ commands = append(commands, fmt.Sprintf("%s:%s %s %s", c.Mode.String(), options, file, c.Regex.Serialize()))
}
return
}
diff --git a/internal/clients/grepclient.go b/internal/clients/grepclient.go
index e6fc94a..5fa0ae0 100644
--- a/internal/clients/grepclient.go
+++ b/internal/clients/grepclient.go
@@ -41,8 +41,9 @@ func (c GrepClient) makeHandler(server string) handlers.Handler {
}
func (c GrepClient) makeCommands() (commands []string) {
+ options := fmt.Sprintf("spartan=%v", c.Args.Spartan)
for _, file := range strings.Split(c.What, ",") {
- commands = append(commands, fmt.Sprintf("%s %s %s", c.Mode.String(), file, c.Regex.Serialize()))
+ commands = append(commands, fmt.Sprintf("%s:%s %s %s", c.Mode.String(), options, file, c.Regex.Serialize()))
}
return
diff --git a/internal/clients/maprclient.go b/internal/clients/maprclient.go
index 6aadd6b..d201d40 100644
--- a/internal/clients/maprclient.go
+++ b/internal/clients/maprclient.go
@@ -112,6 +112,7 @@ func (c MaprClient) makeHandler(server string) handlers.Handler {
func (c MaprClient) makeCommands() (commands []string) {
commands = append(commands, fmt.Sprintf("map %s", c.query.RawQuery))
+ options := fmt.Sprintf("spartan=%v", c.Args.Spartan)
modeStr := "cat"
if c.Mode == omode.TailClient {
@@ -123,7 +124,7 @@ func (c MaprClient) makeCommands() (commands []string) {
commands = append(commands, fmt.Sprintf("timeout %d %s %s %s", c.Timeout, modeStr, file, c.Regex.Serialize()))
continue
}
- commands = append(commands, fmt.Sprintf("%s %s %s", modeStr, file, c.Regex.Serialize()))
+ commands = append(commands, fmt.Sprintf("%s:%s %s %s", modeStr, options, file, c.Regex.Serialize()))
}
return
diff --git a/internal/clients/stats.go b/internal/clients/stats.go
index 2ec6f22..3ea59b7 100644
--- a/internal/clients/stats.go
+++ b/internal/clients/stats.go
@@ -34,7 +34,7 @@ func newTailStats(connectionsTotal int) *stats {
// Start starts printing client connection stats every time a signal is recieved or
// connection count has changed.
-func (s *stats) Start(ctx context.Context, throttleCh <-chan struct{}, statsCh <-chan string) {
+func (s *stats) Start(ctx context.Context, throttleCh <-chan struct{}, statsCh <-chan string, spartan bool) {
var connectedLast int
for {
@@ -55,7 +55,7 @@ func (s *stats) Start(ctx context.Context, throttleCh <-chan struct{}, statsCh <
newConnections := connected - connectedLast
- if connected == connectedLast && !force {
+ if (connected == connectedLast || spartan) && !force {
continue
}
diff --git a/internal/clients/tailclient.go b/internal/clients/tailclient.go
index ff2f46e..853bdf1 100644
--- a/internal/clients/tailclient.go
+++ b/internal/clients/tailclient.go
@@ -38,8 +38,9 @@ func (c TailClient) makeHandler(server string) handlers.Handler {
}
func (c TailClient) makeCommands() (commands []string) {
+ options := fmt.Sprintf("spartan=%v", c.Args.Spartan)
for _, file := range strings.Split(c.What, ",") {
- commands = append(commands, fmt.Sprintf("%s %s %s", c.Mode.String(), file, c.Regex.Serialize()))
+ commands = append(commands, fmt.Sprintf("%s:%s %s %s", c.Mode.String(), options, file, c.Regex.Serialize()))
}
logger.Debug(commands)
diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go
index 3d1a53d..5b948b3 100644
--- a/internal/server/handlers/serverhandler.go
+++ b/internal/server/handlers/serverhandler.go
@@ -43,6 +43,7 @@ type ServerHandler struct {
ackCloseReceived chan struct{}
activeCommands int32
activeReaders int32
+ spartan bool
}
// NewServerHandler returns the server handler.
@@ -245,6 +246,12 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args []
commandFinished()
return
}
+ if spartan, ok := options["spartan"]; ok {
+ if spartan == "true" {
+ logger.Debug(h.user, "Enabling spartan mode")
+ h.spartan = true
+ }
+ }
switch commandName {
case "grep", "cat":
diff --git a/internal/user/server/user.go b/internal/user/server/user.go
index c4e8b7b..637945c 100644
--- a/internal/user/server/user.go
+++ b/internal/user/server/user.go
@@ -40,6 +40,10 @@ func (u *User) String() string {
// HasFilePermission is used to determine whether user is alowed to read a file.
func (u *User) HasFilePermission(filePath, permissionType string) (hasPermission bool) {
logger.Debug(u, filePath, permissionType, "Checking config permissions")
+ if config.ServerRelaxedAuthEnable {
+ logger.Fatal(u, filePath, permissionType, "Server releaxed auth enabled")
+ return true
+ }
if u.Name == config.ScheduleUser || u.Name == config.ContinuousUser {
// Background user has same permissions as dtail process itself.
diff --git a/samples/dtail.json.sample b/samples/dtail.json.sample
index fa799ce..33d445f 100644
--- a/samples/dtail.json.sample
+++ b/samples/dtail.json.sample
@@ -10,19 +10,16 @@
"HostKeyBits" : 2048,
"Permissions": {
"Default": [
- "readfiles:^/.*$",
- "runcommands:^/.*$"
+ "readfiles:^/.*$"
],
"Users": {
"pbuetow": [
- "readfiles:^/.*$",
- "runcommands:^/.*$"
+ "readfiles:^/.*$"
],
"jblake": [
"readfiles:^/tmp/foo.log$",
"readfiles:^/.*$",
- "readfiles:!^/tmp/bar.log$",
- "runcommands:!^/.*$"
+ "readfiles:!^/tmp/bar.log$"
]
}
}