Documentation
¶
Overview ¶
Package sshkey reads SSH public keys from flags and files. It provides the kong flag structs the commands share, validates the keys they are passed in the authorized_keys format and converts them to the API types.
Index ¶
- func AnyFile(files []*os.File) bool
- func ParseAuthorizedKeys(r io.Reader) ([]string, error)
- func ReadAuthorizedKeys(w *format.Writer, flag string, values []string, files []*os.File) ([]string, error)
- func StorageKeysWithDeprecatedFile(w *format.Writer, keys []string, deprecatedFile *os.File) ([]storage.SSHKey, error)
- func StorageSSHKeys(keys []string) []storage.SSHKey
- type DeprecatedKeysFlags
- type SSHKeysFlags
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyFile ¶
AnyFile reports whether files holds at least one file Kong decoded. A repeated file flag may hold nil entries, those do not count as passed as there is nothing to read from them.
func ParseAuthorizedKeys ¶
ParseAuthorizedKeys reads SSH public keys from r. Every key is expected on its own line in the SSH format defined in RFC4253, blank lines and lines prefixed with # are ignored.
The keys are validated with ssh.ParseAuthorizedKey but returned as they were read, only stripped of surrounding whitespace, so that key comments and options are preserved.
func ReadAuthorizedKeys ¶
func ReadAuthorizedKeys(w *format.Writer, flag string, values []string, files []*os.File) ([]string, error)
ReadAuthorizedKeys returns the validated SSH public keys of values, followed by the keys read from files, in that order. flag names the flag values were passed to and is only used to report errors and warnings. The files are closed, they are read exactly once.
A source which holds no key at all is not an error, but it is warned about on w as it is most likely not what the user intended. Values which hold nothing but whitespace are not warned about, as that is how a configured list of keys is cleared.
func StorageKeysWithDeprecatedFile ¶
func StorageKeysWithDeprecatedFile(w *format.Writer, keys []string, deprecatedFile *os.File) ([]storage.SSHKey, error)
StorageKeysWithDeprecatedFile converts keys to the type of the storage API, with the keys of the deprecated --ssh-keys-file appended. Its use is warned about on w, pointing at the flag which replaces it. A nil file was not passed and contributes no keys.
It is shared by the database create and update commands, which declare the same three flags but differ in how the flags they replace are declared.
func StorageSSHKeys ¶
StorageSSHKeys converts keys to the type of the storage API. An empty list of keys converts to nil, so that callers can tell "no keys were given" from "the configured keys are to be cleared" through the flags instead of the result.
Types ¶
type DeprecatedKeysFlags ¶
type DeprecatedKeysFlags struct {
DeprecatedKeys []string `name:"keys" hidden:"" help:"Deprecated, use --ssh-keys instead."`
DeprecatedKeysFromFiles []*os.File `name:"keys-from-files" hidden:"" completion-predictor:"local:file" help:"Deprecated, use --ssh-keys-from-files instead."`
}
DeprecatedKeysFlags declares the --keys and --keys-from-files flags which SSHKeysFlags replaces. It has to be embedded with the prefix the flags were registered under before the rename:
sshkey.DeprecatedKeysFlags `prefix:"public-"`
The flags are hidden, they only exist to keep the previous spelling working. Unlike SSHKeysFlags they do not set sep:"none", so that values which used to be split on commas keep being split the same way. The fields carry a name tag so that they can be told apart from the fields of SSHKeysFlags wherever both are embedded, the flags are still registered as --<prefix>keys and --<prefix>keys-from-files.
func (DeprecatedKeysFlags) Keys ¶
Keys returns the validated SSH public keys of the deprecated flags registered under prefix, or nil if none of them was passed. Their use is warned about on w, pointing at the flags which SSHKeysFlags registered under replacement.
func (DeprecatedKeysFlags) Set ¶
func (f DeprecatedKeysFlags) Set() bool
Set reports whether one of the deprecated flags was passed. Unlike the flags of SSHKeysFlags they cannot be used to clear a configured list of keys.
type SSHKeysFlags ¶
type SSHKeysFlags struct {
// sep:"none" keeps Kong from splitting a value on commas,
// which would tear apart the options of an authorized_keys line.
// Repeat the flag or separate the keys by newlines to pass more than one.
SSHKeys []string `` /* 223-byte string literal not displayed */
SSHKeysFromFiles []*os.File `` /* 205-byte string literal not displayed */
}
SSHKeysFlags declares the --ssh-keys and --ssh-keys-from-files flags. Embed it with a prefix to scope the flags to a part of a resource and set ssh_keys_purpose to the clause which says what the keys are used for, it completes the help of both flags:
sshkey.SSHKeysFlags `prefix:"rescue-" set:"ssh_keys_purpose=to connect while booted into rescue"`
The same prefix has to be passed to SSHKeysFlags.Keys, as Kong does not tell a flag which name it ended up being registered under. A mismatch between the two only shows in the errors and warnings, so every command embedding the flags is expected to have a test which parses real arguments through Kong and asserts the flag names those messages spell out.