-
Notifications
You must be signed in to change notification settings - Fork 1
Switch CI to hardened runners and route uv installs through JFrog OIDC #25
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| name: 'Authenticate for JFrog' | ||
| description: 'Authenticate with JFrog using OIDC based on the GitHub repository.' | ||
| outputs: | ||
| jfrog-access-token: | ||
| description: "Access token for JFrog" | ||
| value: "${{ steps.jfrog-auth.outputs.jfrog-access-token }}" | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - id: jfrog-auth | ||
| name: Authenticate against JFrog | ||
| shell: bash | ||
| run: | | ||
| if [[ -z "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]] || [[ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" ]] | ||
| then | ||
| printf '::error::%s\n' 'This action uses OIDC: job must have "id-token: write" permission' | ||
| exit 1 | ||
| fi | ||
| "${GITHUB_ACTION_PATH}/jfrog-auth" "${ACTIONS_ID_TOKEN_REQUEST_URL}" "${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" | ||
|
|
||
| - id: detect-cmds | ||
| name: Detecting package/project managers. | ||
| shell: bash | ||
| run: | | ||
| for cmd in bun coursier mvn npm pip3 sbt uv | ||
| do | ||
| command -v "${cmd}" > /dev/null && found=true || found=false | ||
| printf '::debug::%s\n' "Found ${cmd}: ${found}" | ||
| printf '%s=%s\n' "command_${cmd}" "${found}" >> "${GITHUB_OUTPUT}" | ||
| done | ||
|
|
||
| - name: Configure bun for JFrog | ||
| if: "${{ steps.detect-cmds.outputs.command_bun == 'true' }}" | ||
| shell: bash | ||
| env: | ||
| JFROG_ACCESS_TOKEN: "${{ steps.jfrog-auth.outputs.jfrog-access-token }}" | ||
| run: | | ||
| umask 077 | ||
| cat > ~/.bunfig.toml << 'EOF' | ||
| [install] | ||
| registry = { url = "https://databricks.jfrog.io/artifactory/api/npm/db-npm/", token = "$jfrog_access_token" } | ||
| EOF | ||
| cat > "${RUNNER_TEMP}/.bun.env" << EOF | ||
| jfrog_access_token='${JFROG_ACCESS_TOKEN}' | ||
| EOF | ||
| printf '%s=%s\n' 'BUN_OPTIONS' "--env-file=${RUNNER_TEMP}/.bun.env" >> "${GITHUB_ENV}" | ||
| printf '::debug::%s\n' 'Configured JFrog access for bun.' | ||
| printf '::warning::%s\n' 'JFrog has compatibility issues with bun; it will probably not work.' | ||
|
|
||
| - name: Configure coursier for JFrog | ||
| if: "${{ steps.detect-cmds.outputs.command_coursier == 'true' || | ||
| steps.detect-cmds.outputs.command_sbt == 'true' }}" | ||
| shell: bash | ||
| env: | ||
| JFROG_ACCESS_TOKEN: "${{ steps.jfrog-auth.outputs.jfrog-access-token }}" | ||
| run: | | ||
| umask 077 | ||
| cat > "${RUNNER_TEMP}/.coursier-credentials.properties" << EOF | ||
| jfrog.host=databricks.jfrog.io | ||
| jfrog.realm=Artifactory Realm | ||
| jfrog.username=gha-service-account | ||
| jfrog.password=${JFROG_ACCESS_TOKEN} | ||
| EOF | ||
| printf '%s=%s\n' 'COURSIER_CREDENTIALS' "${RUNNER_TEMP}/.coursier-credentials.properties" >> "${GITHUB_ENV}" | ||
| printf '::debug::%s\n' 'Configured JFrog access for Coursier.' | ||
|
|
||
| - name: Configure Maven for JFrog | ||
| if: "${{ steps.detect-cmds.outputs.command_mvn == 'true' }}" | ||
| shell: bash | ||
| env: | ||
| JFROG_ACCESS_TOKEN: "${{ steps.jfrog-auth.outputs.jfrog-access-token }}" | ||
| run: | | ||
| umask 077 | ||
| mkdir -p ~/.m2 | ||
| cat > ~/.m2/settings.xml << EOF | ||
| <settings> | ||
| <mirrors> | ||
| <mirror> | ||
| <id>jfrog-central</id> | ||
| <mirrorOf>*</mirrorOf> | ||
| <url>https://databricks.jfrog.io/artifactory/db-maven/</url> | ||
| </mirror> | ||
| </mirrors> | ||
| <servers> | ||
| <server> | ||
| <id>jfrog-central</id> | ||
| <username>gha-service-account</username> | ||
| <password>${JFROG_ACCESS_TOKEN}</password> | ||
| </server> | ||
| </servers> | ||
| </settings> | ||
| EOF | ||
| printf '::debug::%s\n' 'Configured JFrog access for maven.' | ||
|
|
||
| - name: Configure netrc for JFrog | ||
| if: "${{ steps.detect-cmds.outputs.command_pip3 == 'true' || | ||
| steps.detect-cmds.outputs.command_uv == 'true' }}" | ||
| shell: bash | ||
| env: | ||
| JFROG_ACCESS_TOKEN: "${{ steps.jfrog-auth.outputs.jfrog-access-token }}" | ||
| run: | | ||
| umask 077 | ||
| cat > "${RUNNER_TEMP}/.netrc" << EOF | ||
| machine databricks.jfrog.io | ||
| login gha-service-account | ||
| password ${JFROG_ACCESS_TOKEN} | ||
| EOF | ||
| printf '%s=%s\n' 'NETRC' "${RUNNER_TEMP}/.netrc" >> "${GITHUB_ENV}" | ||
|
|
||
| - name: Configure npm/yarn (classic) for JFrog | ||
| if: "${{ steps.detect-cmds.outputs.command_npm == 'true' }}" | ||
| shell: bash | ||
| env: | ||
| JFROG_ACCESS_TOKEN: "${{ steps.jfrog-auth.outputs.jfrog-access-token }}" | ||
| run: | | ||
| umask 077 | ||
| cat > ~/.npmrc << EOF | ||
| registry=https://databricks.jfrog.io/artifactory/api/npm/db-npm/ | ||
| always-auth=true | ||
| ignore-scripts=true | ||
| //databricks.jfrog.io/artifactory/api/npm/db-npm/:_authToken=${JFROG_ACCESS_TOKEN} | ||
| EOF | ||
| printf '::debug::%s\n' 'Configured JFrog access for npm/yarn (classic).' | ||
|
|
||
| - name: Configure pip for JFrog | ||
| if: "${{ steps.detect-cmds.outputs.command_pip3 == 'true' }}" | ||
| shell: bash | ||
| run: | | ||
| cat > "${RUNNER_TEMP}/.pip.conf" << 'EOF' | ||
| [global] | ||
| index-url = https://databricks.jfrog.io/artifactory/api/pypi/db-pypi/simple | ||
| EOF | ||
| printf '%s=%s\n' 'PIP_CONFIG_FILE' "${RUNNER_TEMP}/.pip.conf" >> "${GITHUB_ENV}" | ||
| printf '::debug::%s\n' 'Configured JFrog access for pip.' | ||
|
|
||
| - name: Configure sbt for JFrog | ||
| if: "${{ steps.detect-cmds.outputs.command_sbt == 'true' }}" | ||
| shell: bash | ||
| env: | ||
| JFROG_ACCESS_TOKEN: "${{ steps.jfrog-auth.outputs.jfrog-access-token }}" | ||
| run: | | ||
| umask 077 | ||
| mkdir -p ~/.sbt/1.0 | ||
| cat > ~/.sbt/repositories << 'EOF' | ||
| [repositories] | ||
| local | ||
| databricks-jfrog: https://databricks.jfrog.io/artifactory/db-maven/ | ||
| EOF | ||
|
|
||
| cat > "${RUNNER_TEMP}/.sbt.credentials" << EOF | ||
| realm=Artifactory Realm | ||
| host=databricks.jfrog.io | ||
| user=gha-service-account | ||
| password=${JFROG_ACCESS_TOKEN} | ||
| EOF | ||
|
|
||
| cat > ~/.sbt/1.0/global.sbt << 'EOF' | ||
| credentials += Credentials(file(sys.env("RUNNER_TEMP")) / ".sbt.credentials") | ||
| EOF | ||
| printf '::debug::%s\n' 'Configured JFrog access for SBT.' | ||
|
|
||
| - name: Configure uv for JFrog | ||
| if: "${{ steps.detect-cmds.outputs.command_uv == 'true' }}" | ||
| shell: bash | ||
| env: | ||
| UV_INDEX_URL: 'https://databricks.jfrog.io/artifactory/api/pypi/db-pypi/simple' | ||
| run: | | ||
| printf '%s=%s\n' 'UV_INDEX_URL' "${UV_INDEX_URL}" >> "${GITHUB_ENV}" | ||
| printf '%s=%s\n' 'UV_FROZEN' '1' >> "${GITHUB_ENV}" | ||
| printf '::debug::%s\n' 'Configured JFrog access for uv.' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/bin/sh | ||
| set -eu | ||
|
|
||
| _request_url="$1" | ||
| _request_token="$2" | ||
|
|
||
| printf '::debug::%s\n' "Fetching OIDC identifier token from GitHub..." | ||
| _id_token="$(curl -sLS \ | ||
| -H 'User-Agent: actions/oidc-client' \ | ||
| -H "Authorization: Bearer ${_request_token}" \ | ||
| "${_request_url}&audience=jfrog-github" | | ||
| jq -r .value)" | ||
| printf '::add-mask::%s\n' "${_id_token}" | ||
|
|
||
| printf '::debug::%s\n' "Exchanging OIDC identifier token for JFrog access token..." | ||
| _access_token=$(curl -fsSL \ | ||
| --json "{\"grant_type\": \"urn:ietf:params:oauth:grant-type:token-exchange\", \"subject_token_type\":\"urn:ietf:params:oauth:token-type:id_token\", \"subject_token\": \"${_id_token}\", \"provider_name\": \"github-actions\"}" \ | ||
| "https://databricks.jfrog.io/access/api/v1/oidc/token" | | ||
| jq -r .access_token) | ||
| printf '::add-mask::%s\n' "${_access_token}" | ||
|
|
||
| if [ -z "${_access_token}" ] || [ "${_access_token}" = 'null' ] | ||
| then | ||
| printf '::error::%s\n' "Could not fetch JFrog access token." | ||
| exit 1 | ||
| fi | ||
|
|
||
| printf '%s=%s\n' 'jfrog-access-token' "${_access_token}" >> "${GITHUB_OUTPUT}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.