-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45919 from ericchiang/audit-webhook-backend
Automatic merge from submit-queue apiserver: add a webhook implementation of the audit backend This builds off of #45315 and is intended to implement an interfaced defined in #45766. TODO: - [x] Rebase on top of API types PR. - [x] Rebase on top of API types updates (#46065) - [x] Rebase on top of feature flag (#46009) - [x] Rebase on top of audit instrumentation. - [x] Hook up API server flag or register plugin (depending on #45766) Features issue kubernetes/enhancements#22 Design proposal https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auditing.md ```release-notes Webhook added to the API server which omits structured audit log events. ``` /cc @soltysh @timstclair @soltysh @deads2k
- Loading branch information
Showing
14 changed files
with
926 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
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 audit | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/util/errors" | ||
auditinternal "k8s.io/apiserver/pkg/apis/audit" | ||
) | ||
|
||
// Union returns an audit Backend which logs events to a set of backends. The returned | ||
// Sink implementation blocks in turn for each call to ProcessEvents. | ||
func Union(backends ...Backend) Backend { | ||
if len(backends) == 1 { | ||
return backends[0] | ||
} | ||
return union{backends} | ||
} | ||
|
||
type union struct { | ||
backends []Backend | ||
} | ||
|
||
func (u union) ProcessEvents(events ...*auditinternal.Event) { | ||
for _, backend := range u.backends { | ||
backend.ProcessEvents(events...) | ||
} | ||
} | ||
|
||
func (u union) Run(stopCh <-chan struct{}) error { | ||
var funcs []func() error | ||
for _, backend := range u.backends { | ||
funcs = append(funcs, func() error { | ||
return backend.Run(stopCh) | ||
}) | ||
} | ||
return errors.AggregateGoroutines(funcs...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
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 audit | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
auditinternal "k8s.io/apiserver/pkg/apis/audit" | ||
) | ||
|
||
type fakeBackend struct { | ||
events []*auditinternal.Event | ||
} | ||
|
||
func (f *fakeBackend) ProcessEvents(events ...*auditinternal.Event) { | ||
f.events = append(f.events, events...) | ||
} | ||
|
||
func (f *fakeBackend) Run(stopCh <-chan struct{}) error { | ||
return nil | ||
} | ||
|
||
func TestUnion(t *testing.T) { | ||
backends := []Backend{ | ||
new(fakeBackend), | ||
new(fakeBackend), | ||
new(fakeBackend), | ||
} | ||
|
||
b := Union(backends...) | ||
|
||
n := 5 | ||
|
||
var events []*auditinternal.Event | ||
for i := 0; i < n; i++ { | ||
events = append(events, &auditinternal.Event{ | ||
AuditID: types.UID(strconv.Itoa(i)), | ||
}) | ||
} | ||
b.ProcessEvents(events...) | ||
|
||
for i, b := range backends { | ||
// so we can inspect the underlying events. | ||
backend := b.(*fakeBackend) | ||
|
||
if got := len(backend.events); got != n { | ||
t.Errorf("backend %d wanted %d events, got %d", i, n, got) | ||
continue | ||
} | ||
for j, event := range backend.events { | ||
wantID := types.UID(strconv.Itoa(j)) | ||
if event.AuditID != wantID { | ||
t.Errorf("backend %d event %d wanted id %s, got %s", i, j, wantID, event.AuditID) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.