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

Allow usage of temporary security credentials to access AWS resources (S3) #435

Closed
carlos-hernandez opened this issue Jul 3, 2023 · 2 comments

Comments

@carlos-hernandez
Copy link

Using the OpenAPI plugin, if we use AWS roles to access our S3 buckets Imposter fails to access the spec files:

java.lang.RuntimeException: Failed to load specification from source [s3://my-sample-bucket/config/OpenAPI-sample.json] or cache
	at io.gatehill.imposter.plugin.openapi.service.SpecificationLoaderService.loadSpecFromSourceOrCache(SpecificationLoaderService.kt:141) ~[imposter-3.24.1.jar:?]
	at io.gatehill.imposter.plugin.openapi.service.SpecificationLoaderService.parseSpecification(SpecificationLoaderService.kt:79) ~[imposter-3.24.1.jar:?]
	at io.gatehill.imposter.plugin.openapi.OpenApiPluginImpl.parseSpecs(OpenApiPluginImpl.kt:166) ~[imposter-3.24.1.jar:?]
	at io.gatehill.imposter.plugin.openapi.OpenApiPluginImpl.configureRoutes(OpenApiPluginImpl.kt:136) ~[imposter-3.24.1.jar:?]
	at io.gatehill.imposter.Imposter.configureRoutes(Imposter.kt:220) ~[imposter-3.24.1.jar:?]
	at io.gatehill.imposter.Imposter.access$configureRoutes(Imposter.kt:87) ~[imposter-3.24.1.jar:?]
	at io.gatehill.imposter.Imposter$start$1.invokeSuspend(Imposter.kt:134) ~[imposter-3.24.1.jar:?]
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[imposter-3.24.1.jar:?]
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) ~[imposter-3.24.1.jar:?]
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) ~[imposter-3.24.1.jar:?]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) ~[imposter-3.24.1.jar:?]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) ~[imposter-3.24.1.jar:?]
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) ~[imposter-3.24.1.jar:?]
Caused by: java.lang.RuntimeException: Error fetching file from S3: s3://my-sample-bucket/config/OpenAPI-sample.json
	at io.gatehill.imposter.config.S3FileDownloader.readFileFromS3(S3FileDownloader.kt:95) ~[imposter-3.24.1.jar:?]
	at io.gatehill.imposter.plugin.openapi.service.SpecificationLoaderService.loadSpecFromSource(SpecificationLoaderService.kt:154) ~[imposter-3.24.1.jar:?]
	at io.gatehill.imposter.plugin.openapi.service.SpecificationLoaderService.loadSpecFromSourceOrCache(SpecificationLoaderService.kt:134) ~[imposter-3.24.1.jar:?]
	... 12 more
Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 2J7H99SCAB45P495; S3 Extended Request ID: lE9RzBFfCbnqjgo1c26YYHsgNIplgjgG7gCTVbBFJ41inNqEHS99NvjAsjvpxaVkpSh2ioVLpA4=; Proxy: null)

The issue is solved by adding aws-java-sdk-sts as a dependency so the WebIdentityTokenCredentialsProvider used in the DefaultAWSCredentialsProviderChain can load the profile defined in the ~/.aws/credentials file:

[default]
region = us-west-2
output = json
role_arn = arn:aws:iam::123456789012:role/myRole
source_profile = personal

[personal]
aws_access_key_id = <access-key>
aws_secret_access_key = <secret-key>
@outofcoffee
Copy link
Owner

Thanks @carlos-hernandez. Added in 96e0939. If everything passes, should be in the next minor release.

@outofcoffee
Copy link
Owner

Released in v3.25.0.

Thanks again @carlos-hernandez.

@outofcoffee outofcoffee removed their assignment Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants