AWSOpenSearchOpenIdConnectasAuthenticationMethod
创始人
2024-09-26 17:01:04
0

AWS OpenSearch支持OpenID Connect(OIDC)作为身份验证方法,使用户可以使用他们在OIDC提供者上拥有的凭据来访问OpenSearch集群。以下是使用OIDC进行身份验证的示例代码:

import boto3
from botocore.config import Config

config = Config(
    region_name='us-west-2'
)

sts_client = boto3.client('sts', config=config)

assumed_role_object=sts_client.assume_role(
    RoleArn="arn:aws:iam::accountId:role/testRole",
    RoleSessionName="AssumeRoleSession1"
)

credentials=assumed_role_object['Credentials']

client = boto3.client('opensearch', config=config,
    aws_access_key_id=credentials['AccessKeyId'],
    aws_secret_access_key=credentials['SecretAccessKey'],
    aws_session_token=credentials['SessionToken']
)

es_domain = "es-domain-endpoint"
oidc_client_id = "oidc-client-id"
oidc_client_secret = "oidc-client-secret"
oidc_issuer_url = "https://oidc-issuer-url.com"
oidc_username_claim = "sub"

response = client.create_elasticsearch_domain(
    DomainName=es_domain,
    ElasticsearchVersion='7.10',
    ElasticsearchClusterConfig={
        'InstanceType': 'r5.large.elasticsearch',
        'InstanceCount': 1,
        'DedicatedMasterEnabled': False,
        'ZoneAwarenessEnabled': False,
        'ZoneAwarenessConfig': {
            'AvailabilityZoneCount': 1
        }
    },
    AccessPolicies={
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Principal": {
                    "Federated": f"arn:aws:iam::{credentials['AwsAccountId']:d}:oidc-provider/{oidc_issuer_url}"
                },
                "Action": "es:*",
                "Resource": f"arn:aws:es:{config.region_name}:{credentials['AwsAccountId']:d}:domain/{es_domain}/*",
                "Condition": {
                    "StringEquals": {

相关内容

热门资讯

玩家必用!wepoker辅助透... 玩家必用!wepoker辅助透视软件(辅助挂)好像真的是有挂(今日头条辅助教程)1、玩家必用!wep...
分享一款!德普之星透视辅助插件... 分享一款!德普之星透视辅助插件(辅助挂)本来是真的有挂(详细教程辅助软件);1、上手简单,内置详细流...
9分钟了解!wepoker辅助... 9分钟了解!wepoker辅助真的假的(辅助挂)竟然有挂(有挂神器辅助攻略)暗藏猫腻,小编详细说明破...
六分钟了解!hhpoker透视... 六分钟了解!hhpoker透视脚本视频(辅助挂)竟然存在有挂(有挂透明挂辅助技巧)1)有没有挂:进一...
科技新动态!wepoker有插... 科技新动态!wepoker有插件吗(辅助挂)果然真的是有挂(有挂猫腻辅助插件)1、完成辅助器v3.3...
每日必看教程!aapoker辅... 每日必看教程!aapoker辅助工具安全吗(辅助挂)本来真的是有挂(有挂秘诀辅助工具)1、透视辅助软...
揭秘!xpoker辅助器(辅助... 揭秘!xpoker辅助器(辅助挂)都是是真的有挂(有挂分享辅助脚本)运辅助工具,进入游戏界面。进入辅...
实测交流!德普之星辅助软件(辅... 实测交流!德普之星辅助软件(辅助挂)本来是真的有挂(详细教程辅助教程)1、许多玩家不知道辅助怎么退出...
重大消息!wpk软件是正规的吗... 重大消息!wpk软件是正规的吗(辅助挂)果然是真的有挂(有挂技巧辅助教程)1、这是跨平台的轻量版有透...
科技新动态!pokemmo脚本... 科技新动态!pokemmo脚本辅助器下载(辅助挂)一直是真的有挂(有挂总结辅助方法)1、点击下载安装...