Skip to content

Commit

Permalink
NAS-130459 / 24.10 / Add audit trails for snapshot and replication ta…
Browse files Browse the repository at this point in the history
…sks (#14148)

Generate audit trail when users configure snapshots and replication.
  • Loading branch information
anodos325 authored Aug 7, 2024
1 parent 69da705 commit 4e9828a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
17 changes: 12 additions & 5 deletions src/middlewared/middlewared/plugins/replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ async def compress(self, data):
Bool("enabled", default=True),
register=True,
strict=True,
)
),
audit="Replication task create:",
audit_extended=lambda data: data["name"]
)
@pass_app(require=True)
async def do_create(self, app, data):
Expand Down Expand Up @@ -350,9 +352,9 @@ async def do_create(self, app, data):
"replication_create",
"replication_update",
("attr", {"update": True}),
))
), audit="Replication task update:", audit_callback=True)
@pass_app(require=True)
async def do_update(self, app, id_, data):
async def do_update(self, app, audit_callback, id_, data):
"""
Update a Replication Task with specific `id`
Expand Down Expand Up @@ -396,6 +398,7 @@ async def do_update(self, app, id_, data):
"""

old = await self.get_instance(id_)
audit_callback(old["name"])

new = old.copy()
if new["ssh_credentials"]:
Expand Down Expand Up @@ -429,9 +432,11 @@ async def do_update(self, app, id_, data):
return await self.get_instance(id_)

@accepts(
Int("id")
Int("id"),
audit="Replication task delete:",
audit_callback=True
)
async def do_delete(self, id_):
async def do_delete(self, audit_callback, id_):
"""
Delete a Replication Task with specific `id`
Expand All @@ -447,6 +452,8 @@ async def do_delete(self, id_):
]
}
"""
task_name = (await self.get_instance(id_))["name"]
audit_callback(task_name)

response = await self.middleware.call(
"datastore.delete",
Expand Down
16 changes: 13 additions & 3 deletions src/middlewared/middlewared/plugins/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ async def extend(self, data, context):
Bool('allow_empty', default=True),
Bool('enabled', default=True),
register=True
)
),
audit='Snapshot task create:',
audit_extended=lambda data: data['dataset']
)
async def do_create(self, data):
"""
Expand Down Expand Up @@ -164,8 +166,10 @@ async def do_create(self, data):
('add', {'name': 'fixate_removal_date', 'type': 'bool'}),
('attr', {'update': True})
),
audit='Snapshot task update:',
audit_callback=True,
)
async def do_update(self, id_, data):
async def do_update(self, audit_callback, id_, data):
"""
Update a Periodic Snapshot Task with specific `id`
Expand Down Expand Up @@ -204,6 +208,7 @@ async def do_update(self, id_, data):
fixate_removal_date = data.pop('fixate_removal_date', False)

old = await self.get_instance(id_)
audit_callback(old['dataset'])
new = old.copy()
new.update(data)

Expand Down Expand Up @@ -256,8 +261,10 @@ async def do_update(self, id_, data):
'options',
Bool('fixate_removal_date', default=False),
),
audit='Snapshot task delete:',
audit_callback=True,
)
async def do_delete(self, id_, options):
async def do_delete(self, audit_callback, id_, options):
"""
Delete a Periodic Snapshot Task with specific `id`
Expand All @@ -274,6 +281,9 @@ async def do_delete(self, id_, options):
}
"""

dataset = (await self.get_instance(id_))['dataset']
audit_callback(dataset)

for replication_task in await self.middleware.call('replication.query', [
['direction', '=', 'PUSH'],
['also_include_naming_schema', '=', []],
Expand Down

0 comments on commit 4e9828a

Please sign in to comment.