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

Support use of role by any service account in a namespace, or other StringLike patterns (iam-role-for-service-account-eks) #200

Closed
tculp opened this issue Mar 7, 2022 · 2 comments · Fixed by #201

Comments

@tculp
Copy link

tculp commented Mar 7, 2022

Is your request related to a new offering from AWS?

No

Is your request related to a problem? Please describe.

Sometimes service accounts are created dynamically, such that it would be challenging to provide the exact service account names.

Describe the solution you'd like.

It would be useful to be able to provide a regex string to represent the service accounts, such as namespace:*.

StringEquals is currently the only supported option.

condition {
        test     = "StringEquals"
        variable = "${replace(statement.value.provider_arn, "/^(.*provider/)/", "")}:sub"
        values   = [for sa in statement.value.namespace_service_accounts : "system:serviceaccount:${sa}"]
      }

I'm currently using a custom role that does the following:

    dynamic "condition" {
      for_each = var.restrict_role_to_serviceaccount && var.serviceaccount != null ? [""] : []

      content {
        test     = "StringEquals"
        variable = "${local.oidc_provider}:sub"

        values = ["system:serviceaccount:${var.namespace}:${var.serviceaccount}"]
      }
    }

    dynamic "condition" {
      for_each = var.restrict_role_to_namespace && var.namespace != null ? [""] : []

      content {
        test     = "StringLike"
        variable = "${local.oidc_provider}:sub"

        values = ["system:serviceaccount:${var.namespace}:*"]
      }
    }

However, it theoretically could also be done by determining if any sa in statement.value.namespace_service_accounts contains a StringLike-supported character (* or ?) per https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String.

Alternatively, an extra variable for role_condition (default "StringEquals") would be a simpler way of allowing the user to specify.

Describe alternatives you've considered.

Dealing with it or continuing to use my custom module.

Additional context

The GitLab helm chart can automatically create many service accounts, but allowing a global annotation to be applied to each. This is a case where hard-coding the (probable) service account names in Terraform would be difficult.

@tculp tculp changed the title Support use of role by any service account in a namespace (iam-role-for-service-account-eks) Support use of role by any service account in a namespace, or other StringLike patterns (iam-role-for-service-account-eks) Mar 7, 2022
@antonbabenko
Copy link
Member

This issue has been resolved in version 4.14.0 🎉

@github-actions
Copy link

github-actions bot commented Nov 8, 2022

I'm going to lock this issue 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 similar to this, 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 Nov 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants