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

feat: Add support for AWS Secrets Manager #151

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/public-dns-external/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ module "wandb_app" {
# If we dont wait, tf will start trying to deploy while the work group is
# still spinning up
depends_on = [module.wandb_infra]

other_wandb_env = merge({
"GORILLA_CUSTOMER_SECRET_STORE_SOURCE" = "aws-secretmanager://${var.namespace}?namespace=${var.namespace}"
}, var.other_wandb_env)
}

output "bucket_name" {
Expand Down
6 changes: 6 additions & 0 deletions examples/public-dns-external/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ variable "allowed_inbound_ipv6_cidr" {
nullable = false
type = list(string)
}

variable "other_wandb_env" {
type = map(string)
description = "Extra environment variables for W&B"
default = {}
}
elainaRenee marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 6 additions & 1 deletion modules/app_eks/iam-policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ resource "aws_iam_policy" "node_s3" {
lifecycle {
create_before_destroy = false
}
}
}

resource "aws_iam_policy" "secrets_manager" {
name = "${var.namespace}-secrets-manager"
policy = data.aws_iam_policy_document.secrets_manager.json
}
15 changes: 15 additions & 0 deletions modules/app_eks/iam-policy-docs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ data "aws_iam_policy_document" "node_s3" {
]
}
}

data "aws_iam_policy_document" "secrets_manager" {
statement {
actions = [
"secretsmanager:CreateSecret",
"secretsmanager:UpdateSecret",
"secretsmanager:DeleteSecret",
"secretsmanager:PutSecretValue",
"secretsmanager:GetSecretValue",
"secretsmanager:DeleteSecretVersion"
]
effect = "Allow"
resources = ["arn:aws:secretsmanager:*:${data.aws_caller_identity.current.account_id}:secret:${var.namespace}*"]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm is there a better default here than allowing access to all secret managers? It looks like the default we are setting for the other policies is ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${aws_iam_role.node.name}"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think limitations are based on the secret, not the secret manager (you can think of the secret manager as some service you can't control)

Our secrets are prefixed, so maybe we can change to:

"arn:aws:secretsmanager:*:${data.aws_caller_identity.current.account_id}:secret:${prefix}-*"

from:

"arn:aws:secretsmanager:*:${data.aws_caller_identity.current.account_id}:secret:*"

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Yeah we need some way to make this a no-op so that we don't give installs access to all secrets. Maybe just put in some junk for the prefix? cc: @gls4 if you have any better ideas here. It be nice to refactor this at some point to not provision the policy at all in the case that no secret manager arn is present.

Copy link
Contributor Author

@andrewtruong andrewtruong Nov 7, 2023

Choose a reason for hiding this comment

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

For simplicity, maybe we can just enforce that the prefix is non-null (or hardcode it as wandb-secret)

I don't think we use the Secret Manager for anything else atm, but maybe in future?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not correct. Please see https://docs.aws.amazon.com/secretsmanager/latest/userguide/reference_iam-permissions.html.

Access to SECRETS needs to be scoped to the cluster, and only for PUT, GET, UPDATE, DELETE operations. There is no need to provide the additional permissions. Moreover, we cannot allow one customer's cluster to read the secrets from another customer, so permissions have got to be scoped correctly from the start.

As for not provisioning the policy in the absence of the arn -- we need to do that now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified permission to be more tightly scoped

}
5 changes: 5 additions & 0 deletions modules/app_eks/iam-role-attachments.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ resource "aws_iam_role_policy_attachment" "ebs_csi" {
role = aws_iam_role.node.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy"
}

resource "aws_iam_role_policy_attachment" "node_secrets_manager" {
role = aws_iam_role.node.name
policy_arn = aws_iam_policy.secrets_manager.arn
}
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,4 @@ variable "elasticache_node_type" {
# type = string
# description = "Weights & Biases license key."
# }

Loading