• Stars
    star
    1,135
  • Rank 41,034 (Top 0.9 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Integrate AWS IAM with Kubernetes

kiam

Docker Repository on Quay

🚨 ⚠️THIS PROJECT IS IN MAINTENANCE MODE ⚠️ 🚨

We developed Kiam years ago as it solved a very specific problem for us as we tried to run applications in AWS on Kubernetes. Since then there have been a lot of advances in this space, the most significant being AWS' official solution: IAM roles for Service Accounts. We believe this solution is significantly superior to Kiam and we have been internally moving away from Kiam for some time. We would encourage others to do the same. We are only a small team and we don't have the capacity to maintain a tool we don't use, so from now on we will only be accepting patches/bug fixes. Thank you to all the external contributors who have helped Kiam grow over the years.

About

kiam runs as an agent on each node in your Kubernetes cluster and allows cluster users to associate IAM roles to Pods.

Docker images are available at https://quay.io/repository/uswitch/kiam.

@jbeda recorded an excellent TGIK video covering IAM configuration and Kiam installation:

For more information about Kiam's origin, design and performance in our production clusters:

Support

If you come across issues please raise them against the GitHub project. Please include as much detail as you can, including relevant logs, version information etc.

We have a #kiam Slack channel in the main Kubernetes community Slack so you can also chat with other users and developers.

Features

  • No client SDK modifications are needed: Kiam intercepts Metadata API requests.
  • Separated Agent and Server processes. Allows user workloads to run on nodes without sts:AssumeRole permissions to enhance cluster security.
  • Denies access to all other AWS Metadata API paths by default (but can be configured via flag)
  • AWS credentials are prefetched to allow fast responses (and avoid problems with races between Pods requesting credentials and the Kubernetes client caches being aware of the Pod)
  • Multi-account IAM support. Pods can assume roles from any AWS account assuming trust relationships permit it
  • Prometheus metrics
  • Uses the Kubernetes Events API to record IAM errors against the Pod so that cluster users can more readily diagnose IAM problems (via kubectl describe pod ...)
  • Text and JSON log formats
  • Optional regional STS endpoint support

Overview

From the AWS documentation on IAM roles:

[a] role is similar to a user, in that it is an AWS identity with permission policies that determine what the identity can and cannot do in AWS. However, instead of being uniquely associated with one person, a role is intended to be assumable by anyone who needs it. Also, a role does not have any credentials (password or access keys) associated with it. Instead, if a user is assigned to a role, access keys are created dynamically and provided to the user.

kiam uses an annotation added to a Pod to indicate which role should be assumed. For example:

kind: Pod
metadata:
  name: foo
  namespace: iam-example
  annotations:
    iam.amazonaws.com/role: reportingdb-reader

You can control the session name used when assuming the role via an annotation added to the Pod, which may be used to further identify the session. For example:

kind: Pod
metadata:
  name: foo
  namespace: session-name-example
  annotations:
    iam.amazonaws.com/role: reportingdb-reader
    iam.amazonaws.com/session-name: my-session-name

You can also control the external id used when assuming the role via an annotation added to the Pod, which may be used to avoid confused deputy scenarios in cross-organisation role assumption. For example:

kind: Pod
metadata:
  name: foo
  namespace: external-id-example
  annotations:
    iam.amazonaws.com/role: reportingdb-reader
    iam.amazonaws.com/external-id: dac7ad46-acab-4ec3-a78e-f3962ecf45d7

Further, all namespaces must also have an annotation with a regular expression expressing which roles are permitted to be assumed within that namespace. Without the namespace annotation the pod will be unable to assume any roles.

kind: Namespace
metadata:
  name: iam-example
  annotations:
    iam.amazonaws.com/permitted: ".*"

When your process starts an AWS SDK library will normally use a chain of credential providers (environment variables, instance metadata, config files etc.) to determine which credentials to use. kiam intercepts the metadata requests and uses the Security Token Service to retrieve temporary role credentials.

Deploying to Kubernetes

Please see the deploy directory for example manifests for deploying to Kubernetes.

TLS assets must be created to mutually authenticate the agents and server processes; notes are in docs/TLS.md.

Please also make note of how to configure IAM in your AWS account; notes in docs/IAM.md.

Helm

We maintain and host Helm charts for Kiam, which are automatically packaged upon merging chart changes to the master branch in this repo. The charts can be found in the repo here.

The charts can easily be installed by adding the Kiam Helm repository and running a helm install:

helm repo add uswitch https://uswitch.github.io/kiam-helm-charts/charts/
helm repo update
helm install uswitch/kiam

More detailed Helm usage can be found on the Helm Hub:

Kiam - Helm Hub

How it Works

Kiam is split into two processes that run independently.

Agent

This is the process that would typically be deployed as a DaemonSet to ensure that Pods have no access to the AWS Metadata API. Instead, the agent runs an HTTP proxy which intercepts credentials requests and passes on anything else. An DNAT iptables rule is required to intercept the traffic. The agent is capable of adding and removing the required rule for you through use of the --iptables flag. This is the name of the interface where pod traffic originates and it is different for the various CNI implementations. The flag also supports the ! prefix for inverted matches should you need to match all but one interface.

Typical CNI Interface Names
CNI Interface Notes
amazon-vpc-cni-k8s and cni-ipvlan-vpc-k8s !eth0 This CNI plugin attaches multiple ENIs to the instance. Typically eth1-ethN (N depends on the instance type) are used for pods which leaves eth0 for the kubernetes control plane. The ! prefix on the interface name inverts the match so metadata service traffic from all interfaces except eth0 will be sent to the kiam agent. Requires kiam v2.7 or newer.
weave weave
calico/canal cali+
kube-router kube-bridge This is the default bridge interface that all the pods are connected to when using kube-router
kops (kubenet) cbr0 When using the default CNI (kubenet)
cilium lxc+

Server

This process is responsible for connecting to the Kubernetes API Servers to watch Pods and communicating with AWS STS to request credentials. It also maintains a cache of credentials for roles currently in use by running pods- ensuring that credentials are refreshed every few minutes and stored in advance of Pods needing them.

Building locally

If you want to build and run locally:

  • go version >= 1.9
  • run the following
mkdir -p $GOPATH/src/github.com/uswitch
git clone [email protected]:uswitch/kiam.git $GOPATH/src/github.com/uswitch/kiam
cd $GOPATH/src/github.com/uswitch/kiam
make

License

Copyright 2017 uSwitch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Thanks to Kube2iam

We owe a huge thanks to the creators and maintainers of Kube2iam which we ran for many months as we were bootstrapping our clusters.

We wanted to overcome two things in kube2iam:

  1. We had data races under load causing incorrect credentials to be issued #46.
  2. Prefetch credentials to reduce start latency and improve reliability.

Other improvements/changes we made were (largely driven out of how we have our systems setup):

  1. Use structured logging to improve the integration into our ELK setup with pod names, roles, access key ids etc.
  2. Use metrics to track response times, cache hit rates etc.

More Repositories

1

lambada

A more passionate way to write AWS Lambda functions
Clojure
315
star
2

yggdrasil

Envoy Control Plane for Kubernetes Multi-cluster Ingress
Go
189
star
3

blueshift

Automate copying data from S3 into Amazon Redshift
Clojure
119
star
4

bifrost

Safely archive data from Apache Kafka to S3 with no Hadoop dependencies :)
Clojure
100
star
5

vault-creds

Sidecar container for requesting dynamic Vault database secrets
Go
86
star
6

nidhogg

Kubernetes Node taints based on Daemonset Pods
Go
73
star
7

terrafying

A small ruby dsl for terraform.
Ruby
58
star
8

torus-pong

A massive multiplayer online take on the arcade classic, written as a part of Clojure Cup 2013
Clojure
50
star
9

speculate

A library that transforms clojure.spec
Clojure
44
star
10

klint

A 'realtime' kubernetes resource linter
Go
41
star
11

sqs-autoscaler-controller

Kubernetes controller for scaling Deployments based on AWS SQS queue length
Go
31
star
12

serverless-hooks-plugin

A plugin to run arbitrary commands on any lifecycle event in serverless
JavaScript
30
star
13

vault-webhook

Kubernetes Mutating Webhook to inject Vault-Creds Sidecar into pods
Go
26
star
14

baldr-old-dead

Pure and light binary records
Clojure
23
star
15

surtr

AWS Kubernetes Node Terminator
Go
22
star
16

heimdall

Generate PrometheusRule CRDs from Ingress annotations and Go templates
Go
22
star
17

big-replicate

Replicates data between Google Cloud BigQuery projects
Clojure
21
star
18

journald-forwarder

Forward systemd journals to Loggly
Go
21
star
19

ustyle

A living styleguide and pattern library by uSwitch.
Smarty
19
star
20

syslogger

Forwards syslog messages to Kafka
Go
16
star
21

koa-core

🎾 Core libraries and example project of how to use @uswitch/koa libraries
JavaScript
16
star
22

ej

a tool to convert from EDN to JSON
Haskell
16
star
23

opencensus-clojure

Clojure
15
star
24

transducers-workshop

Transducers workshop slides and labs
Clojure
15
star
25

incident-app

Incident Management Slack Bot
Ruby
13
star
26

analytij

Clojure client library to interact with the Google Analytics API
Clojure
12
star
27

bqshift

Export data from Redshift to BigQuery
Go
12
star
28

hermod

The Messenger of the Gods
Go
11
star
29

clj-rad

Clojure wrapper of Netflix Surus Robust Anomaly Detection
Clojure
9
star
30

k8s-podmon

A service to monitor failing jobs and pods
Go
9
star
31

loglet

Forward journald log messages to Kafka
Go
8
star
32

adworj

Clojure library to make it easier to interact with Google AdWords
Clojure
8
star
33

rest-client-logger

Adds logging of RestClient requests to the Rails debug log
Ruby
7
star
34

ustyle-react

uStyle + React for the people.
JavaScript
7
star
35

node-problem-detector

Custom plugins for node-problem-detector used in uSwitch
Shell
7
star
36

ssi-loader

Webpack ssi loader
JavaScript
7
star
37

kf

kafka follow
Go
6
star
38

dagr

runs programs every day (in Norse mythology, Dagr is day personified)
Go
6
star
39

etcd-experiment

An experiment in zero downtime clojure app deployments using etcd
Clojure
6
star
40

koa-access

💀DEPRECATED 👌A Koa middleware for reporting JSON access logs
JavaScript
6
star
41

vault-tokens

Generates Vault tokens for a User based off their AD groups
Go
5
star
42

ontology

Ruby
4
star
43

fsnotify

Cross-platform file system notifications for Go. https://fsnotify.org
Go
4
star
44

elastic-log-lag

Calculates the log lag on Elasticsearch indexes
Go
3
star
45

terraform-provider-segment

A Terraform provider to manage Segment resources via code.
Go
3
star
46

terrafying-components

Ruby
3
star
47

blueshift-riemann-metrics

Riemann metric publishing for Blueshift
Clojure
3
star
48

kubernetes-google-auth

Go
2
star
49

log4-clj-layout

Clojure
2
star
50

labs-window-functions

Provides a docker environment for playing with window functions in PostgreSQL
Shell
2
star
51

rack-ssi

Rack middleware for SSI processing, based on nginx HttpSsiModule
Ruby
2
star
52

terraform-aws-to-gcp-vpn

Creates infrastructure in AWS and GCP for HA VPNs between the two.
HCL
2
star
53

fads

Clojure
1
star
54

browser-tools

Suite of favelets, chrome extensions, audits and snippets to help test and debug the uSwitch website in the browser.
JavaScript
1
star
55

trustyle

React components with style
TypeScript
1
star
56

hypermq

Hypermedia (AtomPub like) message queue
Clojure
1
star
57

rabbitmq-worker

A small wrapper around the Langohr RabbitMQ client
Clojure
1
star
58

fed-convert

Converts Kubernetes resource files into Federated resources
Go
1
star
59

bdcat

decode baldr files in Go
Go
1
star
60

ontology-ui

JavaScript
1
star
61

stdout-fs

Python
1
star
62

instance-signals

Go
1
star
63

riemann-redis-info

Ruby
1
star
64

baldrcat

Tool to print contents of .baldr archives on S3
Clojure
1
star
65

uswitch-academy

Stuff related to courses, internal training and logistic thereof.
JavaScript
1
star
66

airship-aio-ticketing

composite github action for ticketing
1
star
67

bqstream

Stream newline-delimited JSON into BigQuery from STDIN
Go
1
star
68

ookla-netgauge-server

Docker image definition for Ookla Netgauge Server
1
star
69

dockerfiles-etcd-srv-bootstrap

etcd and helper script to do DNS/SRV discovery
Python
1
star