Start a Conversation

Unsolved

H

1 Rookie

 • 

2 Posts

48

March 6th, 2024 16:05

How can I use URI for lifecycle

Hello there, I am trying to achieve creating lifecycle policies using URI but stuck calculating signature in ansible.

Here what I have done so far but failing with code 403

ansible code I used to generate signature

 - name: Calculate AWS authorization header signature
    shell: |
      # Define request parameters (replace with your actual values)
      method="GET"
      service="s3"
      region="us-east-1"
      endpoint="http://{{ NameSpace }}.{{ ECS_host }}"
      resource="/{{ BucketName }}?versioning"
      access_key="{{ accesskey }}"
      secret_key="{{ secretkey }}"

      # Construct canonical URI
      canonical_uri="http://{{ ECS_host }}/{{ BucketName }}?versioning"

      # Build string to sign
      timestamp=$(date -u +"%Y%m%d")
      credential_scope="$timestamp/{{ region }}/s3/aws4_request"
      string_to_sign="AWS4-HMAC-SHA256\n$timestamp\n$credential_scope\n$(openssl dgst -sha256 -hex <<< $(echo -n "$method\n\n\n\nhost:$endpoint\n\nx-amz-date:$timestamp\n"))"

      # Calculate signature
      signature=$(echo -n "$string_to_sign" | openssl dgst -sha256 -hmac key:/home/support/ecs-ansible/uri/creds_key -binary | openssl base64)

      # Build authorization header
      authorization="AWS4-HMAC-SHA256 Credential=$access_key/$(echo $credential_scope | cut -d '/' -f1,2,3)/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=$signature"

      echo "$authorization"

I been struggling with for last 15 days, any help will be greatly appreciated.

No Responses!
No Events found!

Top