Giter Site home page Giter Site logo

Comments (8)

eriksw avatar eriksw commented on July 28, 2024 1

FYI: The parameters are encrypted with a PARAMETER_ARN encryption context key. You should take advantage of this to restrict which ciphertext blobs can be decrypted, instead of allowing decryption of every ciphertext blob encrypted using the key.

Add this to the statement allowing decryption:

condition {
  test     = "StringLike"
  variable = "kms:EncryptionContext:PARAMETER_ARN"

  values = [
    "arn:aws:ssm:${var.region}:${var.AccountID}:parameter/${var.ssm_prefix}.*",
  ]
}

from chamber.

FernandoMiguel avatar FernandoMiguel commented on July 28, 2024

HTH

data "aws_iam_policy_document" "ssm-read-policy-document" {
  statement {
    sid = "SSMDescribeParameters"

    actions = [
      "ssm:DescribeParameters",
    ]

    resources = [
      "*",
    ]
  }

  statement {
    sid = "SSMGetParameters"

    actions = [
      "ssm:GetParameters",
    ]

    resources = [
      "arn:aws:ssm:${var.region}:${var.AccountID}:parameter/${var.ssm_prefix}.*",
    ]
  }

  statement {
    sid = "KMSDecrypt"

    actions = [
      "kms:Decrypt",
    ]

    resources = [
      "${aws_kms_key.kms-key.arn}",
    ]
  }
}

resource "aws_iam_policy" "STS-policy-SSM-read" {
  name   = "STS-SSM-read-${var.ssm_prefix}-${random_pet.random_pet.id}"
  policy = "${data.aws_iam_policy_document.ssm-read-policy-document.json}"
}

data "aws_iam_policy_document" "ssm-manage-policy-document" {
  statement {
    sid = "SSMDescribeParameters"

    actions = [
      "ssm:DescribeParameters",
    ]

    resources = [
      "*",
    ]
  }

  statement {
    sid = "SSMSetParameters"

    actions = [
      "ssm:GetParameters",
      "ssm:PutParameter",
      "ssm:DeleteParameter",
      "ssm:DeleteParameters",
    ]

    resources = [
      "arn:aws:ssm:${var.region}:${var.AccountID}:parameter/${var.ssm_prefix}.*",
    ]
  }

  statement {
    sid = "KMSEncrypt"

    actions = [
      "kms:Decrypt",
      "kms:Encrypt",
    ]

    resources = [
      "${aws_kms_key.kms-key.arn}",
    ]
  }
}

resource "aws_iam_policy" "STS-policy-SSM-manage" {
  name   = "STS-SSM-manage-${var.ssm_prefix}-${random_pet.random_pet.id}"
  policy = "${data.aws_iam_policy_document.ssm-manage-policy-document.json}"
}

https://aws.amazon.com/blogs/compute/managing-secrets-for-amazon-ecs-applications-using-parameter-store-and-iam-roles-for-tasks/
https://docs.aws.amazon.com/kms/latest/developerguide/iam-policies.html

from chamber.

phantomwhale avatar phantomwhale commented on July 28, 2024

Commenting here as this seems to be the only attempt to document this (I am also searching around for the answer here).

Running chamber with similar permissions to those above, I get a message suggesting I should be granting the ssm:ssm:GetParametersByPath permission to my resources, but aside from seeing that in the code, it doesn't seem to appear to be documented?

from chamber.

phantomwhale avatar phantomwhale commented on July 28, 2024

Have settled on:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "kms:Decrypt",
                "kms:DescribeKey"
            ],
            "Resource": [
                "arn:aws:kms:us-east-1:$MY_ACCOUNT:key/$MY_KMS_KEY"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ssm:GetParameters"
            ],
            "Resource": [
                "arn:aws:ssm:*:*:parameter/$APP_NAME/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ssm:GetParametersByPath"
            ],
            "Resource": "*"
        }
    ]
}

As my "secret access for chamber" policy. Seems to be working, and got rid of the "GetParametersByPath" deprecation warning I was getting too

from chamber.

nickatsegment avatar nickatsegment commented on July 28, 2024

That looks pretty good to me. I'd approve that PR ;)

from chamber.

stale avatar stale commented on July 28, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from chamber.

stale avatar stale commented on July 28, 2024

This issue has been automatically marked stale because it has not had any activity in the last 60 days. If no further activity occurs within 7 days, it will be closed. Closed does not mean "never", just that it has no momentum to get accomplished any time soon.
See CONTRIBUTING.md for more info.

from chamber.

stale avatar stale commented on July 28, 2024

Closing due to staleness. Closed does not mean "never", just that it has no momentum to get accomplished any time soon.
See CONTRIBUTING.md for more info.

from chamber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.