Skip to content

Audit policy config observer - #845

Merged
openshift-merge-robot merged 2 commits into
openshift:masterfrom
tkashem:audit-config
Jul 24, 2020
Merged

openshift-merge-robot merged 2 commits into
openshift:masterfrom
tkashem:audit-config

Conversation

@tkashem

@tkashem tkashem commented Jul 22, 2020

Copy link
Copy Markdown
Contributor

No description provided.

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 22, 2020
@tkashem

tkashem commented Jul 22, 2020

Copy link
Copy Markdown
Contributor Author

holding it, as soon as the openshift/api PR openshift/api#681 merges we can remove the replace from go.mod

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 22, 2020
GetAuditPolicyPath(profile string) (string, error)

// GetDefaultAuditPolicyPath returns the path to the default audit policy.
GetDefaultAuditPolicyPath() string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why isn't that GetAuditPolicyPath("Default")?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@tkashem tkashem Jul 23, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I have added the pruner.

return defaultObservedConfig, errs
}

return defaultObservedConfig, append(errs, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

// this should never happen because we have a default value on the field

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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]
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return old config, not default. Avoids flapping.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's returning the current config, I changed the variable name. I think it boils down to the question I posted here - #845 (comment).

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 23, 2020
@tkashem
tkashem force-pushed the audit-config branch 5 times, most recently from 260ae1b to 1a2ed63 Compare July 24, 2020 18:13
@tkashem tkashem changed the title [WIP] Audit config Audit policy config observer Jul 24, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 24, 2020
@tkashem

tkashem commented Jul 24, 2020

Copy link
Copy Markdown
Contributor Author

good for review

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 24, 2020

desiredProfile := string(apiServer.Spec.Audit.Profile)
if len(desiredProfile) == 0 {
return existingConfig, errs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

empty config

@sttts

sttts commented Jul 24, 2020

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 24, 2020
@openshift-ci-robot

Copy link
Copy Markdown

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 24, 2020
@tkashem

tkashem commented Jul 24, 2020

Copy link
Copy Markdown
Contributor Author

/retest

@openshift-merge-robot
openshift-merge-robot merged commit 1ed21c4 into openshift:master Jul 24, 2020
@tkashem
tkashem deleted the audit-config branch July 24, 2020 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants