2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-08-28 03:59:17 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2016-08-28 03:59:17 +00:00
|
|
|
"net/http"
|
2017-01-12 00:40:58 +00:00
|
|
|
"strings"
|
2016-08-28 03:59:17 +00:00
|
|
|
|
2021-06-26 04:46:51 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/config"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/service/middleware/authzcheck"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/service/middleware/ratelimit"
|
2016-09-26 17:14:39 +00:00
|
|
|
"github.com/go-kit/kit/endpoint"
|
2016-08-28 03:59:17 +00:00
|
|
|
kitlog "github.com/go-kit/kit/log"
|
2021-02-10 20:13:11 +00:00
|
|
|
"github.com/go-kit/kit/log/level"
|
2016-08-28 03:59:17 +00:00
|
|
|
kithttp "github.com/go-kit/kit/transport/http"
|
|
|
|
"github.com/gorilla/mux"
|
2016-12-22 17:39:44 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-03-26 18:23:29 +00:00
|
|
|
"github.com/throttled/throttled/v2"
|
2016-08-28 03:59:17 +00:00
|
|
|
)
|
|
|
|
|
2021-06-04 23:51:18 +00:00
|
|
|
// FleetEndpoints is a collection of RPC endpoints implemented by the Fleet API.
|
|
|
|
type FleetEndpoints struct {
|
2018-05-17 22:54:34 +00:00
|
|
|
Login endpoint.Endpoint
|
|
|
|
Logout endpoint.Endpoint
|
|
|
|
ForgotPassword endpoint.Endpoint
|
|
|
|
ResetPassword endpoint.Endpoint
|
|
|
|
Me endpoint.Endpoint
|
|
|
|
ChangePassword endpoint.Endpoint
|
2020-11-05 01:06:55 +00:00
|
|
|
CreateUserWithInvite endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
CreateUser endpoint.Endpoint
|
|
|
|
GetUser endpoint.Endpoint
|
|
|
|
ListUsers endpoint.Endpoint
|
|
|
|
ModifyUser endpoint.Endpoint
|
2021-04-08 23:53:33 +00:00
|
|
|
DeleteUser endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
RequirePasswordReset endpoint.Endpoint
|
|
|
|
PerformRequiredPasswordReset endpoint.Endpoint
|
|
|
|
GetSessionsForUserInfo endpoint.Endpoint
|
|
|
|
DeleteSessionsForUser endpoint.Endpoint
|
|
|
|
GetSessionInfo endpoint.Endpoint
|
|
|
|
DeleteSession endpoint.Endpoint
|
|
|
|
GetAppConfig endpoint.Endpoint
|
|
|
|
ModifyAppConfig endpoint.Endpoint
|
2020-05-29 16:12:39 +00:00
|
|
|
ApplyEnrollSecretSpec endpoint.Endpoint
|
|
|
|
GetEnrollSecretSpec endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
CreateInvite endpoint.Endpoint
|
|
|
|
ListInvites endpoint.Endpoint
|
|
|
|
DeleteInvite endpoint.Endpoint
|
|
|
|
VerifyInvite endpoint.Endpoint
|
|
|
|
GetQuery endpoint.Endpoint
|
|
|
|
ListQueries endpoint.Endpoint
|
|
|
|
CreateQuery endpoint.Endpoint
|
|
|
|
ModifyQuery endpoint.Endpoint
|
|
|
|
DeleteQuery endpoint.Endpoint
|
2018-06-15 14:13:11 +00:00
|
|
|
DeleteQueryByID endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
DeleteQueries endpoint.Endpoint
|
|
|
|
ApplyQuerySpecs endpoint.Endpoint
|
|
|
|
GetQuerySpecs endpoint.Endpoint
|
|
|
|
GetQuerySpec endpoint.Endpoint
|
|
|
|
CreateDistributedQueryCampaign endpoint.Endpoint
|
|
|
|
CreateDistributedQueryCampaignByNames endpoint.Endpoint
|
2018-06-15 14:13:11 +00:00
|
|
|
CreatePack endpoint.Endpoint
|
|
|
|
ModifyPack endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
GetPack endpoint.Endpoint
|
|
|
|
ListPacks endpoint.Endpoint
|
|
|
|
DeletePack endpoint.Endpoint
|
2018-06-15 14:13:11 +00:00
|
|
|
DeletePackByID endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
GetScheduledQueriesInPack endpoint.Endpoint
|
2018-06-15 14:13:11 +00:00
|
|
|
ScheduleQuery endpoint.Endpoint
|
|
|
|
GetScheduledQuery endpoint.Endpoint
|
|
|
|
ModifyScheduledQuery endpoint.Endpoint
|
|
|
|
DeleteScheduledQuery endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
ApplyPackSpecs endpoint.Endpoint
|
|
|
|
GetPackSpecs endpoint.Endpoint
|
|
|
|
GetPackSpec endpoint.Endpoint
|
2021-07-16 13:15:15 +00:00
|
|
|
GlobalScheduleQuery endpoint.Endpoint
|
|
|
|
GetGlobalSchedule endpoint.Endpoint
|
|
|
|
ModifyGlobalSchedule endpoint.Endpoint
|
|
|
|
DeleteGlobalSchedule endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
EnrollAgent endpoint.Endpoint
|
|
|
|
GetClientConfig endpoint.Endpoint
|
|
|
|
GetDistributedQueries endpoint.Endpoint
|
|
|
|
SubmitDistributedQueryResults endpoint.Endpoint
|
|
|
|
SubmitLogs endpoint.Endpoint
|
2020-11-05 04:45:16 +00:00
|
|
|
CarveBegin endpoint.Endpoint
|
|
|
|
CarveBlock endpoint.Endpoint
|
2018-06-18 17:09:08 +00:00
|
|
|
CreateLabel endpoint.Endpoint
|
|
|
|
ModifyLabel endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
GetLabel endpoint.Endpoint
|
|
|
|
ListLabels endpoint.Endpoint
|
2020-03-30 02:19:54 +00:00
|
|
|
ListHostsInLabel endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
DeleteLabel endpoint.Endpoint
|
2018-06-25 20:56:59 +00:00
|
|
|
DeleteLabelByID endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
ApplyLabelSpecs endpoint.Endpoint
|
|
|
|
GetLabelSpecs endpoint.Endpoint
|
|
|
|
GetLabelSpec endpoint.Endpoint
|
|
|
|
GetHost endpoint.Endpoint
|
2020-04-22 20:54:32 +00:00
|
|
|
HostByIdentifier endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
DeleteHost endpoint.Endpoint
|
2021-05-13 20:09:22 +00:00
|
|
|
RefetchHost endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
ListHosts endpoint.Endpoint
|
|
|
|
GetHostSummary endpoint.Endpoint
|
2021-05-17 19:23:21 +00:00
|
|
|
AddHostsToTeam endpoint.Endpoint
|
2021-05-26 04:29:52 +00:00
|
|
|
AddHostsToTeamByFilter endpoint.Endpoint
|
2018-05-17 22:54:34 +00:00
|
|
|
SearchTargets endpoint.Endpoint
|
|
|
|
GetCertificate endpoint.Endpoint
|
|
|
|
ChangeEmail endpoint.Endpoint
|
|
|
|
InitiateSSO endpoint.Endpoint
|
|
|
|
CallbackSSO endpoint.Endpoint
|
|
|
|
SSOSettings endpoint.Endpoint
|
2019-08-13 16:42:58 +00:00
|
|
|
StatusResultStore endpoint.Endpoint
|
2020-01-14 00:53:04 +00:00
|
|
|
StatusLiveQuery endpoint.Endpoint
|
2020-11-05 04:45:16 +00:00
|
|
|
ListCarves endpoint.Endpoint
|
2020-11-13 03:06:56 +00:00
|
|
|
GetCarve endpoint.Endpoint
|
2020-11-05 04:45:16 +00:00
|
|
|
GetCarveBlock endpoint.Endpoint
|
2021-03-27 01:03:31 +00:00
|
|
|
Version endpoint.Endpoint
|
2021-03-18 04:59:00 +00:00
|
|
|
CreateTeam endpoint.Endpoint
|
|
|
|
ModifyTeam endpoint.Endpoint
|
2021-05-12 17:38:00 +00:00
|
|
|
ModifyTeamAgentOptions endpoint.Endpoint
|
2021-04-20 17:20:52 +00:00
|
|
|
DeleteTeam endpoint.Endpoint
|
2021-04-06 18:40:14 +00:00
|
|
|
ListTeams endpoint.Endpoint
|
2021-04-22 03:54:09 +00:00
|
|
|
ListTeamUsers endpoint.Endpoint
|
|
|
|
AddTeamUsers endpoint.Endpoint
|
|
|
|
DeleteTeamUsers endpoint.Endpoint
|
2021-05-31 16:02:05 +00:00
|
|
|
TeamEnrollSecrets endpoint.Endpoint
|
2021-07-13 19:54:22 +00:00
|
|
|
ListActivities endpoint.Endpoint
|
2016-09-26 17:14:39 +00:00
|
|
|
}
|
2016-09-04 05:13:42 +00:00
|
|
|
|
2021-06-04 23:51:18 +00:00
|
|
|
// MakeFleetServerEndpoints creates the Fleet API endpoints.
|
2021-06-07 01:10:58 +00:00
|
|
|
func MakeFleetServerEndpoints(svc fleet.Service, urlPrefix string, limitStore throttled.GCRAStore) FleetEndpoints {
|
2021-03-26 18:23:29 +00:00
|
|
|
limiter := ratelimit.NewMiddleware(limitStore)
|
|
|
|
|
2021-06-04 23:51:18 +00:00
|
|
|
return FleetEndpoints{
|
2021-06-03 23:24:15 +00:00
|
|
|
Login: limiter.Limit(
|
|
|
|
throttled.RateQuota{MaxRate: throttled.PerMin(10), MaxBurst: 9})(
|
2021-03-26 18:23:29 +00:00
|
|
|
makeLoginEndpoint(svc),
|
|
|
|
),
|
|
|
|
Logout: makeLogoutEndpoint(svc),
|
|
|
|
ForgotPassword: limiter.Limit(
|
|
|
|
throttled.RateQuota{MaxRate: throttled.PerHour(10), MaxBurst: 9})(
|
|
|
|
makeForgotPasswordEndpoint(svc),
|
|
|
|
),
|
2020-11-05 01:06:55 +00:00
|
|
|
ResetPassword: makeResetPasswordEndpoint(svc),
|
2021-06-03 23:24:15 +00:00
|
|
|
CreateUserWithInvite: makeCreateUserFromInviteEndpoint(svc),
|
2020-11-05 01:06:55 +00:00
|
|
|
VerifyInvite: makeVerifyInviteEndpoint(svc),
|
|
|
|
InitiateSSO: makeInitiateSSOEndpoint(svc),
|
|
|
|
CallbackSSO: makeCallbackSSOEndpoint(svc, urlPrefix),
|
|
|
|
SSOSettings: makeSSOSettingsEndpoint(svc),
|
2016-09-29 04:21:39 +00:00
|
|
|
|
2017-01-10 04:42:50 +00:00
|
|
|
// PerformRequiredPasswordReset needs only to authenticate the
|
|
|
|
// logged in user
|
2021-06-16 17:55:41 +00:00
|
|
|
PerformRequiredPasswordReset: canPerformPasswordReset(makePerformRequiredPasswordResetEndpoint(svc)),
|
|
|
|
|
|
|
|
// Standard user authentication routes
|
|
|
|
Me: authenticatedUser(svc, makeGetSessionUserEndpoint(svc)),
|
|
|
|
ChangePassword: authenticatedUser(svc, makeChangePasswordEndpoint(svc)),
|
|
|
|
GetUser: authenticatedUser(svc, makeGetUserEndpoint(svc)),
|
|
|
|
ListUsers: authenticatedUser(svc, makeListUsersEndpoint(svc)),
|
|
|
|
ModifyUser: authenticatedUser(svc, makeModifyUserEndpoint(svc)),
|
|
|
|
DeleteUser: authenticatedUser(svc, makeDeleteUserEndpoint(svc)),
|
|
|
|
RequirePasswordReset: authenticatedUser(svc, makeRequirePasswordResetEndpoint(svc)),
|
|
|
|
CreateUser: authenticatedUser(svc, makeCreateUserEndpoint(svc)),
|
|
|
|
GetSessionsForUserInfo: authenticatedUser(svc, makeGetInfoAboutSessionsForUserEndpoint(svc)),
|
|
|
|
DeleteSessionsForUser: authenticatedUser(svc, makeDeleteSessionsForUserEndpoint(svc)),
|
|
|
|
GetSessionInfo: authenticatedUser(svc, makeGetInfoAboutSessionEndpoint(svc)),
|
|
|
|
DeleteSession: authenticatedUser(svc, makeDeleteSessionEndpoint(svc)),
|
|
|
|
GetAppConfig: authenticatedUser(svc, makeGetAppConfigEndpoint(svc)),
|
|
|
|
ModifyAppConfig: authenticatedUser(svc, makeModifyAppConfigEndpoint(svc)),
|
|
|
|
ApplyEnrollSecretSpec: authenticatedUser(svc, makeApplyEnrollSecretSpecEndpoint(svc)),
|
|
|
|
GetEnrollSecretSpec: authenticatedUser(svc, makeGetEnrollSecretSpecEndpoint(svc)),
|
|
|
|
CreateInvite: authenticatedUser(svc, makeCreateInviteEndpoint(svc)),
|
|
|
|
ListInvites: authenticatedUser(svc, makeListInvitesEndpoint(svc)),
|
|
|
|
DeleteInvite: authenticatedUser(svc, makeDeleteInviteEndpoint(svc)),
|
2021-06-07 01:10:58 +00:00
|
|
|
GetQuery: authenticatedUser(svc, makeGetQueryEndpoint(svc)),
|
|
|
|
ListQueries: authenticatedUser(svc, makeListQueriesEndpoint(svc)),
|
|
|
|
CreateQuery: authenticatedUser(svc, makeCreateQueryEndpoint(svc)),
|
|
|
|
ModifyQuery: authenticatedUser(svc, makeModifyQueryEndpoint(svc)),
|
|
|
|
DeleteQuery: authenticatedUser(svc, makeDeleteQueryEndpoint(svc)),
|
|
|
|
DeleteQueryByID: authenticatedUser(svc, makeDeleteQueryByIDEndpoint(svc)),
|
|
|
|
DeleteQueries: authenticatedUser(svc, makeDeleteQueriesEndpoint(svc)),
|
|
|
|
ApplyQuerySpecs: authenticatedUser(svc, makeApplyQuerySpecsEndpoint(svc)),
|
|
|
|
GetQuerySpecs: authenticatedUser(svc, makeGetQuerySpecsEndpoint(svc)),
|
|
|
|
GetQuerySpec: authenticatedUser(svc, makeGetQuerySpecEndpoint(svc)),
|
|
|
|
CreateDistributedQueryCampaign: authenticatedUser(svc, makeCreateDistributedQueryCampaignEndpoint(svc)),
|
|
|
|
CreateDistributedQueryCampaignByNames: authenticatedUser(svc, makeCreateDistributedQueryCampaignByNamesEndpoint(svc)),
|
|
|
|
CreatePack: authenticatedUser(svc, makeCreatePackEndpoint(svc)),
|
|
|
|
ModifyPack: authenticatedUser(svc, makeModifyPackEndpoint(svc)),
|
|
|
|
GetPack: authenticatedUser(svc, makeGetPackEndpoint(svc)),
|
|
|
|
ListPacks: authenticatedUser(svc, makeListPacksEndpoint(svc)),
|
|
|
|
DeletePack: authenticatedUser(svc, makeDeletePackEndpoint(svc)),
|
|
|
|
DeletePackByID: authenticatedUser(svc, makeDeletePackByIDEndpoint(svc)),
|
|
|
|
GetScheduledQueriesInPack: authenticatedUser(svc, makeGetScheduledQueriesInPackEndpoint(svc)),
|
|
|
|
ScheduleQuery: authenticatedUser(svc, makeScheduleQueryEndpoint(svc)),
|
|
|
|
GetScheduledQuery: authenticatedUser(svc, makeGetScheduledQueryEndpoint(svc)),
|
|
|
|
ModifyScheduledQuery: authenticatedUser(svc, makeModifyScheduledQueryEndpoint(svc)),
|
|
|
|
DeleteScheduledQuery: authenticatedUser(svc, makeDeleteScheduledQueryEndpoint(svc)),
|
|
|
|
ApplyPackSpecs: authenticatedUser(svc, makeApplyPackSpecsEndpoint(svc)),
|
|
|
|
GetPackSpecs: authenticatedUser(svc, makeGetPackSpecsEndpoint(svc)),
|
|
|
|
GetPackSpec: authenticatedUser(svc, makeGetPackSpecEndpoint(svc)),
|
2021-07-16 13:15:15 +00:00
|
|
|
GlobalScheduleQuery: authenticatedUser(svc, makeGlobalScheduleQueryEndpoint(svc)),
|
|
|
|
GetGlobalSchedule: authenticatedUser(svc, makeGetGlobalScheduleEndpoint(svc)),
|
|
|
|
ModifyGlobalSchedule: authenticatedUser(svc, makeModifyGlobalScheduleEndpoint(svc)),
|
|
|
|
DeleteGlobalSchedule: authenticatedUser(svc, makeDeleteGlobalScheduleEndpoint(svc)),
|
2021-06-07 01:10:58 +00:00
|
|
|
GetHost: authenticatedUser(svc, makeGetHostEndpoint(svc)),
|
|
|
|
HostByIdentifier: authenticatedUser(svc, makeHostByIdentifierEndpoint(svc)),
|
|
|
|
ListHosts: authenticatedUser(svc, makeListHostsEndpoint(svc)),
|
|
|
|
GetHostSummary: authenticatedUser(svc, makeGetHostSummaryEndpoint(svc)),
|
|
|
|
DeleteHost: authenticatedUser(svc, makeDeleteHostEndpoint(svc)),
|
|
|
|
AddHostsToTeam: authenticatedUser(svc, makeAddHostsToTeamEndpoint(svc)),
|
|
|
|
AddHostsToTeamByFilter: authenticatedUser(svc, makeAddHostsToTeamByFilterEndpoint(svc)),
|
|
|
|
RefetchHost: authenticatedUser(svc, makeRefetchHostEndpoint(svc)),
|
|
|
|
CreateLabel: authenticatedUser(svc, makeCreateLabelEndpoint(svc)),
|
|
|
|
ModifyLabel: authenticatedUser(svc, makeModifyLabelEndpoint(svc)),
|
|
|
|
GetLabel: authenticatedUser(svc, makeGetLabelEndpoint(svc)),
|
|
|
|
ListLabels: authenticatedUser(svc, makeListLabelsEndpoint(svc)),
|
|
|
|
ListHostsInLabel: authenticatedUser(svc, makeListHostsInLabelEndpoint(svc)),
|
|
|
|
DeleteLabel: authenticatedUser(svc, makeDeleteLabelEndpoint(svc)),
|
|
|
|
DeleteLabelByID: authenticatedUser(svc, makeDeleteLabelByIDEndpoint(svc)),
|
|
|
|
ApplyLabelSpecs: authenticatedUser(svc, makeApplyLabelSpecsEndpoint(svc)),
|
|
|
|
GetLabelSpecs: authenticatedUser(svc, makeGetLabelSpecsEndpoint(svc)),
|
|
|
|
GetLabelSpec: authenticatedUser(svc, makeGetLabelSpecEndpoint(svc)),
|
|
|
|
SearchTargets: authenticatedUser(svc, makeSearchTargetsEndpoint(svc)),
|
|
|
|
GetCertificate: authenticatedUser(svc, makeCertificateEndpoint(svc)),
|
|
|
|
ChangeEmail: authenticatedUser(svc, makeChangeEmailEndpoint(svc)),
|
|
|
|
ListCarves: authenticatedUser(svc, makeListCarvesEndpoint(svc)),
|
|
|
|
GetCarve: authenticatedUser(svc, makeGetCarveEndpoint(svc)),
|
|
|
|
GetCarveBlock: authenticatedUser(svc, makeGetCarveBlockEndpoint(svc)),
|
|
|
|
Version: authenticatedUser(svc, makeVersionEndpoint(svc)),
|
2021-06-16 17:55:41 +00:00
|
|
|
CreateTeam: authenticatedUser(svc, makeCreateTeamEndpoint(svc)),
|
|
|
|
ModifyTeam: authenticatedUser(svc, makeModifyTeamEndpoint(svc)),
|
|
|
|
ModifyTeamAgentOptions: authenticatedUser(svc, makeModifyTeamAgentOptionsEndpoint(svc)),
|
|
|
|
DeleteTeam: authenticatedUser(svc, makeDeleteTeamEndpoint(svc)),
|
|
|
|
ListTeams: authenticatedUser(svc, makeListTeamsEndpoint(svc)),
|
|
|
|
ListTeamUsers: authenticatedUser(svc, makeListTeamUsersEndpoint(svc)),
|
|
|
|
AddTeamUsers: authenticatedUser(svc, makeAddTeamUsersEndpoint(svc)),
|
|
|
|
DeleteTeamUsers: authenticatedUser(svc, makeDeleteTeamUsersEndpoint(svc)),
|
|
|
|
TeamEnrollSecrets: authenticatedUser(svc, makeTeamEnrollSecretsEndpoint(svc)),
|
2021-07-13 19:54:22 +00:00
|
|
|
ListActivities: authenticatedUser(svc, makeListActivitiesEndpoint(svc)),
|
2016-09-29 04:21:39 +00:00
|
|
|
|
2019-08-13 16:42:58 +00:00
|
|
|
// Authenticated status endpoints
|
2021-06-07 01:10:58 +00:00
|
|
|
StatusResultStore: authenticatedUser(svc, makeStatusResultStoreEndpoint(svc)),
|
|
|
|
StatusLiveQuery: authenticatedUser(svc, makeStatusLiveQueryEndpoint(svc)),
|
2019-08-13 16:42:58 +00:00
|
|
|
|
2016-09-29 04:21:39 +00:00
|
|
|
// Osquery endpoints
|
2021-06-16 17:55:41 +00:00
|
|
|
EnrollAgent: makeEnrollAgentEndpoint(svc),
|
|
|
|
// Authenticated osquery endpoints
|
2016-09-29 04:21:39 +00:00
|
|
|
GetClientConfig: authenticatedHost(svc, makeGetClientConfigEndpoint(svc)),
|
|
|
|
GetDistributedQueries: authenticatedHost(svc, makeGetDistributedQueriesEndpoint(svc)),
|
|
|
|
SubmitDistributedQueryResults: authenticatedHost(svc, makeSubmitDistributedQueryResultsEndpoint(svc)),
|
|
|
|
SubmitLogs: authenticatedHost(svc, makeSubmitLogsEndpoint(svc)),
|
2020-11-05 04:45:16 +00:00
|
|
|
CarveBegin: authenticatedHost(svc, makeCarveBeginEndpoint(svc)),
|
|
|
|
// For some reason osquery does not provide a node key with the block
|
|
|
|
// data. Instead the carve session ID should be verified in the service
|
|
|
|
// method.
|
|
|
|
CarveBlock: makeCarveBlockEndpoint(svc),
|
2016-09-26 17:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-04 05:13:42 +00:00
|
|
|
|
2021-06-04 23:51:18 +00:00
|
|
|
type fleetHandlers struct {
|
2018-05-17 22:54:34 +00:00
|
|
|
Login http.Handler
|
|
|
|
Logout http.Handler
|
|
|
|
ForgotPassword http.Handler
|
|
|
|
ResetPassword http.Handler
|
|
|
|
Me http.Handler
|
|
|
|
ChangePassword http.Handler
|
2020-11-05 01:06:55 +00:00
|
|
|
CreateUserWithInvite http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
CreateUser http.Handler
|
|
|
|
GetUser http.Handler
|
|
|
|
ListUsers http.Handler
|
|
|
|
ModifyUser http.Handler
|
2021-04-08 23:53:33 +00:00
|
|
|
DeleteUser http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
RequirePasswordReset http.Handler
|
|
|
|
PerformRequiredPasswordReset http.Handler
|
|
|
|
GetSessionsForUserInfo http.Handler
|
|
|
|
DeleteSessionsForUser http.Handler
|
|
|
|
GetSessionInfo http.Handler
|
|
|
|
DeleteSession http.Handler
|
|
|
|
GetAppConfig http.Handler
|
|
|
|
ModifyAppConfig http.Handler
|
2020-05-29 16:12:39 +00:00
|
|
|
ApplyEnrollSecretSpec http.Handler
|
|
|
|
GetEnrollSecretSpec http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
CreateInvite http.Handler
|
|
|
|
ListInvites http.Handler
|
|
|
|
DeleteInvite http.Handler
|
|
|
|
VerifyInvite http.Handler
|
|
|
|
GetQuery http.Handler
|
|
|
|
ListQueries http.Handler
|
|
|
|
CreateQuery http.Handler
|
|
|
|
ModifyQuery http.Handler
|
|
|
|
DeleteQuery http.Handler
|
2018-06-15 14:13:11 +00:00
|
|
|
DeleteQueryByID http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
DeleteQueries http.Handler
|
|
|
|
ApplyQuerySpecs http.Handler
|
|
|
|
GetQuerySpecs http.Handler
|
|
|
|
GetQuerySpec http.Handler
|
|
|
|
CreateDistributedQueryCampaign http.Handler
|
|
|
|
CreateDistributedQueryCampaignByNames http.Handler
|
2018-06-15 14:13:11 +00:00
|
|
|
CreatePack http.Handler
|
|
|
|
ModifyPack http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
GetPack http.Handler
|
|
|
|
ListPacks http.Handler
|
|
|
|
DeletePack http.Handler
|
2018-06-15 14:13:11 +00:00
|
|
|
DeletePackByID http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
GetScheduledQueriesInPack http.Handler
|
2018-06-15 14:13:11 +00:00
|
|
|
ScheduleQuery http.Handler
|
|
|
|
GetScheduledQuery http.Handler
|
|
|
|
ModifyScheduledQuery http.Handler
|
|
|
|
DeleteScheduledQuery http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
ApplyPackSpecs http.Handler
|
|
|
|
GetPackSpecs http.Handler
|
|
|
|
GetPackSpec http.Handler
|
2021-07-16 13:15:15 +00:00
|
|
|
GlobalScheduleQuery http.Handler
|
|
|
|
GetGlobalSchedule http.Handler
|
|
|
|
ModifyGlobalSchedule http.Handler
|
|
|
|
DeleteGlobalSchedule http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
EnrollAgent http.Handler
|
|
|
|
GetClientConfig http.Handler
|
|
|
|
GetDistributedQueries http.Handler
|
|
|
|
SubmitDistributedQueryResults http.Handler
|
|
|
|
SubmitLogs http.Handler
|
2020-11-05 04:45:16 +00:00
|
|
|
CarveBegin http.Handler
|
|
|
|
CarveBlock http.Handler
|
2018-06-18 17:09:08 +00:00
|
|
|
CreateLabel http.Handler
|
|
|
|
ModifyLabel http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
GetLabel http.Handler
|
|
|
|
ListLabels http.Handler
|
2020-03-30 02:19:54 +00:00
|
|
|
ListHostsInLabel http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
DeleteLabel http.Handler
|
2018-06-25 20:56:59 +00:00
|
|
|
DeleteLabelByID http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
ApplyLabelSpecs http.Handler
|
|
|
|
GetLabelSpecs http.Handler
|
|
|
|
GetLabelSpec http.Handler
|
|
|
|
GetHost http.Handler
|
2020-04-22 20:54:32 +00:00
|
|
|
HostByIdentifier http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
DeleteHost http.Handler
|
2021-05-13 20:09:22 +00:00
|
|
|
RefetchHost http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
ListHosts http.Handler
|
|
|
|
GetHostSummary http.Handler
|
2021-05-17 19:23:21 +00:00
|
|
|
AddHostsToTeam http.Handler
|
2021-05-26 04:29:52 +00:00
|
|
|
AddHostsToTeamByFilter http.Handler
|
2018-05-17 22:54:34 +00:00
|
|
|
SearchTargets http.Handler
|
|
|
|
GetCertificate http.Handler
|
|
|
|
ChangeEmail http.Handler
|
|
|
|
InitiateSSO http.Handler
|
|
|
|
CallbackSSO http.Handler
|
|
|
|
SettingsSSO http.Handler
|
2019-08-13 16:42:58 +00:00
|
|
|
StatusResultStore http.Handler
|
2020-01-14 00:53:04 +00:00
|
|
|
StatusLiveQuery http.Handler
|
2020-11-05 04:45:16 +00:00
|
|
|
ListCarves http.Handler
|
2020-11-13 03:06:56 +00:00
|
|
|
GetCarve http.Handler
|
2020-11-05 04:45:16 +00:00
|
|
|
GetCarveBlock http.Handler
|
2021-03-27 01:03:31 +00:00
|
|
|
Version http.Handler
|
2021-03-18 04:59:00 +00:00
|
|
|
CreateTeam http.Handler
|
|
|
|
ModifyTeam http.Handler
|
2021-05-12 17:38:00 +00:00
|
|
|
ModifyTeamAgentOptions http.Handler
|
2021-04-20 17:20:52 +00:00
|
|
|
DeleteTeam http.Handler
|
2021-04-06 18:40:14 +00:00
|
|
|
ListTeams http.Handler
|
2021-04-22 03:54:09 +00:00
|
|
|
ListTeamUsers http.Handler
|
|
|
|
AddTeamUsers http.Handler
|
|
|
|
DeleteTeamUsers http.Handler
|
2021-05-31 16:02:05 +00:00
|
|
|
TeamEnrollSecrets http.Handler
|
2021-07-13 19:54:22 +00:00
|
|
|
ListActivities http.Handler
|
2016-09-26 17:14:39 +00:00
|
|
|
}
|
2016-09-04 05:13:42 +00:00
|
|
|
|
2021-06-04 23:51:18 +00:00
|
|
|
func makeKitHandlers(e FleetEndpoints, opts []kithttp.ServerOption) *fleetHandlers {
|
2016-12-22 17:39:44 +00:00
|
|
|
newServer := func(e endpoint.Endpoint, decodeFn kithttp.DecodeRequestFunc) http.Handler {
|
2021-06-03 23:24:15 +00:00
|
|
|
e = authzcheck.NewMiddleware().AuthzCheck()(e)
|
2017-03-15 15:55:30 +00:00
|
|
|
return kithttp.NewServer(e, decodeFn, encodeResponse, opts...)
|
2016-09-26 17:14:39 +00:00
|
|
|
}
|
2021-06-04 23:51:18 +00:00
|
|
|
return &fleetHandlers{
|
2018-05-17 22:54:34 +00:00
|
|
|
Login: newServer(e.Login, decodeLoginRequest),
|
|
|
|
Logout: newServer(e.Logout, decodeNoParamsRequest),
|
|
|
|
ForgotPassword: newServer(e.ForgotPassword, decodeForgotPasswordRequest),
|
|
|
|
ResetPassword: newServer(e.ResetPassword, decodeResetPasswordRequest),
|
|
|
|
Me: newServer(e.Me, decodeNoParamsRequest),
|
|
|
|
ChangePassword: newServer(e.ChangePassword, decodeChangePasswordRequest),
|
2020-11-05 01:06:55 +00:00
|
|
|
CreateUserWithInvite: newServer(e.CreateUserWithInvite, decodeCreateUserRequest),
|
2018-05-17 22:54:34 +00:00
|
|
|
CreateUser: newServer(e.CreateUser, decodeCreateUserRequest),
|
|
|
|
GetUser: newServer(e.GetUser, decodeGetUserRequest),
|
|
|
|
ListUsers: newServer(e.ListUsers, decodeListUsersRequest),
|
|
|
|
ModifyUser: newServer(e.ModifyUser, decodeModifyUserRequest),
|
2021-04-08 23:53:33 +00:00
|
|
|
DeleteUser: newServer(e.DeleteUser, decodeDeleteUserRequest),
|
2018-05-17 22:54:34 +00:00
|
|
|
RequirePasswordReset: newServer(e.RequirePasswordReset, decodeRequirePasswordResetRequest),
|
|
|
|
PerformRequiredPasswordReset: newServer(e.PerformRequiredPasswordReset, decodePerformRequiredPasswordResetRequest),
|
|
|
|
GetSessionsForUserInfo: newServer(e.GetSessionsForUserInfo, decodeGetInfoAboutSessionsForUserRequest),
|
|
|
|
DeleteSessionsForUser: newServer(e.DeleteSessionsForUser, decodeDeleteSessionsForUserRequest),
|
|
|
|
GetSessionInfo: newServer(e.GetSessionInfo, decodeGetInfoAboutSessionRequest),
|
|
|
|
DeleteSession: newServer(e.DeleteSession, decodeDeleteSessionRequest),
|
|
|
|
GetAppConfig: newServer(e.GetAppConfig, decodeNoParamsRequest),
|
|
|
|
ModifyAppConfig: newServer(e.ModifyAppConfig, decodeModifyAppConfigRequest),
|
2020-05-29 16:12:39 +00:00
|
|
|
ApplyEnrollSecretSpec: newServer(e.ApplyEnrollSecretSpec, decodeApplyEnrollSecretSpecRequest),
|
|
|
|
GetEnrollSecretSpec: newServer(e.GetEnrollSecretSpec, decodeNoParamsRequest),
|
2018-05-17 22:54:34 +00:00
|
|
|
CreateInvite: newServer(e.CreateInvite, decodeCreateInviteRequest),
|
|
|
|
ListInvites: newServer(e.ListInvites, decodeListInvitesRequest),
|
|
|
|
DeleteInvite: newServer(e.DeleteInvite, decodeDeleteInviteRequest),
|
|
|
|
VerifyInvite: newServer(e.VerifyInvite, decodeVerifyInviteRequest),
|
|
|
|
GetQuery: newServer(e.GetQuery, decodeGetQueryRequest),
|
|
|
|
ListQueries: newServer(e.ListQueries, decodeListQueriesRequest),
|
|
|
|
CreateQuery: newServer(e.CreateQuery, decodeCreateQueryRequest),
|
|
|
|
ModifyQuery: newServer(e.ModifyQuery, decodeModifyQueryRequest),
|
|
|
|
DeleteQuery: newServer(e.DeleteQuery, decodeDeleteQueryRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
DeleteQueryByID: newServer(e.DeleteQueryByID, decodeDeleteQueryByIDRequest),
|
2018-05-17 22:54:34 +00:00
|
|
|
DeleteQueries: newServer(e.DeleteQueries, decodeDeleteQueriesRequest),
|
|
|
|
ApplyQuerySpecs: newServer(e.ApplyQuerySpecs, decodeApplyQuerySpecsRequest),
|
|
|
|
GetQuerySpecs: newServer(e.GetQuerySpecs, decodeNoParamsRequest),
|
|
|
|
GetQuerySpec: newServer(e.GetQuerySpec, decodeGetGenericSpecRequest),
|
|
|
|
CreateDistributedQueryCampaign: newServer(e.CreateDistributedQueryCampaign, decodeCreateDistributedQueryCampaignRequest),
|
|
|
|
CreateDistributedQueryCampaignByNames: newServer(e.CreateDistributedQueryCampaignByNames, decodeCreateDistributedQueryCampaignByNamesRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
CreatePack: newServer(e.CreatePack, decodeCreatePackRequest),
|
|
|
|
ModifyPack: newServer(e.ModifyPack, decodeModifyPackRequest),
|
|
|
|
GetPack: newServer(e.GetPack, decodeGetPackRequest),
|
|
|
|
ListPacks: newServer(e.ListPacks, decodeListPacksRequest),
|
|
|
|
DeletePack: newServer(e.DeletePack, decodeDeletePackRequest),
|
|
|
|
DeletePackByID: newServer(e.DeletePackByID, decodeDeletePackByIDRequest),
|
|
|
|
GetScheduledQueriesInPack: newServer(e.GetScheduledQueriesInPack, decodeGetScheduledQueriesInPackRequest),
|
|
|
|
ScheduleQuery: newServer(e.ScheduleQuery, decodeScheduleQueryRequest),
|
|
|
|
GetScheduledQuery: newServer(e.GetScheduledQuery, decodeGetScheduledQueryRequest),
|
|
|
|
ModifyScheduledQuery: newServer(e.ModifyScheduledQuery, decodeModifyScheduledQueryRequest),
|
|
|
|
DeleteScheduledQuery: newServer(e.DeleteScheduledQuery, decodeDeleteScheduledQueryRequest),
|
|
|
|
ApplyPackSpecs: newServer(e.ApplyPackSpecs, decodeApplyPackSpecsRequest),
|
|
|
|
GetPackSpecs: newServer(e.GetPackSpecs, decodeNoParamsRequest),
|
|
|
|
GetPackSpec: newServer(e.GetPackSpec, decodeGetGenericSpecRequest),
|
2021-07-16 13:15:15 +00:00
|
|
|
GlobalScheduleQuery: newServer(e.GlobalScheduleQuery, decodeGlobalScheduleQueryRequest),
|
|
|
|
GetGlobalSchedule: newServer(e.GetGlobalSchedule, decodeGetGlobalScheduleRequest),
|
|
|
|
ModifyGlobalSchedule: newServer(e.ModifyGlobalSchedule, decodeModifyGlobalScheduleRequest),
|
|
|
|
DeleteGlobalSchedule: newServer(e.DeleteGlobalSchedule, decodeDeleteGlobalScheduleRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
EnrollAgent: newServer(e.EnrollAgent, decodeEnrollAgentRequest),
|
|
|
|
GetClientConfig: newServer(e.GetClientConfig, decodeGetClientConfigRequest),
|
|
|
|
GetDistributedQueries: newServer(e.GetDistributedQueries, decodeGetDistributedQueriesRequest),
|
|
|
|
SubmitDistributedQueryResults: newServer(e.SubmitDistributedQueryResults, decodeSubmitDistributedQueryResultsRequest),
|
|
|
|
SubmitLogs: newServer(e.SubmitLogs, decodeSubmitLogsRequest),
|
2020-11-05 04:45:16 +00:00
|
|
|
CarveBegin: newServer(e.CarveBegin, decodeCarveBeginRequest),
|
|
|
|
CarveBlock: newServer(e.CarveBlock, decodeCarveBlockRequest),
|
2018-06-18 17:09:08 +00:00
|
|
|
CreateLabel: newServer(e.CreateLabel, decodeCreateLabelRequest),
|
|
|
|
ModifyLabel: newServer(e.ModifyLabel, decodeModifyLabelRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
GetLabel: newServer(e.GetLabel, decodeGetLabelRequest),
|
|
|
|
ListLabels: newServer(e.ListLabels, decodeListLabelsRequest),
|
2020-03-30 02:19:54 +00:00
|
|
|
ListHostsInLabel: newServer(e.ListHostsInLabel, decodeListHostsInLabelRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
DeleteLabel: newServer(e.DeleteLabel, decodeDeleteLabelRequest),
|
2018-06-25 20:56:59 +00:00
|
|
|
DeleteLabelByID: newServer(e.DeleteLabelByID, decodeDeleteLabelByIDRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
ApplyLabelSpecs: newServer(e.ApplyLabelSpecs, decodeApplyLabelSpecsRequest),
|
|
|
|
GetLabelSpecs: newServer(e.GetLabelSpecs, decodeNoParamsRequest),
|
|
|
|
GetLabelSpec: newServer(e.GetLabelSpec, decodeGetGenericSpecRequest),
|
|
|
|
GetHost: newServer(e.GetHost, decodeGetHostRequest),
|
2020-04-22 20:54:32 +00:00
|
|
|
HostByIdentifier: newServer(e.HostByIdentifier, decodeHostByIdentifierRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
DeleteHost: newServer(e.DeleteHost, decodeDeleteHostRequest),
|
2021-05-13 20:09:22 +00:00
|
|
|
RefetchHost: newServer(e.RefetchHost, decodeRefetchHostRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
ListHosts: newServer(e.ListHosts, decodeListHostsRequest),
|
|
|
|
GetHostSummary: newServer(e.GetHostSummary, decodeNoParamsRequest),
|
2021-05-17 19:23:21 +00:00
|
|
|
AddHostsToTeam: newServer(e.AddHostsToTeam, decodeAddHostsToTeamRequest),
|
2021-05-26 04:29:52 +00:00
|
|
|
AddHostsToTeamByFilter: newServer(e.AddHostsToTeamByFilter, decodeAddHostsToTeamByFilterRequest),
|
2018-06-15 14:13:11 +00:00
|
|
|
SearchTargets: newServer(e.SearchTargets, decodeSearchTargetsRequest),
|
|
|
|
GetCertificate: newServer(e.GetCertificate, decodeNoParamsRequest),
|
|
|
|
ChangeEmail: newServer(e.ChangeEmail, decodeChangeEmailRequest),
|
|
|
|
InitiateSSO: newServer(e.InitiateSSO, decodeInitiateSSORequest),
|
|
|
|
CallbackSSO: newServer(e.CallbackSSO, decodeCallbackSSORequest),
|
|
|
|
SettingsSSO: newServer(e.SSOSettings, decodeNoParamsRequest),
|
2019-08-13 16:42:58 +00:00
|
|
|
StatusResultStore: newServer(e.StatusResultStore, decodeNoParamsRequest),
|
2020-01-14 00:53:04 +00:00
|
|
|
StatusLiveQuery: newServer(e.StatusLiveQuery, decodeNoParamsRequest),
|
2020-11-05 04:45:16 +00:00
|
|
|
ListCarves: newServer(e.ListCarves, decodeListCarvesRequest),
|
2020-11-13 03:06:56 +00:00
|
|
|
GetCarve: newServer(e.GetCarve, decodeGetCarveRequest),
|
|
|
|
GetCarveBlock: newServer(e.GetCarveBlock, decodeGetCarveBlockRequest),
|
2021-03-27 01:03:31 +00:00
|
|
|
Version: newServer(e.Version, decodeNoParamsRequest),
|
2021-03-18 04:59:00 +00:00
|
|
|
CreateTeam: newServer(e.CreateTeam, decodeCreateTeamRequest),
|
|
|
|
ModifyTeam: newServer(e.ModifyTeam, decodeModifyTeamRequest),
|
2021-05-12 17:38:00 +00:00
|
|
|
ModifyTeamAgentOptions: newServer(e.ModifyTeamAgentOptions, decodeModifyTeamAgentOptionsRequest),
|
2021-04-20 17:20:52 +00:00
|
|
|
DeleteTeam: newServer(e.DeleteTeam, decodeDeleteTeamRequest),
|
2021-04-06 18:40:14 +00:00
|
|
|
ListTeams: newServer(e.ListTeams, decodeListTeamsRequest),
|
2021-04-22 03:54:09 +00:00
|
|
|
ListTeamUsers: newServer(e.ListTeamUsers, decodeListTeamUsersRequest),
|
|
|
|
AddTeamUsers: newServer(e.AddTeamUsers, decodeModifyTeamUsersRequest),
|
|
|
|
DeleteTeamUsers: newServer(e.DeleteTeamUsers, decodeModifyTeamUsersRequest),
|
2021-05-31 16:02:05 +00:00
|
|
|
TeamEnrollSecrets: newServer(e.TeamEnrollSecrets, decodeTeamEnrollSecretsRequest),
|
2021-07-13 19:54:22 +00:00
|
|
|
ListActivities: newServer(e.ListActivities, decodeListActivitiesRequest),
|
2016-09-26 17:14:39 +00:00
|
|
|
}
|
2016-09-04 19:43:12 +00:00
|
|
|
}
|
2016-09-01 04:51:38 +00:00
|
|
|
|
2021-03-26 18:23:29 +00:00
|
|
|
type errorHandler struct {
|
|
|
|
logger kitlog.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *errorHandler) Handle(ctx context.Context, err error) {
|
|
|
|
// get the request path
|
|
|
|
path, _ := ctx.Value(kithttp.ContextKeyRequestPath).(string)
|
|
|
|
logger := level.Info(kitlog.With(h.logger, "path", path))
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
if e, ok := err.(fleet.ErrWithInternal); ok {
|
2021-06-03 23:24:15 +00:00
|
|
|
logger = kitlog.With(logger, "internal", e.Internal())
|
|
|
|
}
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
if e, ok := err.(fleet.ErrWithLogFields); ok {
|
2021-06-05 13:22:13 +00:00
|
|
|
logger = kitlog.With(logger, e.LogFields()...)
|
|
|
|
}
|
|
|
|
|
2021-03-26 18:23:29 +00:00
|
|
|
switch e := err.(type) {
|
|
|
|
case ratelimit.Error:
|
|
|
|
res := e.Result()
|
|
|
|
logger.Log("err", "limit exceeded", "retry_after", res.RetryAfter)
|
|
|
|
|
|
|
|
default:
|
|
|
|
logger.Log("err", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 17:39:32 +00:00
|
|
|
// MakeHandler creates an HTTP handler for the Fleet server endpoints.
|
2021-06-06 22:07:29 +00:00
|
|
|
func MakeHandler(svc fleet.Service, config config.FleetConfig, logger kitlog.Logger, limitStore throttled.GCRAStore) http.Handler {
|
2021-06-04 23:51:18 +00:00
|
|
|
fleetAPIOptions := []kithttp.ServerOption{
|
2016-09-04 19:43:12 +00:00
|
|
|
kithttp.ServerBefore(
|
2017-12-01 00:52:23 +00:00
|
|
|
kithttp.PopulateRequestContext, // populate the request context with common fields
|
2021-06-07 01:10:58 +00:00
|
|
|
setRequestsContexts(svc),
|
2016-09-04 19:43:12 +00:00
|
|
|
),
|
2021-03-26 18:23:29 +00:00
|
|
|
//kithttp.ServerErrorLogger(logger),
|
|
|
|
kithttp.ServerErrorHandler(&errorHandler{logger}),
|
2016-09-23 02:41:58 +00:00
|
|
|
kithttp.ServerErrorEncoder(encodeError),
|
2016-09-04 19:43:12 +00:00
|
|
|
kithttp.ServerAfter(
|
|
|
|
kithttp.SetContentType("application/json; charset=utf-8"),
|
|
|
|
),
|
|
|
|
}
|
2016-08-28 03:59:17 +00:00
|
|
|
|
2021-06-07 01:10:58 +00:00
|
|
|
fleetEndpoints := MakeFleetServerEndpoints(svc, config.Server.URLPrefix, limitStore)
|
2021-06-04 23:51:18 +00:00
|
|
|
fleetHandlers := makeKitHandlers(fleetEndpoints, fleetAPIOptions)
|
2016-09-26 17:14:39 +00:00
|
|
|
|
2016-09-04 19:43:12 +00:00
|
|
|
r := mux.NewRouter()
|
2021-02-10 20:13:11 +00:00
|
|
|
|
2021-06-04 23:51:18 +00:00
|
|
|
attachFleetAPIRoutes(r, fleetHandlers)
|
2021-07-16 18:28:13 +00:00
|
|
|
attachNewStyleFleetAPIRoutes(r, svc, fleetAPIOptions)
|
2021-02-10 20:13:11 +00:00
|
|
|
|
2020-11-13 03:06:56 +00:00
|
|
|
// Results endpoint is handled different due to websockets use
|
2021-02-10 20:13:11 +00:00
|
|
|
r.PathPrefix("/api/v1/fleet/results/").
|
2021-06-07 01:10:58 +00:00
|
|
|
Handler(makeStreamDistributedQueryCampaignResultsHandler(svc, logger)).
|
2021-02-10 20:13:11 +00:00
|
|
|
Name("distributed_query_results")
|
|
|
|
r.PathPrefix("/api/v1/fleet/results/").
|
2021-06-07 01:10:58 +00:00
|
|
|
Handler(makeStreamDistributedQueryCampaignResultsHandler(svc, logger)).
|
2017-03-01 21:14:26 +00:00
|
|
|
Name("distributed_query_results")
|
|
|
|
|
2020-11-13 03:06:56 +00:00
|
|
|
addMetrics(r)
|
|
|
|
|
2016-08-28 03:59:17 +00:00
|
|
|
return r
|
|
|
|
}
|
2016-09-26 17:14:39 +00:00
|
|
|
|
2016-12-22 17:39:44 +00:00
|
|
|
// addMetrics decorates each hander with prometheus instrumentation
|
|
|
|
func addMetrics(r *mux.Router) {
|
|
|
|
walkFn := func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
|
|
|
|
route.Handler(prometheus.InstrumentHandler(route.GetName(), route.GetHandler()))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
r.Walk(walkFn)
|
|
|
|
}
|
|
|
|
|
2021-06-04 23:51:18 +00:00
|
|
|
func attachFleetAPIRoutes(r *mux.Router, h *fleetHandlers) {
|
2021-02-10 20:13:11 +00:00
|
|
|
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")
|
|
|
|
r.Handle("/api/v1/fleet/reset_password", h.ResetPassword).Methods("POST").Name("reset_password")
|
|
|
|
r.Handle("/api/v1/fleet/me", h.Me).Methods("GET").Name("me")
|
|
|
|
r.Handle("/api/v1/fleet/change_password", h.ChangePassword).Methods("POST").Name("change_password")
|
|
|
|
r.Handle("/api/v1/fleet/perform_required_password_reset", h.PerformRequiredPasswordReset).Methods("POST").Name("perform_required_password_reset")
|
|
|
|
r.Handle("/api/v1/fleet/sso", h.InitiateSSO).Methods("POST").Name("intiate_sso")
|
|
|
|
r.Handle("/api/v1/fleet/sso", h.SettingsSSO).Methods("GET").Name("sso_config")
|
|
|
|
r.Handle("/api/v1/fleet/sso/callback", h.CallbackSSO).Methods("POST").Name("callback_sso")
|
|
|
|
r.Handle("/api/v1/fleet/users", h.ListUsers).Methods("GET").Name("list_users")
|
|
|
|
r.Handle("/api/v1/fleet/users", h.CreateUserWithInvite).Methods("POST").Name("create_user_with_invite")
|
|
|
|
r.Handle("/api/v1/fleet/users/admin", h.CreateUser).Methods("POST").Name("create_user")
|
|
|
|
r.Handle("/api/v1/fleet/users/{id}", h.GetUser).Methods("GET").Name("get_user")
|
|
|
|
r.Handle("/api/v1/fleet/users/{id}", h.ModifyUser).Methods("PATCH").Name("modify_user")
|
2021-04-08 23:53:33 +00:00
|
|
|
r.Handle("/api/v1/fleet/users/{id}", h.DeleteUser).Methods("DELETE").Name("delete_user")
|
2021-02-10 20:13:11 +00:00
|
|
|
r.Handle("/api/v1/fleet/users/{id}/require_password_reset", h.RequirePasswordReset).Methods("POST").Name("require_password_reset")
|
|
|
|
r.Handle("/api/v1/fleet/users/{id}/sessions", h.GetSessionsForUserInfo).Methods("GET").Name("get_session_for_user")
|
|
|
|
r.Handle("/api/v1/fleet/users/{id}/sessions", h.DeleteSessionsForUser).Methods("DELETE").Name("delete_session_for_user")
|
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/sessions/{id}", h.GetSessionInfo).Methods("GET").Name("get_session_info")
|
|
|
|
r.Handle("/api/v1/fleet/sessions/{id}", h.DeleteSession).Methods("DELETE").Name("delete_session")
|
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/config/certificate", h.GetCertificate).Methods("GET").Name("get_certificate")
|
|
|
|
r.Handle("/api/v1/fleet/config", h.GetAppConfig).Methods("GET").Name("get_app_config")
|
|
|
|
r.Handle("/api/v1/fleet/config", h.ModifyAppConfig).Methods("PATCH").Name("modify_app_config")
|
|
|
|
r.Handle("/api/v1/fleet/spec/enroll_secret", h.ApplyEnrollSecretSpec).Methods("POST").Name("apply_enroll_secret_spec")
|
|
|
|
r.Handle("/api/v1/fleet/spec/enroll_secret", h.GetEnrollSecretSpec).Methods("GET").Name("get_enroll_secret_spec")
|
|
|
|
r.Handle("/api/v1/fleet/invites", h.CreateInvite).Methods("POST").Name("create_invite")
|
|
|
|
r.Handle("/api/v1/fleet/invites", h.ListInvites).Methods("GET").Name("list_invites")
|
|
|
|
r.Handle("/api/v1/fleet/invites/{id}", h.DeleteInvite).Methods("DELETE").Name("delete_invite")
|
|
|
|
r.Handle("/api/v1/fleet/invites/{token}", h.VerifyInvite).Methods("GET").Name("verify_invite")
|
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/email/change/{token}", h.ChangeEmail).Methods("GET").Name("change_email")
|
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/queries/{id}", h.GetQuery).Methods("GET").Name("get_query")
|
|
|
|
r.Handle("/api/v1/fleet/queries", h.ListQueries).Methods("GET").Name("list_queries")
|
|
|
|
r.Handle("/api/v1/fleet/queries", h.CreateQuery).Methods("POST").Name("create_query")
|
|
|
|
r.Handle("/api/v1/fleet/queries/{id}", h.ModifyQuery).Methods("PATCH").Name("modify_query")
|
|
|
|
r.Handle("/api/v1/fleet/queries/{name}", h.DeleteQuery).Methods("DELETE").Name("delete_query")
|
|
|
|
r.Handle("/api/v1/fleet/queries/id/{id}", h.DeleteQueryByID).Methods("DELETE").Name("delete_query_by_id")
|
|
|
|
r.Handle("/api/v1/fleet/queries/delete", h.DeleteQueries).Methods("POST").Name("delete_queries")
|
|
|
|
r.Handle("/api/v1/fleet/spec/queries", h.ApplyQuerySpecs).Methods("POST").Name("apply_query_specs")
|
|
|
|
r.Handle("/api/v1/fleet/spec/queries", h.GetQuerySpecs).Methods("GET").Name("get_query_specs")
|
|
|
|
r.Handle("/api/v1/fleet/spec/queries/{name}", h.GetQuerySpec).Methods("GET").Name("get_query_spec")
|
|
|
|
r.Handle("/api/v1/fleet/queries/run", h.CreateDistributedQueryCampaign).Methods("POST").Name("create_distributed_query_campaign")
|
|
|
|
r.Handle("/api/v1/fleet/queries/run_by_names", h.CreateDistributedQueryCampaignByNames).Methods("POST").Name("create_distributed_query_campaign_by_names")
|
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/packs", h.CreatePack).Methods("POST").Name("create_pack")
|
|
|
|
r.Handle("/api/v1/fleet/packs/{id}", h.ModifyPack).Methods("PATCH").Name("modify_pack")
|
|
|
|
r.Handle("/api/v1/fleet/packs/{id}", h.GetPack).Methods("GET").Name("get_pack")
|
|
|
|
r.Handle("/api/v1/fleet/packs", h.ListPacks).Methods("GET").Name("list_packs")
|
|
|
|
r.Handle("/api/v1/fleet/packs/{name}", h.DeletePack).Methods("DELETE").Name("delete_pack")
|
|
|
|
r.Handle("/api/v1/fleet/packs/id/{id}", h.DeletePackByID).Methods("DELETE").Name("delete_pack_by_id")
|
|
|
|
r.Handle("/api/v1/fleet/packs/{id}/scheduled", h.GetScheduledQueriesInPack).Methods("GET").Name("get_scheduled_queries_in_pack")
|
|
|
|
r.Handle("/api/v1/fleet/schedule", h.ScheduleQuery).Methods("POST").Name("schedule_query")
|
|
|
|
r.Handle("/api/v1/fleet/schedule/{id}", h.GetScheduledQuery).Methods("GET").Name("get_scheduled_query")
|
|
|
|
r.Handle("/api/v1/fleet/schedule/{id}", h.ModifyScheduledQuery).Methods("PATCH").Name("modify_scheduled_query")
|
|
|
|
r.Handle("/api/v1/fleet/schedule/{id}", h.DeleteScheduledQuery).Methods("DELETE").Name("delete_scheduled_query")
|
|
|
|
r.Handle("/api/v1/fleet/spec/packs", h.ApplyPackSpecs).Methods("POST").Name("apply_pack_specs")
|
|
|
|
r.Handle("/api/v1/fleet/spec/packs", h.GetPackSpecs).Methods("GET").Name("get_pack_specs")
|
|
|
|
r.Handle("/api/v1/fleet/spec/packs/{name}", h.GetPackSpec).Methods("GET").Name("get_pack_spec")
|
|
|
|
|
2021-07-16 13:15:15 +00:00
|
|
|
r.Handle("/api/v1/fleet/global/schedule", h.GetGlobalSchedule).Methods("GET").Name("set_global_schedule")
|
|
|
|
r.Handle("/api/v1/fleet/global/schedule", h.GlobalScheduleQuery).Methods("POST").Name("add_to_global_schedule")
|
|
|
|
r.Handle("/api/v1/fleet/global/schedule/{id}", h.ModifyGlobalSchedule).Methods("PATCH").Name("modify_global_schedule")
|
|
|
|
r.Handle("/api/v1/fleet/global/schedule/{id}", h.DeleteGlobalSchedule).Methods("DELETE").Name("delete_global_schedule")
|
|
|
|
|
2021-02-10 20:13:11 +00:00
|
|
|
r.Handle("/api/v1/fleet/labels", h.CreateLabel).Methods("POST").Name("create_label")
|
|
|
|
r.Handle("/api/v1/fleet/labels/{id}", h.ModifyLabel).Methods("PATCH").Name("modify_label")
|
|
|
|
r.Handle("/api/v1/fleet/labels/{id}", h.GetLabel).Methods("GET").Name("get_label")
|
|
|
|
r.Handle("/api/v1/fleet/labels", h.ListLabels).Methods("GET").Name("list_labels")
|
|
|
|
r.Handle("/api/v1/fleet/labels/{id}/hosts", h.ListHostsInLabel).Methods("GET").Name("list_hosts_in_label")
|
|
|
|
r.Handle("/api/v1/fleet/labels/{name}", h.DeleteLabel).Methods("DELETE").Name("delete_label")
|
|
|
|
r.Handle("/api/v1/fleet/labels/id/{id}", h.DeleteLabelByID).Methods("DELETE").Name("delete_label_by_id")
|
|
|
|
r.Handle("/api/v1/fleet/spec/labels", h.ApplyLabelSpecs).Methods("POST").Name("apply_label_specs")
|
|
|
|
r.Handle("/api/v1/fleet/spec/labels", h.GetLabelSpecs).Methods("GET").Name("get_label_specs")
|
|
|
|
r.Handle("/api/v1/fleet/spec/labels/{name}", h.GetLabelSpec).Methods("GET").Name("get_label_spec")
|
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/hosts", h.ListHosts).Methods("GET").Name("list_hosts")
|
|
|
|
r.Handle("/api/v1/fleet/host_summary", h.GetHostSummary).Methods("GET").Name("get_host_summary")
|
|
|
|
r.Handle("/api/v1/fleet/hosts/{id}", h.GetHost).Methods("GET").Name("get_host")
|
|
|
|
r.Handle("/api/v1/fleet/hosts/identifier/{identifier}", h.HostByIdentifier).Methods("GET").Name("host_by_identifier")
|
|
|
|
r.Handle("/api/v1/fleet/hosts/{id}", h.DeleteHost).Methods("DELETE").Name("delete_host")
|
2021-05-17 19:23:21 +00:00
|
|
|
r.Handle("/api/v1/fleet/hosts/transfer", h.AddHostsToTeam).Methods("POST").Name("add_hosts_to_team")
|
2021-05-26 04:29:52 +00:00
|
|
|
r.Handle("/api/v1/fleet/hosts/transfer/filter", h.AddHostsToTeamByFilter).Methods("POST").Name("add_hosts_to_team_by_filter")
|
2021-05-13 20:09:22 +00:00
|
|
|
r.Handle("/api/v1/fleet/hosts/{id}/refetch", h.RefetchHost).Methods("POST").Name("refetch_host")
|
2021-02-10 20:13:11 +00:00
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/targets", h.SearchTargets).Methods("POST").Name("search_targets")
|
|
|
|
|
2021-03-27 01:03:31 +00:00
|
|
|
r.Handle("/api/v1/fleet/version", h.Version).Methods("GET").Name("version")
|
|
|
|
|
2021-02-10 20:13:11 +00:00
|
|
|
r.Handle("/api/v1/fleet/status/result_store", h.StatusResultStore).Methods("GET").Name("status_result_store")
|
|
|
|
r.Handle("/api/v1/fleet/status/live_query", h.StatusLiveQuery).Methods("GET").Name("status_live_query")
|
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/carves", h.ListCarves).Methods("GET").Name("list_carves")
|
|
|
|
r.Handle("/api/v1/fleet/carves/{id}", h.GetCarve).Methods("GET").Name("get_carve")
|
|
|
|
r.Handle("/api/v1/fleet/carves/{id}/block/{block_id}", h.GetCarveBlock).Methods("GET").Name("get_carve_block")
|
2020-11-05 04:45:16 +00:00
|
|
|
|
2021-03-18 04:59:00 +00:00
|
|
|
r.Handle("/api/v1/fleet/teams", h.CreateTeam).Methods("POST").Name("create_team")
|
2021-04-06 18:40:14 +00:00
|
|
|
r.Handle("/api/v1/fleet/teams", h.ListTeams).Methods("GET").Name("list_teams")
|
2021-03-18 04:59:00 +00:00
|
|
|
r.Handle("/api/v1/fleet/teams/{id}", h.ModifyTeam).Methods("PATCH").Name("modify_team")
|
2021-04-20 17:20:52 +00:00
|
|
|
r.Handle("/api/v1/fleet/teams/{id}", h.DeleteTeam).Methods("DELETE").Name("delete_team")
|
2021-05-12 17:38:00 +00:00
|
|
|
r.Handle("/api/v1/fleet/teams/{id}/agent_options", h.ModifyTeamAgentOptions).Methods("POST").Name("modify_team_agent_options")
|
2021-04-22 03:54:09 +00:00
|
|
|
r.Handle("/api/v1/fleet/teams/{id}/users", h.ListTeamUsers).Methods("GET").Name("team_users")
|
|
|
|
r.Handle("/api/v1/fleet/teams/{id}/users", h.AddTeamUsers).Methods("PATCH").Name("add_team_users")
|
|
|
|
r.Handle("/api/v1/fleet/teams/{id}/users", h.DeleteTeamUsers).Methods("DELETE").Name("delete_team_users")
|
2021-05-31 16:02:05 +00:00
|
|
|
r.Handle("/api/v1/fleet/teams/{id}/secrets", h.TeamEnrollSecrets).Methods("GET").Name("get_team_enroll_secrets")
|
2021-03-18 04:59:00 +00:00
|
|
|
|
2016-12-22 17:39:44 +00:00
|
|
|
r.Handle("/api/v1/osquery/enroll", h.EnrollAgent).Methods("POST").Name("enroll_agent")
|
|
|
|
r.Handle("/api/v1/osquery/config", h.GetClientConfig).Methods("POST").Name("get_client_config")
|
|
|
|
r.Handle("/api/v1/osquery/distributed/read", h.GetDistributedQueries).Methods("POST").Name("get_distributed_queries")
|
|
|
|
r.Handle("/api/v1/osquery/distributed/write", h.SubmitDistributedQueryResults).Methods("POST").Name("submit_distributed_query_results")
|
|
|
|
r.Handle("/api/v1/osquery/log", h.SubmitLogs).Methods("POST").Name("submit_logs")
|
2020-11-05 04:45:16 +00:00
|
|
|
r.Handle("/api/v1/osquery/carve/begin", h.CarveBegin).Methods("POST").Name("carve_begin")
|
|
|
|
r.Handle("/api/v1/osquery/carve/block", h.CarveBlock).Methods("POST").Name("carve_block")
|
2021-07-13 19:54:22 +00:00
|
|
|
|
|
|
|
r.Handle("/api/v1/fleet/activities", h.ListActivities).Methods("GET").Name("list_activities")
|
2016-09-26 17:14:39 +00:00
|
|
|
}
|
2016-11-09 17:19:07 +00:00
|
|
|
|
2021-07-16 18:28:13 +00:00
|
|
|
func attachNewStyleFleetAPIRoutes(r *mux.Router, svc fleet.Service, opts []kithttp.ServerOption) {
|
|
|
|
handle("POST", "/api/v1/fleet/users/roles/spec", makeApplyUserRoleSpecsEndpoint(svc, opts), "apply_user_roles_spec", r)
|
2021-07-21 17:03:10 +00:00
|
|
|
handle("POST", "/api/v1/fleet/translate", makeTranslatorEndpoint(svc, opts), "translator", r)
|
2021-07-19 19:48:49 +00:00
|
|
|
handle("POST", "/api/v1/fleet/spec/teams", makeApplyTeamSpecsEndpoint(svc, opts), "apply_team_specs", r)
|
2021-07-16 18:28:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func handle(verb, path string, handler http.Handler, name string, r *mux.Router) {
|
|
|
|
r.Handle(
|
|
|
|
path,
|
|
|
|
handler,
|
|
|
|
).Methods(verb).Name(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this duplicates the one in makeKitHandler
|
|
|
|
func newServer(e endpoint.Endpoint, decodeFn kithttp.DecodeRequestFunc, opts []kithttp.ServerOption) http.Handler {
|
|
|
|
e = authzcheck.NewMiddleware().AuthzCheck()(e)
|
|
|
|
return kithttp.NewServer(e, decodeFn, encodeResponse, opts...)
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:10:55 +00:00
|
|
|
// WithSetup is an http middleware that checks if setup procedures have been completed.
|
2017-02-09 18:43:45 +00:00
|
|
|
// If setup hasn't been completed it serves the API with a setup middleware.
|
2016-11-09 17:19:07 +00:00
|
|
|
// If the server is already configured, the default API handler is exposed.
|
2021-06-06 22:07:29 +00:00
|
|
|
func WithSetup(svc fleet.Service, logger kitlog.Logger, next http.Handler) http.HandlerFunc {
|
2016-12-02 18:46:31 +00:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
configRouter := http.NewServeMux()
|
|
|
|
configRouter.Handle("/api/v1/setup", kithttp.NewServer(
|
|
|
|
makeSetupEndpoint(svc),
|
|
|
|
decodeSetupRequest,
|
|
|
|
encodeResponse,
|
|
|
|
))
|
2017-01-12 00:40:58 +00:00
|
|
|
// whitelist osqueryd endpoints
|
|
|
|
if strings.HasPrefix(r.URL.Path, "/api/v1/osquery") {
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
return
|
|
|
|
}
|
2021-06-03 23:24:15 +00:00
|
|
|
requireSetup, err := svc.SetupRequired(context.Background())
|
2017-02-09 18:43:45 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Log("msg", "fetching setup info from db", "err", err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if requireSetup {
|
2016-12-02 18:46:31 +00:00
|
|
|
configRouter.ServeHTTP(w, r)
|
2017-02-09 18:43:45 +00:00
|
|
|
return
|
2016-12-02 18:46:31 +00:00
|
|
|
}
|
2017-02-09 18:43:45 +00:00
|
|
|
next.ServeHTTP(w, r)
|
2016-11-09 17:19:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-29 23:36:36 +00:00
|
|
|
// RedirectLoginToSetup detects if the setup endpoint should be used. If setup is required it redirect all
|
|
|
|
// frontend urls to /setup, otherwise the frontend router is used.
|
2021-06-06 22:07:29 +00:00
|
|
|
func RedirectLoginToSetup(svc fleet.Service, logger kitlog.Logger, next http.Handler, urlPrefix string) http.HandlerFunc {
|
2016-12-29 23:36:36 +00:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
redirect := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2017-09-01 16:42:46 +00:00
|
|
|
if r.URL.Path == "/setup" {
|
2016-12-29 23:36:36 +00:00
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
newURL := r.URL
|
2019-10-16 23:40:45 +00:00
|
|
|
newURL.Path = urlPrefix + "/setup"
|
2016-12-29 23:36:36 +00:00
|
|
|
http.Redirect(w, r, newURL.String(), http.StatusTemporaryRedirect)
|
|
|
|
})
|
2017-02-09 18:43:45 +00:00
|
|
|
|
2021-06-03 23:24:15 +00:00
|
|
|
setupRequired, err := svc.SetupRequired(context.Background())
|
2017-02-09 18:43:45 +00:00
|
|
|
if err != nil {
|
2017-09-01 16:42:46 +00:00
|
|
|
logger.Log("msg", "fetching setupinfo from db", "err", err)
|
2017-02-09 18:43:45 +00:00
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if setupRequired {
|
2016-12-29 23:36:36 +00:00
|
|
|
redirect.ServeHTTP(w, r)
|
2017-02-09 18:43:45 +00:00
|
|
|
return
|
2016-12-29 23:36:36 +00:00
|
|
|
}
|
2019-10-16 23:40:45 +00:00
|
|
|
RedirectSetupToLogin(svc, logger, next, urlPrefix).ServeHTTP(w, r)
|
2016-11-09 17:19:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 16:42:46 +00:00
|
|
|
// RedirectSetupToLogin forces the /setup path to be redirected to login. This middleware is used after
|
2017-01-11 19:05:07 +00:00
|
|
|
// the app has been setup.
|
2021-06-06 22:07:29 +00:00
|
|
|
func RedirectSetupToLogin(svc fleet.Service, logger kitlog.Logger, next http.Handler, urlPrefix string) http.HandlerFunc {
|
2017-01-11 19:05:07 +00:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Path == "/setup" {
|
|
|
|
newURL := r.URL
|
2019-10-16 23:40:45 +00:00
|
|
|
newURL.Path = urlPrefix + "/login"
|
2017-01-11 19:05:07 +00:00
|
|
|
http.Redirect(w, r, newURL.String(), http.StatusTemporaryRedirect)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
}
|