Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jun 6, 2022
1 parent b28bd10 commit a02c947
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/cluster-roles/read-only/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# read-only

This contains two files.

* read-only.tf

Place this into the `cluster-roles` directory. Then run `tf-apply`.

* main.tf

Create a directory for the specific IAM (SAML) role, like `r-ditd-readonly`, and place this file
inside it. Initialize the `tf-run` environment. Then process `tf-run.sh apply`.

Note, change the `aws_role_name` value accordingly.

```script
cd cluster-roles
mkdir r-ditd-readonly
cd r-ditd-readonly
cp EXAMPLEDIR/cluster-roles/read-only/main.tf .
cp ../region.tf .
tf-run.sh init
tf-run.sh apply
```
23 changes: 23 additions & 0 deletions examples/cluster-roles/read-only/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
locals {
aws_auth_users = []
aws_auth_roles = [
{
rolearn = ""
aws_rolename = "r-ditd-readonly"
username = "eks-readonly"
groups = ["eks-console-restricted-access"]
},
]
}

module "awsauth" {
source = "git@github.e.it.census.gov:terraform-modules/aws-eks.git//patch-aws-auth"

region = local.region
profile = var.profile
cluster_name = var.cluster_name
aws_auth_users = local.aws_auth_users
aws_auth_roles = local.aws_auth_roles

keep_temporary_files = false
}
54 changes: 54 additions & 0 deletions examples/cluster-roles/read-only/read-only.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# from https://stackoverflow.com/questions/60277163/read-only-user-gets-full-access

resource "kubernetes_cluster_role" "read_only" {
metadata {
name = format("%v-cluster-role", var.read_only_name)
}

rule {
api_groups = [""]
resources = ["*"]
verbs = ["get", "list", "watch"]
}

rule {
api_groups = ["extensions"]
resources = ["*"]
verbs = ["get", "list", "watch"]
}

rule {
api_groups = ["apps"]
resources = ["*"]
verbs = ["get", "list", "watch"]
}

}

resource "kubernetes_cluster_role_binding" "read_only" {
metadata {
name = format("%v-clusterrole-binding", var.read_only_name)
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = format("%v-cluster-role", var.read_only_name)
}
subject {
kind = "User"
name = var.read_only_name
api_group = "rbac.authorization.k8s.io"
}
# subject {
# kind = "Group"
# name = "system:masters"
# api_group = "rbac.authorization.k8s.io"
# }
}


variable "read_only_name" {
description = "Read-only Role Name"
type = string
default = "eks-readonly"
}

0 comments on commit a02c947

Please sign in to comment.