openshift/cloud-credential-operator

Improve awsPolicyEqualsDesiredPolicy function to handle IAM policies that may have out of order items

Closed this issue · 6 comments

if currentUserPolicy != desiredUserPolicy {

There are a couple of issues with this approach:

  1. As written the above code will fail if two otherwise identical policies have permissions that are not in the exact same order.
  2. If the currentUserPolicy contains line breaks or even a tab, but the policy is the same as the desiredUserPolicy the function will return false

For example:

time="2020-11-17T22:07:51Z" level=debug msg="desired user policy: {\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"ec2:CreateTags\",\"ec2:DescribeAvailabilityZones\",\"ec2:DescribeDhcpOptions\",\"ec2:DescribeImages\",\"ec2:DescribeInstances\",\"ec2:DescribeSecurityGroups\",\"ec2:DescribeSubnets\",\"ec2:DescribeVpcs\",\"ec2:RunInstances\",\"ec2:TerminateInstances\",\"elasticloadbalancing:DescribeLoadBalancers\",\"elasticloadbalancing:DescribeTargetGroups\",\"elasticloadbalancing:RegisterInstancesWithLoadBalancer\",\"elasticloadbalancing:RegisterTargets\",\"iam:PassRole\"],\"Resource\":\"*\"},{\"Effect\":\"Allow\",\"Action\":[\"iam:GetUser\"],\"Resource\":\"arn:aws:iam::8675309:user/ocp4-ext-dev-east-nz-openshift-machine-api-aws-xxxxx\"}]}" actuator=aws cr=openshift-cloud-credential-operator/openshift-machine-api-aws

time="2020-11-17T22:07:51Z" level=debug msg="current user policy: {\r\n    \"Version\": \"2012-10-17\",\r\n    \"Statement\": [\r\n        {\r\n            \"Effect\": \"Allow\",\r\n            \"Action\": [\r\n                \"ec2:CreateTags\",\r\n                \"ec2:DescribeAvailabilityZones\",\r\n                \"ec2:DescribeDhcpOptions\",\r\n                \"ec2:DescribeImages\",\r\n                \"ec2:DescribeInstances\",\r\n                \"ec2:DescribeSecurityGroups\",\r\n                \"ec2:DescribeSubnets\",\r\n                \"ec2:DescribeVpcs\",\r\n                \"ec2:RunInstances\",\r\n                \"ec2:TerminateInstances\",\r\n                \"elasticloadbalancing:DescribeLoadBalancers\",\r\n                \"elasticloadbalancing:DescribeTargetGroups\",\r\n                \"elasticloadbalancing:RegisterInstancesWithLoadBalancer\",\r\n                \"elasticloadbalancing:RegisterTargets\",\r\n                \"iam:PassRole\"\r\n            ],\r\n            \"Resource\": \"*\"\r\n        },\r\n        {\r\n            \"Effect\": \"Allow\",\r\n            \"Action\": [\r\n                \"iam:GetUser\"\r\n            ],\r\n            \"Resource\": \"arn:aws:iam::8675309:user/ocp4-ext-dev-east-nz-openshift-machine-api-aws-xxxxx\"\r\n        }\r\n    ]\r\n}" actuator=aws cr=openshift-cloud-credential-operator/openshift-machine-api-aws

time="2020-11-17T22:07:51Z" level=debug msg="policy differences detected" actuator=aws cr=openshift-cloud-credential-operator/openshift-machine-api-aws

If the CCO created the credentials, it should match exact, if CCO is however in manual mode I would not expect us to do be doing any checks on the policy today. (although I would like to change that and thus this is a reasonable request) I've added a link to this issue on our Jira board and we'll discuss for future sprints.

Just curious about how you get into this state given the above though. Passthrough mode perhaps?

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.