mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Vault SSH: Revoking key after SSH session from CLI
This commit is contained in:
10
api/ssh.go
10
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))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user