CloudSnorkel / cdk-github-runners

CDK constructs for self-hosted GitHub Actions runners
https://constructs.dev/packages/@cloudsnorkel/cdk-github-runners/
Apache License 2.0
258 stars 37 forks source link

Long org/repository names can cause conflicts on the state machine naming #554

Closed jonathanmorley closed 1 month ago

jonathanmorley commented 1 month ago

This line (https://github.com/CloudSnorkel/cdk-github-runners/blob/main/src/webhook-handler.lambda.ts#L179) in the webhook handler lambda tries to calculate a unique name for the statemachine execution.

However, if the org name and/or repo name is long enough, then there is not enough space for the (actually unique) x-github-delivery header.

I have encountered collisions with a 19 character org name, and a 42 character repository name, as this results in a combined 63 characters (including separators), leaving only 1 character for the x-github-delivery header.

I suggest reducing each component individually, and maintaining a minimum hash length that the x-github-delivery header cannot go below.

kichik commented 1 month ago

Thanks 🤦🏻

jonathanmorley commented 1 month ago

I'm using the following patch in case it helps others

-  let executionName = `${payload.repository.full_name.replace("/", "-")}-${getHeader(event, "x-github-delivery")}`.slice(0, 64);
+  let deliveryId = getHeader(event, "x-github-delivery");
+  let executionName = `${payload.repository.full_name.replace("/", "-").slice(0, 64-deliveryId.length-1)}-${deliveryId}`;

which does middle-out truncation