Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aws::S3::Encryption::Client can't put_object without having the access keys in ENV #801

Closed
apurvis opened this issue Apr 30, 2015 · 0 comments

Comments

@apurvis
Copy link

apurvis commented Apr 30, 2015

This is kind of not so awesome; we need to be able to manage multiple credentials/connections sometimes.

key = OpenSSL::PKey::RSA.new(1024)

region = 'us-east-1'

s3_client_options = {
  region: region,
  credentials: Aws::Credentials.new(valid_key, valid_s_key)
}

# Have to set this because of other bug
# https://github.com/aws/aws-sdk-ruby/issues/800
ENV['AWS_DEFAULT_REGION'] = region

@s3_client = Aws::S3::Encryption::Client.new(s3_client_options.merge(encryption_key: key))
f = File.new('/var/log/file.csv')
@s3_client.put_object(bucket: 'bucket', key: 'some/path/to/test/encryption', body: f)
Aws::Errors::MissingCredentialsError: unable to sign request without credentials set
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/request_signer.rb:94:in `require_credentials'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/s3_request_signer.rb:26:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/xml/error_handler.rb:8:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/s3_request_signer.rb:124:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/s3_redirects.rb:15:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/retry_errors.rb:88:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/s3_md5s.rb:33:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/s3_expect_100_continue.rb:21:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/s3_bucket_dns.rb:31:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/rest_body_handler.rb:9:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/user_agent.rb:12:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/seahorse/client/plugins/restful_bindings.rb:13:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/seahorse/client/plugins/endpoint.rb:35:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-resources-2.0.41/lib/aws-sdk-resources/services/s3/encryption/encrypt_handler.rb:19:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/seahorse/client/plugins/param_validation.rb:22:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/seahorse/client/plugins/raise_response_errors.rb:14:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/s3_sse_cpk.rb:18:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/seahorse/client/plugins/param_conversion.rb:22:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/seahorse/client/plugins/response_target.rb:18:in `call'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.41/lib/seahorse/client/request.rb:70:in `send_request'
    from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/aws-sdk-resources-2.0.41/lib/aws-sdk-resources/services/s3/encryption/client.rb:217:in `put_object'
    from (irb):17
    from /opt/rbenv/versions/2.1.5/bin/irb:11:in `<main>'irb(main):018:0> 

But if we try again after setting keys in the ENV

ENV['AWS_ACCESS_KEY_ID'] = valid_key
ENV['AWS_SECRET_ACCESS_KEY'] = valid_s_key
@s3_client = Aws::S3::Encryption::Client.new(s3_client_options.merge(encryption_key: key))
irb(main):022:0* @s3_client.put_object(bucket: 'bucket', key: 'some/path/to/test/encryption', body: f)
=> #<Aws::PageableResponse:0x007ff40134ba28 @pager=#<Aws::Paging::NullPager:0x007ff40134ba50>, @context=#<Seahorse::Client::RequestContext:0x007ff4012c2728 @operation_name="put_object", @o
trevorrowe added a commit that referenced this issue May 1, 2015
The @option tag for the `:client` option contained a typo
preventing it from rendering in the API reference documentation.
The current usage is:

    s3 = Aws::S3::Client.new(region:'...', credentials: ...)
    s3 = Aws::S3::Encryption::Client(client: s3)

See #800
See #801
@srchase srchase added the bug label Dec 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants