mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #74617 from deads2k/audit-request-metadata
make audit metadata work for custom resources
This commit is contained in:
commit
c103ba914e
@ -19,6 +19,7 @@ go_library(
|
|||||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/audit",
|
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/audit",
|
||||||
importpath = "k8s.io/apiserver/pkg/audit",
|
importpath = "k8s.io/apiserver/pkg/audit",
|
||||||
deps = [
|
deps = [
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
|
@ -20,13 +20,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"reflect"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
@ -117,8 +117,9 @@ func LogRequestObject(ae *auditinternal.Event, obj runtime.Object, gvr schema.Gr
|
|||||||
if ae.ObjectRef == nil {
|
if ae.ObjectRef == nil {
|
||||||
ae.ObjectRef = &auditinternal.ObjectReference{}
|
ae.ObjectRef = &auditinternal.ObjectReference{}
|
||||||
}
|
}
|
||||||
if acc, ok := obj.(metav1.ObjectMetaAccessor); ok {
|
|
||||||
meta := acc.GetObjectMeta()
|
// meta.Accessor is more general than ObjectMetaAccessor, but if it fails, we can just skip setting these bits
|
||||||
|
if meta, err := meta.Accessor(obj); err == nil {
|
||||||
if len(ae.ObjectRef.Namespace) == 0 {
|
if len(ae.ObjectRef.Namespace) == 0 {
|
||||||
ae.ObjectRef.Namespace = meta.GetNamespace()
|
ae.ObjectRef.Namespace = meta.GetNamespace()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user