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

Add example to add iam policies to task role #68

Conversation

EvilPlankton
Copy link

what

Add permission to get SecretsManager values form exec task

why

Needed for Fargate to access SecretsManager when task is instantiated by service

references

should close #67

@nitrocode nitrocode changed the title Update main.tf Update aws_iam_policy_document.ecs_exec to include secretsmanager:GetSecretValue Aug 4, 2020
@nitrocode nitrocode changed the title Update aws_iam_policy_document.ecs_exec to include secretsmanager:GetSecretValue Add secretsmanager:GetSecretValue to ecs_exec policy Aug 4, 2020
@nitrocode
Copy link
Member

Interesting. It does look like it's needed in the execution role and surprisingly not in the task role.

@nitrocode
Copy link
Member

/test all

@nitrocode nitrocode requested a review from jamengual August 4, 2020 23:49
@jamengual
Copy link
Contributor

I'm torn about this since Secrets are things that usually have more access restrictions and having blanket access to the secret will not work with many ISO, CIS compliant companies.

We output the roles and is easy enough to add this permission to it which in many cases is a to a few specific secrets.

Maybe we can add examples on how to do this.

@EvilPlankton
Copy link
Author

Just a suggestion, but we could have a separate Resource section with the specific ARNs that should be allowed access. These would be inferred from the Secrets section of the task definition. I do not know how to do this programmatically, but I suspect it would be a foreach over each secret valueFrom like

statement {
    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:us-east-1:<account id>: secret :<secret name 1>",
                 "arn:aws:secretsmanager:us-east-1:<account id>: secret :<secret name 2>"
      ]

    actions = [
      "secretsmanager:GetSecretValue",
    ]
  }

Alternatively, pass a wildcard path for granting access as a variable.

secret_path=foo_app/staging/*

    effect    = "Allow"
    resources = ["arn:aws:secretsmanager:us-east-1:<account id>: secret :var.secret_path
      ]

    actions = [
      "secretsmanager:GetSecretValue",
    ]
  }

@jamengual
Copy link
Contributor

that will work, it will give you the flexibility and only permission to the specific ARNs of the secrets. @EvilPlankton could you update your PR with that?

@nitrocode
Copy link
Member

We output the roles and is easy enough to add this permission to it which in many cases is a to a few specific secrets.

I agree more with this statement than integrating this PR. It seems a lot easier and allows this module to be less rigid. If we can easily attach a role policy outside of the module, why would we bake it in here if we don't have to?

@osterman
Copy link
Member

osterman commented Aug 7, 2020

I agree with @nitrocode and @jamengual - we should just use IAM policy attachments on the role outside of this module.

@nitrocode
Copy link
Member

Perhaps this example would help. Like @jamengual said, we could add this to the docs to make it more clear.

module "ecs_alb_service_task" {
  source = "git::https://github.com/cloudposse/terraform-aws-ecs-alb-service-task.git?ref=master"

  ...
}

resource "aws_iam_role_policy" "ssm" {
  name   = "ssm"
  policy = data.aws_iam_policy_document.ssm.json
  role   = module.ecs_alb_service_task.task_exec_role_name
}

data "aws_iam_policy_document" "ssm" {
  statement {
    sid    = ""
    effect = "Allow"

    actions = [
      "secretsmanager:GetSecretValue",
    ]

    resources = [
      ...
    ]
  }
}

@jamengual
Copy link
Contributor

Perhaps this example would help. Like @jamengual said, we could add this to the docs to make it more clear.

module "ecs_alb_service_task" {
  source = "git::https://github.com/cloudposse/terraform-aws-ecs-alb-service-task.git?ref=master"

  ...
}

resource "aws_iam_role_policy" "ssm" {
  name   = "ssm"
  policy = data.aws_iam_policy_document.ssm.json
  role   = module.ecs_alb_service_task.task_exec_role_name
}

data "aws_iam_policy_document" "ssm" {
  statement {
    sid    = ""
    effect = "Allow"

    actions = [
      "secretsmanager:GetSecretValue",
    ]

    resources = [
      ...
    ]
  }
}

yes the example should more than enough for people to implement it, I will only suggest to add a Secret manager Example and Parameter Store example.

@jamengual
Copy link
Contributor

@EvilPlankton do you want to have a stab at updating the docs?

Copy link
Contributor

@jamengual jamengual left a comment

Choose a reason for hiding this comment

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

doc updates should suffice

@nitrocode nitrocode changed the title Add secretsmanager:GetSecretValue to ecs_exec policy Add example to add iam policies to task role Sep 11, 2020
@nitrocode
Copy link
Member

@EvilPlankton ping

@nitrocode
Copy link
Member

Let us know if you're interested in taking this up @EvilPlankton and we'll re-open.

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.

Add example to add iam policies to task role
4 participants