2016-09-01 04:51:38 +00:00
|
|
|
// Package kitserver holds the implementation of the kolide service interface and the HTTP endpoints
|
|
|
|
// for the API
|
2016-08-28 03:59:17 +00:00
|
|
|
package kitserver
|
|
|
|
|
2016-09-01 04:51:38 +00:00
|
|
|
import (
|
2016-09-04 05:13:42 +00:00
|
|
|
"io"
|
|
|
|
|
2016-09-01 04:51:38 +00:00
|
|
|
kitlog "github.com/go-kit/kit/log"
|
|
|
|
"github.com/kolide/kolide-ose/kolide"
|
2016-09-04 05:13:42 +00:00
|
|
|
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
2016-09-01 04:51:38 +00:00
|
|
|
)
|
2016-08-28 03:59:17 +00:00
|
|
|
|
|
|
|
// configuration defaults
|
2016-09-01 04:51:38 +00:00
|
|
|
// TODO move to main?
|
2016-08-28 03:59:17 +00:00
|
|
|
const (
|
2016-09-04 05:13:42 +00:00
|
|
|
defaultBcryptCost int = 12
|
|
|
|
defaultSaltKeySize int = 24
|
|
|
|
defaultCookieName string = "KolideSession"
|
|
|
|
defaultEnrollSecret string = "xxx change me"
|
|
|
|
defaultNodeKeySize int = 24
|
2016-08-28 03:59:17 +00:00
|
|
|
)
|
|
|
|
|
2016-09-01 04:51:38 +00:00
|
|
|
// NewService creates a new service from the config struct
|
|
|
|
func NewService(config ServiceConfig) (kolide.Service, error) {
|
2016-08-28 03:59:17 +00:00
|
|
|
var svc kolide.Service
|
2016-09-04 05:13:42 +00:00
|
|
|
|
|
|
|
logFile := func(path string) io.Writer {
|
|
|
|
return &lumberjack.Logger{
|
|
|
|
Filename: path,
|
|
|
|
MaxSize: 500, // megabytes
|
|
|
|
MaxBackups: 3,
|
|
|
|
MaxAge: 28, //days
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-28 03:59:17 +00:00
|
|
|
svc = service{
|
2016-09-04 05:13:42 +00:00
|
|
|
ds: config.Datastore,
|
|
|
|
logger: config.Logger,
|
|
|
|
saltKeySize: config.SaltKeySize,
|
|
|
|
bcryptCost: config.BcryptCost,
|
|
|
|
jwtKey: config.JWTKey,
|
|
|
|
cookieName: config.SessionCookieName,
|
|
|
|
osqueryEnrollSecret: config.OsqueryEnrollSecret,
|
|
|
|
osqueryNodeKeySize: config.OsqueryNodeKeySize,
|
|
|
|
osqueryStatusLogWriter: logFile(config.OsqueryStatusLogPath),
|
|
|
|
osqueryResultsLogWriter: logFile(config.OsqueryResultsLogPath),
|
2016-08-28 03:59:17 +00:00
|
|
|
}
|
|
|
|
svc = validationMiddleware{svc}
|
|
|
|
return svc, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type service struct {
|
2016-09-01 04:51:38 +00:00
|
|
|
ds kolide.Datastore
|
|
|
|
logger kitlog.Logger
|
|
|
|
|
2016-08-28 03:59:17 +00:00
|
|
|
saltKeySize int
|
2016-09-01 04:51:38 +00:00
|
|
|
bcryptCost int
|
|
|
|
|
|
|
|
jwtKey string
|
|
|
|
cookieName string
|
|
|
|
|
2016-09-04 05:13:42 +00:00
|
|
|
osqueryEnrollSecret string
|
|
|
|
osqueryNodeKeySize int
|
|
|
|
osqueryStatusLogWriter io.Writer
|
|
|
|
osqueryResultsLogWriter io.Writer
|
2016-09-01 04:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceConfig holds the parameters for creating a Service
|
|
|
|
type ServiceConfig struct {
|
|
|
|
Datastore kolide.Datastore
|
|
|
|
Logger kitlog.Logger
|
|
|
|
|
|
|
|
// password config
|
|
|
|
SaltKeySize int
|
|
|
|
BcryptCost int
|
|
|
|
|
|
|
|
// session config
|
|
|
|
JWTKey string
|
|
|
|
SessionCookieName string
|
|
|
|
|
|
|
|
// osquery config
|
2016-09-04 05:13:42 +00:00
|
|
|
OsqueryEnrollSecret string
|
|
|
|
OsqueryNodeKeySize int
|
|
|
|
OsqueryStatusLogPath string
|
|
|
|
OsqueryResultsLogPath string
|
2016-08-28 03:59:17 +00:00
|
|
|
}
|