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

Fixed AWS to work when no secrets specified #686

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

brian-golfplusvr
Copy link

@brian-golfplusvr brian-golfplusvr commented Jan 30, 2025

Changes

  • Updated AWS task definition related code so that it would allow creation of the cloud formation stack and not complain if the ContainerDefinition secrets were null

  • See Discord discussion

Checklist

  • Read the contribution guide and accept the
    code of conduct
  • Docs (If new inputs or outputs have been added or changes to behavior that should be documented. Please make a PR
    in the documentation repo)
  • Readme (updated or not needed)
  • Tests (added, updated or not needed)

Summary by CodeRabbit

  • New Features

    • Enhanced AWS CloudFormation template generation with improved secret management.
    • Added logging for better traceability during AWS job stack and task definition processes.
    • Introduced new input parameters cloneDepth and cloudRunnerRepoName for repository cloning operations.
    • Dynamic construction of Unity Builder repository URL based on configuration.
  • Refactor

    • Updated secret handling in CloudFormation template configuration.
    • Removed Secrets property from container definitions.
    • Changed imageRollingVersion property type from number to string for better data representation.
    • Added static getters for cloneDepth and cloudRunnerRepoName in CloudRunner options.
    • Modified cloning logic to include a depth parameter for optimization.
  • Chores

    • Improved code comments for clarity in secret template generation.

Copy link

coderabbitai bot commented Jan 30, 2025

📝 Walkthrough

Walkthrough

The pull request introduces modifications to AWS CloudFormation template generation and secret management across multiple files. The changes focus on enhancing the way secrets are defined and handled within cloud infrastructure templates, specifically in AWS-related cloud runner components. Key updates include adding a Secrets array in the getSecretDefinitionTemplate method, enhancing logging in the setupCloudFormations method, removing the Secrets property from the ContainerDefinitions, changing the type of imageRollingVersion in the ImageTag class, and adding new input parameters in the action configuration.

Changes

File Change Summary
src/model/cloud-runner/providers/aws/aws-cloud-formation-templates.ts Added new Secrets array definition in getSecretDefinitionTemplate method with dynamic secret name and value generation.
src/model/cloud-runner/providers/aws/aws-job-stack.ts Added logging statements for taskDefCloudFormation and createStackInput, updated comment for secret template insertion.
src/model/cloud-runner/providers/aws/cloud-formations/task-definition-formation.ts Removed Secrets property from ContainerDefinitions, added clarifying comment.
src/model/image-tag.ts Changed type of imageRollingVersion from number to string in ImageTag class.
action.yml Added new input parameters cloneDepth and cloudRunnerRepoName with default values.
src/model/build-parameters.ts Added public properties cloneDepth and cloudRunnerRepoName to BuildParameters class.
src/model/cloud-runner/options/cloud-runner-options.ts Added static getter methods for cloudRunnerRepoName and cloneDepth.
src/model/cloud-runner/remote-client/index.ts Modified cloneRepoWithoutLFSFiles method to include --depth option in git clone command.
src/model/cloud-runner/options/cloud-runner-folders.ts Updated unityBuilderRepoUrl getter to construct URL dynamically based on CloudRunner.buildParameters.

Sequence Diagram

sequenceDiagram
    participant CloudRunner as Cloud Runner
    participant AWSTmpl as AWS Templates
    participant AWSSec as AWS Secrets Manager
    
    CloudRunner->>AWSTmpl: Generate CloudFormation Template
    AWSTmpl->>AWSTmpl: Define Secret References
    AWSTmpl->>AWSSec: Create Secret Mappings
    AWSSec-->>AWSTmpl: Confirm Secret Configuration
Loading

Poem

🐰 In clouds of AWS, secrets take flight,
Templates dancing with templates so bright.
Logs whisper tales of infrastructure's might,
Refactored code, a technological delight,
Secrets hidden, yet perfectly right! 🔐


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc4de42 and db9abc4.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (2)
  • action.yml (1 hunks)
  • src/model/cloud-runner/options/cloud-runner-folders.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/model/cloud-runner/options/cloud-runner-folders.ts
  • action.yml

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Cat Gif

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/model/cloud-runner/providers/aws/aws-job-stack.ts (1)

149-149: Remove redundant logging statement.

This logging statement is redundant with the one on line 117.

-      CloudRunnerLogger.log(`TaskDef Cloud formation: ${taskDefCloudFormation}`);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83c8532 and b048e94.

📒 Files selected for processing (3)
  • src/model/cloud-runner/providers/aws/aws-cloud-formation-templates.ts (1 hunks)
  • src/model/cloud-runner/providers/aws/aws-job-stack.ts (3 hunks)
  • src/model/cloud-runner/providers/aws/cloud-formations/task-definition-formation.ts (1 hunks)
🔇 Additional comments (6)
src/model/cloud-runner/providers/aws/aws-cloud-formation-templates.ts (1)

24-27: LGTM! The secret definition template follows AWS CloudFormation best practices.

The template correctly structures secrets with Name and ValueFrom properties, following AWS CloudFormation syntax.

src/model/cloud-runner/providers/aws/cloud-formations/task-definition-formation.ts (2)

129-129: LGTM! Correct configuration for EFS mount points.

The ReadOnly flag is properly set to false, allowing write access to the EFS volume.


130-130: LGTM! Clear template marker for secrets injection.

The comment provides a clear insertion point for dynamic secret injection, maintaining code clarity.

src/model/cloud-runner/providers/aws/aws-job-stack.ts (3)

73-73: LGTM! Clear template marker for secret definition.

The comment provides a consistent marker for secret template insertion.


116-118: LGTM! Enhanced logging for task definition template.

Added logging to help debug template generation issues.


146-147: LGTM! Enhanced logging for stack creation.

Added logging to help debug stack creation issues.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
src/model/cloud-runner/options/cloud-runner-options.ts (2)

77-79: LGTM! Consider documenting the purpose.

The getter implementation is correct, providing a sensible default value.

Consider adding a JSDoc comment to document the purpose and usage of this configuration option:

+/**
+ * Gets the repository name for cloud runner operations.
+ * @returns {string} The configured repo name or defaults to 'game-ci/unity-builder'
+ */
 static get cloudRunnerRepoName(): string {
   return CloudRunnerOptions.getInput('cloudRunnerRepoName') || `game-ci/unity-builder`;
 }

147-149: LGTM! Consider validating the input.

The getter implementation is correct, providing a sensible default value.

Consider adding input validation to ensure a positive integer value:

 static get cloneDepth(): string {
-  return CloudRunnerOptions.getInput('cloneDepth') || `50`;
+  const depth = CloudRunnerOptions.getInput('cloneDepth') || `50`;
+  const parsedDepth = parseInt(depth, 10);
+  if (isNaN(parsedDepth) || parsedDepth <= 0) {
+    throw new Error('cloneDepth must be a positive integer');
+  }
+  return depth;
 }
src/model/build-parameters.ts (2)

70-70: LGTM! Consider adding property documentation.

The property declarations are correctly typed.

Consider adding JSDoc comments to document these properties:

+/** The maximum depth when cloning repositories */
 public cloneDepth!: number;

+/** The repository name used for cloud runner operations */
 public cloudRunnerRepoName!: string;

Also applies to: 78-78


199-201: LGTM! Consider handling parsing errors.

The initialization of properties is correct, with proper fallback values.

Consider adding error handling for the number parsing:

-      cloneDepth: Number.parseInt(CloudRunnerOptions.cloneDepth),
+      cloneDepth: (() => {
+        const parsed = Number.parseInt(CloudRunnerOptions.cloneDepth);
+        if (isNaN(parsed)) {
+          throw new Error('Failed to parse cloneDepth as a number');
+        }
+        return parsed;
+      })(),

Also applies to: 225-225

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05bb993 and dc4de42.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (4)
  • action.yml (1 hunks)
  • src/model/build-parameters.ts (4 hunks)
  • src/model/cloud-runner/options/cloud-runner-folders.ts (1 hunks)
  • src/model/cloud-runner/options/cloud-runner-options.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • action.yml
🔇 Additional comments (1)
src/model/build-parameters.ts (1)

1-267: Verify alignment with PR objectives.

The changes in these files appear to be unrelated to the PR's stated objective of fixing AWS task definition code to handle null secrets. Instead, they add configuration options for clone depth and repository naming.

Please clarify if:

  1. These changes are intentionally included in this PR
  2. The AWS-related changes are in other files not shown here
  3. The PR description needs to be updated to reflect these changes
🧰 Tools
🪛 Biome (1.9.4)

[error] 105-105: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 137-137: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Comment on lines 75 to 77
public static get unityBuilderRepoUrl(): string {
return `https://${CloudRunner.buildParameters.gitPrivateToken}@github.com/game-ci/unity-builder.git`;
return `https://${CloudRunner.buildParameters.gitPrivateToken}@github.com/${CloudRunner.buildParameters.unityBuilderRepo}.git`;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

⚠️ Potential issue

🧩 Analysis chain

Security: Avoid exposing git tokens in URLs.

The current implementation has several security concerns:

  1. Git tokens in URLs can be exposed through logs or error messages.
  2. Using a read-write token for cloning operations violates the principle of least privilege.
  3. The unityBuilderRepo value is not validated, potentially allowing injection attacks.

Consider these improvements:

  1. Use environment variables or git configuration for authentication:
-    return `https://${CloudRunner.buildParameters.gitPrivateToken}@github.com/${CloudRunner.buildParameters.unityBuilderRepo}.git`;
+    const repo = CloudRunner.buildParameters.unityBuilderRepo;
+    if (!repo.match(/^[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+$/)) {
+      throw new Error('Invalid repository name format');
+    }
+    return `https://github.com/${repo}.git`;
  1. Configure git to use credentials from environment variables:

  2. Use a read-only token specifically for cloning operations.

Let's verify if the repository name format is consistently validated across the codebase:


🏁 Script executed:

git config --global credential.helper store
echo "https://github.com:$GITHUB_TOKEN" > ~/.git-credentials

Length of output: 72


🏁 Script executed:

#!/bin/bash
# Search for other instances where repository names are used in URLs
rg -A 5 'github\.com/.*\.git'

# Search for repository name validation
ast-grep --pattern 'if (!$_repo.match(/^[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+$/)) { $$$_ }'

Length of output: 67754


Security issues found – Sensitive token exposure and lack of repository name validation

• The unityBuilderRepoUrl getter directly embeds the git private token in the URL, which can lead to undesired exposure through logs or error messages.
• Our search for consistent repository name validation (using regex checks) in the codebase returned no matches. This confirms that the proposed input validation is missing.
• Similar patterns exist in other getters (e.g., targetBuildRepoUrl), indicating that the issue is not isolated to a single occurrence.

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