Skip to content

Conversation

@Stromweld
Copy link
Contributor

Description

add chef-ice package_manger support to generated scripts

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • If Gemfile.lock has changed, I have used --conservative to do it and included the full output in the Description above.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
@Stromweld Stromweld changed the title add chef-ice package_manger support to generated scripts CHEF-29762 add chef-ice package_manger support to generated scripts Jan 23, 2026
…will be source of truth

Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
…ssing license_id option

Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
# @return [String] the omnibus URL (commercial/trial or standard omnitruck)
# @api private
def omnibus_url_for_license
return omnibus_url if license_id.nil? || license_id.to_s.empty? || !omnibus_url.include?("omnitruck.chef.io")

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
omnitruck.chef.io
' can be anywhere in the URL, and arbitrary hosts may come before or after it.

Copilot Autofix

AI 33 minutes ago

In general, the problem should be fixed by parsing the URL and validating the host component explicitly, rather than using a substring check on the entire URL string. That means using URI.parse (from Ruby’s standard library) to get uri.host, and then comparing that to an allowlist ("omnitruck.chef.io" and any officially supported aliases) or a strict pattern, instead of using .include?.

In this specific file, on line 227 we should replace !omnibus_url.include?("omnitruck.chef.io") with a small helper that safely checks the host of omnibus_url. To keep behavior consistent and localized:

  • Add a private helper method in ScriptGenerator that:
    • Uses URI.parse(omnibus_url.to_s) to parse the URL.
    • Returns true only if uri.host matches "omnitruck.chef.io" (or, if appropriate for this project, matches a small set of official hosts).
    • Rescues URI::InvalidURIError and returns false in that case.
  • Update omnibus_url_for_license to call this helper (e.g., !omnitruck_host?(omnibus_url) instead of !omnibus_url.include?("omnitruck.chef.io")).

We only need to modify lib/mixlib/install/script_generator.rb, adding the helper method near the other private helpers (e.g., after metadata_endpoint_from_project) and updating the conditional in omnibus_url_for_license. URI is a standard Ruby library; since the file doesn’t currently require it explicitly, we should add require "uri" near the top alongside the other requires.

Suggested changeset 1
lib/mixlib/install/script_generator.rb

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/lib/mixlib/install/script_generator.rb b/lib/mixlib/install/script_generator.rb
--- a/lib/mixlib/install/script_generator.rb
+++ b/lib/mixlib/install/script_generator.rb
@@ -21,6 +21,7 @@
 require_relative "generator/powershell"
 require_relative "dist"
 require "cgi"
+require "uri"
 
 module Mixlib
   class Install
@@ -220,11 +221,27 @@
         end
       end
 
+      # Returns true if the given URL points to the official Omnitruck host.
+      # @param url [String] the URL to check
+      # @return [Boolean] whether the URL's host matches the Omnitruck host
+      # @api private
+      def omnitruck_host?(url)
+        return false if url.nil? || url.to_s.empty?
+
+        begin
+          uri = URI.parse(url.to_s)
+          host = uri.host
+          host == "omnitruck.chef.io"
+        rescue URI::InvalidURIError
+          false
+        end
+      end
+
       # Returns the appropriate omnibus URL based on whether license_id is provided
       # @return [String] the omnibus URL (commercial/trial or standard omnitruck)
       # @api private
       def omnibus_url_for_license
-        return omnibus_url if license_id.nil? || license_id.to_s.empty? || !omnibus_url.include?("omnitruck.chef.io")
+        return omnibus_url if license_id.nil? || license_id.to_s.empty? || !omnitruck_host?(omnibus_url)
 
         # Determine if this is a trial or commercial license
         base_url = if license_id.start_with?("free-", "trial-")
EOF
@@ -21,6 +21,7 @@
require_relative "generator/powershell"
require_relative "dist"
require "cgi"
require "uri"

module Mixlib
class Install
@@ -220,11 +221,27 @@
end
end

# Returns true if the given URL points to the official Omnitruck host.
# @param url [String] the URL to check
# @return [Boolean] whether the URL's host matches the Omnitruck host
# @api private
def omnitruck_host?(url)
return false if url.nil? || url.to_s.empty?

begin
uri = URI.parse(url.to_s)
host = uri.host
host == "omnitruck.chef.io"
rescue URI::InvalidURIError
false
end
end

# Returns the appropriate omnibus URL based on whether license_id is provided
# @return [String] the omnibus URL (commercial/trial or standard omnitruck)
# @api private
def omnibus_url_for_license
return omnibus_url if license_id.nil? || license_id.to_s.empty? || !omnibus_url.include?("omnitruck.chef.io")
return omnibus_url if license_id.nil? || license_id.to_s.empty? || !omnitruck_host?(omnibus_url)

# Determine if this is a trial or commercial license
base_url = if license_id.start_with?("free-", "trial-")
Copilot is powered by AI and may make mistakes. Always verify output.
@sonarqubecloud
Copy link

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.

2 participants