Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/fleet-server into feat/bulk…
Browse files Browse the repository at this point in the history
…-api-update
  • Loading branch information
michalpristas committed Sep 19, 2022
2 parents 36a72bf + 33b812c commit be82f8b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- Give a grace period when starting the unenroll monitor. {issue}1500[1500]
- Fixes a race condition between the unenroller goroutine and the main goroutine for the coordinator monitor. {issues}1738[1738]
- Remove events from agent checkin body. {issue}1774[1774]
- Improve authc debug logging. {pull}1870[1870]
- Add error detail to catch-all HTTP error response. {pull}1854[1854]
==== New Features

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/integration/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ELASTICSEARCH_VERSION=8.5.0-589a4a10-SNAPSHOT
ELASTICSEARCH_VERSION=8.5.0-c7913db3-SNAPSHOT
ELASTICSEARCH_USERNAME=elastic
ELASTICSEARCH_PASSWORD=changeme
TEST_ELASTICSEARCH_HOSTS=localhost:9200
15 changes: 10 additions & 5 deletions internal/pkg/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var (
func authAPIKey(r *http.Request, bulker bulk.Bulk, c cache.Cache) (*apikey.APIKey, error) {
span, ctx := apm.StartSpan(r.Context(), "authAPIKey", "auth")
defer span.End()
start := time.Now()
reqID := r.Header.Get(logger.HeaderRequestID)

key, err := apikey.ExtractAPIKey(r)
if err != nil {
Expand All @@ -41,15 +43,17 @@ func authAPIKey(r *http.Request, bulker bulk.Bulk, c cache.Cache) (*apikey.APIKe

if c.ValidAPIKey(*key) {
span.Context.SetLabel("api_key_cache_hit", true)
log.Debug().
Str("id", key.ID).
Str(ECSHTTPRequestID, reqID).
Int64(ECSEventDuration, time.Since(start).Nanoseconds()).
Bool("fleet.api_key.cache_hit", true).
Msg("ApiKey authenticated")
return key, nil
} else {
span.Context.SetLabel("api_key_cache_hit", false)
}

reqID := r.Header.Get(logger.HeaderRequestID)

start := time.Now()

info, err := bulker.APIKeyAuth(ctx, *key)

if err != nil {
Expand All @@ -62,14 +66,15 @@ func authAPIKey(r *http.Request, bulker bulk.Bulk, c cache.Cache) (*apikey.APIKe
return nil, err
}

log.Trace().
log.Debug().
Str("id", key.ID).
Str(ECSHTTPRequestID, reqID).
Int64(ECSEventDuration, time.Since(start).Nanoseconds()).
Str("userName", info.UserName).
Strs("roles", info.Roles).
Bool("enabled", info.Enabled).
RawJSON("meta", info.Metadata).
Bool("fleet.api_key.cache_hit", false).
Msg("ApiKey authenticated")

c.SetAPIKey(*key, info.Enabled)
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func NewHTTPErrResp(err error) HTTPErrResp {
return HTTPErrResp{
StatusCode: http.StatusBadRequest,
Error: "BadRequest",
Message: err.Error(),
Level: zerolog.InfoLevel,
}
}
Expand Down

0 comments on commit be82f8b

Please sign in to comment.