Skip to content

Logstash S3 input plugin assume role not working #213

@christiangda

Description

@christiangda

Hi,

I'm trying to use the assume role functionality with logstash S3 input plugin but I get the following error:

NOTE: Looks like the plugin is not assuming the role, I can't see any trace about assume a role

[2020-07-20T07:18:46,508][ERROR][logstash.inputs.s3       ][main][790d495ae7a1e587d317915855ea5c21d64f412fed2b6c1bb7abb425f681f82f] 
Unable to list objects in bucket {:exception=>Aws::S3::Errors::AccessDenied, :message=>"Access Denied", 
:backtrace=>["/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/seahorse/client/plugins/raise_response_errors.rb:15:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/aws-sdk-core/plugins/s3_sse_cpk.rb:19:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/aws-sdk-core/plugins/s3_dualstack.rb:24:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/aws-sdk-core/plugins/s3_accelerate.rb:34:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/aws-sdk-core/plugins/idempotency_token.rb:18:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/aws-sdk-core/plugins/param_converter.rb:20:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/aws-sdk-core/plugins/response_paging.rb:26:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/seahorse/client/plugins/response_target.rb:21:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/seahorse/client/request.rb:70:in 
`send_request'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-core-2.11.501/lib/seahorse/client/base.rb:207:in 
`block in define_operation_methods'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-resources-2.11.501/lib/aws-sdk-resources/request.rb:24:in 
`call'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-resources-2.11.501/lib/aws-sdk-resources/operations.rb:139:in 
`all_batches'", "org/jruby/RubyEnumerator.java:396:in 
`each'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/aws-sdk-resources-2.11.501/lib/aws-sdk-resources/collection.rb:18:in 
`each'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-s3-3.5.0/lib/logstash/inputs/s3.rb:132:in 
`list_new_files'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-s3-3.5.0/lib/logstash/inputs/s3.rb:172:in 
`process_files'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-s3-3.5.0/lib/logstash/inputs/s3.rb:123:in 
`block in run'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/stud-0.0.23/lib/stud/interval.rb:20:in 
`interval'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-s3-3.5.0/lib/logstash/inputs/s3.rb:122:in 
`run'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:345:in `inputworker'", 
"/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:336:in `block in start_input'"], :prefix=>nil}

I have two AWS account, the first one only contains AWS IAM credentials and users, the second one has the S3 buckets.

Account A

Here I have an IAM programmatic user which inside a Group with a policy to assume a role to account b

access_key_id
secret_access_key

Policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AssumeRoleProd",
      "Effect": "Allow",
      "Action": "sts:AssumeRole",
      "Resource": [
        "arn:aws:I am::<my accounted removed, account b id>:role/<removed role name>"
      ]
    }
  ]
}

Account b

Here I have one bucket with data logs and a role to be assumed with access to this bucket

S3://mybucket

Role:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "VisualEditor0",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::mybucket/*",
        "arn:aws:s3:::mybucket"
      ]
    }
  ]
}

As I mentioned before, looks like the plugins in not assuming the role.

NOTE: If I create credentials directly into the account b, the pluging work fine, what I mean, this works when do not need to assume a role, with a conf like:

          input {
            s3 {
              access_key_id => "account b credentials"
              secret_access_key =>"account b credentials"
              #role_arn => "arn:aws:I am::<my accounted removed>:role/<removed role name>" 
              #role_session_name => "logstash_from_<removed information here>"
              bucket => "aleaplay.events.dynamo.i.player"
              #prefix => "2020/07/17/16" # not necessary, without it read all
              region => "eu-west-1"
              interval => 60
              gzip_pattern => "\.gz(ip)?$"
              additional_settings => {
                force_path_style => true
                follow_redirects => false
              }
            }
          }

Please let me know if I'm doing something wrong with this plugin, or if I have left some configuration off.

Environment information

  • Version:
# inside the container
bash-4.2$ logstash --version
logstash 7.8.0

bash-4.2$ logstash-plugin list --verbose --installed
# inside the container
...
logstash-input-s3 (3.5.0)
...
  • Operating System:
    • CentOS 8 (podman container, docker.elastic.co/logstash/logstash-oss:7.8.0)
# inside the container
bash-4.2$ cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
  • Config File (if you have sensitive info, please remove it):
bash-4.2$ cat config/logstash.yml
---
node.name: logstash-01
http.host: 0.0.0.0
path.config: "/usr/share/logstash/pipeline"
path.logs: "/usr/share/logstash/logs"

log.level: debug
bash-4.2$ cat pipeline/logstash.conf
# Ansible managed
input {
  s3 {
    access_key_id => "removed"
    secret_access_key => "removed"
    role_arn => "arn:aws:I am::<my accounted removed>:role/<removed role name>"
    role_session_name => "logstash_from_<removed information here>"
    bucket => "<removed information here>"
    #prefix => "2020/07/17/16" # not necessary, without it read all
    region => "eu-west-1"
    interval => 60
    gzip_pattern => "\.gz(ip)?$"
    additional_settings => {
      force_path_style => true
      follow_redirects => false
    }
  }
}

output {
  elasticsearch {
    ilm_enabled => false
    hosts => ["https://<removed information here>:9200"]
    index => "<removed information here>-%{+YYYY.MM.dd}"
    user => "<removed information here>"
    password => "<removed information here>"
    ssl => true
    ssl_certificate_verification => false
    cacert => "/usr/share/logstash/config/root-ca.pem"
  }
}
  • Sample Data:
    NA
  • Steps to Reproduce:
podman run -d \
    --name=logstash-01 \
    --net=odfe \
    --hostname=logstash-01 \
    --privileged \
    --ulimit=host \
    --security-opt label=disable \
    --volume {{ logstash_host_volume_conf_path }}:/usr/share/logstash/config:ro \
    --volume {{ logstash_host_volume_pipeline_path }}:/usr/share/logstash/pipeline:ro \
    --volume {{ logstash_host_volume_data_path }}:/usr/share/logstash/data:rw \
    --volume {{ logstash_host_volume_logs_path }}:/usr/share/logstash/logs:rw \
    --cpus 1 \
    --memory 1g \
    --memory-reservation 512m \
    --memory-swap 1g \
  docker.elastic.co/logstash/logstash-oss:7.8.0 bash -c "bin/logstash-plugin install logstash-input-s3 && bin/logstash"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions