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

Add support for AWS keys requiring session tokens #52

Merged
merged 2 commits into from
May 16, 2024
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
22 changes: 17 additions & 5 deletions TeamFiltration/TeamFiltration/Handlers/AWSHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public class AWSHandler
private static GlobalArgumentsHandler _globalProperties { get; set; }
private static DatabaseHandler _databaseHandler { get; set; }
private static BasicAWSCredentials _basicAWSCredentials { get; set; }
private static SessionAWSCredentials _sessionAWSCredentials { get; set; }
private static AWSCredentials _AWSCredentials { get; set; }


public async Task<bool> DeleteFireProxEndpoint(string fireProxId, string region)
{
var amazonAPIGatewayClient = new AmazonAPIGatewayClient(_basicAWSCredentials, Amazon.RegionEndpoint.GetBySystemName(region));
var amazonAPIGatewayClient = new AmazonAPIGatewayClient(_AWSCredentials, Amazon.RegionEndpoint.GetBySystemName(region));

Amazon.APIGateway.Model.DeleteRestApiResponse deleteRestApiResponse = await amazonAPIGatewayClient.DeleteRestApiAsync(new Amazon.APIGateway.Model.DeleteRestApiRequest() { RestApiId = fireProxId });

Expand All @@ -44,15 +46,15 @@ public async Task ListFireProxEndpoint()

foreach (var item in _globalProperties.AWSRegions)
{
var amazonAPIGatewayClient = new AmazonAPIGatewayClient(_basicAWSCredentials, Amazon.RegionEndpoint.GetBySystemName(item));
var amazonAPIGatewayClient = new AmazonAPIGatewayClient(_AWSCredentials, Amazon.RegionEndpoint.GetBySystemName(item));

Amazon.APIGateway.Model.GetRestApisResponse getRestApisResponse = await amazonAPIGatewayClient.GetRestApisAsync(new Amazon.APIGateway.Model.GetRestApisRequest() { });
}
}
*/
public async Task<(Amazon.APIGateway.Model.CreateDeploymentRequest, Models.AWS.FireProxEndpoint)> CreateFireProxEndPoint(string url, string title, string region)
{
var amazonAPIGatewayClient = new AmazonAPIGatewayClient(_basicAWSCredentials, Amazon.RegionEndpoint.GetBySystemName(region));
var amazonAPIGatewayClient = new AmazonAPIGatewayClient(_AWSCredentials, Amazon.RegionEndpoint.GetBySystemName(region));

if (url.EndsWith('/'))
url = url.Substring(0, url.Length - 1);
Expand Down Expand Up @@ -198,17 +200,27 @@ public async Task ListFireProxEndpoint()
return (createDeploymentRequest, fireproxEndpoint);
}

public AWSHandler(string AWSAccessKey, string AWSSecretKey, DatabaseHandler databaseHandler)
public AWSHandler(string AWSAccessKey, string AWSSecretKey, string AWSSessionToken, DatabaseHandler databaseHandler)
{
_databaseHandler = databaseHandler;

if (!string.IsNullOrEmpty(AWSAccessKey) && !string.IsNullOrEmpty(AWSSecretKey))
if (!string.IsNullOrEmpty(AWSAccessKey) && !string.IsNullOrEmpty(AWSSecretKey) && string.IsNullOrEmpty(AWSSessionToken))
{

_basicAWSCredentials = new BasicAWSCredentials(
AWSAccessKey,
AWSSecretKey
);
_AWSCredentials = _basicAWSCredentials;
}
else if (!string.IsNullOrEmpty(AWSAccessKey) && !string.IsNullOrEmpty(AWSSecretKey) && !string.IsNullOrEmpty(AWSSessionToken))
{
_sessionAWSCredentials = new SessionAWSCredentials(
AWSAccessKey,
AWSSecretKey,
AWSSessionToken
);
_AWSCredentials = _sessionAWSCredentials;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public GlobalArgumentsHandler(string[] args, DatabaseHandler databaseHandler, bo
//Do AWS FireProx generation checks
if (!string.IsNullOrEmpty(TeamFiltrationConfig?.AWSSecretKey) && !string.IsNullOrEmpty(TeamFiltrationConfig?.AWSAccessKey))
{
_awsHandler = new AWSHandler(this.TeamFiltrationConfig.AWSAccessKey, this.TeamFiltrationConfig.AWSSecretKey, databaseHandler);
_awsHandler = new AWSHandler(this.TeamFiltrationConfig.AWSAccessKey, this.TeamFiltrationConfig.AWSSecretKey, this.TeamFiltrationConfig.AWSSessionToken, databaseHandler);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public class Config {
public string proxyEndpoint { get; set; }
public string AWSAccessKey { get; set; }
public string AWSSecretKey { get; set; }
public string AWSSessionToken { get; set; }



public string UserAgent { get; set; }
public List<string> AwsRegions { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion TeamFiltration/TeamFiltration/Modules/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static void DatabaseStart(string[] args)
}
if (string.IsNullOrEmpty(_globalProperties.TeamFiltrationConfig?.AWSAccessKey) || string.IsNullOrEmpty(_globalProperties.TeamFiltrationConfig?.AWSSecretKey))
{
Console.WriteLine("[!] Missing AWSAccessKey and/or AWSSecretKey, must be provided in the configuration file using '--config'");
Console.WriteLine("[!] Missing AWSAccessKey, AWSSecretKey, and/or AWSSessionToken, must be provided in the configuration file using '--config'");
Environment.Exit(0);
}

Expand Down
1 change: 1 addition & 0 deletions TeamFiltrationConfig_Example.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"proxyEndpoint": "http://127.0.0.1:8080",
"AWSAccessKey": "",
"AWSSecretKey": "",
"AWSSessionToken": "",
"UserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Teams/1.3.00.30866 Chrome/80.0.3987.165 Electron/8.5.1 Safari/537.36",
"AwsRegions":["us-east-1", "us-west-1", "us-west-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "eu-north-1"]
}