diff --git a/docs/1-Using-Fleet/3-REST-API.md b/docs/1-Using-Fleet/3-REST-API.md index 551cf25dee..f5ed734729 100644 --- a/docs/1-Using-Fleet/3-REST-API.md +++ b/docs/1-Using-Fleet/3-REST-API.md @@ -25,8 +25,6 @@ Fleet is powered by a Go API server which serves three types of endpoints: The React app uses React Router to determine whether or not the URI is a valid route and what to do. -Note: We have deprecated `/api/v1/kolide/` routes and will remove them in the Fleet 4.0 release. Please migrate all routes to `/api/v1/fleet/`. - ### fleetctl Many of the operations that a user may wish to perform with an API are currently best performed via the [fleetctl](./2-fleetctl-CLI.md) tooling. These CLI tools allow updating of the osquery configuration entities, as well as performing live queries. diff --git a/docs/3-Deployment/2-Configuration.md b/docs/3-Deployment/2-Configuration.md index 8320b88d9e..b30437bf87 100644 --- a/docs/3-Deployment/2-Configuration.md +++ b/docs/3-Deployment/2-Configuration.md @@ -60,8 +60,6 @@ In order of precedence, options can be specified via: - Environment variables - Command-line flags -Note: We have deprecated `KOLIDE_` environment variables and will remove them in the Fleet 4.0 release. Please migrate all environment variables to `FLEET_`. - For example, all of the following ways of launching Fleet are equivalent: ##### Using only CLI flags @@ -69,7 +67,7 @@ For example, all of the following ways of launching Fleet are equivalent: ``` /usr/bin/fleet serve \ --mysql_address=127.0.0.1:3306 \ ---mysql_database=kolide \ +--mysql_database=fleet \ --mysql_username=root \ --mysql_password=toor \ --redis_address=127.0.0.1:6379 \ @@ -83,7 +81,7 @@ For example, all of the following ways of launching Fleet are equivalent: ``` FLEET_MYSQL_ADDRESS=127.0.0.1:3306 \ -FLEET_MYSQL_DATABASE=kolide \ +FLEET_MYSQL_DATABASE=fleet \ FLEET_MYSQL_USERNAME=root \ FLEET_MYSQL_PASSWORD=toor \ FLEET_REDIS_ADDRESS=127.0.0.1:6379 \ @@ -100,7 +98,7 @@ FLEET_AUTH_JWT_KEY=changeme \ echo ' mysql: address: 127.0.0.1:3306 - database: kolide + database: fleet username: root password: toor redis: @@ -112,8 +110,8 @@ logging: json: true auth: jwt_key: changeme -' > /tmp/kolide.yml -fleet serve --config /tmp/kolide.yml +' > /tmp/fleet.yml +fleet serve --config /tmp/fleet.yml ``` #### What are the options? @@ -670,52 +668,6 @@ Options are `filesystem`, `firehose`, `kinesis`, `lambda`, `pubsub`, and `stdout result_log_plugin: firehose ``` -###### `osquery_status_log_file` - -DEPRECATED: Use filesystem_status_log_file. - -The path which osquery status logs will be logged to. - -- Default value: `/tmp/osquery_status` -- Environment variable: `FLEET_OSQUERY_STATUS_LOG_FILE` -- Config file format: - - ``` - osquery: - status_log_file: /var/log/osquery/status.log - ``` - -###### `osquery_result_log_file` - -DEPRECATED: Use filesystem_result_log_file. - -The path which osquery result logs will be logged to. - -- Default value: `/tmp/osquery_result` -- Environment variable: `FLEET_OSQUERY_RESULT_LOG_FILE` -- Config file format: - - ``` - osquery: - result_log_file: /var/log/osquery/result.log - ``` - -###### `osquery_enable_log_rotation` - -DEPRECATED: Use fileystem_enable_log_rotation. - -This flag will cause the osquery result and status log files to be automatically -rotated when files reach a size of 500 Mb or an age of 28 days. - -- Default value: `false` -- Environment variable: `FLEET_OSQUERY_ENABLE_LOG_ROTATION` -- Config file format: - - ``` - osquery: - enable_log_rotation: true - ``` - ##### Logging (Fleet server logging) ###### `logging_debug` diff --git a/server/config/config.go b/server/config/config.go index 80d067ffe0..4a210dff60 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -356,29 +356,6 @@ func (man Manager) addConfigs() { // LoadConfig will load the config variables into a fully initialized // KolideConfig struct func (man Manager) LoadConfig() KolideConfig { - // Shim old style environment variables with a warning - // TODO #260 remove this on major version release - haveLogged := false - for _, e := range os.Environ() { - if strings.HasPrefix(e, "KOLIDE_") { - splits := strings.SplitN(e, "=", 2) - if len(splits) != 2 { - panic("env " + e + " does not contain 2 splits") - } - - key, val := splits[0], splits[1] - - if !haveLogged { - fmt.Println("Environment variables prefixed with KOLIDE_ are deprecated. Please migrate to FLEET_ prefixes.`") - haveLogged = true - } - - if err := os.Setenv("FLEET"+strings.TrimPrefix(key, "KOLIDE"), val); err != nil { - panic(err) - } - } - } - man.loadConfigFile() return KolideConfig{ diff --git a/server/service/handler.go b/server/service/handler.go index d131335294..327e4623b7 100644 --- a/server/service/handler.go +++ b/server/service/handler.go @@ -4,7 +4,6 @@ import ( "context" "net/http" "strings" - "time" "github.com/fleetdm/fleet/server/config" "github.com/fleetdm/fleet/server/kolide" @@ -15,13 +14,12 @@ import ( "github.com/go-kit/kit/log/level" kithttp "github.com/go-kit/kit/transport/http" "github.com/gorilla/mux" - "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/throttled/throttled/v2" ) -// KolideEndpoints is a collection of RPC endpoints implemented by the Kolide API. -type KolideEndpoints struct { +// FleetEndpoints is a collection of RPC endpoints implemented by the Fleet API. +type FleetEndpoints struct { Login endpoint.Endpoint Logout endpoint.Endpoint ForgotPassword endpoint.Endpoint @@ -122,11 +120,11 @@ type KolideEndpoints struct { TeamEnrollSecrets endpoint.Endpoint } -// MakeKolideServerEndpoints creates the Kolide API endpoints. -func MakeKolideServerEndpoints(svc kolide.Service, jwtKey, urlPrefix string, limitStore throttled.GCRAStore) KolideEndpoints { +// MakeFleetServerEndpoints creates the Fleet API endpoints. +func MakeFleetServerEndpoints(svc kolide.Service, jwtKey, urlPrefix string, limitStore throttled.GCRAStore) FleetEndpoints { limiter := ratelimit.NewMiddleware(limitStore) - return KolideEndpoints{ + return FleetEndpoints{ Login: limiter.Limit( throttled.RateQuota{MaxRate: throttled.PerMin(10), MaxBurst: 9})( makeLoginEndpoint(svc), @@ -252,7 +250,7 @@ func MakeKolideServerEndpoints(svc kolide.Service, jwtKey, urlPrefix string, lim } } -type kolideHandlers struct { +type fleetHandlers struct { Login http.Handler Logout http.Handler ForgotPassword http.Handler @@ -353,12 +351,12 @@ type kolideHandlers struct { TeamEnrollSecrets http.Handler } -func makeKolideKitHandlers(e KolideEndpoints, opts []kithttp.ServerOption) *kolideHandlers { +func makeKitHandlers(e FleetEndpoints, opts []kithttp.ServerOption) *fleetHandlers { newServer := func(e endpoint.Endpoint, decodeFn kithttp.DecodeRequestFunc) http.Handler { e = authzcheck.NewMiddleware().AuthzCheck()(e) return kithttp.NewServer(e, decodeFn, encodeResponse, opts...) } - return &kolideHandlers{ + return &fleetHandlers{ Login: newServer(e.Login, decodeLoginRequest), Logout: newServer(e.Logout, decodeNoParamsRequest), ForgotPassword: newServer(e.ForgotPassword, decodeForgotPasswordRequest), @@ -485,7 +483,7 @@ func (h *errorHandler) Handle(ctx context.Context, err error) { // MakeHandler creates an HTTP handler for the Fleet server endpoints. func MakeHandler(svc kolide.Service, config config.KolideConfig, logger kitlog.Logger, limitStore throttled.GCRAStore) http.Handler { - kolideAPIOptions := []kithttp.ServerOption{ + fleetAPIOptions := []kithttp.ServerOption{ kithttp.ServerBefore( kithttp.PopulateRequestContext, // populate the request context with common fields setRequestsContexts(svc, config.Auth.JwtKey), @@ -498,15 +496,12 @@ func MakeHandler(svc kolide.Service, config config.KolideConfig, logger kitlog.L ), } - kolideEndpoints := MakeKolideServerEndpoints(svc, config.Auth.JwtKey, config.Server.URLPrefix, limitStore) - kolideHandlers := makeKolideKitHandlers(kolideEndpoints, kolideAPIOptions) + fleetEndpoints := MakeFleetServerEndpoints(svc, config.Auth.JwtKey, config.Server.URLPrefix, limitStore) + fleetHandlers := makeKitHandlers(fleetEndpoints, fleetAPIOptions) r := mux.NewRouter() - attachKolideAPIRoutes(r, kolideHandlers) - - // TODO #42 remove the shims - shimRoutes(r, logger) + attachFleetAPIRoutes(r, fleetHandlers) // Results endpoint is handled different due to websockets use r.PathPrefix("/api/v1/fleet/results/"). @@ -530,54 +525,7 @@ func addMetrics(r *mux.Router) { r.Walk(walkFn) } -func shimRoutes(r *mux.Router, logger kitlog.Logger) { - if err := r.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error { - path, err := route.GetPathTemplate() - if err != nil { - return errors.Wrap(err, "get path template") - } - - if !strings.HasPrefix(path, "/api/v1/fleet") { - return nil - } - - methods, err := route.GetMethods() - if err != nil { - methods = []string{} - } - - path = strings.Replace(path, "fleet", "kolide", 1) - router.Handle(path, route.GetHandler()).Methods(methods...).Name(route.GetName()) - - return nil - }); err != nil { - panic(err) - } - - // Shim the routes to allow them to be referred as /api/v1/fleet or - // /api/v1/kolide. - var lastShimLogTime time.Time - r.Use(func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if time.Now().After(lastShimLogTime.Add(1 * time.Hour)) { - if strings.HasPrefix(r.URL.Path, "/api/v1/kolide") { - // There's a race condition with this timestamp but it's not - // a big deal if we accidentally log this message more than - // once. The point is to not overwhelm the logs with these - // messages and this code will be killed soon anyway. - lastShimLogTime = time.Now() - level.Info(logger).Log( - "msg", "client used deprecated route", - "deprecated", r.URL.Path, - ) - } - } - next.ServeHTTP(w, r) - }) - }) -} - -func attachKolideAPIRoutes(r *mux.Router, h *kolideHandlers) { +func attachFleetAPIRoutes(r *mux.Router, h *fleetHandlers) { r.Handle("/api/v1/fleet/login", h.Login).Methods("POST").Name("login") r.Handle("/api/v1/fleet/logout", h.Logout).Methods("POST").Name("logout") r.Handle("/api/v1/fleet/forgot_password", h.ForgotPassword).Methods("POST").Name("forgot_password") diff --git a/server/service/handler_test.go b/server/service/handler_test.go index dfbad47c1b..364917aa5c 100644 --- a/server/service/handler_test.go +++ b/server/service/handler_test.go @@ -20,9 +20,9 @@ func TestAPIRoutes(t *testing.T) { r := mux.NewRouter() limitStore, _ := memstore.New(0) - ke := MakeKolideServerEndpoints(svc, "CHANGEME", "", limitStore) - kh := makeKolideKitHandlers(ke, nil) - attachKolideAPIRoutes(r, kh) + ke := MakeFleetServerEndpoints(svc, "CHANGEME", "", limitStore) + kh := makeKitHandlers(ke, nil) + attachFleetAPIRoutes(r, kh) handler := mux.NewRouter() handler.PathPrefix("/").Handler(r) diff --git a/server/service/http_auth_test.go b/server/service/http_auth_test.go index bd7fc335ac..e4cc50780d 100644 --- a/server/service/http_auth_test.go +++ b/server/service/http_auth_test.go @@ -40,9 +40,9 @@ func TestLogin(t *testing.T) { } r := mux.NewRouter() limitStore, _ := memstore.New(0) - ke := MakeKolideServerEndpoints(svc, "CHANGEME", "", limitStore) - kh := makeKolideKitHandlers(ke, opts) - attachKolideAPIRoutes(r, kh) + ke := MakeFleetServerEndpoints(svc, "CHANGEME", "", limitStore) + kh := makeKitHandlers(ke, opts) + attachFleetAPIRoutes(r, kh) r.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "index") }))