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

feat(HMS-1246): Use permission checks in statuser #504

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

avitova
Copy link
Member

@avitova avitova commented Apr 19, 2023

This adds permission logging in case of missing permissions. Caching should also be done for this. I feel like the source result should not be flagged as Unavailable or with Error in case of missing permission, as this is neither of these. Therefore, I thought adding the MissingPermission parameter might be suitable, but let me know, what you think.
For testing the missing permission in statuser, you could change iam_client hardcoded struct.

@avitova avitova force-pushed the StatuserCheckPermissions branch 2 times, most recently from 1f8ce2e to 33a1f72 Compare April 19, 2023 13:36
@lzap
Copy link
Member

lzap commented Apr 20, 2023

I feel like the source result should not be flagged as Unavailable or with Error in case of missing permission, as this is neither of these.

That is correct, I think a warning in logs is enough. We should not see many of these, only old sources would experience this.

@lzap
Copy link
Member

lzap commented Apr 20, 2023

Test failure seems relevant (timeout)?

Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Looks great, there is a failure can you take a look?

if err != nil {
sr.Status = kafka.StatusUnavailable
sr.Err = err
logger.Warn().Err(err).Msg("Could not get aws assumed client")
chSend <- sr
logger.Warn().Err(err).Msgf("Could not get aws assumed client %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

Please do not send error messages to messages because of Sentry.

#488

}
sr.MissingPermissions = permissions
if len(permissions) != 0 {
logger.Warn().Err(err).Msgf("No sufficient permissions: %s", permissions)
Copy link
Member

Choose a reason for hiding this comment

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

This does not seem correct. CheckPermissions either returns nil result and error, or something in the result. You reported the error above, here I would simply issue a warning with the list. Also can you add a field so we can easily find all records in Kibana, for example:

logger.Warn().Bool("missing_permission", true).Msgf("No sufficient permissions: %s", permissions)

permissions, err := ec2Client.CheckPermission(ctx, &s.Authentication)
if err != nil {
sr.Err = err
logger.Warn().Err(err).Msgf("Could not check aws permissions %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

internal/kafka/source_result.go Show resolved Hide resolved
@mshriver
Copy link
Member

/retest

1 similar comment
@akhil-jha
Copy link
Member

/retest

@lzap
Copy link
Member

lzap commented May 17, 2023

For the record, @avitova might not get to working on this PR. This is not high-priority so let’s keep it opened.

@lzap
Copy link
Member

lzap commented Jul 11, 2023

Let me know when this is ready for re-review.

@avitova
Copy link
Member Author

avitova commented Jul 12, 2023

@lzap The statuser shows the error during the permission check and the array of missing permissions. Ready for review:)

Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Small nitpicks, looks great. Please rebase tests are failing for some reason, they were broken I think.

cmd/pbackend/statuser.go Outdated Show resolved Hide resolved
}
sr.MissingPermissions = permissions
if permissions != nil {
logger.Warn().Bool("missing_permission", true).Msgf("No sufficient permissions: %s", permissions)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps "insufficient" is better wording.

Also you can use strings.Join to join string slice by comma, but this works too.

Finally, when CheckPermission returns nil it likely returns an error too, can you squash this into just a single warning message? You can stuff everything into one log record, me as someone who is debugging this issue would be interested in:

  • source id (already present in the context logger)
  • account number (could be added in the processMessage too as it is in the identity but perhaps out of scope of this PR)
  • error message (via Err function)
  • missing permissions

So basically this line contains it all, perhaps just delete the 167 and move this into the if statement above or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a very good point. The CheckPermission function returned only missing permissions when something was missing, and the error value was returned only when something else failed. We should return an error for missing permissions, so I changed it in this PR. I hope this now makes more sense.

cmd/pbackend/statuser.go Outdated Show resolved Hide resolved
@avitova avitova force-pushed the StatuserCheckPermissions branch 2 times, most recently from 57034d4 to df277f2 Compare July 12, 2023 13:09
@ezr-ondrej
Copy link
Member

ezr-ondrej commented Jul 13, 2023

The AWS account used in the pr_check doesn't seem to have permissions to check assigned policies

1:24PM DBG Listing attached role policies client=ec2 hostname=provisioning-backend-statuser-654d6c7dd-r4blm version=60e5
1:24PM TRC request failed with unretryable error https response error StatusCode: 403, RequestID: fe4b8847-33fe-48ee-aaf7-e6f9f05056db, api error AccessDenied: User: arn:aws:sts::093942615996:assumed-role/redhat-provisioning-arn-role/name is not authorized to perform: iam:ListAttachedRolePolicies on resource: role redhat-provisioning-arn-role because no identity-based policy allows the iam:ListAttachedRolePolicies action client=ec2 hostname=provisioning-backend-statuser-654d6c7dd-r4blm version=60e5
1:24PM WRN AWS permission check failed error="cannot list attached role policies: operation error IAM: ListAttachedRolePolicies, https response error StatusCode: 403, RequestID: fe4b8847-33fe-48ee-aaf7-e6f9f05056db, api error AccessDenied: User: arn:aws:sts::093942615996:assumed-role/redhat-provisioning-arn-role/name is not authorized to perform: iam:ListAttachedRolePolicies on resource: role redhat-provisioning-arn-role because no identity-based policy allows the iam:ListAttachedRolePolicies action" hostname=provisioning-backend-statuser-654d6c7dd-r4blm missing_permissions=true source_id=5 version=60e5
1:24PM TRC Sending 1 source availability status messages (tick) hostname=provisioning-backend-statuser-654d6c7dd-r4blm messages=1 version=60e5

Update: the policy of the AWS account had been updated and necessary permissions added, THANK YOU @akhil-jha 🧡

@ezr-ondrej
Copy link
Member

/retest

2 similar comments
@ezr-ondrej
Copy link
Member

/retest

@ezr-ondrej
Copy link
Member

/retest

@ezr-ondrej
Copy link
Member

Different failure now xD that one definitelly does not sound related, but let see :)

@ezr-ondrej
Copy link
Member

🎉 ... no idea what was the failure before, but now it works 😏

@avitova avitova force-pushed the StatuserCheckPermissions branch 3 times, most recently from 369487c to fa863a1 Compare July 18, 2023 08:17
Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

I'm good here, thanks! 🧡

Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

One detail - the error length is unlimited and in case user actually forgot to add any permission this gets rendered to screen as something very long (covering whole screen or something).

In another PR, I suggest to limit the list to some reasonable length and in these cases add and more to the error.

@lzap lzap merged commit 9a23611 into RHEnVision:main Jul 19, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants