Issues setting up s3 bucket for snapshot repository using IAM Role

I’m trying to setup an s3 bucket snapshot repository, using IAM roles to allow access to the bucket. I am unable to get the repository setup to complete, it gives this error:

        "reason" : "sdk_client_exception: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), WebIdentityTokenCredentialsProvider: You must specify a value for roleArn and roleSessionName, com.amazonaws.auth.profile.ProfileCredentialsProvider@6669063f: access denied (\"java.io.FilePermission\" \"/usr/share/opensearch/.aws/credentials\" \"read\"), com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@2ab72ee2: Failed to connect to service endpoint: ]"

I have added the Role ARN and Role Session Name in multiple ways, environment variables, in the opensearch keystore, defining the role in the request to create the repository, etc.

No matter how I define the role information, I keep getting the same error, and the repository setup will not complete.

Any ideas what I might be missing to get this to work? The opensearch cluster is running on AWS ECS.

@tfmm could you please share a) what OpenSearch version you are running b) what settings you are using to configure IAM? Thank you.

Opensearch 2.2.0, built off the official docker image, just with our certificates and such added.

As far as IAM Settings, the role has complete control over the bucket, and I have confirmed that awscli commands to upload / otherwise interact with the bucket work from the container. I’ll include the full policy below.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:PutAnalyticsConfiguration",
                "s3:GetObjectVersionTagging",
                "s3:ReplicateObject",
                "s3:GetObjectAcl",
                "s3:PutLifecycleConfiguration",
                "s3:GetObjectVersionAcl",
                "s3:PutObjectTagging",
                "s3:HeadBucket",
                "s3:DeleteObject",
                "s3:DeleteObjectTagging",
                "s3:GetBucketPolicyStatus",
                "s3:GetBucketWebsite",
                "s3:DeleteObjectVersionTagging",
                "s3:GetBucketNotification",
                "s3:GetReplicationConfiguration",
                "s3:ListMultipartUploadParts",
                "s3:PutObject",
                "s3:GetObject",
                "s3:GetAnalyticsConfiguration",
                "s3:GetObjectVersionForReplication",
                "s3:GetLifecycleConfiguration",
                "s3:ListBucketByTags",
                "s3:GetInventoryConfiguration",
                "s3:GetBucketTagging",
                "s3:PutAccelerateConfiguration",
                "s3:DeleteObjectVersion",
                "s3:GetBucketLogging",
                "s3:ListBucketVersions",
                "s3:ReplicateTags",
                "s3:RestoreObject",
                "s3:ListBucket",
                "s3:GetAccelerateConfiguration",
                "s3:GetBucketPolicy",
                "s3:GetEncryptionConfiguration",
                "s3:GetObjectVersionTorrent",
                "s3:AbortMultipartUpload",
                "s3:GetBucketRequestPayment",
                "s3:GetObjectTagging",
                "s3:GetMetricsConfiguration",
                "s3:GetBucketPublicAccessBlock",
                "s3:ListBucketMultipartUploads",
                "s3:PutObjectVersionTagging",
                "s3:GetBucketVersioning",
                "s3:GetBucketAcl",
                "s3:GetObjectTorrent",
                "s3:GetAccountPublicAccessBlock",
                "s3:ListAllMyBuckets",
                "s3:GetBucketCORS",
                "s3:GetBucketLocation",
                "s3:ReplicateDelete",
                "s3:GetObjectVersion"
            ],
            "Effect": "Allow",
            "Resource": [
                "ARN_OF_BUCKET/*",
                "ARN_OF_BUCKET"
            ]
        },
        {
            "Effect": "Allow",
      "Action": [
        "s3:ListAllMyBuckets"
      ],

            "Resource": [
		"*"
	    ]
        }
    ]
}

I just realized you may be asking for what opensearch settings I’m using to configure IAM. I have tried multiple:

Keystore entries:

s3.client.default.role_arn
s3.client.default.role_session_name

Environment variables:

AWS_ROLE_SESSION_NAME
AWS_ROLE_ARN

And several combinations of these. I attempted to follow the instructions here: Take and restore snapshots - OpenSearch documentation

But am still having no luck.

Thanks @tfmm, the steps / settings are looking right, I suspect that the keystore you are configuring is not being picked by OpenSearch, could you please confirm that is / is not the case?

@reta could you give me a hand knowing how to confirm if the keystore is being picked up?

It should be in the folder pointed by OPENSEARCH_PATH_CONF, the exact location of this folder is available in logs, the server prints it on startup. Thank you.

Thanks. So the keystore is in the config path specified on startup:

[2022-09-26T15:54:46,830][INFO ][o.o.s.OpenSearchSecurityPlugin] [] OpenSearch Config path is /usr/share/opensearch/config


[opensearch@ config]$ pwd
/usr/share/opensearch/config
[opensearch@ config]$ ls -lah *.keystore
-rw-rw---- 1 opensearch opensearch 335 Sep 26 15:54 opensearch.keystore
[opensearch@ config]$ opensearch-keystore list
keystore.seed
s3.client.default.role_arn
s3.client.default.role_session_name

Thanks @tfmm, kystore is looking right, do you mind please to share the stack trace from OpenSearch logs relevant to S3 credentials issue, it would help to identify path being taken for credentials resolution, thank you.