基于terraform搭建aws eks集群(未完成)

首先说一下 aws对pod的授权过程:

1.将IAM role关联到k8s的service account上

2.将service account关联到pod上

3.pod请求openid provider,通过身份验证拿到token

4.pod带着token请求IAM的assumerolewithwebidentity接口拿到一个临时证书,获取第一步IAM role中配置的权限。

解释trust policy

cat >trust-relationship.json <<EOF

{

"Version": "2012-10-17",

"Statement": [

{

"Effect": "Allow",

"Principal": { "Federated": "arn:aws:iam::$account_id:oidc-provider/$oidc_provider" },

"Action": "sts:AssumeRoleWithWebIdentity",

"Condition": {

    "StringEquals": {

    "$oidc_provider:aud": "sts.amazonaws.com",

    "$oidc_provider:sub": "system:serviceaccount:$namespace:$service_account"

}} } ]}

EOF

sub所指对象将会向$oidc_provider申请ID token,用来访问aud所指应用

关于AssumeRoleWithWebIdentity的解释:

Permissions for AssumeRole, AssumeRoleWithSAML, and AssumeRoleWithWebIdentity - AWS Identity and Access Management (amazon.com)- 这篇文章提到,当一个账号AssumeRole时,他的原始具有哪些policy不会被评估,原始policy会被暂时弃用,role所具有的policy会被临时启用。而对于AssumeRoleWithSAML and AssumeRoleWithWebIdentity,压根就没有可以评估的policy,因为调用这两个api的对象不是一个aws的身份。这也就说明了二者区别。即AssumeRoleWithSAML and AssumeRoleWithWebIdentity适用于非aws上的身份对象,所以需要第三方认证来做一个token颁发,而AssumeRole的对象是aws上的,所以他可以直接调用。可试着从以下两个例子理解区别。



IAM roles for service accounts - Amazon EKS

Configure Service Accounts for Pods | Kubernetes

Configure a Kubernetes service account to assume an IAM role - Amazon EKS 

aws_eks_cluster | Resources | hashicorp/aws | Terraform | Terraform Registry

OIDC 与 OAuth2.0 综述 | Authing 文档

我在一个vpc内创建一个eks cluster, 然后在另一个vpc内创建一个instance并安装kubectl连接 esk cluster,报错如下。我猜是因为没有处理跨vpc连接的权限问题,后续补充。

E0618 01:41:30.279062 3417 memcache.go:265] couldn't get current server API group list: the server has asked for the client to provide credentials

error: You must be logged in to the server (the server has asked for the client to provide credentials)

vpc endpoint 与aws privateLink区别: aws private link 是由vpc endpoint和endpoint service组合实现的。

k8s pod用的是虚拟的IP地址,底层网络插件会根绝虚拟ip地址对请求做一个转发,因为多了转发这个一个步骤,如果pod之间需要频繁通讯,那么通讯效率明显低下。而在eks中,使用插件amazon-vpc-cni-k8s,给每一个pod分配vpc内的真实物理ip地址提高pod之间通信效率。

通常有两种类型的身份可以访问您的 Amazon EKS 集群,IAM principal  基于 IAM 的 EKS 权限管理详解(上) 和您自己的 OpenID Connect (OIDC) identity provider 中的用户 通过外部 OIDC 提供者向用户授予对 Kubernetes 的访问权限

EKS的access entry中可以引用的policy们的详细内容介绍access-policies

如何创建access entry creating-access-entries

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容