open-vault/builtin/logical/ssh/secret_otp.go

47 lines
1.0 KiB
Go

package ssh
import (
"fmt"
"time"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
const SecretOTPType = "secret_otp_type"
func secretOTP(b *backend) *framework.Secret {
return &framework.Secret{
Type: SecretOTPType,
Fields: map[string]*framework.FieldSchema{
"otp": &framework.FieldSchema{
Type: framework.TypeString,
Description: "One time password",
},
},
DefaultDuration: 10 * time.Minute,
DefaultGracePeriod: 2 * time.Minute,
Revoke: b.secretOTPRevoke,
}
}
func (b *backend) secretOTPRevoke(req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
otpRaw, ok := req.Secret.InternalData["otp"]
if !ok {
return nil, fmt.Errorf("secret is missing internal data")
}
otp, ok := otpRaw.(string)
if !ok {
return nil, fmt.Errorf("secret is missing internal data")
}
otpSalted := b.salt.SaltID(otp)
otpPath := fmt.Sprintf("otp/%s", otpSalted)
err := req.Storage.Delete(otpPath)
if err != nil {
return nil, err
}
return nil, nil
}