@@ -19,35 +19,76 @@ inputs:
1919 description : " where the CTK components will be installed to, relative to $PWD"
2020 required : false
2121 default : " ./cuda_toolkit"
22+ redist-base-url :
23+ description : >
24+ Base URL of a redistrib server (manifest and component archives).
25+ Defaults to the public NVIDIA developer server.
26+ Override to install from an alternate redistrib server.
27+ required : false
28+ default : " https://developer.download.nvidia.com/compute/cuda/redist"
2229
2330runs :
2431 using : composite
2532 steps :
33+ - name : Install Unix dependencies
34+ if : ${{ runner.os == 'Linux' }}
35+ uses : ./.github/actions/install_unix_deps
36+ with :
37+ dependencies : " zstd curl xz-utils"
38+ dependent_exes : " zstd curl xz"
39+
40+ - name : Install Windows dependencies
41+ if : ${{ runner.os == 'Windows' }}
42+ uses : ./.github/actions/install_windows_deps
43+ with :
44+ dependent_exes : " curl unzip tar sha256sum cygpath"
45+
2646 - name : Set up CTK cache variable
2747 shell : bash --noprofile --norc -xeuo pipefail {0}
2848 run : |
29- # Pre-process the component list to ensure hash uniqueness
3049 # Use the runtime workspace mount so this also works inside container jobs.
3150 CTK_REDIST_TOOL="${GITHUB_WORKSPACE}/ci/tools/fetch_ctk_redistrib.py"
32- CTK_CACHE_COMPONENTS=${{ inputs.cuda-components }}
33- CTK_JSON_URL="https://developer.download.nvidia.com/compute/cuda/redist/redistrib_${{ inputs.cuda-version }}.json"
51+ CTK_BASE_URL="${{ inputs.redist-base-url }}"
52+ # A trailing slash would defeat the public-server comparison below and double up in URLs.
53+ CTK_BASE_URL="${CTK_BASE_URL%/}"
54+ # RUNNER_TEMP persists across steps, so "Get CUDA components" reuses this file.
55+ CTK_JSON_FILE="$RUNNER_TEMP/redistrib-${{ inputs.cuda-version }}.json"
56+ curl -LSs --fail --retry 3 --retry-delay 2 "${CTK_BASE_URL}/redistrib_${{ inputs.cuda-version }}.json" -o "$CTK_JSON_FILE"
57+
58+ # Pin the metadata JSON: the per-archive sha256 checks below are only
59+ # trustworthy if the JSON that carries those hashes is itself trusted.
60+ # The pins describe the public server; alternate servers only warn.
61+ if [[ "$CTK_BASE_URL" == "https://developer.download.nvidia.com/compute/cuda/redist" ]]; then
62+ METADATA_SOURCE=public
63+ else
64+ METADATA_SOURCE=custom
65+ fi
66+ python "$CTK_REDIST_TOOL" verify-metadata \
67+ --cuda-version "${{ inputs.cuda-version }}" \
68+ --metadata-path "$CTK_JSON_FILE" \
69+ --metadata-source "$METADATA_SOURCE"
70+
71+ # Pre-process the component list to ensure hash uniqueness
3472 CTK_CACHE_COMPONENTS="$(python "$CTK_REDIST_TOOL" filter-components \
3573 --host-platform "${{ inputs.host-platform }}" \
3674 --cuda-version "${{ inputs.cuda-version }}" \
37- --components "$CTK_CACHE_COMPONENTS " \
38- --metadata-url "$CTK_JSON_URL ")"
75+ --components "${{ inputs.cuda-components }} " \
76+ --metadata-path "$CTK_JSON_FILE ")"
3977
78+ # Alternate redist servers (non-default) publish different manifests for the
79+ # same CUDA version; keying on the full manifest hash keeps them from restoring
80+ # each other's toolkit (a truncated hash could be collided on purpose).
81+ # Hash via stdin: with a backslash in the path (Windows RUNNER_TEMP), sha256sum
82+ # prefixes its output line with "\", which would end up in the cache key.
83+ MANIFEST_SHA256="$(sha256sum < "$CTK_JSON_FILE" | awk '{print $1}')"
4084 HASH=$(echo -n "${CTK_CACHE_COMPONENTS}" | sha256sum | awk '{print $1}')
41- echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}-$HASH" >> $GITHUB_ENV
42- echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}-$HASH.tar.gz" >> $GITHUB_ENV
43- echo "CTK_CACHE_COMPONENTS=${CTK_CACHE_COMPONENTS}" >> $GITHUB_ENV
44-
45- - name : Install dependencies
46- uses : ./.github/actions/install_unix_deps
47- continue-on-error : false
48- with :
49- dependencies : " zstd curl xz-utils"
50- dependent_exes : " zstd curl xz"
85+ {
86+ echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}-$HASH-m$MANIFEST_SHA256"
87+ echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}-$HASH-m$MANIFEST_SHA256.tar.gz"
88+ echo "CTK_CACHE_COMPONENTS=${CTK_CACHE_COMPONENTS}"
89+ echo "CTK_BASE_URL=${CTK_BASE_URL}"
90+ echo "CTK_JSON_FILE=${CTK_JSON_FILE}"
91+ } >> "$GITHUB_ENV"
5192
5293 - name : Download CTK cache
5394 id : ctk-get-cache
@@ -68,13 +109,10 @@ runs:
68109 rm -rf $CACHE_TMP_DIR
69110 mkdir $CACHE_TMP_DIR
70111
71- # The binary archives (redist) are guaranteed to be updated as part of the release posting.
72112 # Use the runtime workspace mount so this also works inside container jobs.
73113 CTK_REDIST_TOOL="${GITHUB_WORKSPACE}/ci/tools/fetch_ctk_redistrib.py"
74- CTK_BASE_URL="https://developer.download.nvidia.com/compute/cuda/redist/"
75- CTK_JSON_URL="$CTK_BASE_URL/redistrib_${{ inputs.cuda-version }}.json"
76- CTK_JSON_FILE="$CACHE_TMP_DIR/redistrib.json"
77- curl -LSs "$CTK_JSON_URL" -o "$CTK_JSON_FILE"
114+ # CTK_BASE_URL and the verified manifest at CTK_JSON_FILE come from
115+ # "Set up CTK cache variable".
78116 if [[ "${{ inputs.host-platform }}" == linux* ]]; then
79117 function extract() {
80118 tar -xvf $1 -C $CACHE_TMP_DIR --strip-components=1
@@ -102,6 +140,13 @@ runs:
102140 CTK_COMPONENT_URL="${CTK_BASE_URL}/${CTK_COMPONENT_REL_PATH}"
103141 CTK_COMPONENT_COMPONENT_FILENAME="$(basename $CTK_COMPONENT_REL_PATH)"
104142 download $CTK_COMPONENT_URL $CTK_COMPONENT_COMPONENT_FILENAME
143+ # Verify the downloaded archive against the sha256 in the (pinned)
144+ # metadata before extracting; fail closed on any mismatch.
145+ CTK_COMPONENT_SHA256="$(python "$CTK_REDIST_TOOL" component-sha256 \
146+ --host-platform "${{ inputs.host-platform }}" \
147+ --component "$CTK_COMPONENT" \
148+ --metadata-path "$CTK_JSON_FILE")"
149+ echo "${CTK_COMPONENT_SHA256} ${CTK_COMPONENT_COMPONENT_FILENAME}" | sha256sum --check --strict -
105150 extract $CTK_COMPONENT_COMPONENT_FILENAME
106151 rm $CTK_COMPONENT_COMPONENT_FILENAME
107152 }
0 commit comments