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.dry(反义词)__________________  2.writ...
复活节英文怎么说 复活节英文怎么说?复活节的英语翻译是什么?复活节:Easter;"Easter,anniversar...
2008年北京奥运会主题曲 2008年北京奥运会(第29届夏季奥林匹克运动会),2008年8月8日到2008年8月24日在中华人...
英语道歉信 英语道歉信15篇  在日常生活中,道歉信的使用频率越来越高,通过道歉信,我们可以更好地解释事情发生的...
六年级英语专题训练(连词成句... 六年级英语专题训练(连词成句30题)  1. have,playhouse,many,I,toy,i...
上班迟到情况说明英语   每个人都或多或少的迟到过那么几次,因为各种原因,可能生病,可能因为交通堵车,可能是因为天气冷,有...
小学英语教学论文 小学英语教学论文范文  引导语:英语教育一直都是每个家长所器重的,那么有关小学英语教学论文要怎么写呢...
英语口语学习必看的方法技巧 英语口语学习必看的方法技巧如何才能说流利的英语? 说外语时,我们主要应做到四件事:理解、回答、提问、...
四级英语作文选:Birth ... 四级英语作文范文选:Birth controlSince the Chinese Governmen...
金融专业英语面试自我介绍 金融专业英语面试自我介绍3篇  金融专业的学生面试时,面试官要求用英语做自我介绍该怎么说。下面是小编...
我的李老师走了四年级英语日记... 我的李老师走了四年级英语日记带翻译  我上了五个学期的小学却换了六任老师,李老师是带我们班最长的语文...
小学三年级英语日记带翻译捡玉... 小学三年级英语日记带翻译捡玉米  今天,我和妈妈去外婆家,外婆家有刚剥的`玉米棒上带有玉米籽,好大的...
七年级英语优秀教学设计 七年级英语优秀教学设计  作为一位兢兢业业的人民教师,常常要写一份优秀的教学设计,教学设计是把教学原...
我的英语老师作文 我的英语老师作文(通用21篇)  在日常生活或是工作学习中,大家都有写作文的经历,对作文很是熟悉吧,...
英语老师教学经验总结 英语老师教学经验总结(通用19篇)  总结是指社会团体、企业单位和个人对某一阶段的学习、工作或其完成...
初一英语暑假作业答案 初一英语暑假作业答案  英语练习一(基础训练)第一题1.D2.H3.E4.F5.I6.A7.J8.C...
大学生的英语演讲稿 大学生的英语演讲稿范文(精选10篇)  使用正确的写作思路书写演讲稿会更加事半功倍。在现实社会中,越...
VOA美国之音英语学习网址 VOA美国之音英语学习推荐网址 美国之音网站已经成为语言学习最重要的资源站点,在互联网上还有若干网站...
商务英语期末试卷 Part I Term Translation (20%)Section A: Translate ...