Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of disabling audit log functionality per landscape #367

Merged
merged 10 commits into from
Sep 10, 2024

Conversation

mvshao
Copy link
Contributor

@mvshao mvshao commented Sep 5, 2024

Description

Changes proposed in this pull request:

  • Audit Log can be configured as not strict requirement for specific landscapes

Related issue(s)
#286

@mvshao mvshao requested a review from a team as a code owner September 5, 2024 07:30
@kyma-bot kyma-bot added cla: yes Indicates the PR's author has signed the CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 5, 2024
@Disper Disper self-assigned this Sep 5, 2024
@Disper Disper added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 5, 2024
@Disper
Copy link
Member

Disper commented Sep 5, 2024

/hold
should wait for #365

@kyma-bot kyma-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 5, 2024
@Disper Disper removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 5, 2024
@mvshao mvshao removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 9, 2024
)
if err != nil { //nolint:nestif
errorMessage := err.Error()
if strings.Contains(errorMessage, "auditlog config for region") {
Copy link
Member

Choose a reason for hiding this comment

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

Could you extract the "auditlog config for region" string to a const in the auditlogging.go and use the same const here? This line relies on the content of the error message and if someone would change the auditlogging.go then it would break this business logic (unit tests are not detecting this scenario).

Here's another approach on how it should be achieved

@@ -90,6 +93,7 @@ func main() {
flag.BoolVar(&enableRuntimeReconciler, "runtime-reconciler-enabled", defaultRuntimeReconcilerEnabled, "Feature flag for all runtime reconciler functionalities")
flag.StringVar(&converterConfigFilepath, "converter-config-filepath", "/converter-config/converter_config.json", "A file path to the gardener shoot converter configuration.")
flag.BoolVar(&shootSpecDumpEnabled, "shoot-spec-dump-enabled", false, "Feature flag to allow persisting specs of created shoots")
flag.BoolVar(&auditLogMandatory, "audit-log-mandatory", true, "Feature flag to enable strict mode for audit log configuration")
Copy link
Member

Choose a reason for hiding this comment

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

Please document this new paramenter (link)

@mvshao mvshao requested a review from a team as a code owner September 9, 2024 11:11
@kyma-bot kyma-bot added the area/documentation Issues or PRs related to documentation label Sep 9, 2024
errorMessage,
)
} else {
m.log.Info(errorMessage, "Failed to configure Audit Log, missing region mapping for this shoot, but is not mandatory to be configured")
Copy link
Member

@Disper Disper Sep 9, 2024

Choose a reason for hiding this comment

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

A tiny rewording proposal to make it more clear that it's a acceptable behavior. Feel free to ignore this suggestion if you don't agree.

Suggested change
m.log.Info(errorMessage, "Failed to configure Audit Log, missing region mapping for this shoot, but is not mandatory to be configured")
m.log.Info(errorMessage, "Audit Log was not configured, missing region mapping for this shoot. Continuing without error because flag `audit-log-mandatory` is disabled.")

"False",
errorMessage)
} else {
m.log.Info(errorMessage, "Failed to configure Audit Log, but is not mandatory to be configured")
Copy link
Member

Choose a reason for hiding this comment

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

During verification I've encountered a panic:

2024-09-09T15:29:14+02:00       INFO    Observed a panic in reconciler: odd number of arguments passed as key-value pairs for logging   {"controller": "runtime", "controllerGroup": "infrastructuremanager.kyma-project.io", "controllerKind": "Runtime", "Runtime": {"name":"kim-md-al6","namespace":"kcp-system"}, "namespace": "kcp-system", "name": "kim-md-al6", "reconcileID": "1aa26a9a-cc11-4cd7-bdf7-b6b022203af0"}
panic: odd number of arguments passed as key-value pairs for logging [recovered]
        panic: odd number of arguments passed as key-value pairs for logging

Quoting logger api docs:

The key/value pairs must alternate string keys and arbitrary// values.

I wonder if just m.log.Info(errorMessage) wouldn't be enough here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to check code. In my opinion this additional info need to be present to clearly describe that Audit Log was set as not mandatory.

Copy link
Member

Choose a reason for hiding this comment

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

It's possible to add either one parameter (errorMessage) or 3/5/7 etc with additional ones for key name and the value . (always uneven).

When I executed this part I noticed the Error during enabling Audit Logs on shoot: kim-md-al8: missing mapping for selected region in provider config was the errorMessage and passed as a string wasFailed to configure Audit Log, missing region mapping for this shoot, but is not mandatory to be configured . which indeed contains an additional information that's mandatory.

So how about such invocation:
m.log.Info(errorMessage, "AuditLogMandatory", m.RCCfg.AuditLogMandatory)?

The log would look like this
2024-09-10T07:31:51+02:00 INFO reqID 1 Error during enabling Audit Logs on shoot: kim-md-al8: missing mapping for selected region in provider config {"AuditLogMandatory": false}

Copy link
Member

@Disper Disper Sep 10, 2024

Choose a reason for hiding this comment

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

Logging additional information on region and provider type could make it easier to quickly fix such issues. m.log.Info(errorMessage, "AuditLogMandatory", m.RCCfg.AuditLogMandatory, "providerType", s.shoot.Spec.Provider.Type, "region", s.shoot.Spec.Region)

@kyma-bot kyma-bot added the lgtm Looks good to me! label Sep 10, 2024
@kyma-bot kyma-bot merged commit 7da0a88 into kyma-project:main Sep 10, 2024
11 checks passed
@mvshao mvshao deleted the auditlog-strict branch September 10, 2024 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Issues or PRs related to documentation cla: yes Indicates the PR's author has signed the CLA. lgtm Looks good to me! size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants