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 all 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"
)
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