Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[branch/v9] Backport #10665 #11064

Merged
merged 5 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,312 changes: 857 additions & 455 deletions api/types/events/events.pb.go

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions api/types/events/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,22 @@ message RenewableCertificateGenerationMismatch {
[ (gogoproto.nullable) = false, (gogoproto.embed) = true, (gogoproto.jsontag) = "" ];
}

// Unknown is a fallback event used when we don't recognize an event from the backend.
message Unknown {
// Metadata is a common event metadata.
Metadata Metadata = 1
[ (gogoproto.nullable) = false, (gogoproto.embed) = true, (gogoproto.jsontag) = "" ];

// UnknownType is the event type extracted from the unknown event.
string UnknownType = 2 [ (gogoproto.jsontag) = "unknown_event" ];

// UnknownCode is the event code extracted from the unknown event.
string UnknownCode = 3 [ (gogoproto.jsontag) = "unknown_code,omitempty" ];

// Data is the serialized JSON data of the unknown event.
string Data = 4 [ (gogoproto.jsontag) = "data" ];
}

// OneOf is a union of one of audit events submitted to the auth service
message OneOf {
// Event is one of the audit events
Expand Down Expand Up @@ -1867,6 +1883,7 @@ message OneOf {
events.MySQLStatementFetch MySQLStatementFetch = 77;
events.MySQLStatementBulkExecute MySQLStatementBulkExecute = 78;
events.RenewableCertificateGenerationMismatch RenewableCertificateGenerationMismatch = 79;
events.Unknown Unknown = 80;
}
}

Expand Down
24 changes: 23 additions & 1 deletion api/types/events/oneof.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ limitations under the License.
package events

import (
"encoding/json"
"reflect"

"github.com/gravitational/trace"
log "github.com/sirupsen/logrus"
)

// MustToOneOf converts audit event to OneOf
Expand Down Expand Up @@ -353,8 +355,28 @@ func ToOneOf(in AuditEvent) (*OneOf, error) {
out.Event = &OneOf_RenewableCertificateGenerationMismatch{
RenewableCertificateGenerationMismatch: e,
}
case *Unknown:
out.Event = &OneOf_Unknown{
Unknown: e,
}
default:
return nil, trace.BadParameter("event type %T is not supported", in)
log.Errorf("Attempted to convert dynamic event of unknown type \"%v\" into protobuf event.", in.GetType())
unknown := &Unknown{}
unknown.Type = UnknownEvent
unknown.Code = UnknownCode
unknown.Time = in.GetTime()
unknown.ClusterName = in.GetClusterName()
unknown.UnknownType = in.GetType()
unknown.UnknownCode = in.GetCode()
data, err := json.Marshal(in)
if err != nil {
return nil, trace.Wrap(err)
}

unknown.Data = string(data)
out.Event = &OneOf_Unknown{
Unknown: unknown,
}
}
return &out, nil
}
Expand Down
25 changes: 25 additions & 0 deletions api/types/events/unknown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2021 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package events

const (
// UnknownEvent is any event received that isn't recognized as any other event type.
UnknownEvent = "unknown"

// UnknownCode is used when an event of unknown type is encountered.
UnknownCode = "TCC00E"
)
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ require (
github.com/jcmturner/goidentity/v6 v6.0.1 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531
github.com/klauspost/compress v1.9.5 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/pretty v0.3.0
github.com/kr/text v0.2.0 // indirect
github.com/mailgun/metrics v0.0.0-20150124003306-2b3c4565aafd // indirect
github.com/mailgun/minheap v0.0.0-20170619185613-3dbe6c6bf55f // indirect
Expand Down Expand Up @@ -223,7 +222,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
Expand Down Expand Up @@ -253,7 +252,7 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/joshlf/testutil v0.0.0-20170608050642-b5d8aa79d93d // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,12 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531 h1:hgVxRoDDPtQE68PT4LFvNlPz2nBKd3OMlGKIQ69OmR4=
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531/go.mod h1:fqTUQpVYBvhCNIsMXGl2GE9q6z94DIP6NtFKXCSTVbg=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531 h1:hgVxRoDDPtQE68PT4LFvNlPz2nBKd3OMlGKIQ69OmR4=
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531/go.mod h1:fqTUQpVYBvhCNIsMXGl2GE9q6z94DIP6NtFKXCSTVbg=
github.com/joshlf/testutil v0.0.0-20170608050642-b5d8aa79d93d h1:J8tJzRyiddAFF65YVgxli+TyWBi0f79Sld6rJP6CBcY=
github.com/joshlf/testutil v0.0.0-20170608050642-b5d8aa79d93d/go.mod h1:b+Q3v8Yrg5o15d71PSUraUzYb+jWl6wQMSBXSGS/hv0=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down
3 changes: 3 additions & 0 deletions lib/events/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ const (
// DesktopClipboardSendEvent is emitted when local clipboard data
// is sent to Teleport.
DesktopClipboardSendEvent = "desktop.clipboard.send"

// UnknownEvent is any event received that isn't recognized as any other event type.
UnknownEvent = apievents.UnknownEvent
)

const (
Expand Down
5 changes: 5 additions & 0 deletions lib/events/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

package events

import apievents "github.com/gravitational/teleport/api/types/events"

// Event describes an audit log event.
type Event struct {
// Name is the event name.
Expand Down Expand Up @@ -500,4 +502,7 @@ const (
// RenewableCertificateGenerationMismatchCode is the renewable cert
// generation mismatch code.
RenewableCertificateGenerationMismatchCode = "TCB00W"

// UnknownCode is used when an event of unknown type is encountered.
UnknownCode = apievents.UnknownCode
)
16 changes: 15 additions & 1 deletion lib/events/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
apiutils "github.com/gravitational/teleport/api/utils"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/trace"
log "github.com/sirupsen/logrus"

"encoding/json"
)
Expand Down Expand Up @@ -213,8 +214,21 @@ func FromEventFields(fields EventFields) (apievents.AuditEvent, error) {
e = &events.CertificateCreate{}
case RenewableCertificateGenerationMismatchEvent:
e = &events.RenewableCertificateGenerationMismatch{}
case UnknownEvent:
e = &events.Unknown{}
default:
return nil, trace.BadParameter("unknown event type: %q", eventType)
log.Errorf("Attempted to convert dynamic event of unknown type \"%v\" into protobuf event.", eventType)
unknown := &events.Unknown{}
if err := utils.FastUnmarshal(data, unknown); err != nil {
return nil, trace.Wrap(err)
}

unknown.Type = UnknownEvent
unknown.Code = UnknownCode
unknown.UnknownType = eventType
unknown.UnknownCode = fields.GetString(EventCode)
unknown.Data = string(data)
return unknown, nil
}

if err := utils.FastUnmarshal(data, e); err != nil {
Expand Down