-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from SCT-Engineering/subchart_version
add default roles and clusterissuer
- Loading branch information
Showing
14 changed files
with
670 additions
and
14 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,7 @@ | |
| ### fix | ||
|
|
||
| - **main.tf**: add operators ns here | ||
|
|
||
|
|
||
|
|
||
| - change to trigger action | ||
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
File renamed without changes.
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,36 @@ | ||
| # Create a subordinate cert for the cert-manager clusterissuer. | ||
| module "subordinate_ca" { | ||
| # tflint-ignore: terraform_module_pinned_source | ||
| source = "git::https://github.e.it.census.gov/terraform-modules/aws-certificates//acmpca-eks-cert-manager" | ||
|
|
||
| cluster_name = var.cluster_name | ||
| contact_email = var.cluster_mailing_list | ||
| validity_days = 365 | ||
| } | ||
|
|
||
| resource "kubernetes_secret" "ca_key_pair" { | ||
| metadata { | ||
| name = "ca-key-pair" | ||
| namespace = var.namespace | ||
| } | ||
|
|
||
| binary_data = { | ||
| "tls.key" = module.subordinate_ca.certificate_tls_key | ||
| "tls.crt" = module.subordinate_ca.certificate_tls_crt | ||
| } | ||
| } | ||
|
|
||
| resource "kubernetes_manifest" "cluster_issuer" { | ||
| manifest = { | ||
| "apiVersion" = "cert-manager.io/v1" | ||
| "kind" = "ClusterIssuer" | ||
| "metadata" = { | ||
| "name" = "clusterissuer" | ||
| } | ||
| "spec" = { | ||
| "ca" = { | ||
| "secretName" = kubernetes_secret.ca_key_pair.metadata[0].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,24 @@ | ||
| resource "kubernetes_cluster_role" "dba_administrator_cluster_role" { | ||
| metadata { | ||
| name = var.dba_administrator_role_name | ||
| } | ||
| aggregation_rule { | ||
| cluster_role_selectors { | ||
| match_labels = { | ||
| "rbac.authorization.k8s.io/aggregate-to-admin" = "true" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| rule { | ||
| api_groups = ["cert-manager.io", "acme.cert-manager.io"] | ||
| resources = ["certificates", "challenges", "orders", "certificaterequests", "issuers"] | ||
| verbs = ["get", "list", "watch", "create", "update", "patch"] | ||
| } | ||
|
|
||
| rule { | ||
| verbs = ["get", "list", "watch", "create", "update", "patch"] | ||
| api_groups = ["networking.istio.io", "security.istio.io"] | ||
| resources = ["virtualservices", "authorizationpolicies", "destinationrules", "peerauthentications", "requestauthentications"] | ||
| } | ||
| } |
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,40 @@ | ||
| locals { | ||
| dba_managed_namespaces = formatlist("%v-%v", var.cluster_name, var.dba_managed_namespaces) | ||
| dba_k8s_group_name = format("%v%v-%v", local.prefixes["eks-user"], var.cluster_name, var.dba_k8s_group_name) | ||
| } | ||
|
|
||
| resource "kubernetes_namespace" "dba_managed_namespaces" { | ||
| for_each = toset(local.dba_managed_namespaces) | ||
| metadata { | ||
| name = each.key | ||
| labels = { | ||
| istio-injection = "enabled" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "kubernetes_role_binding" "dba_admin_rolebinding" { | ||
| # for_each = toset(local.dba_managed_namespaces) | ||
| for_each = kubernetes_namespace.dba_managed_namespaces | ||
|
|
||
| metadata { | ||
| name = var.dba_admin_rolebinding_name | ||
| namespace = each.key | ||
| } | ||
| role_ref { | ||
| api_group = "rbac.authorization.k8s.io" | ||
| kind = "ClusterRole" | ||
| name = var.dba_administrator_role_name | ||
| } | ||
| subject { | ||
| kind = "User" | ||
| name = var.dba_k8s_user_name | ||
| api_group = "rbac.authorization.k8s.io" | ||
| } | ||
| subject { | ||
| kind = "Group" | ||
| name = local.dba_k8s_group_name | ||
| api_group = "rbac.authorization.k8s.io" | ||
| } | ||
| # depends_on = [kubernetes_namespace.dba_managed_namespaces] | ||
| } |
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,109 @@ | ||
| locals { | ||
| policy_dba_k8s_group_name = replace(local.dba_k8s_group_name, local.prefixes["eks-user"], local.prefixes["eks-policy"]) | ||
| role_dba_k8s_group_name = format("%v%v-%v", local.prefixes["eks"], var.cluster_name, var.dba_k8s_group_name) | ||
| } | ||
|
|
||
| module "role_dba_administrator" { | ||
| source = "git@github.e.it.census.gov:terraform-modules/aws-iam-role.git?ref=tf-upgrade" | ||
|
|
||
| role_name = local.role_dba_k8s_group_name | ||
| role_description = "Role for EKS cluster ${var.cluster_name} for access by ${var.dba_k8s_group_name}" | ||
| enable_ldap_creation = false | ||
| assume_policy_document = data.aws_iam_policy_document.dba_administrator_allow_sts.json | ||
| attached_policies = [aws_iam_policy.dba_administrator.arn] | ||
|
|
||
| } | ||
|
|
||
| resource "aws_iam_policy" "dba_administrator" { | ||
| name = local.policy_dba_k8s_group_name | ||
| path = "/" | ||
| description = "Policy for EKS ${var.cluster_name} IAM access ${var.dba_k8s_group_name}" | ||
| policy = data.aws_iam_policy_document.dba_administrator.json | ||
| } | ||
|
|
||
| locals { | ||
| dba_administrator_policy_statements = { | ||
| ECRRead = { | ||
| actions = [ | ||
| "ecr:Describe*", | ||
| "ecr:Get*", | ||
| "ecr:ListImages", | ||
| "ecr:BatchGetImage", | ||
| "ecr:BatchCheckLayerAvailability", | ||
| "ecr:GetDownloadUrlForLayer", | ||
| ] | ||
| resources = ["*"] | ||
| } | ||
| EKSRead = { | ||
| actions = [ | ||
| "eks:ListClusters", | ||
| ] | ||
| resources = ["*"] | ||
| } | ||
| EKSReadMyClusters = { | ||
| actions = [ | ||
| "eks:DescribeCluster", | ||
| "eks:AccessKubernetesApi", | ||
| ] | ||
| resources = [format(local.common_arn, "eks", format("%v/%v", "cluster", var.cluster_name))] | ||
| } | ||
| STSAssumeRole = { | ||
| actions = ["sts:AssumeRole"] | ||
| resources = [module.role_dba_administrator.role_arn] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "dba_administrator" { | ||
| dynamic "statement" { | ||
| for_each = local.dba_administrator_policy_statements | ||
| iterator = s | ||
| content { | ||
| sid = format("%v%vAccess", lookup(s.value, "effect", "Allow"), s.key) | ||
| effect = lookup(s.value, "effect", "Allow") | ||
| actions = lookup(s.value, "actions", []) | ||
| resources = lookup(s.value, "resources", []) | ||
| not_resources = lookup(s.value, "not_resources", []) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # allow anyone in this account to assume the role, if they have the permission to do so | ||
| data "aws_iam_policy_document" "dba_administrator_allow_sts" { | ||
| statement { | ||
| sid = "AllowSTSAssume" | ||
| effect = "Allow" | ||
| actions = ["sts:AssumeRole"] | ||
| principals { | ||
| type = "AWS" | ||
| identifiers = [ | ||
| format(local.iam_arn, "root"), | ||
| ] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| output "role_dba_administrator_arn" { | ||
| description = "DBA Adminstrator role ARN" | ||
| value = module.role_dba_administrator.role_arn | ||
| } | ||
|
|
||
| module "group_dba_administrator" { | ||
| # tflint-ignore: terraform_module_version | ||
| # tflint-ignore: terraform_module_pinned_source | ||
| source = "git@github.e.it.census.gov:terraform-modules/aws-iam-group.git" | ||
|
|
||
| group_name = local.role_dba_k8s_group_name | ||
| attached_policies = [aws_iam_policy.dba_administrator.arn] | ||
|
|
||
| } | ||
|
|
||
| output "info_dba_administrator" { | ||
| description = "DBA Adminstrator IAM details" | ||
| value = { | ||
| role_name = module.role_dba_administrator.role_name | ||
| role_arn = module.role_dba_administrator.role_arn | ||
| group_name = module.group_dba_administrator.group_name | ||
| group_arn = module.group_dba_administrator.group_arn | ||
| } | ||
| } |
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,67 @@ | ||
| resource "kubernetes_cluster_role" "cicd_deployer_istiosystem_cluster_role" { | ||
| metadata { | ||
| name = var.deployer_istiosystem_role_name | ||
| } | ||
|
|
||
| rule { | ||
| api_groups = ["acme.cert-manager.io"] | ||
| resources = ["challenges", "orders", "certificaterequests"] | ||
| verbs = ["create", "delete", "deletecollection", "get", "list", "patch", "update", "patch"] | ||
| } | ||
|
|
||
| rule { | ||
| api_groups = ["cert-manager.io"] | ||
| resources = ["certificates"] | ||
| verbs = ["create", "delete", "deletecollection", "get", "list", "patch", "update", "patch"] | ||
| } | ||
|
|
||
|
|
||
| rule { | ||
| verbs = ["create", "delete", "deletecollection", "get", "list", "patch", "update", "patch"] | ||
| api_groups = ["networking.istio.io"] | ||
| resources = ["gateways"] | ||
| } | ||
| } | ||
|
|
||
| resource "kubernetes_cluster_role" "cicd_deployer_istio_cluster_role" { | ||
| metadata { | ||
| name = var.deployer_application_istio_role_name | ||
| } | ||
| rule { | ||
| api_groups = ["security.istio.io"] | ||
| verbs = ["create", "delete", "deletecollection", "get", "list", "patch", "update", "patch"] | ||
| resources = ["requestauthentications", "authorizationpolicies", "peerauthentications"] | ||
| } | ||
|
|
||
| rule { | ||
| verbs = ["create", "delete", "deletecollection", "get", "list", "patch", "update", "patch"] | ||
| api_groups = ["networking.istio.io"] | ||
| resources = ["virtualservices", "destinationrules", "gateways"] | ||
| } | ||
| } | ||
|
|
||
| resource "kubernetes_cluster_role" "cicd_deployer_application_cluster_role" { | ||
| metadata { | ||
| name = var.deployer_application_role_name | ||
| } | ||
| aggregation_rule { | ||
| cluster_role_selectors { | ||
| match_labels = { | ||
| "rbac.authorization.k8s.io/aggregate-to-edit" = "true" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| rule { | ||
| api_groups = ["acme.cert-manager.io"] | ||
| resources = ["challenges", "orders", "certificaterequests"] | ||
| verbs = ["create", "delete", "deletecollection", "get", "list", "patch", "update", "patch"] | ||
| } | ||
|
|
||
| rule { | ||
| api_groups = ["cert-manager.io"] | ||
| resources = ["certificates"] | ||
| verbs = ["create", "delete", "deletecollection", "get", "list", "patch", "update", "patch"] | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.