微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 cloudformation 从 eks 集群在 aws 中创建 OIDC 提供程序

如何解决使用 cloudformation 从 eks 集群在 aws 中创建 OIDC 提供程序

我目前正在研究一个 cloudformation 模板。该模板通常会使用集群自动缩放程序创建 EKS 集群。在此过程中,我创建了一个 lambda 函数,该函数将使用 EKS 集群 URL 自动创建 OIDC 提供程序。问题是指纹。我无法为相同的指纹创建指纹,这导致集群自动缩放器 pod 失败。有什么方法可以让我们也从 lambda 函数创建指纹?下面是 lambda 函数代码。现有的指纹是一个样本。

          import boto3
          import json
          import cfnresponse

       
          def lambda_handler(event,context):
            
            client = boto3.client('iam')
            name=  event['ResourceProperties']['cluster_name']
            responseData= {}
            responseStatus="SUCCESS"
            
            try:
              print("In thetry block")
              if event['RequestType'] == 'Delete':
                print("Request Type:",event['RequestType'])
                print("Delete Request - No Physical resources to delete")
              elif event['RequestType'] == 'Create' or event['RequestType'] == 'Update':
                print("The request type is updated")
                response2 = client.create_open_id_connect_provider(
                        ClientIDList=[
                          'my-application-id',],ThumbprintList=[
                          '3768084dfb3d2b68b7897bf5f565da8efEXAMPLE',Url=fetchClusterOIDC(name),)
                print("The OIDC Created")
                oidc_response_url = fetchClusterOIDC(name)
                oidc_response=oidc_response_url.split("https://")[1]
                
                responseData = {'oidc': oidc_response}

                print("Responsedata Created",responseData)
                print("Request Type:",event['RequestType'])
                print("Sending response to custom resource for event type " + event['RequestType'])
                cfnresponse.send(event,context,cfnresponse.SUCCESS,responseData)
            except Exception as e:
              print(e)
              responseData = {'Failed': 'Test Failed.'}
              responseStatus="Failed"
              cfnresponse.send(event,cfnresponse.Failed,responseData)  
          
          def fetchClusterOIDC(cluster_name):
            print("Getting Cluster OIDC value for cluster name "+ cluster_name)
            oidc = ''
            client = boto3.client('eks')
            try:
                response = client.describe_cluster(
                    name=cluster_name
                )
                if response['ResponseMetadata']['HTTPStatusCode'] == 200:
                    print("Success response recieved for describing cluster "+ cluster_name)
                    oidc = (response['cluster']['identity']['oidc']['issuer'])
                    print('OIDC output recieved '+ oidc + ' for Cluster Name ' + cluster_name)
                return oidc
            except Exception as e:
                print('Failed to fetch Cluster OIDC value for cluster name ' + cluster_name,e)

解决方法

我使用了 aws api 而不是 Lambda 函数。 cloudformation 脚本在输出中提供 OIDC url 和 CertificateAuthority。之后我运行 bash 脚本,该脚本自动运行并生成指纹帖子,我们可以使用 Aws API 使用生成的 url 和指纹创建 OIDC 提供程序。

要生成指纹,请点击以下链接: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html

在这里,我们可以直接解码 EKS 集群提供的 CertificateAuthority,而不是执行第 4 步。 解码命令为: echo -n 'CertificateAuthority'| base64 --decode

这将生成证书并使您的工作更轻松。

我发现这种方式比创建 lambda 函数和生成 OIDC 提供程序要容易得多。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?