Skip to content

Commit

Permalink
audits: populate server_version in ServerMetadata (#42282)
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 <tiago.silva@goteleport.com>
  • Loading branch information
tigrato authored Jun 3, 2024
1 parent e5c8e16 commit bf2463a
Show file tree
Hide file tree
Showing 11 changed files with 26 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 @@ -35,6 +35,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 @@ -392,6 +393,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 @@ -450,6 +452,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 @@ -504,6 +507,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 @@ -560,6 +564,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 @@ -23,6 +23,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 @@ -71,7 +72,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 @@ -103,6 +105,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
4 changes: 4 additions & 0 deletions lib/srv/app/common/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/gravitational/trace"
"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"
Expand Down Expand Up @@ -103,6 +104,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 @@ -129,6 +131,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 @@ -155,6 +158,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 @@ -1374,6 +1374,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
2 changes: 2 additions & 0 deletions lib/srv/db/common/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/gravitational/trace"
"github.com/sirupsen/logrus"

"github.com/gravitational/teleport"
apidefaults "github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/api/types/events"
Expand Down Expand Up @@ -198,6 +199,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 @@ -409,6 +409,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 @@ -29,6 +29,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 @@ -455,7 +456,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 @@ -242,6 +242,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 @@ -1371,6 +1372,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 @@ -880,6 +880,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 @@ -331,6 +331,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 @@ -26,6 +26,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 @@ -274,6 +275,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 bf2463a

Please sign in to comment.