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

Make IAM role credentials default #31

Merged
merged 2 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion doc/01-Installation-and-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ Next please download and extract the [latest v2](https://github.com/aws/aws-sdk-
the AWS PHP SDK [releases](https://github.com/aws/aws-sdk-php/releases) page.
You need to extract the AWS PHP SDK v2 to `library/vendor/aws`.

AWS IAM role credentials
------------------------

If you run Icinga Web on AWS you can use IAM roles to allow access. This is the
default and there is nothing to configure. Select IAM role and configure access
in AWS itself.

AWS key configuration
---------------------

The last required step is to provide at least one AWS access key in `keys.ini`.
If you want to use access keys you need to have at least one key in `keys.ini`.
Create a file `/etc/icingaweb2/modules/aws/keys.ini` as follows:

```ini
Expand Down
5 changes: 3 additions & 2 deletions doc/02-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ You can choose your AWS region from a dropdown:

![AWS import source region](img/03_aws_import_region.png)

It is also necessary to choose one of your AWS keys:
It is also necessary to choose your preferred access method:

![AWS import source key](img/04_aws_import_source_key.png)

In case this list is empty, please check back to the [Installation and Configuration](01-Installation-and-Configuration.md)
In case you need a key and this list is empty, please check back to the
[Installation and Configuration](01-Installation-and-Configuration.md)
section. Now you are ready to preview and/or run your first import. Don't
worry, nothing bad will happen. An Import run just imports plain data from
your import source, it won't touch any of your hosts or services in your
Expand Down
Binary file modified doc/img/02_aws_import_source_basics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/03_aws_import_region.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/04_aws_import_source_key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions library/Aws/AwsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Icinga\Module\Aws;

use Aws\Common\Aws;
use Aws\Common\Credentials\RefreshableInstanceProfileCredentials;
use Aws\Common\Exception\InstanceProfileCredentialsException;
use Icinga\Application\Config;

class AwsClient
Expand All @@ -13,7 +15,7 @@ class AwsClient

protected $region;

public function __construct(AwsKey $key, $region)
public function __construct(AwsKey $key = null, $region)
{
$this->region = $region;
$this->key = $key;
Expand Down Expand Up @@ -224,10 +226,13 @@ protected function client()
protected function initializeClient()
{
$params = array(
'region' => $this->region,
'credentials' => $this->key->getCredentials(),
'region' => $this->region
);

if ($this->key instanceof AwsKey) {
$params['credentials'] = $this->key->getCredentials();
}

$config = Config::module('aws');
if ($proxy = $config->get('network', 'proxy')) {
$params['request.options'] = array(
Expand Down
3 changes: 2 additions & 1 deletion library/Aws/AwsKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public static function listNames()
public static function enumKeyNames()
{
$names = static::listNames();
return array_combine($names, $names);
$labels = array_map(function ($name) { return $name . ' (Key)'; }, $names);
return array_combine($names, $labels);
}

protected static function config()
Expand Down
24 changes: 15 additions & 9 deletions library/Aws/ProvidedHook/Director/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ class ImportSource extends ImportSourceHook

public function fetchData()
{
$client = new AwsClient(
AwsKey::loadByName($this->getSetting('aws_access_key')),
$this->getSetting('aws_region')
);
$keyName = $this->getSetting('aws_access_key');
$key = null;

if ($keyName) {
$key = AwsKey::loadByName($keyName);
}

$client = new AwsClient($key, $this->getSetting('aws_region'));

switch ($this->getObjectType()) {
case 'asg':
Expand Down Expand Up @@ -124,13 +128,15 @@ public static function addSettingsFormFields(QuickForm $form)
));

$form->addElement('select', 'aws_access_key', array(
'label' => 'AWS access key',
'required' => true,
'label' => 'AWS access method',
'required' => false,
'description' => $form->translate(
'Your AWS key, this shows all keys from your keys.ini. Please'
. ' check the documentation in case this list is empty'
'Use IAM role credential or select your AWS key. This shows all keys from your keys.ini.'
. ' Please check the documentation if you miss the keys in the list.'
),
'multiOptions' => $form->optionalEnum(AwsKey::enumKeyNames()),
'multiOptions' => $form->optionalEnum(AwsKey::enumKeyNames(), $form->translate(
'IAM role credentials'
)),
'class' => 'autosubmit',
));

Expand Down