Skip to content

Commit 283f327

Browse files
committed
add ssh-key signing
1 parent 7a64d52 commit 283f327

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

ssh.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package vault
2+
3+
type SSH struct {
4+
Service
5+
}
6+
7+
func (c *Client) SSH() *SSH {
8+
return c.SSHWithMountPoint("ssh")
9+
}
10+
11+
func (c *Client) SSHWithMountPoint(mountPoint string) *SSH {
12+
return &SSH{
13+
Service: Service{
14+
client: c,
15+
MountPoint: mountPoint,
16+
},
17+
}
18+
}
19+
20+
type SSHSignOptions struct {
21+
PublicKey string `json:"public_key"`
22+
CertType string `json:"cert_type,omitempty"`
23+
ValidPrincipals string `json:"valid_principals,omitempty"`
24+
}
25+
26+
type SSHSignResponse struct {
27+
LeaseID string `json:"lease_id"`
28+
Renewable bool `json:"renewable"`
29+
LeaseDuration int `json:"lease_duration"`
30+
Data struct {
31+
SerialNumber string `json:"serial_number"`
32+
SignedKey string `json:"signed_key"`
33+
} `json:"data"`
34+
}
35+
36+
func (k *SSH) Sign(role string, sshopts SSHSignOptions) (*SSHSignResponse, error) {
37+
response := &SSHSignResponse{}
38+
err := k.client.Write(
39+
[]string{
40+
"v1",
41+
k.MountPoint,
42+
"sign",
43+
role,
44+
}, sshopts, response, nil,
45+
)
46+
if err != nil {
47+
return nil, err
48+
}
49+
50+
return response, nil
51+
}

0 commit comments

Comments
 (0)