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

fix: Fix conditions with multiple subjects in assume role with oidc policy #74

Merged
merged 1 commit into from
Jun 10, 2020

Conversation

miguelaferreira
Copy link
Contributor

Fixes #73

Description

This PR fixes the logic that creates the assume role policy with OIDC to allow users to specify multiple subjects for the policy.

Motivation and Context

See #73

Breaking Changes

No breaking changes

How Has This Been Tested?

This PR was tested by extending the example provided with the module (examples/iam-assumable-role-with-oidc) with the failing use case reported in #73. Then asking for a plan of that example shows that the policy is now created with two subjects.

  # module.iam_assumable_role_admin.aws_iam_role.this[0] will be created
  + resource "aws_iam_role" "this" {
      + arn                   = (known after apply)
      + assume_role_policy    = jsonencode(
            {
              + Statement = [
                  + {
                      + Action    = "sts:AssumeRoleWithWebIdentity"
                      + Condition = {
                          + StringEquals = {
                              + oidc.eks.eu-west-1.amazonaws.com/id/BA9E170D464AF7B92084EF72A69B9DC8:sub = [
                                  + "system:serviceaccount:default:sa2",
                                  + "system:serviceaccount:default:sa1",
                                ]
                            }
                        }
                      + Effect    = "Allow"
                      + Principal = {
                          + Federated = "arn:aws:iam::119393867667:oidc-provider/oidc.eks.eu-west-1.amazonaws.com/id/BA9E170D464AF7B92084EF72A69B9DC8"
                        }
                      + Sid       = ""
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + create_date           = (known after apply)
      + force_detach_policies = false
      + id                    = (known after apply)
      + max_session_duration  = 3600
      + name                  = "role-with-oidc"
      + path                  = "/"
      + tags                  = {
          + "Role" = "role-with-oidc"
        }
      + unique_id             = (known after apply)
    }

@LS80
Copy link

LS80 commented May 13, 2020

FYI there are three other open PRs all fixing the same issue
#53
#63
#66

@miguelaferreira
Copy link
Contributor Author

Thanks for letting me know @LS80.
I'm happy to close this in favour of an earlier PR.

@LS80
Copy link

LS80 commented Jun 1, 2020

I have no preference, I was just pointing out the other fixes in case it was instructive. Can we get this merged?

@miguelaferreira
Copy link
Contributor Author

I understand @LS80. I often have the same problem even when I'm the maintainer of a module I do not have the freedom to merge, or release the code. That is by design so I would advise you to reach out to the owners of this organisation. You can find them here: https://github.com/orgs/terraform-aws-modules/people

@antonbabenko antonbabenko changed the title Fix conditions with multiple subjects in assume role with oidc policy fix: Fix conditions with multiple subjects in assume role with oidc policy Jun 10, 2020
@antonbabenko antonbabenko merged commit e47ee04 into terraform-aws-modules:master Jun 10, 2020
@antonbabenko
Copy link
Member

Thanks, @miguelaferreira !

v2.12.0 has been just released.

Fixes #73

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 10, 2022
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.

Multiple oidc_fully_qualified_subjects not working with iam-assumable-role-with-oidc
3 participants