-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathssh.go
77 lines (67 loc) · 1.51 KB
/
ssh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package vault
type SSH struct {
Service
}
func (c *Client) SSH() *SSH {
return c.SSHWithMountPoint("ssh")
}
func (c *Client) SSHWithMountPoint(mountPoint string) *SSH {
return &SSH{
Service: Service{
client: c,
MountPoint: mountPoint,
},
}
}
type SSHSignOptions struct {
PublicKey string `json:"public_key"`
CertType string `json:"cert_type,omitempty"`
ValidPrincipals string `json:"valid_principals,omitempty"`
}
type SSHSignResponse struct {
LeaseID string `json:"lease_id"`
Renewable bool `json:"renewable"`
LeaseDuration int `json:"lease_duration"`
Data struct {
SerialNumber string `json:"serial_number"`
SignedKey string `json:"signed_key"`
} `json:"data"`
}
type SSHReadPubKeyResponse struct {
LeaseID string `json:"lease_id"`
Renewable bool `json:"renewable"`
LeaseDuration int `json:"lease_duration"`
Data struct {
PublicKey string `json:"public_key"`
} `json:"data"`
}
func (k *SSH) Sign(role string, sshopts SSHSignOptions) (*SSHSignResponse, error) {
response := &SSHSignResponse{}
err := k.client.Write(
[]string{
"v1",
k.MountPoint,
"sign",
role,
}, sshopts, response, nil,
)
if err != nil {
return nil, err
}
return response, nil
}
func (k *SSH) GetVaultPubKey() (string, error) {
response := &SSHReadPubKeyResponse{}
err := k.client.Read(
[]string{
"v1",
k.MountPoint,
"config",
"ca",
}, response, nil,
)
if err != nil {
return "", err
}
return response.Data.PublicKey, nil
}