-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kiam to oidc iam/helm kube prometheus stack (#426)
* Modified iam policy document for helm-kube-prometheus-stack to use oidc * trim identifier for iam policy * Use preexisting data for oidc value instead of var * Added aws_subnet_exporter module; Updated oidc for kube-prometheus-stack * Remove roles from namespace IAM annotation, no longer needed after switch to oidc iam
- Loading branch information
Showing
10 changed files
with
246 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
data "aws_iam_policy_document" "subnet_exporter" { | ||
statement { | ||
effect = "Allow" | ||
|
||
actions = [ | ||
"ec2:DescribeSubnets", | ||
] | ||
|
||
resources = ["*"] | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "subnet_exporter_trust" { | ||
statement { | ||
effect = "Allow" | ||
|
||
principals { | ||
type = "Federated" | ||
|
||
identifiers = [ | ||
"arn:aws:iam::${var.aws_account_id}:oidc-provider/${var.oidc_issuer}", | ||
] | ||
} | ||
|
||
condition { | ||
test = "StringEquals" | ||
values = ["system:serviceaccount:${var.namespace_name}:${local.serviceaccount_name}"] | ||
variable = "${var.oidc_issuer}:sub" | ||
} | ||
|
||
actions = ["sts:AssumeRoleWithWebIdentity"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
locals { | ||
serviceaccount_name = "subnet-exporter" | ||
deployment_name = "aws-subnet-exporter" | ||
iam_role_name = "SubnetExporter" | ||
} | ||
|
||
resource "aws_iam_role" "this" { | ||
name = local.iam_role_name | ||
path = "/" | ||
description = "Role for subnet-exporter to describe ec2 subnets" | ||
assume_role_policy = data.aws_iam_policy_document.subnet_exporter_trust.json | ||
max_session_duration = 3600 | ||
} | ||
|
||
resource "aws_iam_role_policy" "this" { | ||
name = local.iam_role_name | ||
role = aws_iam_role.this.id | ||
policy = data.aws_iam_policy_document.subnet_exporter.json | ||
} | ||
|
||
resource "kubernetes_service_account" "this" { | ||
metadata { | ||
name = local.serviceaccount_name | ||
namespace = var.namespace_name | ||
annotations = { | ||
"eks.amazonaws.com/role-arn" = aws_iam_role.this.arn | ||
"eks.amazonaws.com/sts-regional-endpoints" = "true" | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_deployment" "this" { | ||
metadata { | ||
name = local.deployment_name | ||
namespace = var.namespace_name | ||
|
||
labels = { | ||
app = local.deployment_name | ||
} | ||
} | ||
|
||
spec { | ||
replicas = 1 | ||
|
||
selector { | ||
match_labels = { | ||
app = local.deployment_name | ||
} | ||
} | ||
|
||
template { | ||
metadata { | ||
labels = { | ||
app = local.deployment_name | ||
} | ||
} | ||
|
||
spec { | ||
service_account_name = local.serviceaccount_name | ||
automount_service_account_token = true | ||
container { | ||
name = local.deployment_name | ||
image = "dfdsdk/aws-subnet-exporter:${var.image_tag}" | ||
|
||
env { | ||
name = "REGION" | ||
value = var.aws_region | ||
} | ||
|
||
env { | ||
name = "FILTER" | ||
value = "*eks*" | ||
} | ||
|
||
env { | ||
name = "PERIOD" | ||
value = "30s" | ||
} | ||
|
||
env { | ||
name = "PORT" | ||
value = ":8080" | ||
} | ||
|
||
resources { | ||
requests = { | ||
cpu = "20m" | ||
|
||
memory = "64Mi" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_service" "this" { | ||
metadata { | ||
name = local.deployment_name | ||
namespace = var.namespace_name | ||
|
||
labels = { | ||
app = local.deployment_name | ||
|
||
scrape-service-metrics = "true" | ||
} | ||
} | ||
|
||
spec { | ||
port { | ||
name = "metrics" | ||
protocol = "TCP" | ||
port = 8080 | ||
target_port = "8080" | ||
} | ||
|
||
selector = { | ||
app = local.deployment_name | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
variable "aws_account_id" { | ||
type = string | ||
description = "Used for iam policy oidc trust" | ||
} | ||
|
||
variable "aws_region" { | ||
type = string | ||
description = "Used to filter subnets by AWS region" | ||
} | ||
|
||
variable "oidc_issuer" { | ||
type = string | ||
description = "Used for iam policy oidc trust" | ||
validation { | ||
condition = substr(var.oidc_issuer, 0, 8) != "https://" | ||
error_message = "Oidc_issuer may not contain https:// in the start of the variable." | ||
} | ||
} | ||
|
||
variable "namespace_name" { | ||
type = string | ||
description = "K8s namespace for deployment/iam policy" | ||
} | ||
|
||
variable "image_tag" { | ||
type = string | ||
description = "K8s subnet-exporter image tag" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform { | ||
required_version = "~> 1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters