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

NAS-130459 / 24.10 / Add audit trails for snapshot and replication tasks #14148

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading