mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-24 02:25:42 +08:00
Add unknown event instead of error on audit log read (#10665)
This commit is contained in:
+857
-455
File diff suppressed because it is too large
Load Diff
@@ -1782,6 +1782,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
|
||||
@@ -1865,6 +1881,7 @@ message OneOf {
|
||||
events.MySQLStatementFetch MySQLStatementFetch = 77;
|
||||
events.MySQLStatementBulkExecute MySQLStatementBulkExecute = 78;
|
||||
events.RenewableCertificateGenerationMismatch RenewableCertificateGenerationMismatch = 79;
|
||||
events.Unknown Unknown = 80;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -115,6 +115,8 @@ require (
|
||||
k8s.io/kubectl v0.23.3
|
||||
)
|
||||
|
||||
require k8s.io/component-base v0.23.3 // indirect
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.100.2 // indirect
|
||||
cloud.google.com/go/compute v0.1.0 // indirect
|
||||
@@ -246,7 +248,6 @@ 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
|
||||
k8s.io/component-base v0.23.3 // indirect
|
||||
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
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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.
|
||||
@@ -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
|
||||
)
|
||||
|
||||
+15
-1
@@ -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"
|
||||
)
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user