Getting 403 when trying to set/update index settings with CURL

1

I have setup a collection, a role for an ECS task that grants aoss:APIAccessAll to the collection to the task, and a data access policy that grants all aoss perms to the task role, and a network access policy. I then grab a command line shell on the task container using ecs execute command, set the the appropriate IAM auth variables/tokens/secrets and then attmept to use curl to create an index.

First attempt at creating an index and setting index settings during creation. It fails with a 403 Forbidden.

bash-5.2# curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -XPUT --json '{ "settings": { "index.max_result_window" : "1000000" }}' "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2" {"status":403,"request-id":"9f9c5b03-5fb0-97d4-94ae-496f9d896ab7","error":{"reason":"403 Forbidden","type":"Forbidden"}}

Second attempt at creation w/o any settings. It succeeds with a 200.

bash-5.2# curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -XPUT "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2" {"acknowledged":true,"shards_acknowledged":true,"index":"dn_scottdnrm_sf2"}

So notice in my first attempt I try to set some index settings during creation and I get 403 forbidden . But it I try w/o setting any index setting it is successful. That does not make sense.

Then I try to user update the settings REST API after I create the index and I still get a 403.

bash-5.2# curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -XPUT --json '{ "index": { "max_result_window" : "1000000" }}' "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2/_settings" {"status":403,"request-id":"6c1f6043-c308-9e2a-b2fa-c909aa1e3f2d","error":{"reason":"403 Forbidden","type":"Forbidden"}}

I am able to query the index settings: bash-5.2# curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -XGET "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2/_settings" {"dn_scottdnrm_sf2":{"settings":{"index":{"number_of_shards":"2","number_of_replicas":"0","uuid":"mmOH5ooB5JD2sfGgAXJJ","version":{"created":"135217827"},"provided_name":"dn_scottdnrm_sf2"}}}}

Why am I getting 403 errors trying to set/update index settings?

asked 7 months ago373 views
2 Answers
1
Accepted Answer

So my problem ended being that I was not including the x-amz-content-sha256 header in my curl command. I mistakenly thought that CURL would add it when I used the --aws-sigv4 flag.

So the following ended up working:

$ PAYLOAD='{ "settings": { "index": { "max_result_window" : 1000000 }}}'

$ SHA256_PAYLOAD=$(echo -n "$PAYLOAD" | openssl dgst -sha256)

$ curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "Content-Type: application/json" -H "x-amz-content-sha256:

$SHA256_PAYLOAD" -X PUT "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2" -d "$PAYLOAD"

answered 7 months ago
0

Hello,

 

Based on information shared, you are getting AccessDenied errors when append the --json to curl command. Please check CloudTrail events for any errors with respect to "aoss" service and it will give you more details about the exact AccessDenied error and confirms whether it is actually hitting the API correctly.

[+] Cloudtrail: https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events-console.html

[+] https://docs.aws.amazon.com/opensearch-service/latest/developerguide/logging-using-cloudtrail.html

[+] https://docs.aws.amazon.com/opensearch-service/latest/ServerlessAPIReference/API_Operations.html

 

I have also searched about the curl command option to use PUT method and it must use a whitespace between -X and PUT, like "-X PUT" but where as in your execution without whitespace. Please try execute below formatted commands and refer the curl manual page for more information.

[+] https://curl.se/docs/manpage.html

[+] https://reqbin.com/req/c-d4os3720/curl-put-example

curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -X PUT  "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2"  --json '{ "settings": { "index.max_result_window" : "1000000" }}'

curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -X PUT  "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2/_settings" --json '{ "index": { "max_result_window" : "1000000" }}'

 

If above one is not working try explicitly mentioning the content type in curl command like below.

curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -X PUT  "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2"  -H "Content-Type: application/json" -d  '{ "settings": { "index.max_result_window" : "1000000" }}'

curl --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -X PUT  "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2/_settings"  -H "Content-Type: application/json" -d  '{ "index": { "max_result_window" : "1000000" }}'

 

In case, if you still encounter the issue, please share the verbose output by adding "-vvv" suffix to the above curl commands.

Thank you.

answered 7 months ago
  • Vijay, I looked in cloudtrail and found no relevant events.

    In addition I tried the other CURL suggestions and the exact same response back.

  • And here is the curl with -vvv (will have to split up)

    bash-5.2# curl -vvv --user "$aws_access_key:$aws_secret_key" --aws-sigv4 "aws:amz:us-east-1:aoss" -H "x-amz-security-token: $aws_session_token" -X PUT "$OPENSEARCH_ENDPOINT/dn_scottdnrm_sf2" --json '{ "settings": { "index.max_result_window" : "1000000" }}'

    • Trying 10.1.50.68:443...
    • Connected to REPLACED.us-east-1.aoss.amazonaws.com (10.1.50.68) port 443 (#0)
    • ALPN: offers h2,http/1.1
    • TLSv1.3 (OUT), TLS handshake, Client hello (1):
    • CAfile: /etc/pki/tls/certs/ca-bundle.crt
    • CApath: none
    • TLSv1.3 (IN), TLS handshake, Server hello (2):
    • TLSv1.2 (IN), TLS handshake, Certificate (11):
    • TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    • TLSv1.2 (IN), TLS handshake, Server finished (14):
    • TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    • TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
    • TLSv1.2 (OUT), TLS handshake, Finished (20):
    • TLSv1.2 (IN), TLS handshake, Finished (20):
    • SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
    • ALPN: server did not agree on a protocol. Uses default.
    • Server certificate:
    • subject: CN=*.us-east-1.aoss.amazonaws.com
    • start date: Dec 18 00:00:00 2022 GMT
    • expire date: Jan 16 23:59:59 2024 GMT
    • subjectAltName: host "REPLACED.us-east-1.aoss.amazonaws.com" matched cert's "*.us-east-1.aoss.amazonaws.com"
    • issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M01
    • SSL certificate verify ok.
    • using HTTP/1.x
  • next part of curl -vvv Server auth using AWS_SIGV4 with user 'REPLACED'

    PUT /dn_scottdnrm_sf2 HTTP/1.1 Host: REPLACED.us-east-1.aoss.amazonaws.com Authorization: AWS4-HMAC-SHA256 Credential=REPLACED/20231004/us-east-1/aoss/aws4_request, SignedHeaders=accept;content-type;host;x-amz-date;x-amz-security-token, Signature=REPLACED X-Amz-Date: 20231004T195111Z User-Agent: curl/8.0.1 x-amz-security-token:REPLACED Content-Type: application/json Accept: application/json Content-Length: 56

    < HTTP/1.1 403 Forbidden < x-request-id: 821f3626-7355-9f5a-989f-2e7aff86e858 < content-length: 121 < x-aoss-response-hint: X01:gw-helper-deny < content-type: application/json < date: Wed, 04 Oct 2023 19:51:11 GMT < server: aoss-amazon < {"status":403,"request-id":"821f3626-7355-9f5a-989f-2e7aff86e858","error":{"reason":"403 Forbidden","type":"Forbidden"}}

    • Connection #0 to host m28i4dfrdgi82e4ymbe6.us-east-1.aoss.amazonaws.com left intact

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions