Skip to content

Prevent falling back to default token for onprem #3997

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thyeggman
Copy link
Contributor

...

@Copilot Copilot AI review requested due to automatic review settings August 21, 2025 23:40
@thyeggman thyeggman requested a review from a team as a code owner August 21, 2025 23:40
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR prevents GitHub Actions runners from falling back to default tokens when downloading actions from GitHub.com in on-premises environments, specifically for GitHub Enterprise Cloud with data residency scenarios.

  • Adds logic to detect GitHub Enterprise Cloud environments with data residency
  • Implements conditional token fallback that prevents using default tokens for external action downloads
  • Introduces URL pattern validation to identify action downloads from GitHub.com

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Runner.Worker/ActionManager.cs Adds GitHub URL detection and conditional logic to prevent default token fallback for on-premises scenarios
src/Runner.Sdk/Util/UrlUtil.cs Implements new utility method to detect GHEC data residency fallback scenarios with regex pattern matching

#if OS_WINDOWS
if (downloadInfo.ZipballUrl != null && !Regex.IsMatch(downloadInfo.ZipballUrl.ToString(), pattern))
#else
if (downloadInfo.TarballUrl != null && !Regex.IsMatch(downloadInfo.TarballUrl.ToString(), pattern))
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

The regex pattern should be extracted as a private static readonly field to improve maintainability and avoid recompilation on each method call.

Suggested change
if (downloadInfo.TarballUrl != null && !Regex.IsMatch(downloadInfo.TarballUrl.ToString(), pattern))
#if OS_WINDOWS
if (downloadInfo.ZipballUrl != null && !GHECDRFallbackPattern.IsMatch(downloadInfo.ZipballUrl.ToString()))
#else
if (downloadInfo.TarballUrl != null && !GHECDRFallbackPattern.IsMatch(downloadInfo.TarballUrl.ToString()))

Copilot uses AI. Check for mistakes.

@@ -21,6 +22,28 @@ public static bool IsHostedServer(UriBuilder gitHubUrl)
gitHubUrl.Host.EndsWith(".ghe.com", StringComparison.OrdinalIgnoreCase);
}

// For GitHub Enterprise Cloud with data residency, we allow fallback to GitHub.com for Actions resolution
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

This public method lacks XML documentation. Add a summary explaining the method's purpose, parameters, and return value to improve API clarity.

Suggested change
// For GitHub Enterprise Cloud with data residency, we allow fallback to GitHub.com for Actions resolution
/// <summary>
/// Determines whether the given GitHub Enterprise Cloud with data residency (GHEC DR) URL should fall back to GitHub.com for Actions resolution.
/// </summary>
/// <param name="gitHubUrl">The base GitHub URL to check.</param>
/// <param name="downloadInfo">The action download information containing tarball or zipball URLs.</param>
/// <returns>
/// True if the URL is for a GHEC DR instance that should fall back to GitHub.com for Actions resolution; otherwise, false.
/// </returns>

Copilot uses AI. Check for mistakes.

// Default auth token
if (string.IsNullOrEmpty(actionDownloadInfo.Authentication?.Token))
// Use default auth token unless falling back from OnPrem
if (string.IsNullOrEmpty(actionDownloadInfo.Authentication?.Token) && !UrlUtil.IsGHECDRFallbackToDotcom(gitHubUrl, actionDownloadInfo))
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

The method IsGHECDRFallbackToDotcom is called with a potentially null gitHubUrl parameter. This will cause a null reference exception if both serverUrl and runnerSettings.GitHubUrl are null or empty.

Suggested change
if (string.IsNullOrEmpty(actionDownloadInfo.Authentication?.Token) && !UrlUtil.IsGHECDRFallbackToDotcom(gitHubUrl, actionDownloadInfo))
if (string.IsNullOrEmpty(actionDownloadInfo.Authentication?.Token) && (gitHubUrl == null || !UrlUtil.IsGHECDRFallbackToDotcom(gitHubUrl, actionDownloadInfo)))

Copilot uses AI. Check for mistakes.

@thyeggman thyeggman marked this pull request as draft August 21, 2025 23:43
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