From 0a59e84cefbfce1b35c5adfaccc6cf7c3ea83091 Mon Sep 17 00:00:00 2001 From: Vishal Nayak Date: Mon, 6 Jul 2015 11:05:02 -0400 Subject: [PATCH] Vault SSH: Revoking key after SSH session from CLI --- api/ssh.go | 10 ++++++++++ command/ssh.go | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/api/ssh.go b/api/ssh.go index 3fa8a28c07..7c572445cc 100644 --- a/api/ssh.go +++ b/api/ssh.go @@ -15,6 +15,16 @@ func (c *Client) SSH() *SSH { return &SSH{c: c} } +// Invokes the SSH backend API to revoke a key identified by its lease ID. +func (c *SSH) KeyRevoke(id string) error { + r := c.c.NewRequest("PUT", "/v1/sys/revoke/"+id) + resp, err := c.c.RawRequest(r) + if err == nil { + defer resp.Body.Close() + } + return err +} + // Invokes the SSH backend API to create a dynamic key func (c *SSH) KeyCreate(role string, data map[string]interface{}) (*Secret, error) { r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/ssh/creds/%s", role)) diff --git a/command/ssh.go b/command/ssh.go index 81960417f5..e4232f67e8 100644 --- a/command/ssh.go +++ b/command/ssh.go @@ -80,7 +80,12 @@ func (c *SSHCommand) Run(args []string) int { err = os.Remove(sshDynamicKeyFileName) if err != nil { - c.Ui.Error(fmt.Sprintf("Error deleting temporary file:%s", sshDynamicKeyFileName)) + c.Ui.Error("Error cleaning up") // Intentionally not mentioning the exact error + } + + err = client.SSH().KeyRevoke(keySecret.LeaseID) + if err != nil { + c.Ui.Error("Error cleaning up") // Intentionally not mentioning the exact error } return 0