mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
* fix(cloudformation): leave root security out of SAM REST auth defaults AWS::Serverless::Api Auth (DefaultAuthorizer: AWS_IAM, ApiKeyRequired) gave each operation without security of its own a copy of the document's root security before adding the defaults. SAM reads only the operation's own security and leaves the root security as written, and API Gateway does not apply root-level security. As a result: - a root requirement naming a SigV4 scheme or an authorizer, beside the generated AWS_IAM default, failed the import with "Only one Authorizer or IAM authorization is allowed per operation", where SAM gives the operation the one AWS_IAM requirement; - other root requirements, such as an API key scheme, were copied into every operation and enforced, where AWS does not enforce them. The defaults now start from the operation's own security. An Auth that selects no default, such as ApiKeyRequired: false alone, now leaves the body as written, as SAM does; it used to copy the root security into every operation. The docs also say that floci's REST importer still applies root-level security to an operation that has none of its own, which API Gateway does not. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(cloudformation): add SAM REST auth defaults inside Fn::If branches An Fn::If written around a path item or an operation in the DefinitionBody of an AWS::Serverless::Api kept the Auth defaults from reaching the operation. A conditional path item was skipped, because its only key is not a method, and a conditional operation got the default beside the Fn::If, which the template engine drops when it keeps the chosen branch. Either way the method was imported with authorizationType NONE and answered unsigned calls, where SAM adds the default inside each branch. The defaults are now added inside each branch, skipping an AWS::NoValue one, as SAM's get_conditional_contents does. When a default applies, a nested Fn::If, or one whose value is not a list, is refused with a ValidationError instead of being left without the defaults. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(cloudformation): refuse SAM REST bodies that would lose the defaults Some DefinitionBody shapes lost the generated AWS_IAM and api_key schemes or requirements on their way to the REST importer, which then imported the methods with authorizationType NONE: - a securityDefinitions, components or securitySchemes map written as an intrinsic function such as Fn::If. The generated schemes were written beside the function, and the template engine keeps only its result; - a body with an Fn::If key beside its own keys, which the engine replaces with the chosen branch; - an existing AWS_IAM or api_key scheme with the expected fields and an Fn::If key, which the engine replaces with a branch that need not be that scheme; - a body declaring both swagger: "2.0" and an openapi version. The transform wrote the schemes into securityDefinitions, which the importer, reading the body as OpenAPI 3, ignores. When a default applies, these are now refused with a ValidationError, as a path item written as a $ref already is. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(cloudformation): cover SAM REST root security through the SDK The SDK suite creates a stack whose AWS::Serverless::Api root security names its own SigV4 scheme, with DefaultAuthorizer: AWS_IAM, in Swagger 2.0 and OpenAPI 3.0. It checks that the stack deploys, that the processed template keeps the root security and gives the operation the one AWS_IAM requirement, and that the method is imported as AWS_IAM without an API key. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(cloudformation): pin false Fn::If routes and conditional bodies An Fn::If around a path item or an operation whose condition is false resolves to AWS::NoValue. The transform adds no default to that branch, and the REST importer creates no resource or method for it, so the API has no such route, as on AWS, while the other routes keep the AWS_IAM default. A DefinitionBody written as an Fn::If is refused for any non-empty Auth, ApiKeyRequired: false included. SAM refuses it too: for every non-empty Auth, _add_auth checks SwaggerEditor.is_valid, which needs a literal paths object. The docs now say so. Neither behavior changes here; the tests keep both in place. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * docs(cloudformation): say a SAM REST Auth needs a paths object The sentence added in the previous commit said any non-empty Auth needs a literal paths object. The transform, like SAM, accepts any object there, a paths map written as Fn::If included when no default is selected. What it refuses is a DefinitionBody without one, such as a body written as Fn::If. The previous commit's message also said a false Fn::If around an operation leaves no route. That holds for get, post and the other HTTP methods. For x-amazon-apigateway-any-method the REST importer fails the stack instead, with "expected an Operation object", on main too and without Auth. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(cloudformation): check no-default SAM REST bodies as SAM does An Auth that selects no default, such as ApiKeyRequired: false alone, returned once the DefinitionBody had a paths object. SAM checks more for any non-empty Auth before it applies a default: SwaggerEditor.is_valid wants a truthy swagger or an openapi version 3.x, and the SwaggerEditor constructor wants every paths entry, and each branch of an Fn::If around one, to be an object. floci therefore accepted a body without a version, a paths map written as Fn::If, or a path item that is not an object, all of which SAM refuses. The previous commit's message said SAM accepts such a paths map; it does not. These are now refused with a ValidationError when no default is selected too. Nothing else is checked in that case, as in SAM: an OpenAPI 3.1 body, a $ref path item, a nested Fn::If or a malformed security requirement is left as written. SamTransformProcessor's isTruthy helper, which already models SAM's truthiness, becomes package-private so the check can share it. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(cloudformation): leave nested Fn::If operations as SAM does With a default selected, an Fn::If around an operation whose branch was itself an Fn::If failed the transform with "Auth does not support a nested Fn::If in paths". SAM does not fail there. Its iter_on_all_methods_for_path reads one level of Fn::If around an operation and skips a method definition without an x-amazon-apigateway-integration. It therefore leaves the nested branch as written, adds the defaults only to the plain one, and the template deploys on AWS. Such a branch is now left as written, without the defaults, and the plain branches still get them. A nested Fn::If around a path item is still refused: SAM fails there too, once it reads the methods of the inner Fn::If. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(cloudformation): share the SAM REST stack deploy in one helper Three SamRestApiAuthIntegrationTest cases each created the stack, waited for it, read its ApiId output and deleted it in a finally block. withDeployedApi now does that once: it adds the ApiId output, deploys the template, hands the API id to the assertions once the stack is CREATE_COMPLETE, and deletes the stack in its finally. The assertions are unchanged; a failed deploy now reports the stack's own status reason in all three cases. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * test(cloudformation): keep the failed resource's reason in deploy failures withDeployedApi reported only the stack's status reason when a stack did not reach CREATE_COMPLETE. For a resource failure that is the generic "The following resource(s) failed to create", where two of its callers used to report the failed resource's own reason, such as the importer's refusal. The helper now appends that reason when the stack rolled back, and keeps the stack's reason alone for a transform failure, which has no failed resource. Only failure messages change. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> --------- Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>