Skip to content

Conversation

allamand
Copy link

Create a new backstage template and kro RGD for the CICD pipeline


// Should have ECR registry entries
const registryKeys = Object.keys(dockerConfig.auths);
expect(registryKeys.some(key => key.includes('.dkr.ecr.') && key.includes('.amazonaws.com'))).toBe(true);

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

'
.amazonaws.com
' can be anywhere in the URL, and arbitrary hosts may come before or after it.

Copilot Autofix

AI about 12 hours ago

The fix is to parse the registry key as a URL (or at least separate out its host component) and explicitly match it against the exact allowed patterns. In this context, Docker registry keys are typically hostnames like <aws_account_id>.dkr.ecr.<region>.amazonaws.com (with or without protocol), so we can use a regular expression or direct string checks to validate the format more robustly.

  1. Replace the substring check with a regular expression that requires the key to conform to the AWS ECR registry host pattern.
  2. Ensure the regular expression matches only valid AWS ECR hosts, not arbitrary hosts containing .amazonaws.com somewhere in the name.
  3. No additional import is needed, unless robust URL parsing is desired, but for hostname patterns, a simple regex is sufficient.
  4. Only lines within the provided file need to be changed.

Change only the registry key assertion, on (and around) line 265 in aws-resource-validation.integration.test.js.


Suggested changeset 1
gitops/addons/charts/kro/resource-groups/cicd-pipeline/tests/integration/aws-resource-validation.integration.test.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/gitops/addons/charts/kro/resource-groups/cicd-pipeline/tests/integration/aws-resource-validation.integration.test.js b/gitops/addons/charts/kro/resource-groups/cicd-pipeline/tests/integration/aws-resource-validation.integration.test.js
--- a/gitops/addons/charts/kro/resource-groups/cicd-pipeline/tests/integration/aws-resource-validation.integration.test.js
+++ b/gitops/addons/charts/kro/resource-groups/cicd-pipeline/tests/integration/aws-resource-validation.integration.test.js
@@ -262,7 +262,9 @@
 
       // Should have ECR registry entries
       const registryKeys = Object.keys(dockerConfig.auths);
-      expect(registryKeys.some(key => key.includes('.dkr.ecr.') && key.includes('.amazonaws.com'))).toBe(true);
+      // Match pattern: <account-id>.dkr.ecr.<region>.amazonaws.com optionally with :port
+      const ecrRegistryRegex = /^\d{12}\.dkr\.ecr\.[a-z0-9-]+\.amazonaws\.com(:\d+)?$/;
+      expect(registryKeys.some(key => ecrRegistryRegex.test(key))).toBe(true);
     });
   });
 });
\ No newline at end of file
EOF
@@ -262,7 +262,9 @@

// Should have ECR registry entries
const registryKeys = Object.keys(dockerConfig.auths);
expect(registryKeys.some(key => key.includes('.dkr.ecr.') && key.includes('.amazonaws.com'))).toBe(true);
// Match pattern: <account-id>.dkr.ecr.<region>.amazonaws.com optionally with :port
const ecrRegistryRegex = /^\d{12}\.dkr\.ecr\.[a-z0-9-]+\.amazonaws\.com(:\d+)?$/;
expect(registryKeys.some(key => ecrRegistryRegex.test(key))).toBe(true);
});
});
});
Copilot is powered by AI and may make mistakes. Always verify output.
allamand and others added 25 commits September 27, 2025 01:19
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
- Fix readyWhen conditions to only reference current resource (no cross-resource refs)
- Escape shell variables to avoid CEL expression parser conflicts
- Update shell variable naming from UPPERCASE to lowercase to prevent template parsing
- Replace Gitea references with GitLab for current workshop version
- Update secret references from gitea-credentials to gitlab-credentials
- Change GITEA_TOKEN to GITLAB_TOKEN environment variable

Key fixes:
- readyWhen patterns: self-reference only, dependencies via template variables
- Shell variables: gitlab_hostname, webhook_url, api_url (lowercase)
- Validation: RGD now passes Kro CLI validation successfully

Resolves CEL expression validation errors:
- undeclared reference to 'GITLAB_HOSTNAME'
- undeclared reference to 'hooks_api_url'
- undeclared reference to 'GITEA_TOKEN'
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Workshop User <workshopuser@example.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Signed-off-by: Sébastien Allamand <sallaman@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant