Skip to content

Commit

Permalink
audits: populate server_version in ServerMetadata (#42283)
Browse files Browse the repository at this point in the history
This PR completes the work introduced by
#42157 to all usages of
`ServerMetadata`.

Signed-off-by: Tiago Silva <[email protected]>
  • Loading branch information
tigrato authored Jun 3, 2024
1 parent afd86d2 commit a590006
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/bpf/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/gravitational/trace"
"github.com/gravitational/ttlmap"

ossteleport "github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/constants"
apievents "github.com/gravitational/teleport/api/types/events"
controlgroup "github.com/gravitational/teleport/lib/cgroup"
Expand Down Expand Up @@ -388,6 +389,7 @@ func (s *Service) emitCommandEvent(eventBytes []byte) {
Code: events.SessionCommandCode,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: ossteleport.Version,
ServerID: ctx.ServerID,
ServerHostname: ctx.ServerHostname,
ServerNamespace: ctx.Namespace,
Expand Down Expand Up @@ -446,6 +448,7 @@ func (s *Service) emitDiskEvent(eventBytes []byte) {
Code: events.SessionDiskCode,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: ossteleport.Version,
ServerID: ctx.ServerID,
ServerHostname: ctx.ServerHostname,
ServerNamespace: ctx.Namespace,
Expand Down Expand Up @@ -500,6 +503,7 @@ func (s *Service) emit4NetworkEvent(eventBytes []byte) {
Code: events.SessionNetworkCode,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: ossteleport.Version,
ServerID: ctx.ServerID,
ServerHostname: ctx.ServerHostname,
ServerNamespace: ctx.Namespace,
Expand Down Expand Up @@ -556,6 +560,7 @@ func (s *Service) emit6NetworkEvent(eventBytes []byte) {
Code: events.SessionNetworkCode,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: ossteleport.Version,
ServerID: ctx.ServerID,
ServerHostname: ctx.ServerHostname,
ServerNamespace: ctx.Namespace,
Expand Down
5 changes: 4 additions & 1 deletion lib/events/eventstest/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/google/uuid"
"github.com/jonboulle/clockwork"

"github.com/gravitational/teleport"
apievents "github.com/gravitational/teleport/api/types/events"
"github.com/gravitational/teleport/lib/events"
)
Expand Down Expand Up @@ -73,7 +74,8 @@ func GenerateTestSession(params SessionParams) []apievents.AuditEvent {
ClusterName: params.ClusterName,
},
ServerMetadata: apievents.ServerMetadata{
ServerID: params.ServerID,
ServerVersion: teleport.Version,
ServerID: params.ServerID,
ServerLabels: map[string]string{
"kernel": "5.3.0-42-generic",
"date": "Mon Mar 30 08:58:54 PDT 2020",
Expand Down Expand Up @@ -105,6 +107,7 @@ func GenerateTestSession(params SessionParams) []apievents.AuditEvent {
Time: params.Clock.Now().UTC().Add(time.Hour + time.Second + 7*time.Millisecond),
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: params.ServerID,
ServerNamespace: "default",
},
Expand Down
3 changes: 3 additions & 0 deletions lib/srv/app/common/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (a *audit) OnSessionStart(ctx context.Context, serverID string, identity *t
ClusterName: identity.RouteToApp.ClusterName,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: serverID,
ServerNamespace: apidefaults.Namespace,
},
Expand All @@ -132,6 +133,7 @@ func (a *audit) OnSessionEnd(ctx context.Context, serverID string, identity *tls
ClusterName: identity.RouteToApp.ClusterName,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: serverID,
ServerNamespace: apidefaults.Namespace,
},
Expand All @@ -158,6 +160,7 @@ func (a *audit) OnSessionChunk(ctx context.Context, serverID, chunkID string, id
ClusterName: identity.RouteToApp.ClusterName,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: serverID,
ServerNamespace: apidefaults.Namespace,
},
Expand Down
1 change: 1 addition & 0 deletions lib/srv/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,7 @@ func (c *ServerContext) GetExecRequest() (Exec, error) {

func (c *ServerContext) GetServerMetadata() apievents.ServerMetadata {
return apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: c.srv.HostUUID(),
ServerHostname: c.srv.GetInfo().GetHostname(),
ServerNamespace: c.srv.GetNamespace(),
Expand Down
1 change: 1 addition & 0 deletions lib/srv/db/common/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func MakeEventMetadata(session *Session, eventType, eventCode string) events.Met
// MakeServerMetadata returns common server metadata for database session.
func MakeServerMetadata(session *Session) events.ServerMetadata {
return events.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: session.HostID,
ServerNamespace: apidefaults.Namespace,
}
Expand Down
1 change: 1 addition & 0 deletions lib/srv/forward/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func (s *Server) TargetMetadata() apievents.ServerMetadata {
}

return apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerNamespace: s.GetNamespace(),
ServerID: s.targetID,
ServerAddr: s.targetAddr,
Expand Down
4 changes: 3 additions & 1 deletion lib/srv/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/types"
apievents "github.com/gravitational/teleport/api/types/events"
Expand Down Expand Up @@ -457,7 +458,8 @@ func (w *Monitor) emitDisconnectEvent(reason string) error {
RemoteAddr: w.Conn.RemoteAddr().String(),
},
ServerMetadata: apievents.ServerMetadata{
ServerID: w.ServerID,
ServerVersion: teleport.Version,
ServerID: w.ServerID,
},
Reason: reason,
}
Expand Down
2 changes: 2 additions & 0 deletions lib/srv/regular/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ type Server struct {
// TargetMetadata returns metadata about the server.
func (s *Server) TargetMetadata() apievents.ServerMetadata {
return apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerNamespace: s.GetNamespace(),
ServerID: s.ID(),
ServerAddr: s.Addr(),
Expand Down Expand Up @@ -1503,6 +1504,7 @@ func (s *Server) HandleNewChan(ctx context.Context, ccx *sshutils.ConnectionCont
RemoteAddr: ccx.ServerConn.RemoteAddr().String(),
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: s.uuid,
ServerNamespace: s.GetNamespace(),
},
Expand Down
1 change: 1 addition & 0 deletions lib/srv/sess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ func TestTrackingSession(t *testing.T) {
},
},
serverMeta: apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerHostname: "test",
ServerID: "123",
},
Expand Down
1 change: 1 addition & 0 deletions lib/srv/session_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ func (s *SessionController) emitRejection(ctx context.Context, userMetadata apie
RemoteAddr: remoteAddr,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: s.cfg.ServerID,
ServerNamespace: apidefaults.Namespace,
},
Expand Down
2 changes: 2 additions & 0 deletions lib/web/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/gravitational/trace"
"github.com/julienschmidt/httprouter"

"github.com/gravitational/teleport"
apiclient "github.com/gravitational/teleport/api/client"
"github.com/gravitational/teleport/api/client/proto"
apidefaults "github.com/gravitational/teleport/api/defaults"
Expand Down Expand Up @@ -287,6 +288,7 @@ func (h *Handler) createAppSession(w http.ResponseWriter, r *http.Request, p htt
ClusterName: identity.RouteToApp.ClusterName,
},
ServerMetadata: apievents.ServerMetadata{
ServerVersion: teleport.Version,
ServerID: h.cfg.HostUUID,
ServerNamespace: apidefaults.Namespace,
},
Expand Down

0 comments on commit a590006

Please sign in to comment.