Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No more plugins #37

Merged
merged 4 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ notifications:
email: false

script:
- go build -buildmode=plugin -o plugins/logging_dispatcher_plugin.so plugins/logging_dispatcher/*.go
- go build -buildmode=plugin -o plugins/db_logging_plugin.so plugins/db_logging/*.go
- go build -buildmode=plugin -o plugins/graylog_logging_plugin.so plugins/graylog_logging/*.go
- go build -buildmode=plugin -o plugins/splunk_logging_plugin.so plugins/splunk_logging/*.go
- go build -o bin/osctrl-tls cmd/tls/*.go
- go build -o bin/osctrl-admin cmd/admin/*.go
- go build -o bin/osctrl-cli cmd/cli/*.go
- go build -o bin/osctrl-tls tls/*.go
- go build -o bin/osctrl-admin admin/*.go
- go build -o bin/osctrl-cli cli/*.go
40 changes: 10 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,30 @@ export GO111MODULE=on

SHELL := /bin/bash

TLS_DIR = cmd/tls
TLS_DIR = tls
TLS_NAME = osctrl-tls
TLS_CODE = ${TLS_DIR:=/*.go}

ADMIN_DIR = cmd/admin
ADMIN_DIR = admin
ADMIN_NAME = osctrl-admin
ADMIN_CODE = ${ADMIN_DIR:=/*.go}

API_DIR = cmd/api
API_DIR = api
API_NAME = osctrl-api
API_CODE = ${API_DIR:=/*.go}

CLI_DIR = cmd/cli
CLI_DIR = cli
CLI_NAME = osctrl-cli
CLI_CODE = ${CLI_DIR:=/*.go}

PKGS_DIR = pkg
PLUGINS_DIR = plugins

DEST ?= /opt/osctrl

OUTPUT = bin

.PHONY: all build clean plugins

all: build
.PHONY: build clean tls admin cli api

# Build code according to caller OS and architecture
build:
make plugins
make tls
make admin
make api
Expand All @@ -53,20 +47,12 @@ api:
cli:
go build -o $(OUTPUT)/$(CLI_NAME) $(CLI_CODE)

# Build plugins
plugins:
go build -buildmode=plugin -o $(PLUGINS_DIR)/logging_dispatcher_plugin.so $(PLUGINS_DIR)/logging_dispatcher/*.go
go build -buildmode=plugin -o $(PLUGINS_DIR)/db_logging_plugin.so $(PLUGINS_DIR)/db_logging/*.go
go build -buildmode=plugin -o $(PLUGINS_DIR)/graylog_logging_plugin.so $(PLUGINS_DIR)/graylog_logging/*.go
go build -buildmode=plugin -o $(PLUGINS_DIR)/splunk_logging_plugin.so $(PLUGINS_DIR)/splunk_logging/*.go

# Delete all compiled binaries
clean:
rm -rf $(OUTPUT)/$(TLS_NAME)
rm -rf $(OUTPUT)/$(ADMIN_NAME)
rm -rf $(OUTPUT)/$(API_NAME)
rm -rf $(OUTPUT)/$(CLI_NAME)
rm -rf $(PLUGINS_DIR)/*.so

# Remove all unused dependencies
tidy:
Expand Down Expand Up @@ -135,24 +121,24 @@ vagrant_up:

# Build docker containers and run them (also generates new certificates)
docker_all:
./docker/dockerize.sh -u -b -f
./deploy/docker/dockerize.sh -u -b -f

# Run docker containers
docker_up:
./docker/dockerize.sh -u
./deploy/docker/dockerize.sh -u

# Build docker containers
docker_build:
./docker/dockerize.sh -b
./deploy/docker/dockerize.sh -b

# Takes down docker containers
docker_down:
./docker/dockerize.sh -d
./deploy/docker/dockerize.sh -d

# Cleans docker containers and certificates
docker_clean:
make docker_down
./docker/dockerize.sh -x
./deploy/docker/dockerize.sh -x
docker volume rm osctrl_db-data
rm -Rf docker/certs/*
rm -Rf docker/config/*
Expand All @@ -171,12 +157,6 @@ gofmt-api:
gofmt-cli:
gofmt $(GOFMT_ARGS) ./$(CLI_CODE)

gofmt-pkgs:
gofmt $(GOFMT_ARGS) ./$(PKGS_DIR)

gofmt-plugins:
gofmt $(GOFMT_ARGS) ./$(PLUGINS_DIR)

# Run all tests
test:
# Install dependencies for TLS
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin/auth.go → admin/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"strings"

"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/settings"
)

const (
Expand Down
28 changes: 28 additions & 0 deletions admin/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"log"

_ "github.com/jinzhu/gorm/dialects/postgres"
)

// Automigrate of tables
func automigrateDB() error {
var err error
// table osquery_status_data
err = db.AutoMigrate(OsqueryStatusData{}).Error
if err != nil {
log.Fatalf("Failed to AutoMigrate table (osquery_status_data): %v", err)
}
// table osquery_result_data
err = db.AutoMigrate(OsqueryResultData{}).Error
if err != nil {
log.Fatalf("Failed to AutoMigrate table (osquery_result_data): %v", err)
}
// table osquery_query_data
err = db.AutoMigrate(OsqueryQueryData{}).Error
if err != nil {
log.Fatalf("Failed to AutoMigrate table (osquery_query_data): %v", err)
}
return nil
}
8 changes: 4 additions & 4 deletions cmd/admin/handlers-get.go → admin/handlers-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"strconv"
"strings"

"github.com/jmpsec/osctrl/pkg/carves"
"github.com/jmpsec/osctrl/pkg/environments"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/utils"
"github.com/jmpsec/osctrl/carves"
"github.com/jmpsec/osctrl/utils"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/environments"

"github.com/gorilla/mux"
)
Expand Down
36 changes: 18 additions & 18 deletions cmd/admin/handlers-post.go → admin/handlers-post.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"log"
"net/http"

"github.com/jmpsec/osctrl/pkg/environments"
"github.com/jmpsec/osctrl/pkg/queries"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/utils"
"github.com/jmpsec/osctrl/environments"
"github.com/jmpsec/osctrl/queries"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/utils"

"github.com/gorilla/mux"
)
Expand Down Expand Up @@ -59,7 +59,7 @@ func loginPOSTHandler(w http.ResponseWriter, r *http.Request) {
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -112,7 +112,7 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) {
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -259,7 +259,7 @@ send_response:
response = []byte("error formating response")
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -418,7 +418,7 @@ send_response:
response = []byte("error formating response")
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -504,7 +504,7 @@ send_response:
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -572,7 +572,7 @@ send_response:
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -666,7 +666,7 @@ send_response:
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -754,7 +754,7 @@ func intervalsPOSTHandler(w http.ResponseWriter, r *http.Request) {
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -860,7 +860,7 @@ func expirationPOSTHandler(w http.ResponseWriter, r *http.Request) {
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -930,7 +930,7 @@ func nodeActionsPOSTHandler(w http.ResponseWriter, r *http.Request) {
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -1047,7 +1047,7 @@ send_response:
}
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -1170,7 +1170,7 @@ send_response:
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -1328,7 +1328,7 @@ send_response:
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down Expand Up @@ -1422,7 +1422,7 @@ send_response:
response = []byte(responseMessage)
}
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(responseCode)
_, _ = w.Write(response)
if settingsmgr.DebugService(settings.ServiceAdmin) {
Expand Down
8 changes: 4 additions & 4 deletions cmd/admin/handlers-tokens.go → admin/handlers-tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/utils"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/utils"
)

// TokenJSON to be used to populate a JSON token
Expand Down Expand Up @@ -60,7 +60,7 @@ func tokensGETHandler(w http.ResponseWriter, r *http.Request) {
return
}
// Header to serve JSON
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(http.StatusOK)
_, _ = w.Write(returnedJSON)
incMetric(metricTokenOK)
Expand Down Expand Up @@ -131,6 +131,6 @@ func tokensPOSTHandler(w http.ResponseWriter, r *http.Request) {
return
}
// Serialize and serve JSON
apiHTTPResponse(w, JSONApplicationUTF8, http.StatusOK, response)
apiHTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, response)
incMetric(metricTokenOK)
}
17 changes: 4 additions & 13 deletions cmd/admin/handlers.go → admin/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"net/http"

"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/utils"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/utils"
)

const (
Expand All @@ -21,15 +21,6 @@ const (
metricHealthOK = "health-ok"
)

// JSONApplication for Content-Type headers
const JSONApplication string = "application/json"

// ContentType for header key
const contentType string = "Content-Type"

// JSONApplicationUTF8 for Content-Type headers, UTF charset
const JSONApplicationUTF8 string = JSONApplication + "; charset=UTF-8"

// Empty default osquery configuration
const emptyConfiguration string = "data/osquery-empty.json"

Expand All @@ -38,7 +29,7 @@ func healthHTTPHandler(w http.ResponseWriter, r *http.Request) {
incMetric(metricHealthReq)
utils.DebugHTTPDump(r, settingsmgr.DebugHTTP(settings.ServiceAdmin), true)
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("✅"))
incMetric(metricHealthOK)
Expand All @@ -48,7 +39,7 @@ func healthHTTPHandler(w http.ResponseWriter, r *http.Request) {
func errorHTTPHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, settingsmgr.DebugHTTP(settings.ServiceAdmin), true)
// Send response
w.Header().Set("Content-Type", JSONApplicationUTF8)
w.Header().Set(utils.ContentType, utils.JSONApplicationUTF8)
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte("oh no..."))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin/headers.go → admin/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"log"

"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/types"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/types"
"github.com/spf13/viper"
)

Expand Down
Loading