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

🐛 azure: fail gracefully if unable to get security contacts #5183

Closed
wants to merge 3 commits into from

Conversation

afiune
Copy link
Contributor

@afiune afiune commented Feb 8, 2025

Closes #4997

Copy link
Contributor

github-actions bot commented Feb 8, 2025

Test Results

3 257 tests  ±0   3 253 ✅ ±0   2m 0s ⏱️ +15s
  385 suites ±0       4 💤 ±0 
   29 files   ±0       0 ❌ ±0 

Results for commit 3cf9a23. ± Comparison against base commit c8a3641.

♻️ This comment has been updated with latest results.

@afiune
Copy link
Contributor Author

afiune commented Feb 8, 2025

Failing because of #5184

@afiune afiune changed the title 🐛 azure: fail gracefully if unable to read AlertNotifications 🐛 azure: fail gracefully if unable to read armsecurity.Contact.Properties Feb 8, 2025
@afiune afiune force-pushed the azure/bug/alertNotifications branch from b3bce03 to fb4477f Compare February 8, 2025 04:15
@afiune afiune force-pushed the azure/bug/alertNotifications branch from fb4477f to 04f80ca Compare February 8, 2025 04:15
@afiune afiune changed the title 🐛 azure: fail gracefully if unable to read armsecurity.Contact.Properties 🐛 azure: fail gracefully if unable to get security contacts Feb 8, 2025
@afiune
Copy link
Contributor Author

afiune commented Feb 8, 2025

Test

cnquery> azure.subscription.cloudDefender.securityContacts {alertNotifications }
! fail gracefully error="failed to fetch security contacts from https://management.azure.com/subscriptions/1234567-abc6-1234-xyz3-3943298239/providers/Microsoft.Security/securityContacts: 500 Internal Server Error"
azure.subscription.cloudDefender.securityContacts: []

list, err := getSecurityContacts(ctx, armConn)
if err != nil {
return nil, err
// https: //github.com/mondoohq/cnquery/issues/4997
log.Warn().Err(err).Msg("fail gracefully")
Copy link
Member

Choose a reason for hiding this comment

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

Why is that a warn?

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 was debating between this an a simple debug log message, I fee that is a better option, would you agree?

}
res := []interface{}{}
for _, contact := range list {
alertNotifications, err := convert.JsonToDict(contact.Properties.AlertNotifications)
Copy link
Member

Choose a reason for hiding this comment

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

do we need to check if contact or contact.Properties are set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, we probably should have done that, I'll add the check.

for _, contact := range list {
alertNotifications, err := convert.JsonToDict(contact.Properties.AlertNotifications)
if err != nil {
return nil, err
log.Debug().Err(err).Msg("unable to convert armsecurity.Contact.Properties.AlertNotifications to dict")
}
notificationsByRole, err := convert.JsonToDict(contact.Properties.NotificationsByRole)
Copy link
Member

Choose a reason for hiding this comment

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

do we need to check if contact or contact.Properties are set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, we probably should have done that, I'll add the check.

for _, contact := range list {
alertNotifications, err := convert.JsonToDict(contact.Properties.AlertNotifications)
if err != nil {
return nil, err
log.Debug().Err(err).Msg("unable to convert armsecurity.Contact.Properties.AlertNotifications to dict")
Copy link
Member

Choose a reason for hiding this comment

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

in which cases can this happen? We should continue to error out and handle the case properly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We haven't seen this but, the issue says that, any error trying to get the security contacts should fail gracefully. So I checked other places that we could end up in an undesirable error.

Signed-off-by: Salim Afiune Maya <[email protected]>
@afiune
Copy link
Contributor Author

afiune commented Feb 10, 2025

@chris-rock updated with your comments, thank you!

Also, I much rather go this way #5185 - Thoughts?

@afiune
Copy link
Contributor Author

afiune commented Feb 10, 2025

Closing in favor of #5185

@afiune afiune closed this Feb 10, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Feb 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azure.subscription.cloudDefender.securityContacts {alertNotifications } throws 500 if not set
3 participants