Skip to content
Closed
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
67 changes: 57 additions & 10 deletions keps/sig-auth/0014-dynamic-audit-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,67 @@ A cluster scoped configuration object will be provided that applies to all event

```golang
// AuditConfiguration represents a dynamic audit configuration
type AuditConfiguration struct {
type AuditSink struct {
metav1.TypeMeta

v1.ObjectMeta

// Policy is the current audit v1beta1 Policy object
// if undefined it will default to the statically configured cluster policy if available
// The Level that all requests are recorded at.
// if not provided this will default to Metadata level
// if neither exist the backend will fail
Policy *Policy

// Backend to send events
Backend *Backend
}

// Level defines the amount of information logged during auditing
type Level string

// Valid audit levels
const (
// LevelNone disables auditing
LevelNone Level = "None"
// LevelMetadata provides the basic level of auditing.
LevelMetadata Level = "Metadata"
// LevelRequest provides Metadata level of auditing, and additionally
// logs the request object (does not apply for non-resource requests).
LevelRequest Level = "Request"
// LevelRequestResponse provides Request level of auditing, and additionally
// logs the response object (does not apply for non-resource requests and watches).
LevelRequestResponse Level = "RequestResponse"
)

// Stage defines the stages in request handling during which audit events may be generated.
type Stage string

// Valid audit stages.
const (
// The stage for events generated after the audit handler receives the request, but before it
// is delegated down the handler chain.
StageRequestReceived = "RequestReceived"
// The stage for events generated after the response headers are sent, but before the response body
// is sent. This stage is only generated for long-running requests (e.g. watch).
StageResponseStarted = "ResponseStarted"
// The stage for events generated after the response body has been completed, and no more bytes
// will be sent.
StageResponseComplete = "ResponseComplete"
// The stage for events generated when a panic occurred.
StagePanic = "Panic"
)

// Policy is a scoped down policy for audit webhooks
type Policy struct {
// The Level that all requests are recorded at.
// if not provided this will default to Metadata level
// +optional
Level *Level

// OmitStages is a list of stages for which no events are created.
// +optional
OmitStages []Stage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please make this a whitelist? I know it deviates from the static version, but IMO not making that a whitelist was a mistake (IncludeStages). Must be non-empty (or default to all?).

}

// Backend holds the configuration for the backend
type Backend struct {
// Webhook holds the webhook backend
Expand Down Expand Up @@ -151,8 +198,7 @@ kind: AuditConfiguration
metadata:
name: <name>
policy:
rules:
- level: <level>
level: <level>
omitStages:
- stage: <stage>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this shouldn't have stage:, just - <stage>

backend:
Expand Down Expand Up @@ -192,11 +238,12 @@ called `withDynamicAudit`. Another conditional clause will be added where the ha
[provisioned](https://github.com/kubernetes/apiserver/blob/master/pkg/server/config.go#L536) allowing for the proper feature gating.

#### Policy Enforcement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add a note somewhere in here that this approach lets us prototype the flexible policy design as a CRD with a proxy backend?

This addition will move policy enforcement from the main handler to the backends. From the `withDynamicAudit` handler,
the full event will be generated and then passed to the backends. Each backend will copy the event and then be required to
drop any pieces that do not conform to its policy. A new sink interface will be required for these changes called `EnforcedSink`,
this will largely follow suite with the existing sink but take a fully formed event and the authorizer attributes as its
parameters. It will then utilize the `LevelAndStages` method in the policy
This addition will move policy enforcement from the main handler to the backends. The policy object is a scoped down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Rather than "... is a scoped down version ...", I would say "... is a minimal top-level policy ..."

version of the V1 Policy object, further filtering will be done in a proxy. This has been done because how we handle policy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: and further filtering...

may change in the future. From the `withDynamicAudit` handler, the full event will be generated and then passed to the backends.
Each backend will copy the event and then be required to drop any pieces that do not conform to its policy. A new sink interface
will be required for these changes called `EnforcedSink`, this will largely follow suite with the existing sink but take a
fully formed event and the authorizer attributes as its parameters. It will then utilize the `LevelAndStages` method in the policy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by this. What is EnforcedSink? Is that client (apiserver) side, or server (webhook) side? Is it just another audit backend plugin, or something else?

[checker](https://github.com/kubernetes/apiserver/blob/master/pkg/audit/policy/checker.go) to enforce its policy on the event,
and drop any unneeded sections. The new dynamic backend will implement the `EnforcedSink` interface, and update its state
based on a shared informer. For the existing backends to comply, a method will be added that implements the `EnforcedSink` interface.
Expand Down