Description
Is your feature request related to a problem? Please describe.
The current reference implementation adds post-deployment testing by calling addPost
and passing a SoapUITest or JMeterTest, both of which extend CodeBuildStep
and are defined without a scope
or environment. This works well for test executions which only rely on calling an external Internet-available endpoint (which is passed into these TestStacks as a CfnOutput
).
However, for test cases which require interacting with created resources directly (perhaps to assert on conditions that should not be visible via the public API), or even if the apiUrl was instead an ApiGatewayLambda (which enforces IAM authentication), we have a problem:
- In order to set a resource-based policy permitting the CodeBuild Role to interact with a resource, the ARN of the Role must be known at the time of defining the resource
- In order for the CodeBuild Role to have a known Arn, the Role must be manually created and passed to the CodeBuild Step (if we reference
codeBuildStep?.role?.roleArn
orcodeBuildStep?.role?.roleName
for a CodeBuild step without an explicitly passed Role, the value isundefined
) - In order to manually create a Role,
new Role(...)
requires ascope
- which is not available in the current setup of creating a CodeBuild step.
Describe the solution you'd like
An expansion of the reference pipeline to demonstrate how to execute tests that require granting resource-based permissions to the Role that will execute the tests (or, a standalone example of how to do so)
Describe alternatives you've considered
- Only grant the CodeBuildStep Role
AssumeRole
privileges, and create specific Roles for it to assume in order to carry out testing- I suspect that this will be the preferred solution. Note, though, that unless the assumable roles grant Assumption privileges to all Roles in the account where the test execution role resides, we have recovered the same problem of "how can these Roles define the Roles that should be able to assume them if the test execution role has an undefined name?". The attack surface area here is probably a lot smaller, though.
- If there are multiple assumable roles created for the Test Execution Role to assume, this abstraction will leak into the test code, which must "know about" which role to assume for which action.
- Create the role in the context of the pipeline, and pass into the service stack and the testing step
- Into the service stack to reference for resource-based policies; into the testing step to use in the CodeBuildStep.
- This also implies that all testing roles will be in the same account, adding a minor irritation that their IDs and names will have to be differentiated.
- Create the role in the context of the stage and pass out to the testing step
- Avoid tests which require resource-based policies
- This might well be possible, but seems a restrictive solution. Tests which only exercise the public interface of a system have their place, but some behaviours of a system (off the top of my head - those which rely on updating some "behind-the-scenes" value, or those which should trigger an asynchronous job) would be impractical to test purely via an external interface.
Additional context
Add any other context or screenshots about the feature request here.