From 094853c10d15defa2651c7452f83f8ee8c338a97 Mon Sep 17 00:00:00 2001 From: Joscha Alisch Date: Tue, 4 Feb 2020 22:13:05 +0100 Subject: [PATCH] Disallow shell access when in readonly mode --- internal/view/container.go | 12 +++++++++++- internal/view/pod.go | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/view/container.go b/internal/view/container.go index 18f1684e..8a6d1357 100644 --- a/internal/view/container.go +++ b/internal/view/container.go @@ -40,11 +40,21 @@ func NewContainer(gvr client.GVR) ResourceViewer { // Name returns the component name. func (c *Container) Name() string { return containerTitle } +func (c *Container) bindDangerousKeys(aa ui.KeyActions) { + aa.Add(ui.KeyActions{ + ui.KeyS: ui.NewKeyAction("Shell", c.shellCmd, true), + }) +} + func (c *Container) bindKeys(aa ui.KeyActions) { aa.Delete(tcell.KeyCtrlSpace, ui.KeySpace) + + if !c.App().Config.K9s.GetReadOnly() { + c.bindDangerousKeys(aa) + } + aa.Add(ui.KeyActions{ ui.KeyShiftF: ui.NewKeyAction("PortForward", c.portFwdCmd, true), - ui.KeyS: ui.NewKeyAction("Shell", c.shellCmd, true), ui.KeyShiftC: ui.NewKeyAction("Sort CPU", c.GetTable().SortColCmd(6, false), false), ui.KeyShiftM: ui.NewKeyAction("Sort MEM", c.GetTable().SortColCmd(7, false), false), ui.KeyShiftX: ui.NewKeyAction("Sort %CPU (REQ)", c.GetTable().SortColCmd(8, false), false), diff --git a/internal/view/pod.go b/internal/view/pod.go index 77e71c8e..cc03de98 100644 --- a/internal/view/pod.go +++ b/internal/view/pod.go @@ -38,6 +38,7 @@ func NewPod(gvr client.GVR) ResourceViewer { func (p *Pod) bindDangerousKeys(aa ui.KeyActions) { aa.Add(ui.KeyActions{ tcell.KeyCtrlK: ui.NewKeyAction("Kill", p.killCmd, true), + ui.KeyS: ui.NewKeyAction("Shell", p.shellCmd, true), }) } @@ -47,7 +48,6 @@ func (p *Pod) bindKeys(aa ui.KeyActions) { } aa.Add(ui.KeyActions{ - ui.KeyS: ui.NewKeyAction("Shell", p.shellCmd, true), ui.KeyShiftR: ui.NewKeyAction("Sort Ready", p.GetTable().SortColCmd(1, true), false), ui.KeyShiftS: ui.NewKeyAction("Sort Status", p.GetTable().SortColCmd(2, true), false), ui.KeyShiftT: ui.NewKeyAction("Sort Restart", p.GetTable().SortColCmd(3, false), false),