-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from markwirth-mw/ssh-key_signing
add ssh-key signing
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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"` | ||
} | ||
|
||
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 | ||
} |