Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Fix OptionsDeleter audit log keys#4704

Merged
mitchell852 merged 4 commits into
apache:masterfrom
rawlinp:fix-topology-delete-audit-log
May 20, 2020
Merged

Fix OptionsDeleter audit log keys#4704
mitchell852 merged 4 commits into
apache:masterfrom
rawlinp:fix-topology-delete-audit-log

Conversation

@rawlinp
Copy link
Copy Markdown
Contributor

@rawlinp rawlinp commented May 20, 2020

What does this PR (Pull Request) do?

Fixed the audit logging of OptionsDeleter to set the keys on the to-be-deleted object so that they are included in the audit log entry when deleted.

  • This PR is not related to any Issue

Which Traffic Control components are affected by this PR?

  • Traffic Ops

What is the best way to verify this PR?

Run the unit tests and TO API tests, verify they pass. Observe the deletion audit log entries, verify they contain the key/name of the deleted resource (specifically Topologies and Regions, which both use the OptionsDeleter interface).

If this is a bug fix, what versions of Traffic Control are affected?

  • master
  • 4.1.0-RC0

The following criteria are ALL met by this PR

  • This PR includes tests
  • bugfix, no docs necessary
  • unreleased (as of yet), so no changelog necessary
  • This PR includes any and all required license headers
  • This PR ensures that database migration sequence is correct OR this PR does not include a database migration
  • This PR DOES NOT FIX A SERIOUS SECURITY VULNERABILITY (see the Apache Software Foundation's security guidelines for details)

@rawlinp rawlinp added bug something isn't working as intended Traffic Ops related to Traffic Ops labels May 20, 2020
HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
return
}
if !deleteKeyOptionExists {
Copy link
Copy Markdown
Contributor Author

@rawlinp rawlinp May 20, 2020

Choose a reason for hiding this comment

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

The diff is kind of hard to read here, all I did was remove the if !deleteKeyOptionExists so that keys are still set with either Deleter or OptionsDeleter. This can be confirmed by clicking the wheel icon above and hiding whitespace changes.

@rawlinp rawlinp marked this pull request as ready for review May 20, 2020 17:26
@mitchell852
Copy link
Copy Markdown
Member

I created and deleted a region and don't see the name in the audit log

image

@rawlinp
Copy link
Copy Markdown
Contributor Author

rawlinp commented May 20, 2020

Oh, maybe it wasn't clear, it would be either the ID or the name, depending on what the PK of the resource is. So regions uses IDs for deletion whereas Topologies uses the name, but I do agree that when deleting things we should probably always include the name (if it has one). I imagine that is a problem we have with a lot of our APIs currently. But for this PR, it fixes the regions audit log entry to include at least the ID and the topologies log entry to include the name. I think we should address the ID vs name thing separately.

@rawlinp
Copy link
Copy Markdown
Contributor Author

rawlinp commented May 20, 2020

retest this please

@mitchell852
Copy link
Copy Markdown
Member

Oh, maybe it wasn't clear, it would be either the ID or the name, depending on what the PK of the resource is. So regions uses IDs for deletion whereas Topologies uses the name, but I do agree that when deleting things we should probably always include the name (if it has one). I imagine that is a problem we have with a lot of our APIs currently. But for this PR, it fixes the regions audit log entry to include at least the ID and the topologies log entry to include the name. I think we should address the ID vs name thing separately.

makes sense.

@mitchell852 mitchell852 merged commit 09bfc37 into apache:master May 20, 2020
@zrhoffman
Copy link
Copy Markdown
Member

Was this reviewed?

HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
return
}
if !deleteKeyOptionExists {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can't remove this condition here without re-adding the logic elsewhere. Normal delete requires all all keys exist, so Identifier.GetKeyFieldsInfo() generally only contains a single key.

HasDeleteKeyOptions.DeleteKeyOptions() is a separate array containing keys that can identify a resource, but only requires that one such key exists.

if !deleteKeyOptionExists {} is used to keep the handler from exiting if Identifier.GetKeyFieldsInfo() keys do not all exist but at least 1 HasDeleteKeyOptions.DeleteKeyOptions() key does.

DELETE regions?name={{name}} currently fails with "missing key: id".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Opened a PR to add an API test for the failing route: #4707

@rawlinp rawlinp deleted the fix-topology-delete-audit-log branch May 20, 2020 22:36
rawlinp added a commit to rawlinp/trafficcontrol that referenced this pull request May 28, 2020
* Fix OptionsDeleter audit log keys

* Added TO API test to check audit log message

* Undo whitespace addition in changelog message because it breaks tests

* fixes timing of error message on delete

Co-authored-by: Jeremy Mitchell <mitchell852@gmail.com>
(cherry picked from commit 09bfc37)
rawlinp added a commit that referenced this pull request May 28, 2020
* Fix OptionsDeleter audit log keys

* Added TO API test to check audit log message

* Undo whitespace addition in changelog message because it breaks tests

* fixes timing of error message on delete

Co-authored-by: Jeremy Mitchell <mitchell852@gmail.com>
(cherry picked from commit 09bfc37)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug something isn't working as intended Traffic Ops related to Traffic Ops

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants