Skip to content

Commit

Permalink
DynamoDB events by session ID (#13284)
Browse files Browse the repository at this point in the history
  • Loading branch information
smallinsky authored Jul 4, 2022
1 parent 7ffebb3 commit eb2401d
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 182 deletions.
2 changes: 1 addition & 1 deletion lib/auth/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ func (s *APIServer) searchSessionEvents(auth ClientI, w http.ResponseWriter, r *
}
}
// only pull back start and end events to build list of completed sessions
eventsList, _, err := auth.SearchSessionEvents(from, to, limit, types.EventOrderDescending, "", nil)
eventsList, _, err := auth.SearchSessionEvents(from, to, limit, types.EventOrderDescending, "", nil, "")
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down
6 changes: 3 additions & 3 deletions lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2950,7 +2950,7 @@ func (a *ServerWithRoles) findSessionEndEvent(namespace string, sid session.ID)
&types.WhereExpr{Equals: types.WhereExpr2{
L: &types.WhereExpr{Field: events.SessionEventID},
R: &types.WhereExpr{Literal: sid.String()},
}},
}}, sid.String(),
)
if err != nil {
return nil, trace.Wrap(err)
Expand Down Expand Up @@ -4144,7 +4144,7 @@ func (a *ServerWithRoles) SearchEvents(fromUTC, toUTC time.Time, namespace strin
}

// SearchSessionEvents allows searching session audit events with pagination support.
func (a *ServerWithRoles) SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr) (events []apievents.AuditEvent, lastKey string, err error) {
func (a *ServerWithRoles) SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr, sessionID string) (events []apievents.AuditEvent, lastKey string, err error) {
if cond != nil {
return nil, "", trace.BadParameter("cond is an internal parameter, should not be set by client")
}
Expand All @@ -4155,7 +4155,7 @@ func (a *ServerWithRoles) SearchSessionEvents(fromUTC, toUTC time.Time, limit in
}

// TODO(codingllama): Refactor cond out of SearchSessionEvents and simplify signature.
events, lastKey, err = a.alog.SearchSessionEvents(fromUTC, toUTC, limit, order, startKey, cond)
events, lastKey, err = a.alog.SearchSessionEvents(fromUTC, toUTC, limit, order, startKey, cond, sessionID)
if err != nil {
return nil, "", trace.Wrap(err)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/clt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ func (c *Client) SearchEvents(fromUTC, toUTC time.Time, namespace string, eventT
}

// SearchSessionEvents returns session related events to find completed sessions.
func (c *Client) SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr) ([]apievents.AuditEvent, string, error) {
func (c *Client) SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr, sessionID string) ([]apievents.AuditEvent, string, error) {
events, lastKey, err := c.APIClient.SearchSessionEvents(context.TODO(), fromUTC, toUTC, limit, order, startKey)
if err != nil {
return nil, "", trace.Wrap(err)
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3208,7 +3208,7 @@ func (g *GRPCServer) GetSessionEvents(ctx context.Context, req *proto.GetSession
return nil, trace.Wrap(err)
}

rawEvents, lastkey, err := auth.ServerWithRoles.SearchSessionEvents(req.StartDate, req.EndDate, int(req.Limit), types.EventOrder(req.Order), req.StartKey, nil)
rawEvents, lastkey, err := auth.ServerWithRoles.SearchSessionEvents(req.StartDate, req.EndDate, int(req.Limit), types.EventOrder(req.Order), req.StartKey, nil, "")
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/events/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ type IAuditLog interface {
// a query to be resumed.
//
// This function may never return more than 1 MiB of event data.
SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr) ([]apievents.AuditEvent, string, error)
SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr, sessionID string) ([]apievents.AuditEvent, string, error)

// StreamSessionEvents streams all events from a given session recording. An error is returned on the first
// channel if one is encountered. Otherwise the event channel is closed when the stream ends.
Expand Down
15 changes: 8 additions & 7 deletions lib/events/auditlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ import (
"sync"
"time"

"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"

"github.com/gravitational/teleport"
apidefaults "github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/api/types"
apievents "github.com/gravitational/teleport/api/types/events"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/session"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -870,12 +871,12 @@ func (l *AuditLog) SearchEvents(fromUTC, toUTC time.Time, namespace string, even
return l.localLog.SearchEvents(fromUTC, toUTC, namespace, eventType, limit, order, startKey)
}

func (l *AuditLog) SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr) ([]apievents.AuditEvent, string, error) {
func (l *AuditLog) SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr, sessionID string) ([]apievents.AuditEvent, string, error) {
l.log.Debugf("SearchSessionEvents(%v, %v, %v)", fromUTC, toUTC, limit)
if l.ExternalLog != nil {
return l.ExternalLog.SearchSessionEvents(fromUTC, toUTC, limit, order, startKey, cond)
return l.ExternalLog.SearchSessionEvents(fromUTC, toUTC, limit, order, startKey, cond, sessionID)
}
return l.localLog.SearchSessionEvents(fromUTC, toUTC, limit, order, startKey, cond)
return l.localLog.SearchSessionEvents(fromUTC, toUTC, limit, order, startKey, cond, sessionID)
}

// StreamSessionEvents streams all events from a given session recording. An error is returned on the first
Expand Down
2 changes: 1 addition & 1 deletion lib/events/discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (d *DiscardAuditLog) GetSessionEvents(namespace string, sid session.ID, aft
func (d *DiscardAuditLog) SearchEvents(fromUTC, toUTC time.Time, namespace string, eventType []string, limit int, order types.EventOrder, startKey string) ([]apievents.AuditEvent, string, error) {
return make([]apievents.AuditEvent, 0), "", nil
}
func (d *DiscardAuditLog) SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr) ([]apievents.AuditEvent, string, error) {
func (d *DiscardAuditLog) SearchSessionEvents(fromUTC, toUTC time.Time, limit int, order types.EventOrder, startKey string, cond *types.WhereExpr, sessionID string) ([]apievents.AuditEvent, string, error) {
return make([]apievents.AuditEvent, 0), "", nil
}
func (d *DiscardAuditLog) EmitAuditEvent(ctx context.Context, event apievents.AuditEvent) error {
Expand Down
Loading

0 comments on commit eb2401d

Please sign in to comment.