use of com.amazonaws.services.securitytoken.model.AssumeRoleResult in project Gatekeeper by FINRAOS.
the class AwsSessionService method getFreshCredentials.
private BasicSessionCredentials getFreshCredentials(AWSEnvironment environment) throws GatekeeperException {
logger.info("Assuming role for environment " + environment.getAccount() + " on region " + environment.getRegion() + " with timeout of " + (sessionTimeout / 1000) + " seconds (with " + (sessionTimeoutPad / 1000) + " padding.)");
AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(getRoleArn(environment.getAccount())).withDurationSeconds((sessionTimeout + sessionTimeoutPad) / 1000).withRoleSessionName("GATEKEEPER_APP");
AssumeRoleResult assumeResult = awsSecurityTokenServiceClient.assumeRole(assumeRequest);
return new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleResult in project cloudbreak by hortonworks.
the class AwsSessionCredentialClient method retrieveSessionCredentials.
public BasicSessionCredentials retrieveSessionCredentials(AwsCredentialView awsCredential) {
LOGGER.debug("retrieving session credential");
AWSSecurityTokenServiceClient client = awsSecurityTokenServiceClient();
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withDurationSeconds(DEFAULT_SESSION_CREDENTIALS_DURATION).withExternalId(externalId).withRoleArn(awsCredential.getRoleArn()).withRoleSessionName("hadoop-provisioning");
AssumeRoleResult result = client.assumeRole(assumeRoleRequest);
return new BasicSessionCredentials(result.getCredentials().getAccessKeyId(), result.getCredentials().getSecretAccessKey(), result.getCredentials().getSessionToken());
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleResult in project eureka by Netflix.
the class AwsAsgUtil method initializeStsSession.
private Credentials initializeStsSession(String asgAccount) {
AWSSecurityTokenService sts = new AWSSecurityTokenServiceClient(new InstanceProfileCredentialsProvider());
String region = clientConfig.getRegion();
if (!region.equals("us-east-1")) {
sts.setEndpoint("sts." + region + ".amazonaws.com");
}
String roleName = serverConfig.getListAutoScalingGroupsRoleName();
String roleArn = "arn:aws:iam::" + asgAccount + ":role/" + roleName;
AssumeRoleResult assumeRoleResult = sts.assumeRole(new AssumeRoleRequest().withRoleArn(roleArn).withRoleSessionName("sts-session-" + asgAccount));
return assumeRoleResult.getCredentials();
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleResult in project SimianArmy by Netflix.
the class STSAssumeRoleSessionCredentialsProvider method startSession.
/**
* Starts a new session by sending a request to the AWS Security Token
* Service (STS) to assume a Role using the long lived AWS credentials. This
* class then vends the short lived session credentials for the assumed Role
* sent back from STS.
*/
private void startSession() {
AssumeRoleResult assumeRoleResult = securityTokenService.assumeRole(new AssumeRoleRequest().withRoleArn(roleArn).withDurationSeconds(DEFAULT_DURATION_SECONDS).withRoleSessionName("SimianArmy"));
Credentials stsCredentials = assumeRoleResult.getCredentials();
sessionCredentials = new BasicSessionCredentials(stsCredentials.getAccessKeyId(), stsCredentials.getSecretAccessKey(), stsCredentials.getSessionToken());
sessionCredentialsExpiration = stsCredentials.getExpiration();
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleResult in project athenz by yahoo.
the class CloudStoreTest method testAssumeAWSRoleFailedCreds.
@Test
public void testAssumeAWSRoleFailedCreds() {
MockCloudStore cloudStore = new MockCloudStore();
cloudStore.awsEnabled = true;
AssumeRoleResult mockResult = Mockito.mock(AssumeRoleResult.class);
Credentials creds = Mockito.mock(Credentials.class);
Mockito.when(creds.getAccessKeyId()).thenReturn("accesskeyid");
Mockito.when(creds.getSecretAccessKey()).thenReturn("secretaccesskey");
Mockito.when(creds.getSessionToken()).thenReturn("sessiontoken");
Mockito.when(creds.getExpiration()).thenReturn(new Date());
Mockito.when(mockResult.getCredentials()).thenReturn(creds);
cloudStore.setAssumeRoleResult(mockResult);
cloudStore.setReturnSuperAWSRole(true);
// add our key to the invalid cache
cloudStore.putInvalidCacheCreds(cloudStore.getCacheKey("account", "syncer", "athenz.syncer", null, null));
StringBuilder errorMessage = new StringBuilder();
assertNull(cloudStore.assumeAWSRole("account", "syncer", "athenz.syncer", null, null, errorMessage));
errorMessage.setLength(0);
assertNull(cloudStore.assumeAWSRole("account", "syncer", "athenz.syncer", null, null, errorMessage));
// now set the timeout to 1 second and sleep that long and after
// that our test case should work as before
cloudStore.invalidCacheTimeout = 1;
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
errorMessage.setLength(0);
assertNotNull(cloudStore.assumeAWSRole("account", "syncer", "athenz.syncer", null, null, errorMessage));
cloudStore.close();
}
Aggregations