Skip to content

Commit 7eead75

Browse files
committed
Add capability to use IAM instance profile credentials
Instance profiles have three pieces of data necessary for authentication: Access key, secret key, and token. This change allows the user to enter a token if necessary.
1 parent c32ee71 commit 7eead75

File tree

6 files changed

+44
-14
lines changed

6 files changed

+44
-14
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ The policy you use for AWSResco should follow the least privilege access rules.
6363
}
6464
```
6565

66+
If you are using an IAM instance profile you need to use the (access key, secret key, token) tuple to authenticate.
67+
You can retrieve the values from the EC2 metadata API. First, find the name of your instance-profile:
68+
69+
`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/`
70+
71+
Then, plug in the name at the end of the URL
72+
73+
`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/instance-profile`
74+
75+
The resulting JSON will have the necessary credentials to utilize the site.
76+
6677
## Gaps
6778
Currently AWSResco does not take into account `OfferingType`, it assumes that only `Heavy Utilization` is being used as that was the original use case for the tool. There are plans to support all `OfferingType` variations - see [Issue#3](https://github.com/ckelner/AWSResco/issues/3).
6879

@@ -74,7 +85,7 @@ Currently AWSResco does not take into account `OfferingType`, it assumes that on
7485
- Manual process to test
7586

7687
## Build
77-
- Run `sudo bash build.sh` which will uglify css and javascript
88+
- Run `bash build.sh` which will uglify css and javascript
7889

7990
## Deploy
8091
- Manual process of pushing to S3

dev.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,24 @@ <h1>
3737
</h1>
3838
</div>
3939
<div class="row">
40-
<div class="col-md-4">
40+
<div class="col-md-3">
4141
<div class="form-group">
4242
<label for="awsAccessKey">AWS Access Key</label>
4343
<input type="text" class="form-control" id="awsAccessKey" placeholder="AWS Access Key" />
4444
</div>
4545
</div>
46-
<div class="col-md-4">
46+
<div class="col-md-3">
4747
<div class="form-group">
4848
<label for="awsSecretKey">AWS Secret Key</label>
4949
<input type="password" class="form-control" id="awsSecretKey" placeholder="AWS Secret Key" />
5050
</div>
5151
</div>
52+
<div class="col-md-3">
53+
<div class="form-group">
54+
<label for="awsToken">AWS Token (if using instance profile)</label>
55+
<input type="text" class="form-control" id="awsToken" placeholder="AWS Token" />
56+
</div>
57+
</div>
5258
<div class="col-md-2 col-padding-top-25">
5359
<select class="form-control" id="regionSelect">
5460
<option>us-east-1</option>

index.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,24 @@ <h1>
3434
</h1>
3535
</div>
3636
<div class="row">
37-
<div class="col-md-4">
37+
<div class="col-md-3">
3838
<div class="form-group">
3939
<label for="awsAccessKey">AWS Access Key</label>
4040
<input type="text" class="form-control" id="awsAccessKey" placeholder="AWS Access Key" />
4141
</div>
4242
</div>
43-
<div class="col-md-4">
43+
<div class="col-md-3">
4444
<div class="form-group">
4545
<label for="awsSecretKey">AWS Secret Key</label>
4646
<input type="password" class="form-control" id="awsSecretKey" placeholder="AWS Secret Key" />
4747
</div>
4848
</div>
49+
<div class="col-md-3">
50+
<div class="form-group">
51+
<label for="awsToken">AWS Token (if using instance profile)</label>
52+
<input type="text" class="form-control" id="awsToken" placeholder="AWS Token" />
53+
</div>
54+
</div>
4955
<div class="col-md-2 col-padding-top-25">
5056
<select class="form-control" id="regionSelect">
5157
<option>us-east-1</option>

js/aws.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ function resetAWSValues() {
2525
g_EC2DataTimer = null;
2626
}
2727

28-
function queryAllAWSRegionsForEC2Data(key, secret, region) {
28+
function queryAllAWSRegionsForEC2Data(key, secret, token, region) {
2929
if (key != null && secret != null) {
3030
g_REGION = region;
3131
resetEc2DataTable();
3232
resetAWSValues();
3333
if (region.indexOf(g_ALL_Region_Const) != -1) {
3434
for (var i = 0; i < g_AWSRegions.length; i++) {
35-
queryAWSforEC2Data(g_AWSRegions[i], key, secret, false);
36-
queryAWSforEC2Data(g_AWSRegions[i], key, secret, true);
35+
queryAWSforEC2Data(g_AWSRegions[i], key, secret, token, false);
36+
queryAWSforEC2Data(g_AWSRegions[i], key, secret, token, true);
3737
}
3838
} else {
39-
queryAWSforEC2Data(g_REGION, key, secret, false);
40-
queryAWSforEC2Data(g_REGION, key, secret, true);
39+
queryAWSforEC2Data(g_REGION, key, secret, token, false);
40+
queryAWSforEC2Data(g_REGION, key, secret, token, true);
4141
}
4242
// Because of the asynchronous nature of the AWS SDK calls, we need to
4343
// wait until all data is returned for all regions before we proceed
@@ -172,10 +172,11 @@ function combineEC2AndResData(ec2, res) {
172172
return newRes;
173173
}
174174

175-
function queryAWSforEC2Data(region, key, secret, reservations) {
175+
function queryAWSforEC2Data(region, key, secret, token, reservations) {
176176
var ec2 = new AWS.EC2({
177177
accessKeyId: key,
178178
secretAccessKey: secret,
179+
sessionToken: token,
179180
region: region,
180181
maxRetries: 5,
181182
// http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#sslEnabled-property
@@ -334,7 +335,7 @@ function mungeEc2Data(data) {
334335
return mungedDataArr;
335336
}
336337

337-
function testAWSCredentials(key, secret, region) {
338+
function testAWSCredentials(key, secret, token, region) {
338339
resetCredChecks();
339340
if (region.toLowerCase() == "all") {
340341
// pick us-east-1 should always be there
@@ -344,6 +345,7 @@ function testAWSCredentials(key, secret, region) {
344345
var ec2 = new AWS.EC2({
345346
accessKeyId: key,
346347
secretAccessKey: secret,
348+
sessionToken: token,
347349
region: region,
348350
maxRetries: 5,
349351
sslEnabled: true
@@ -390,6 +392,7 @@ function checkCredCheck() {
390392
queryAllAWSRegionsForEC2Data(
391393
getAccessKeyValue(),
392394
getSecretKeyValue(),
395+
getTokenValue(),
393396
getRegionValue()
394397
);
395398
resetCredChecks();

js/main.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ function getSecretKeyValue() {
2424
return validateKeys(document.getElementById('awsSecretKey').value);
2525
}
2626

27+
function getTokenValue() {
28+
return document.getElementById('awsToken').value;
29+
}
30+
2731
function getRegionValue() {
2832
return document.getElementById('regionSelect').value;
2933
}
@@ -33,7 +37,7 @@ function awsQueryButtonAction() {
3337
showPleaseWaitDiv();
3438
hideAccessSecretErrorDiv();
3539
hideCredentialsErrorDiv();
36-
testAWSCredentials(getAccessKeyValue(), getSecretKeyValue(), getRegionValue());
40+
testAWSCredentials(getAccessKeyValue(), getSecretKeyValue(), getTokenValue(), getRegionValue());
3741
waitForCredCheck();
3842
// always return false to avoid page refresh
3943
return false;

main.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)