Merge pull request #465 from nestorsalceda/falco-aws-permissions-fix

Fix AWS permissions for Kubernetes Response Engine
This commit is contained in:
Jorge Salamero Sanz
2018-11-20 10:11:00 +01:00
committed by GitHub
11 changed files with 83 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
.terraform/* .terraform/*
.terraform.* .terraform.*
terraform.* terraform.*
*.yaml aws-auth-patch.yml

View File

@@ -1,11 +1,17 @@
all: create configure deploy: rbac create configure
rbac:
kubectl apply -f cluster-role.yaml
kubectl apply -f cluster-role-binding.yaml
create: create:
terraform apply terraform apply -auto-approve
configure: configure:
kubectl get -n kube-system configmap/aws-auth -o yaml | awk "/mapRoles: \|/{print;print \"$(shell terraform output patch_for_aws_auth)\";next}1" > aws-auth-patch.yml kubectl get -n kube-system configmap/aws-auth -o yaml | awk "/mapRoles: \|/{print;print \"$(shell terraform output patch_for_aws_auth)\";next}1" > aws-auth-patch.yml
kubectl -n kube-system replace -f aws-auth-patch.yml kubectl -n kube-system replace -f aws-auth-patch.yml
clean: clean:
terraform destroy terraform destroy -force
kubectl delete -f cluster-role-binding.yaml
kubectl delete -f cluster-role.yaml

View File

@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: kubernetes-response-engine-cluster-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubernetes-response-engine-cluster-role
subjects:
- kind: User
apiGroup: rbac.authorization.k8s.io
name: kubernetes-response-engine

View File

@@ -0,0 +1,25 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kubernetes-response-engine-cluster-role
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- delete
- list
- patch
- apiGroups:
- ""
resources:
- nodes
verbs:
- patch
- apiGroups:
- batch
resources:
- jobs
verbs:
- create

View File

@@ -1,3 +1,7 @@
resource "aws_iam_user" "kubernetes-response-engine-user" {
name = "kubernetes_response_engine"
}
resource "aws_iam_role" "iam-for-lambda" { resource "aws_iam_role" "iam-for-lambda" {
name = "iam_for_lambda" name = "iam_for_lambda"
@@ -9,7 +13,7 @@ resource "aws_iam_role" "iam-for-lambda" {
"Action": "sts:AssumeRole", "Action": "sts:AssumeRole",
"Principal": { "Principal": {
"Service": "lambda.amazonaws.com", "Service": "lambda.amazonaws.com",
"AWS": "${var.iam-user-arn}" "AWS": "${aws_iam_user.kubernetes-response-engine-user.arn}"
}, },
"Effect": "Allow", "Effect": "Allow",
"Sid": "" "Sid": ""

View File

@@ -1,7 +1,7 @@
locals { locals {
patch_for_aws_auth = <<CONFIGMAPAWSAUTH patch_for_aws_auth = <<CONFIGMAPAWSAUTH
- rolearn: ${aws_iam_role.iam-for-lambda.arn}\n - rolearn: ${aws_iam_role.iam-for-lambda.arn}\n
username: kubernetes-admin\n username: kubernetes-response-engine\n
groups:\n groups:\n
- system:masters - system:masters
CONFIGMAPAWSAUTH CONFIGMAPAWSAUTH

View File

@@ -1,3 +0,0 @@
variable "iam-user-arn" {
type = "string"
}

View File

@@ -1,7 +1,6 @@
deploy: deploy:
kubectl apply -f nats/ kubectl apply -f nats/
kubectl apply -f kubeless/ kubectl apply -f kubeless/
kubectl apply -f network-policy.yaml
kubectl apply -f . kubectl apply -f .
clean: clean:

View File

@@ -1,12 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding kind: ClusterRoleBinding
metadata: metadata:
name: sysdig-kubeless name: kubernetes-response-engine-cluster-role-binding
roleRef: roleRef:
apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io
kind: ClusterRole kind: ClusterRole
name: cluster-admin name: kubernetes-response-engine-cluster-role
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: default name: default
namespace: default namespace: default
apiGroup: rbac.authorization.k8s.io

View File

@@ -0,0 +1,25 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kubernetes-response-engine-cluster-role
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- delete
- list
- patch
- apiGroups:
- ""
resources:
- nodes
verbs:
- patch
- apiGroups:
- batch
resources:
- jobs
verbs:
- create

View File

@@ -16,7 +16,7 @@ You must pass the playbook and at least one topic to subscribe.
Example: Example:
deploy_playbook -p slack -t "falco.error.*" -e SLACK_WEBHOOK_URL=http://foobar.com/... -k sysdig_eks deploy_playbook -p slack -e SLACK_WEBHOOK_URL=http://foobar.com/... -k sysdig_eks
EOF EOF
exit 1 exit 1
} }
@@ -27,7 +27,7 @@ playbook=""
environment=("KUBECONFIG=kubeconfig" "KUBERNETES_LOAD_KUBE_CONFIG=1") environment=("KUBECONFIG=kubeconfig" "KUBERNETES_LOAD_KUBE_CONFIG=1")
eks_cluster="${EKS_CLUSTER}" eks_cluster="${EKS_CLUSTER}"
while getopts "r:e:t:" arg; do while getopts "p:e:k:" arg; do
case $arg in case $arg in
p) p)
playbook="${OPTARG}" playbook="${OPTARG}"