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

Reinstate assume-role functionality (-R) #302

Merged
merged 3 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins

## [Unreleased]

## [12.3.0] - 2018-09-25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general the versioning and dating are left to the maintainers for several reasons:

  • we may disagree on the impact of the change and therefore how its versioned (there is already a 12.4.0 released)
  • we date the release rather then when the contribution was submitted, PR review and acceptance has no SLA and is not guaranteed to be merged within the same day
  • PRs are not a FIFO queue, as such versioning them prior to acceptance leads to needing to ask people to rebase more often

### Changed
- check-instance-events.rb: re-instate assume-role functionality (@pmiles)

## [12.4.0] - 2018-10-03
### Changed
- check-rds.rb: Updated list of RDS instance types and their respective memory allowance (@swibowo)
Expand Down
22 changes: 22 additions & 0 deletions bin/check-instance-events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class CheckInstanceEvents < Sensu::Plugin::Check::CLI
description: "Includes any offending instance's 'Name' tag in the check output",
default: false

option :role,
short: '-R ASSUME_ROLE',
long: '--assume-role-arn ARN',
description: 'IAM Role to assume'

def aws_config
{ access_key_id: config[:aws_access_key],
secret_access_key: config[:aws_secret_access_key],
Expand All @@ -77,6 +82,23 @@ def ec2_regions
Aws.partition('aws').regions.map(&:name)
end

def assume_role
role_config = aws_config

# Delete keys so we can use an IAM role
role_config.delete(:access_key_id)
role_config.delete(:secret_access_key)

Aws.config[:region]=role_config[:region]

role_credentials = Aws::AssumeRoleCredentials.new(
role_arn: config[:role],
role_session_name: "sensu-monitoring"
)

role_config.merge!(credentials: role_credentials)
end

def run
event_instances = []
aws_config = {}
Expand Down