tblev
tblev

Reputation: 462

Production Server Uploading to Staging S3

I have an app running on a ubuntu server. I have a production mode and a staging mode.

Problem is that actions being done on the production site relative to uploading and retrieving images from an S3 bucket are being done to the same bucket as my staging. When I have my configurations set up differently.

production.rb

config.s3_bucket = 'bucket-production'
config.s3_path = 'https://bucket-production.s3.us-east-2.amazonaws.com/'

staging.rb && development.rb

config.s3_bucket = 'bucket-staging'
config.s3_path = 'https://bucket-staging.s3.us-east-2.amazonaws.com/'

storage.yml

    amazon:
      service: S3
      access_key_id:  <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
      secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
      region: us-east-2
      bucket: bucket-staging
      endpoint: http://bucket-staging.us-east-2.amazonaws.com

I'm thinking it could be something with storage.yml but I deleted this entire file and restarted the localhost server and it didn't change anything. Is storage.yml production only?

Also, my logs are logging to staging from production.

Upvotes: 0

Views: 276

Answers (1)

Ashish Bhatia
Ashish Bhatia

Reputation: 629

I would like to ask is prod server/staging server(Ubuntu) running in AWS.if yes, you must have IAM ROLE attached to the server which must be fine-grained to which env application should access which bucket of S3. Also storing access_key_id and secret access key id should not be used as best practice. IAM role can take care of that. Also, I would like to add if the server is in the private subnet you need to explore either NAT gateway or use VPC S3 Endpoint to access the bucket.

Also try printing logs of S3 connection in prod mode how it is acquiring cred to access bucket. You might be granting access using some ENV variables or IAM role. Best way to see is use

printenv

before and after of S3 connection to see the variables and which bucket access is provided.

Thanks Ashish

Upvotes: 1

Related Questions