Disallow shell access when in readonly mode

mine
Joscha Alisch 2020-02-04 22:13:05 +01:00
parent 0ad25ba2f5
commit 094853c10d
No known key found for this signature in database
GPG Key ID: 5CD84D89434B6CB5
2 changed files with 12 additions and 2 deletions

View File

@ -40,11 +40,21 @@ func NewContainer(gvr client.GVR) ResourceViewer {
// Name returns the component name. // Name returns the component name.
func (c *Container) Name() string { return containerTitle } 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) { func (c *Container) bindKeys(aa ui.KeyActions) {
aa.Delete(tcell.KeyCtrlSpace, ui.KeySpace) aa.Delete(tcell.KeyCtrlSpace, ui.KeySpace)
if !c.App().Config.K9s.GetReadOnly() {
c.bindDangerousKeys(aa)
}
aa.Add(ui.KeyActions{ aa.Add(ui.KeyActions{
ui.KeyShiftF: ui.NewKeyAction("PortForward", c.portFwdCmd, true), 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.KeyShiftC: ui.NewKeyAction("Sort CPU", c.GetTable().SortColCmd(6, false), false),
ui.KeyShiftM: ui.NewKeyAction("Sort MEM", c.GetTable().SortColCmd(7, 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), ui.KeyShiftX: ui.NewKeyAction("Sort %CPU (REQ)", c.GetTable().SortColCmd(8, false), false),

View File

@ -38,6 +38,7 @@ func NewPod(gvr client.GVR) ResourceViewer {
func (p *Pod) bindDangerousKeys(aa ui.KeyActions) { func (p *Pod) bindDangerousKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{ aa.Add(ui.KeyActions{
tcell.KeyCtrlK: ui.NewKeyAction("Kill", p.killCmd, true), 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{ 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.KeyShiftR: ui.NewKeyAction("Sort Ready", p.GetTable().SortColCmd(1, true), false),
ui.KeyShiftS: ui.NewKeyAction("Sort Status", p.GetTable().SortColCmd(2, 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), ui.KeyShiftT: ui.NewKeyAction("Sort Restart", p.GetTable().SortColCmd(3, false), false),