Audit policy config observer - #845
Conversation
|
holding it, as soon as the openshift/api PR openshift/api#681 merges we can remove the replace from go.mod /hold |
| GetAuditPolicyPath(profile string) (string, error) | ||
|
|
||
| // GetDefaultAuditPolicyPath returns the path to the default audit policy. | ||
| GetDefaultAuditPolicyPath() string |
There was a problem hiding this comment.
why isn't that GetAuditPolicyPath("Default")?
There was a problem hiding this comment.
to reduce coupling, library-go doesn't need to know the defaulting mechanism, it just needs to know:
- the path to the default audit profle
- given an audit profile, it needs to know the desired path.
on the other hand, the apiserver/component that defines the audit profiles should know well which audit profile is default.
I know we are defaulting at the CRD level, but i think the observer implementation should still guard for empty profile name and other error conditions.
There was a problem hiding this comment.
This func is only called to default the value in the old config. This whole block of code is only needed for the event. Just compare to empty string. Same result.
There was a problem hiding this comment.
It resorts to the default value if the existing/current config is not set. when the existing config is not set and the observer function encounters a lister error or any other before it can set the new/desired configuration, what should the observer return?
| // If we are here, then we are not setting any default for observed audit profile. | ||
| // looks like returning the existing config is the best alternative here. This puts a constraint on the | ||
| // apiserver to have a default configuration in its bindata. | ||
| return existingConfig, append(errs, err) |
There was a problem hiding this comment.
this is wrong. You have to prune the existing config: the input has values from all observers. But you are only allowed to return your fields.
Compare pruning in the defer func in the cloud provider observer.
There was a problem hiding this comment.
yes, I have added the pruner.
| return defaultObservedConfig, errs | ||
| } | ||
|
|
||
| return defaultObservedConfig, append(errs, err) |
There was a problem hiding this comment.
on non-not-found errors we return the existing config. This here would change the config for the apiserver. We don't want that. It creates flapping on error situations.
There was a problem hiding this comment.
on any lister error, the observer function is returning the current/existing config.
|
|
||
| desiredProfile := string(apiServer.Spec.Audit.Profile) | ||
| if len(desiredProfile) == 0 { | ||
| return defaultObservedConfig, errs |
There was a problem hiding this comment.
// this should never happen because we have a default value on the field
There was a problem hiding this comment.
the CRD is not co-located; the observer being a core func, it's a guard against if the CRD schema is accidentally changed.
| } | ||
| if len(current) > 0 { | ||
| auditPolicyPath = current[0] | ||
| } |
There was a problem hiding this comment.
This should only be need further down where you compare with the new value and create an event on change. Move it there.
|
|
||
| observedConfig := map[string]interface{}{} | ||
| if err := unstructured.SetNestedStringSlice(observedConfig, []string{desiredAuditPolicyPath}, apiServerArgumentsAuditPath...); err != nil { | ||
| return defaultObservedConfig, append(errs, fmt.Errorf("failed to set desired audit profile in observed config name=%s", desiredProfile)) |
There was a problem hiding this comment.
return old config, not default. Avoids flapping.
There was a problem hiding this comment.
it's returning the current config, I changed the variable name. I think it boils down to the question I posted here - #845 (comment).
260ae1b to
1a2ed63
Compare
|
good for review /hold cancel |
|
|
||
| desiredProfile := string(apiServer.Spec.Audit.Profile) | ||
| if len(desiredProfile) == 0 { | ||
| return existingConfig, errs |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sttts, tkashem The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
No description provided.