Documentation
¶
Index ¶
- Constants
- func Difference(slice1 []string, slice2 []string) [2][]string
- func JSON(data interface{}) string
- func SplitParts(content string) ([]string, error)
- type Config
- type Data
- func (c *Data) AddGroup(label string, hosts, users []string) error
- func (c *Data) AddHost(host *Host, withUsers bool) error
- func (c *Data) AddUser(newuser *User, host string) error
- func (c *Data) AddUserByEmail(email string) bool
- func (c *Data) AddUserToHosts(newuser *User)
- func (c *Data) DeleteGroup(label string) error
- func (c *Data) DeleteHost(alias string) bool
- func (c *Data) DeleteUser(email string) bool
- func (c *Data) DeleteUserByID(id string) bool
- func (c *Data) FromGroup(host *Host, email string) bool
- func (c *Data) GetGroup(id string) *Group
- func (c *Data) GetGroups() map[string]LabelGroup
- func (c *Data) GetHost(alias string) *Host
- func (c *Data) GetHosts(group string) []*Host
- func (c *Data) GetUser(lsum string) *User
- func (c *Data) GetUserByEmail(email string) (string, *User)
- func (c *Data) GetUserByKey(lsum string) *User
- func (c *Data) GetUsers(group string) []*User
- func (c *Data) Hosts() map[string]*Host
- func (c *Data) Log() *ILog
- func (c *Data) PrepareHost(args ...string) (*Host, error)
- func (c *Data) PrepareUser(email, filename string, groups ...string) (*User, error)
- func (c *Data) Regenerate(aliases ...string)
- func (c *Data) RemoveUserFromHosts(deluser *User) error
- func (c *Data) Roles() map[string]*Role
- func (c *Data) SetHost(alias string, host *Host)
- func (c *Data) SetLog(log *ILog) *Data
- func (c *Data) StopUpdate()
- func (c *Data) Update(aliases ...string)
- func (c *Data) UpdateGroup(groupLabel string, hosts, users []string) error
- func (c *Data) UpdateHost(host *Host) error
- func (c *Data) UpdateUser(newuser *User) error
- func (c *Data) UserExists(lsum string) bool
- func (c *Data) Users() map[string]*User
- func (c *Data) Write()
- type Errors
- type Group
- type Host
- func (h *Host) AddUser(u *User) error
- func (h *Host) DueGroup(u *User) bool
- func (h *Host) GetGroups() []string
- func (h *Host) GetUsers() []*User
- func (h *Host) HasMatchingGroups(user *User) bool
- func (h *Host) HasUser(email string) bool
- func (h *Host) ReadUsers() ([]*User, string, error)
- func (h *Host) RemoveUser(u *User) error
- func (h *Host) SetGroups(groups []string)
- func (h *Host) UpdateGroups(cfg Config, oldgroups []string) bool
- func (h *Host) UpdateUsersList(userlist []*User) error
- func (h *Host) Upload() error
- type ILog
- type ILogMode
- type JsonStorage
- type LabelGroup
- type LogWorker
- type MemoryStorage
- type Role
- type SFTP
- type SFTPConn
- type SFTPMockHost
- type Storage
- type User
Constants ¶
const ( // InfoPrefix is the prefix for info messages InfoPrefix = "\033[1;34mINF\033[0m " // ErrorPrefix is the prefix for error messages ErrorPrefix = "\033[1;31mERR\033[0m " )
const AUTHFILE = ".ssh/authorized_keys"
Variables ¶
This section is empty.
Functions ¶
func Difference ¶
Returns [[removed], [added]]
func SplitParts ¶
SplitParts splits a public key into []string parts order will be key type, key, comment we assume comment is a user name or email
Types ¶
type Config ¶
type Config interface {
AddGroup(label string, users, hosts []string) error
AddHost(host *Host, withUsers bool) error
AddUser(newuser *User, host string) error
AddUserByEmail(email string) bool
AddUserToHosts(newuser *User)
DeleteGroup(label string) error
DeleteHost(alias string) bool
DeleteUser(email string) bool
DeleteUserByID(id string) bool
FromGroup(host *Host, email string) bool
GetGroup(id string) *Group
GetGroups() map[string]LabelGroup
GetHost(alias string) *Host
GetHosts(group string) []*Host
GetUser(lsum string) *User
GetUserByEmail(email string) (string, *User)
GetUserByKey(lsum string) *User
GetUsers(group string) []*User
Hosts() map[string]*Host
Log() *ILog
PrepareHost(args ...string) (*Host, error)
PrepareUser(email, filename string, groups ...string) (*User, error)
Regenerate(aliases ...string)
RemoveUserFromHosts(deluser *User) error
SetLog(log *ILog) *Data
SetHost(alias string, host *Host)
StopUpdate()
Update(aliases ...string)
UpdateGroup(groupLabel string, users, hosts []string) error
UpdateHost(host *Host) error
UpdateUser(newuser *User) error
UserExists(lsum string) bool
Users() map[string]*User
Write()
}
type Data ¶
Data is the main storage (data storage) for the sshman backend
func DefaultConfig ¶
func DefaultConfig() *Data
func (*Data) AddUserByEmail ¶
AddUserByEmail adds a user to the hosts indicated by config groups
func (*Data) AddUserToHosts ¶
AddUserToHosts adds user to all allowed hosts' authorized_keys files
func (*Data) DeleteGroup ¶
DeleteGroup removes a group from the config, removing all users and hosts group labels.
func (*Data) DeleteHost ¶
DeleteHost removes a host from the config
func (*Data) DeleteUser ¶
DeleteUser removes a user from the storage
func (*Data) DeleteUserByID ¶
DeleteUserByID removes a user from the storage
func (*Data) GetGroups ¶
func (c *Data) GetGroups() map[string]LabelGroup
GetGroups returns all groups for frontend (web and cli)
func (*Data) GetUserByEmail ¶
GetUserByEmail get a user from config by email as we store them by key checksum
func (*Data) GetUserByKey ¶
GetUserByKey returns user if exists by ssh key
func (*Data) PrepareHost ¶
PrepareHost will prepare a host entry from array of strings Args: alias, hostname, user, keyfile, groups
func (*Data) PrepareUser ¶
PrepareUser will prepare a user entry from array of strings New user: old groups, email, key file, new groups
func (*Data) Regenerate ¶
Regenerate updates group information for given hosts
func (*Data) RemoveUserFromHosts ¶
RemoveUserFromHosts removes user's key from all hosts' authorized_keys files
func (*Data) UpdateGroup ¶
UpdateGroup updates a group in the config, propagating host/user access changes.
func (*Data) UpdateHost ¶
UpdateHost reads users from host and adds them to users list
func (*Data) UpdateUser ¶
UpdateUser finds and replaces user
func (*Data) UserExists ¶
UserExists checks if a user exists ignoring the result
type Errors ¶
type Errors struct {
// contains filtered or unexported fields
}
Errors handles errors list for hadnling arrays
type Host ¶
type Host struct {
Host string `json:"host"`
User string `json:"user"`
Key string `json:"key"`
Protected map[string]struct{} `json:"protected"`
Alias string `json:"alias"`
Config *Data `json:"-"`
Users []*User `json:"userlist"`
Groups []string `json:"groups"`
LastUpdated time.Time `json:"last_updated"`
Checksum string `json:"checksum"`
Modified bool `json:"modified"`
}
Host holds and manages a host entry in the config
func (*Host) HasMatchingGroups ¶
HasMatchingGroups checks if the host has any matching groups with the user
func (*Host) ReadUsers ¶
ReadUsers reads ssh entries from the host's authorized_keys file, returning user list, checksum and error
func (*Host) RemoveUser ¶
RemoveUser removes a user from the host's authorized_keys file
func (*Host) UpdateGroups ¶
UpdateGroups updates the host's groups based on old groups
func (*Host) UpdateUsersList ¶
UpdateUsersList sets the host's user list
type ILog ¶
type ILog struct {
// contains filtered or unexported fields
}
ILog is a logging engine with ability to send logs to multiple targets
type ILogMode ¶
type ILogMode string
ILogMode is the mode for the log
var ILogModeClosed ILogMode = ""
ILogModeClosed is the closed mode
var ILogModeStdout ILogMode = "stdout"
ILogModeStdout is the stdout mode for CLI
var ILogModeWeb ILogMode = "web"
ILogModeWeb is the web mode for the log
type JsonStorage ¶
type JsonStorage struct {
Path string
// contains filtered or unexported fields
}
func (*JsonStorage) Load ¶
func (m *JsonStorage) Load(data *Data) error
func (*JsonStorage) Save ¶
func (m *JsonStorage) Save(data *Data) error
func (*JsonStorage) Watch ¶
func (m *JsonStorage) Watch(notify func())
type LabelGroup ¶
type LabelGroup struct {
Label string `json:"label"`
Hosts []string `json:"hosts"`
Users []string `json:"users"`
}
LabelGroup is used for returning group information to frontend
type LogWorker ¶
type LogWorker struct {
Source chan interface{}
Quit chan struct{}
}
LogWorker is log transfer agent for web
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
func (*MemoryStorage) Load ¶
func (m *MemoryStorage) Load(data *Data) error
func (*MemoryStorage) Save ¶
func (m *MemoryStorage) Save(data *Data) error
func (*MemoryStorage) Watch ¶
func (m *MemoryStorage) Watch(notify func())
type SFTP ¶
type SFTP interface {
Connect(keyfile, host, user string) error
Write(filename, data string) error
Read(filename string) ([]byte, error)
Close()
}
SFTP is interface for handling authorized_keys files
type SFTPConn ¶
type SFTPConn struct {
// contains filtered or unexported fields
}
SFTPConn is a wrapper around sftp.Client, implements SFTP interface
func MockConn ¶
func MockConn(testHosts map[string]SFTPMockHost) *SFTPConn
func (*SFTPConn) GetHosts ¶
func (s *SFTPConn) GetHosts() map[string]SFTPMockHost
GetHosts is used for testing, returns the list of hosts
func (*SFTPConn) Read ¶
Read reads the authorized_keys file from the remote host when running from tests, returns the mocked data
type SFTPMockHost ¶
SFTPMockHost is a build-in mock for testing
type User ¶
type User struct {
KeyType string `json:"type"`
Name string `json:"name"`
Email string `json:"email"`
Key string `json:"key"`
Groups []string `json:"groups"`
Hosts []string `json:"hosts"`
File string `json:"keyfile,omitempty"`
Roles []string `json:"roles"`
UpdatedAt time.Time `json:"updatedAt"`
Config Config `json:"-"`
}
User holds the user information in the config