aws eks 使用keycloak集成eks oidc访问apiserver
创始人
2024-03-07 19:51:39
0

资料

  • OpenID Connect Tokens

  • Kubernetes 与 OpenID 集成 SSO 登录测试

  • Introducing OIDC identity provider authentication for Amazon EKS

  • Understanding Amazon Cognito user pool OAuth 2.0 grants

  • 在 Kubernetes 中使用 Keycloak OIDC Provider 对用户进行身份验证

  • 深入浅出的谈谈Amazon EKS的身份认证处理

  • https://github.com/int128/kubelogin

eks 的三种认证方式

  • Service account tokens
  • Webhook token authentication
  • OpenID connect tokens

除开集成了AWS IAM的webhook身份认证,EKS还提供了另外一种集成OIDC协议身份池的身份认证。需要注意的是前面一节介绍的webhook认证方式是默认开启的,即使使用OIDC的认证方式,webhook的认证也会持续可用

这种OIDC身份认证方式是开源k8s原生的,与AWS IAM完全无关。让k8s集群将用户池管理完全托管给外部的OIDC兼容的身份池,当k8s需要给来自于外部身份池的user授予权限时,可以直接使用rolebinding的方式,将k8s内部的role权限授予这个外部的user

官方博客提供了两种实现

  • 使用cognito创建用户池
  • 自建oidc ipp(例如keycloak)

使用cognito创建用户池

整体的逻辑如下

  • 创建oidc idp,将用户加入
  • 配置kubectl工具完成访问

cognito本身是aws支持的服务,集成度较高

CLIENT_ID=702vqsrjicklgb7c5b7b50i1gc
ISSUER_URL=https://cognito-idp.us-west-2.amazonaws.com/us-west-2_re1u6bpRA
POOL_ID=us-west-2_re1u6bpRAaws cognito-idp admin-create-user --user-pool-id $POOL_ID --username test@example.com --temporary-password passwordaws cognito-idp admin-set-user-password --user-pool-id $POOL_ID --username test@example.com --password Blah123$ --permanentaws cognito-idp create-group --group-name secret-reader --user-pool-id $POOL_ID aws cognito-idp admin-add-user-to-group --user-pool-id $POOL_ID --username test@example.com --group-name secret-readeraws cognito-idp admin-initiate-auth --auth-flow ADMIN_USER_PASSWORD_AUTH \--client-id $CLIENT_ID \--auth-parameters USERNAME=test@example.com,PASSWORD=Blah123$ \--user-pool-id $POOL_ID \--query 'AuthenticationResult.IdToken' output:
{"sub": "86f7130a-5605-4c05-b402-c970b27633ce","aud": "702vqsrjicklgb7c5b7b50i1gc","cognito:groups": ["secret-reader"],"event_id": "aa0723aa-12f3-49f1-9a21-7a7d542129bd","token_use": "id","auth_time": 1612760751,"iss": "https://cognito-idp.us-west-2.amazonaws.com/us-west-2_re1u6bpRA","cognito:username": "86f7130a-5605-4c05-b402-c970b27633ce","exp": 1612764351,"iat": 1612760751,"email": "test@example.com"
}kubectl config set-credentials cognito-user \--auth-provider=oidc \--auth-provider-arg=idp-issuer-url=$ISSUER_URL \ --auth-provider-arg=client-id=$CLIENT_ID \--auth-provider-arg=refresh-token= \--auth-provider-arg=id-token=

自建keycloak认证访问eks

关于keycloak配置sso访问aws可以参考之前的blog

官方博客给出的方案也使用了keycloak,和saml的配置类似,需要拿到issue url和client id
在这里插入图片描述

{"issuer": "https://xxxxxxxx:8443/realms/myoidc","authorization_endpoint": "https://xxxxxxxx:8443/realms/myoidc/protocol/openid-connect/auth","token_endpoint": "https://xxxxxxxx:8443/realms/myoidc/protocol/openid-connect/token","introspection_endpoint": "https://xxxxxxxx:8443/realms/myoidc/protocol/openid-connect/token/introspect","userinfo_endpoint": "https://xxxxxxxx:8443/realms/myoidc/protocol/openid-connect/userinfo","end_session_endpoint": "https://xxxxxxxx:8443/realms/myoidc/protocol/openid-connect/logout","frontchannel_logout_session_supported": true,"frontchannel_logout_supported": true,"jwks_uri": "https://xxxxxxxx:8443/realms/myoidc/protocol/openid-connect/certs","check_session_iframe": "https://xxxxxxxx:8443/realms/myoidc/protocol/openid-connect/login-status-iframe.html","grant_types_supported": ["authorization_code","implicit","refresh_token","password","client_credentials","urn:ietf:params:oauth:grant-type:device_code","urn:openid:params:grant-type:ciba"],
}

但是执行以下命令关联会报错,查看issueUrl参数,必须使用域名,测试环境没有公开域名,无法继续以后再尝试吧

The URL of the OpenID identity provider that allows the API server to discover public signing keys for verifying tokens. The URL must begin with https:// and should correspond to the iss claim in the provider’s OIDC ID tokens. Per the OIDC standard, path components are allowed but query parameters are not. Typically the URL consists of only a hostname, like https://server.example.org or https://example.com . This URL should point to the level below .well-known/openid-configuration and must be publicly accessible over the internet.

aws eks associate-identity-provider-config \--cluster-name worklearn \--oidc identityProviderConfigName=awsoidc,issuerUrl=https://xxx:8443/realms/myoidc,clientId=awsoidc,groupsClaim=group,groupsPrefix=gid: \--no-verify-ssl \--region cn-north-1

创建完之后控制台结果

在这里插入图片描述
之后可以直接获取token访问apiserver,或者通过kubelogin等插件配置kubectl工具实现认证

curl -k --location --request POST 'https:///auth/realms//protocol/openid-connect/token' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'username=testuser' \--data-urlencode 'password=' \--data-urlencode 'grant_type=password' \--data-urlencode 'client_secret=' \--data-urlencode 'scope=profile openid' \--data-urlencode 'client_id=' | jq '.id_token' -r

相关内容

热门资讯

宫崎骏《起风了》的经典台词 宫崎骏《起风了》的经典台词  1、起风了,唯有努力生存。  2、再没有什么比幸福的回忆更妨碍幸福的了...
公司成立周年庆典主持词 公司成立周年庆典主持词  主持词可以采用和历史文化有关的表述方法去写作以提升活动的文化内涵。在各种集...
辩论赛主持词 关于辩论赛主持词4篇  契合现场环境的主持词能给集会带来双倍的效果。在当下的中国社会,各种集会中主持...
同学三十周年聚会主持词 同学三十周年聚会主持词尊敬的各位老师、亲爱的同学们:  大家好!  风霜雪雨三十载,师生情谊天长地久...
六一儿童节活动主持稿 有关六一儿童节活动主持稿(通用7篇)  随着社会一步步向前发展,越来越多地方需要用到主持稿,主持稿的...
春到福来春晚主持词 春到福来春晚主持词  节目:《春到福来》  朱军:春到福来,春上春伦云天外  周涛:春到福来,春向黄...
平安夜晚会主持词 平安夜晚会主持词  主持词是主持人在节目进行过程中用于串联节目的串联词。在一步步向前发展的社会中,司...
农村简单结婚典礼主持词 农村简单结婚典礼主持词  一、结婚典礼的内容简介  在世界各国大部分的文化里,会发展出一些结婚上的传...
大话西游最经典的台词 大话西游最经典的台词  大话西游是周星驰主演的一部经典的喜剧爱情片。里面的台词曾感染了无数观众。以下...
公司会议主持词 关于公司会议主持词(通用5篇)  主持词要把握好吸引观众、导入主题、创设情境等环节以吸引观众。在如今...
生日派对会的主持串词 关于生日派对会的主持串词  作者:赵可心  题目:我非常高兴  要求:用普通话  环节:  1、 开...
少先队员宣誓主持词 少先队员宣誓主持词(精选8篇)  主持词已成为各种演出活动和集会中不可或缺的一部分。我们眼下的社会,...
圣诞节活动主持词 圣诞节活动主持词(精选14篇)  主持人在台上表演的灵魂就表现在主持词中。在当今中国社会,主持词在各...
葬礼主持词 葬礼主持词(精选8篇)  主持词可以采用和历史文化有关的表述方法去写作以提升活动的文化内涵。在一步步...
主持词 主持词范文(精选21篇)  主持词需要富有情感,充满热情,才能有效地吸引到观众。在如今这个时代,活动...
六一儿童节颁奖主持词 六一儿童节颁奖主持词范文(通用5篇)  主持词分为会议主持词、晚会主持词、活动主持词、婚庆主持词等。...
业主在开工典礼的致辞 业主在开工典礼的致辞范文(精选12篇)  无论在学习、工作或是生活中,大家肯定对各类致辞都很熟悉吧,...
六一儿童节主持词 六一儿童节主持词(精选15篇)  契合现场环境的主持词能给集会带来双倍的效果。在当下的社会中,很多晚...
圣诞节主持词开场白   圣诞节(Christmas)又称耶诞节,译名为“基督弥撒”,西方传统节日,在每年12月25日。下...
黑龙江年度经济风云人物颁奖典... 黑龙江年度经济风云人物颁奖典礼的主持词  (灯光,音乐)  甲:各位领导  乙:各位来宾  丙:现场...