containers-roadmap icon indicating copy to clipboard operation
containers-roadmap copied to clipboard

EKS IAM Roles for Service Accounts (Pods)

Open pauncejones opened this issue 7 years ago • 108 comments

Update 1/9/19:

After talking about this internally, we've been working on a proposed solution for this. Below is a writeup on what we're thinking, and we've included some example scripts so you can get a feel for how we expect this to work.

Our plan for IAM and Kubernetes integration

A recent Kubernetes feature, TokenRequestProjection, allows users of Kubernetes to mount custom projected service account tokens in their pods. A “projected service account” is a bearer token that is intended for use outside of the cluster. Conveniently, these projected service account tokens are also valid OpenID Connect (OIDC) tokens. AWS IAM has supported OIDC as a federated identity provider since 2014, which has allowed customers to use an external identity to assume an IAM role.

By combining these two features, an application running in a pod can pass the projected service account token along with a role ARN to the STS API AssumeRoleWithWebIdentity, and get back temporary role credentials! In order for this to work properly, there is some setup required to create an OIDC provider, and update an IAM role's trust policy so that the Kubernetes service account for a particular cluster is permitted to assume the role.

Some of the advantages to this approach are that any pod (including host pods) can assume a role, there is not a reliance on Kubernetes annotations for security, there are not any extra processes that need to be run on nodes, and you will be able to have nodes without any IAM permissions of their own.

In the coming months we will be building out functionality in EKS to create and manage OIDC providers for EKS clusters, as well as configuring IAM roles that can be used in an EKS cluster. We will also be adding support for this authentication mechanism in the AWS SDKs.

Totally open for comments, questions or suggestions on this -- let us know in the comments!

Micah Hausler (@micahhausler), System Development Engineer on EKS

pauncejones avatar Dec 05 '18 23:12 pauncejones

~Exciting to see this get so much attention. Here is an implementation that was brought up in sig-aws back in July of this year, those of you interested if you want to provide feedback it will help to guide the implementation. https://github.com/kubernetes/community/pull/2329~

We'll publish more about our approach soon.

:+1:

christopherhein avatar Dec 13 '18 22:12 christopherhein

Ahh, I was looking for that.

Will that KEP eventually me moved to https://github.com/kubernetes/enhancements ? It looks like https://github.com/kubernetes/community/pull/2329 was closed due to KEPs being moved out to k/enhancements. Seems to have halted discussion and consideration.

gtaylor avatar Dec 13 '18 22:12 gtaylor

@gtaylor that was actually incorrect. Sorry about that. That was another implementation from the community. We'll have more details about our implementation coming out soon. Sorry for the confusion.

christopherhein avatar Dec 13 '18 23:12 christopherhein

Big fan of this - our organization can't adopt EKS until this is resolved.

cpaika avatar Dec 20 '18 15:12 cpaika

Same here, glad this is shared upfront.

sbkg0002 avatar Dec 23 '18 08:12 sbkg0002

https://github.com/jtblin/kube2iam

007 avatar Dec 23 '18 17:12 007

@007 kube2iam can not handle rapid pod churn and lacks some controls for selectively limiting metadata server exposure. It is not a complete, final solution to this problem.

Source: have used kube2iam in production at a large scale.

gtaylor avatar Dec 23 '18 17:12 gtaylor

@gtaylor : did you try kiam too? Did you find a workaround for the rapid pod churn issues?

I'm in the process of implementing some very spiky workloads and I'm trying to prepare the best I can.

Vlaaaaaaad avatar Dec 23 '18 17:12 Vlaaaaaaad

I think we are going to stick it out for the "final" solution (the one this issue is tracking).

We had looked at kiam but aren't hurting badly enough to the point of having to make such a large change (for us). That might change, though. Kiam is probably where we'll go if we end up in a spot where kube2iam becomes untenable.

gtaylor avatar Dec 23 '18 18:12 gtaylor

my EKS friends, any rough ETA on this one?

oulydna avatar Jan 09 '19 00:01 oulydna

@realAndyLuo "Working On It" https://github.com/aws/containers-roadmap/projects/1 :)

micahhausler avatar Jan 09 '19 00:01 micahhausler

thanks @micahhausler . Does "Working On it" come with any target date? or too much a spoiler to ask for

oulydna avatar Jan 09 '19 00:01 oulydna

@realAndyLuo: Never. As a former Amazonian, I can tell you that it'll be ready when it's ready. "Working on it" is as close as you'll ever get to a time commitment.

Cheers. 👍

skyzyx avatar Jan 09 '19 01:01 skyzyx

I have been working on a replacement for kube2iam/kiam in the form of https://github.com/mikkeloscar/kube-aws-iam-controller. Currently it has only focused on robustness and doesn't have features to restrict what roles you can request within a cluster (there are open issues for that). It also only works with some of the AWS SDKs but eliminates all the race conditions which are inherit in the design of kube2iam and kiam.

Maybe it's interesting for some of you.

mikkeloscar avatar Jan 09 '19 06:01 mikkeloscar

Updated description by @micahhausler

cc @gtaylor @cpaika @sbkg0002 @realAndyLuo @007 @mikkeloscar

christopherhein avatar Jan 10 '19 20:01 christopherhein

The new proposal looks interesting. Quick question though, how would I get/distribute the tokens? Would each token map to one role in IAM?

cullenmcdermott avatar Jan 11 '19 17:01 cullenmcdermott

By combining these two features, an application running in a pod can pass the projected service account token along with a role ARN to the STS API AssumeRoleWithWebIdentity, and get back temporary role credentials! In order for this to work properly, there is some setup required to create an OIDC provider, and update an IAM role's trust policy so that the Kubernetes service account for a particular cluster is permitted to assume the role.

Does this mean that applications have to actively implement this, or would the AWS SDK automatically do it? What I wanted to avoid with https://github.com/mikkeloscar/kube-aws-iam-controller is that applications needs to implement a custom SDK setup for running on Kubernetes. It should just work out of the box whether you run the application on bare EC2 or on Kubernetes or any other AWS like environment IMO. If this is not the case, then there will be a long tail of open source applications which needs to be updated to support this.

mikkeloscar avatar Jan 11 '19 17:01 mikkeloscar

@cullenmcdermott

The new proposal looks interesting. Quick question though, how would I get/distribute the tokens? Would each token map to one role in IAM?

Projected service account tokens are issued via the API server, and mounted via the kubelet. You can add a projected token today on newer versions of Kubernetes by using the projected volume type.

kind: Pod
apiVersion: v1
metadata: 
  name: pod-name
  namespace: default
spec:
  serviceAccountName: default
  containers: 
  - name: container-name
    image: container-image:version
    volumeMounts:
    - mountPath: "/var/run/secrets/something/serviceaccount/"
      name: projected-token
  volumes:
  - name: projected-token
    projected:
      sources:
      - serviceAccountToken:
          audience: "client-id"
          expirationSeconds: 86400
          path: token 

The thinking right now is you would add an annotation to either the ServiceAccount or the Pod (not totally decided yet) with the IAM role ARN, and the token volume, volumeMount, and required env AWS environment variables (variable names TBD, but the SDKs will need a role ARN and token path) would get added via a mutating webhook.

On a high level the user workflow would look like this:

  • Create an EKS cluster, OIDC identity provider gets created in IAM for the cluster automatically
  • User whitelists a specific ServiceAccount namespace/name for a specific cluster to assume the preexisting IAM role, which updates the role's trust policy (similar to this, but we'll make it easier than editing the JSON yourself)
  • User annotates ServiceAccount with the IAM role ARN
  • All pods using that service account get the projected volume and environment variables added by the webhook
  • Updated AWS SDKs running inside the pod know to look for env vars specifying the role and OIDC token path.

@mikkeloscar

Does this mean that applications have to actively implement this, or would the AWS SDK automatically do it?

It would be automatic with new versions of the SDK.

micahhausler avatar Jan 11 '19 17:01 micahhausler

This sounds cool, we'll definitely be looking to adopt (I say that as one of the creators of https://github.com/uswitch/kiam) 😀 Glad to see this in the roadmap.

Given the SDK update requirement we'd probably have to run side-by-side for a while as all our teams update their apps and libs etc but sounds like that's doable too so all good to me. Thanks to the team there for thinking on it and not just taking the first suggestion!

pingles avatar Jan 11 '19 21:01 pingles

Would it be possible without upgrading all AWS SDK? It would be nice that if this component of the SDKs, at least for Java, be a seperate component until we can upgrade?

mustafaakin avatar Jan 22 '19 13:01 mustafaakin