Repository navigation
fix(azure): read Flexible Server log retention from logfiles.retention_days (fixes #11757) - #11761
Conversation
…n_days postgresql_flexible_server_log_retention_days_greater_3 always failed because _get_log_retention_days queried the Single Server parameter name 'log_retention_days', which does not exist on Flexible Server. Azure then raises ConfigurationNotExists, log_retention_days is set to None, and every server is reported as having log retention disabled. Query the correct Flexible Server parameter 'logfiles.retention_days' and add a regression test. Fixes prowler-cloud#11757
📝 WalkthroughWalkthroughThe Azure PostgreSQL Flexible Server log retention lookup now uses ChangesLog retention config key fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
✅ No Conflicts No conflict markers, and the branch merges cleanly into its base. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
prowler/providers/azure/services/postgresql/postgresql_service.py (1)
222-231: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winCorrect fix, but broad
except Exceptionrisks repeating the same silent-failure bug.The key-name fix is correct. However,
_get_log_retention_daysstill swallows any exception and returnsNone, unlike the neighboring_get_connection_throttling(Lines 213-220), which was deliberately hardened to catch onlyResourceNotFoundErrorand let other errors propagate — precisely because silently returningNoneon collection failure gets misinterpreted downstream as a real (failing) retention value, which is the same class of bug this PR fixes. Iflogfiles.retention_daysis ever missing/renamed on some server version, or the SDK call fails for another reason (permissions, throttling), this will again silently produce a falseFAILinstead of surfacing the collection error.♻️ Suggested alignment with `_get_connection_throttling`
def _get_log_retention_days(self, subscription, resouce_group_name, server_name): client = self.clients[subscription] try: log_retention_days = client.configurations.get( resouce_group_name, server_name, "logfiles.retention_days" ) - log_retention_days = log_retention_days.value - except Exception: + log_retention_days = log_retention_days.value + except ResourceNotFoundError: log_retention_days = None return log_retention_days🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@prowler/providers/azure/services/postgresql/postgresql_service.py` around lines 222 - 231, The `_get_log_retention_days` helper is still using a broad `except Exception`, which can hide real collection failures and silently return `None`. Update `_get_log_retention_days` in `postgresql_service.py` to match `_get_connection_throttling` by catching only the expected not-found case for `client.configurations.get(...)` and letting other exceptions propagate, while preserving the existing `logfiles.retention_days` key fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@prowler/providers/azure/services/postgresql/postgresql_service.py`:
- Around line 222-231: The `_get_log_retention_days` helper is still using a
broad `except Exception`, which can hide real collection failures and silently
return `None`. Update `_get_log_retention_days` in `postgresql_service.py` to
match `_get_connection_throttling` by catching only the expected not-found case
for `client.configurations.get(...)` and letting other exceptions propagate,
while preserving the existing `logfiles.retention_days` key fix.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: fdb81ef6-c60b-4a7d-9d0e-a240239f0ea5
📒 Files selected for processing (3)
prowler/CHANGELOG.mdprowler/providers/azure/services/postgresql/postgresql_service.pytests/providers/azure/services/postgresql/postgresql_service_test.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11761 +/- ##
==========================================
- Coverage 93.76% 89.56% -4.21%
==========================================
Files 261 246 -15
Lines 38270 6585 -31685
==========================================
- Hits 35885 5898 -29987
+ Misses 2385 687 -1698
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation and see the Github Action logs for details |
Description
postgresql_flexible_server_log_retention_days_greater_3always FAILs on Azure PostgreSQL Flexible Servers.PostgreSQL._get_log_retention_daysqueries the server-configuration parameterlog_retention_days— but that is the Single Server name. On Flexible Server it does not exist, soclient.configurations.get(...)raisesResourceNotFoundError (ConfigurationNotExists), theexceptbranch setslog_retention_days = None, and the check reports every server as having log retention disabled.Azure Flexible Server exposes this setting under
logfiles.retention_days.Fixes #11757.
Fix
Test
Added
test_log_retention_reads_flexible_server_parameter_name(following the existingTest_PostgreSQL_Service_Resiliencepattern). It mocksconfigurations.getto raiseConfigurationNotExistsfor the oldlog_retention_daysname and to return a value only forlogfiles.retention_days. The test fails onmaster(retention read asNone) and passes with this change.Checklist
Summary by CodeRabbit
logfiles.retention_days), preventing false failures.