diff --git a/.github/dotslash-provisioned-config.json b/.github/dotslash-provisioned-config.json new file mode 100644 index 0000000000..2f7363ed06 --- /dev/null +++ b/.github/dotslash-provisioned-config.json @@ -0,0 +1,16 @@ +{ + "outputs": { + "codex-provisioned": { + "platforms": { + "macos-aarch64": { + "regex": "^codex-provisioned-package-aarch64-apple-darwin\\.tar\\.gz$", + "path": "bin/codex" + }, + "macos-x86_64": { + "regex": "^codex-provisioned-package-x86_64-apple-darwin\\.tar\\.gz$", + "path": "bin/codex" + } + } + } + } +} diff --git a/.github/scripts/build-codex-package-archive.sh b/.github/scripts/build-codex-package-archive.sh index 7b5ac74865..1ac54c0cce 100644 --- a/.github/scripts/build-codex-package-archive.sh +++ b/.github/scripts/build-codex-package-archive.sh @@ -15,7 +15,7 @@ Usage: build-codex-package-archive.sh \ [--zsh-manifest ] \ [--codex-command-runner-bin ] \ [--codex-windows-sandbox-setup-bin ] \ - [--voice-signed-dir --release-version ] \ + [--voice-release-dir --release-version ] \ [--target-suffixed-entrypoint] EOF } @@ -30,7 +30,7 @@ bwrap_bin_provided="false" code_mode_host_bin_provided="false" command_runner_bin_provided="false" sandbox_setup_bin_provided="false" -voice_signed_dir="" +voice_release_dir="" release_version="" while [[ $# -gt 0 ]]; do @@ -93,8 +93,8 @@ while [[ $# -gt 0 ]]; do target_suffixed_entrypoint="true" shift ;; - --voice-signed-dir) - voice_signed_dir="${2:?--voice-signed-dir requires a value}" + --voice-release-dir) + voice_release_dir="${2:?--voice-release-dir requires a value}" shift 2 ;; --release-version) @@ -117,8 +117,8 @@ if [[ -z "$target" || -z "$bundle" || -z "$entrypoint_dir" || -z "$archive_dir" usage >&2 exit 1 fi -if [[ ( -n "$voice_signed_dir" || -n "$release_version" ) && ( -z "$voice_signed_dir" || -z "$release_version" || "$bundle" != "primary" || "$target" != *-apple-darwin ) ]]; then - echo "Signed voice resources require a primary macOS release package version" >&2 +if [[ ( -n "$voice_release_dir" || -n "$release_version" ) && ( -z "$voice_release_dir" || -z "$release_version" || "$bundle" != "primary" || ( "$target" != *-apple-darwin && "$target" != *-unknown-linux-musl ) ) ]]; then + echo "Voice resources require a primary macOS or Linux release package version" >&2 exit 1 fi @@ -204,7 +204,7 @@ python_args=( --cargo-profile release --package-dir "$package_dir" ) -if [[ -z "$voice_signed_dir" ]]; then +if [[ -z "$voice_release_dir" ]]; then python_args+=(--archive-output "$gzip_archive_path" --archive-output "$zstd_archive_path") fi if ((${#resource_args[@]} > 0)); then @@ -214,14 +214,18 @@ python_args+=(--force) "$python_bin" "${python_args[@]}" -if [[ -n "$voice_signed_dir" ]]; then +if [[ -n "$voice_release_dir" ]]; then + voice_target="$target" + if [[ "$target" == *-unknown-linux-musl ]]; then + voice_target="${target%-musl}-gnu" + fi voice_package="${RUNNER_TEMP:-/tmp}/${archive_stem}-voice-${target}" rm -rf "$voice_package" "$python_bin" "${repo_root}/third_party/voice/assemble_package.py" \ --package "$package_dir" \ - --helper "${voice_signed_dir%/}/codex-voice-host" \ - --runtime "${voice_signed_dir%/}/runtime" \ - --voice-target "$target" \ + --helper "${voice_release_dir%/}/codex-voice-host" \ + --runtime "${voice_release_dir%/}/runtime" \ + --voice-target "$voice_target" \ --build-commit "$(git -C "$repo_root" rev-parse HEAD)" \ --release-version "$release_version" \ --output "$voice_package" diff --git a/.github/workflows/rust-release-provisioned-macos.yml b/.github/workflows/rust-release-provisioned-macos.yml index d131835618..6d1b24591f 100644 --- a/.github/workflows/rust-release-provisioned-macos.yml +++ b/.github/workflows/rust-release-provisioned-macos.yml @@ -1,4 +1,5 @@ -# Optional side artifacts only; no release, npm, installer, or DMG publication. +# Verified side packages, published by rust-release.yml when enabled. +# The legacy CLI, npm, installer and DMG packages are unchanged. # Required secrets in the codesigning environment: # - CODEX_CLI_PROVISIONING_PROFILE_BASE64: profile approved for public distribution. # - CODEX_CLI_PROVISIONING_PROFILE_SHA256: reviewed lowercase SHA-256 of that profile. diff --git a/.github/workflows/rust-release.yml b/.github/workflows/rust-release.yml index d351371dfa..b3863a0e4c 100644 --- a/.github/workflows/rust-release.yml +++ b/.github/workflows/rust-release.yml @@ -61,9 +61,8 @@ jobs: needs: tag-check name: Build - ${{ matrix.runner }} - ${{ matrix.target }} - ${{ matrix.bundle }} runs-on: ${{ matrix.runs_on || matrix.runner }} - # Release builds can take a long time, so leave some headroom to avoid - # having to restart the full workflow due to a timeout. - timeout-minutes: 90 + # Linux releases also build the native voice runtime in this job. + timeout-minutes: 120 permissions: contents: read id-token: write @@ -292,6 +291,37 @@ jobs: path: codex-rs/symbols-dist/${{ matrix.artifact_name }}/* if-no-files-found: error + - name: Set up Bazel for Linux voice + if: ${{ matrix.bundle == 'primary' && contains(matrix.target, 'linux') }} + uses: bazel-contrib/setup-bazel@c5acdfb288317d0b5c0bbd7a396a3dc868bb0f86 # 0.19.0 + with: + bazelisk-version: 1.28.1 + + - name: Build Linux voice runtime + if: ${{ matrix.bundle == 'primary' && contains(matrix.target, 'linux') }} + shell: bash + env: + APP_TARGET: ${{ matrix.target }} + run: | + set -euo pipefail + cd "$GITHUB_WORKSPACE" + voice_target="${APP_TARGET%-musl}-gnu" + case "$voice_target" in + aarch64-unknown-linux-gnu) prefix=linux_aarch64 ;; + x86_64-unknown-linux-gnu) prefix=linux_x86_64 ;; + *) exit 1 ;; + esac + bazel build -c opt //codex-rs/voice-host:codex-voice-host //third_party/voice:native_runtime + source="bazel-bin/third_party/voice/native_runtime_${prefix}" + output="${RUNNER_TEMP}/signed-voice/${APP_TARGET}" + mkdir -p "$output" + python3 third_party/voice/release_runtime.py stage \ + --target "$voice_target" --source "$source" --output "$output/runtime" + cp bazel-bin/codex-rs/voice-host/codex-voice-host "$output/codex-voice-host" + chmod 0755 "$output/codex-voice-host" + python3 third_party/voice/release_runtime.py seal \ + --target "$voice_target" --output "$output/runtime" + - if: ${{ runner.os == 'macOS' }} name: Stage unsigned macOS artifacts shell: bash @@ -376,12 +406,26 @@ jobs: BUNDLE: ${{ matrix.bundle }} run: | set -euo pipefail + voice_args=() + if [[ "$BUNDLE" == "primary" && "$TARGET" == *-unknown-linux-musl ]]; then + voice_args+=(--voice-release-dir "${RUNNER_TEMP}/signed-voice/${TARGET}") + voice_args+=(--release-version "${GITHUB_REF_NAME#rust-v}") + fi bash "${GITHUB_WORKSPACE}/.github/scripts/build-codex-package-archive.sh" \ --target "$TARGET" \ --bundle "$BUNDLE" \ --entrypoint-dir "target/${TARGET}/release" \ --archive-dir "dist/${TARGET}" \ - --zsh-manifest "${RUNNER_TEMP}/codex-zsh" + --zsh-manifest "${RUNNER_TEMP}/codex-zsh" \ + "${voice_args[@]}" + + - name: Cosign Linux voice package archives + if: ${{ matrix.bundle == 'primary' && contains(matrix.target, 'linux') }} + uses: ./.github/actions/linux-code-sign + with: + target: ${{ matrix.target }} + artifacts-dir: ${{ github.workspace }}/codex-rs/dist/${{ matrix.target }} + binaries: codex-package-${{ matrix.target }}.tar.gz codex-package-${{ matrix.target }}.tar.zst - name: Build Python runtime wheel if: ${{ matrix.bundle == 'primary' && runner.os != 'macOS' }} @@ -413,13 +457,31 @@ jobs: # the Homebrew Python as externally managed under PEP 668. "${RUNNER_TEMP}/python-runtime-build-venv/bin/python" -m pip install build + # Keep the existing manylinux_2_17 wheel compatible with older glibc. + # GNU voice libraries belong in the signed release package archives, + # but their minimum glibc version is not covered by this wheel tag. + wheel_archives="${RUNNER_TEMP}/voice-free-wheel/${{ matrix.target }}" + bash "${GITHUB_WORKSPACE}/.github/scripts/build-codex-package-archive.sh" \ + --target "${{ matrix.target }}" \ + --bundle primary \ + --entrypoint-dir "target/${{ matrix.target }}/release" \ + --archive-dir "$wheel_archives" \ + --zsh-manifest "${RUNNER_TEMP}/codex-zsh" + wheel_archive="${wheel_archives}/codex-package-${{ matrix.target }}.tar.gz" + python3 - "$wheel_archive" <<'PY' + import sys + import tarfile + with tarfile.open(sys.argv[1]) as archive: + assert not any("codex-resources/voice/" in item.name for item in archive) + PY + stage_dir="${RUNNER_TEMP}/openai-codex-cli-bin-${{ matrix.target }}" wheel_dir="${GITHUB_WORKSPACE}/python-runtime-dist/${{ matrix.target }}" stage_runtime_args=( "${GITHUB_WORKSPACE}/sdk/python/scripts/update_sdk_artifacts.py" stage-runtime "$stage_dir" - "dist/${{ matrix.target }}/codex-package-${{ matrix.target }}.tar.gz" + "$wheel_archive" --codex-version "${GITHUB_REF_NAME}" --platform-tag "$platform_tag" ) @@ -915,7 +977,7 @@ jobs: set -euo pipefail voice_args=() if [[ "$BUNDLE" == "primary" ]]; then - voice_args+=(--voice-signed-dir "${RUNNER_TEMP}/signed-voice/${TARGET}") + voice_args+=(--voice-release-dir "${RUNNER_TEMP}/signed-voice/${TARGET}") voice_args+=(--release-version "${GITHUB_REF_NAME#rust-v}") fi bash "${GITHUB_WORKSPACE}/.github/scripts/build-codex-package-archive.sh" \ @@ -1394,7 +1456,8 @@ jobs: path: codex-rs/dist/${{ matrix.target }}/* if-no-files-found: error - # Separate opt-in candidates never enter the normal release download patterns. + # Keep provisioned packages separate from the legacy CLI/npm/installer layout. + # Desktop consumes the versioned codex-provisioned manifest from this release. provisioned-macos-candidate: needs: finalize-macos if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/rust-v') && vars.CODEX_PROVISIONED_MACOS_CANDIDATE == 'true' @@ -1476,6 +1539,7 @@ jobs: - build-windows - argument-comment-lint-release-assets - stage-npm-packages + - provisioned-macos-candidate if: >- ${{ always() && @@ -1484,7 +1548,10 @@ jobs: needs.finalize-macos.result == 'success' && needs.build-windows.result == 'success' && needs.argument-comment-lint-release-assets.result == 'success' && - needs.stage-npm-packages.result == 'success' + needs.stage-npm-packages.result == 'success' && + (needs.provisioned-macos-candidate.result == 'success' || + (vars.CODEX_PROVISIONED_MACOS_CANDIDATE != 'true' && + needs.provisioned-macos-candidate.result == 'skipped')) }} name: release runs-on: ubuntu-latest @@ -1536,6 +1603,17 @@ jobs: path: dist pattern: "{*-symbols,argument-comment-lint-*,python-runtime-wheel-*}" + - name: Download verified provisioned macOS packages + if: vars.CODEX_PROVISIONED_MACOS_CANDIDATE == 'true' + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + path: dist + pattern: "provisioned-macos-verified-candidate-*" + + - name: Remove per-architecture checksum filenames before release upload + if: vars.CODEX_PROVISIONED_MACOS_CANDIDATE == 'true' + run: rm dist/provisioned-macos-verified-candidate-*/SHA256SUMS + - name: List run: ls -R dist/ @@ -1546,7 +1624,7 @@ jobs: manifest="dist/codex-package_SHA256SUMS" tmp_manifest="$(mktemp)" find dist -type f \ - \( -name 'codex-package-*.tar.gz' -o -name 'codex-app-server-package-*.tar.gz' \) \ + \( -name 'codex-package-*.tar.gz' -o -name 'codex-app-server-package-*.tar.gz' -o -name 'codex-provisioned-package-*.tar.gz' \) \ -print | sort | while IFS= read -r archive; do @@ -1676,6 +1754,15 @@ jobs: tag: ${{ github.ref_name }} config: .github/dotslash-argument-comment-lint-config.json + - name: Publish the provisioned macOS package manifest + if: vars.CODEX_PROVISIONED_MACOS_CANDIDATE == 'true' + uses: facebook/dotslash-publish-release@9c9ec027515c34db9282a09a25a9cab5880b2c52 # v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag: ${{ github.ref_name }} + config: .github/dotslash-provisioned-config.json + # Publish to npm using OIDC authentication. # July 31, 2025: https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/ # npm docs: https://docs.npmjs.com/trusted-publishers diff --git a/MODULE.bazel b/MODULE.bazel index 6f74ef307b..e014c6d32c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -142,6 +142,11 @@ use_repo(osx, "macos_sdk") # Needed to disable xcode... bazel_dep(name = "apple_support", version = "2.1.0") bazel_dep(name = "rules_cc", version = "0.2.18") + +# Windows voice jobs explicitly select the installed MSVC C toolchains. +cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension") +use_repo(cc_configure, "local_config_cc") + single_version_override( module_name = "rules_cc", patch_strip = 1, diff --git a/codex-rs/windows-sandbox-rs/src/acl.rs b/codex-rs/windows-sandbox-rs/src/acl.rs index 064b7fe6fb..8818d89a4e 100644 --- a/codex-rs/windows-sandbox-rs/src/acl.rs +++ b/codex-rs/windows-sandbox-rs/src/acl.rs @@ -21,9 +21,12 @@ use windows_sys::Win32::Security::ACE_HEADER; use windows_sys::Win32::Security::ACL; use windows_sys::Win32::Security::ACL_SIZE_INFORMATION; use windows_sys::Win32::Security::AclSizeInformation; +use windows_sys::Win32::Security::Authorization::ACCESS_MODE; use windows_sys::Win32::Security::Authorization::EXPLICIT_ACCESS_W; +use windows_sys::Win32::Security::Authorization::GRANT_ACCESS; use windows_sys::Win32::Security::Authorization::GetNamedSecurityInfoW; use windows_sys::Win32::Security::Authorization::GetSecurityInfo; +use windows_sys::Win32::Security::Authorization::SET_ACCESS; use windows_sys::Win32::Security::Authorization::SetEntriesInAclW; use windows_sys::Win32::Security::Authorization::SetNamedSecurityInfoW; use windows_sys::Win32::Security::Authorization::SetSecurityInfo; @@ -68,6 +71,8 @@ const ACCESS_ALLOWED_ACE_TYPE: u8 = 0; const ACCESS_DENIED_ACE_TYPE: u8 = 1; const GENERIC_READ_MASK: u32 = 0x8000_0000; const GENERIC_WRITE_MASK: u32 = 0x4000_0000; +const GENERIC_EXECUTE_MASK: u32 = 0x2000_0000; +const GENERIC_ALL_MASK: u32 = 0x1000_0000; const DENY_ACCESS: i32 = 3; // TrustedInstaller is a deterministic service SID, not a machine-local account SID. const TRUSTED_INSTALLER_SID: &str = @@ -444,6 +449,10 @@ pub unsafe fn dacl_has_write_deny_for_sid(p_dacl: *mut ACL, psid: *mut c_void) - } pub unsafe fn dacl_has_read_deny_for_sid(p_dacl: *mut ACL, psid: *mut c_void) -> bool { + dacl_has_deny_mask_for_sid(p_dacl, psid, FILE_GENERIC_READ | GENERIC_READ_MASK) +} + +unsafe fn dacl_has_deny_mask_for_sid(p_dacl: *mut ACL, psid: *mut c_void, deny_mask: u32) -> bool { if p_dacl.is_null() { return false; } @@ -457,7 +466,6 @@ pub unsafe fn dacl_has_read_deny_for_sid(p_dacl: *mut ACL, psid: *mut c_void) -> if ok == 0 { return false; } - let deny_read_mask = FILE_GENERIC_READ | GENERIC_READ_MASK; for i in 0..info.AceCount { let mut p_ace: *mut c_void = std::ptr::null_mut(); if GetAce(p_dacl as *const ACL, i, &mut p_ace) == 0 { @@ -474,7 +482,7 @@ pub unsafe fn dacl_has_read_deny_for_sid(p_dacl: *mut ACL, psid: *mut c_void) -> let base = p_ace as usize; let sid_ptr = (base + std::mem::size_of::() + std::mem::size_of::()) as *mut c_void; - if EqualSid(sid_ptr, psid) != 0 && (ace.Mask & deny_read_mask) != 0 { + if EqualSid(sid_ptr, psid) != 0 && (ace.Mask & deny_mask) != 0 { return true; } } @@ -522,17 +530,33 @@ unsafe fn ensure_allow_mask_aces_with_inheritance_impl( sids: &[*mut c_void], allow_mask: u32, disallow_mask: u32, + access_mode: ACCESS_MODE, inheritance: u32, ) -> Result { let (p_dacl, p_sd) = fetch_dacl_handle(path)?; let mut entries: Vec = Vec::new(); for sid in sids { + // An explicit allow can outrank an inherited deny. All file generic rights + // overlap read/execute through READ_CONTROL or SYNCHRONIZE. + if access_mode == GRANT_ACCESS + && dacl_has_deny_mask_for_sid( + p_dacl, + *sid, + allow_mask + | GENERIC_READ_MASK + | GENERIC_WRITE_MASK + | GENERIC_EXECUTE_MASK + | GENERIC_ALL_MASK, + ) + { + continue; + } if !dacl_allow_mask_needs_refresh(p_dacl, *sid, allow_mask, disallow_mask) { continue; } entries.push(EXPLICIT_ACCESS_W { grfAccessPermissions: allow_mask, - grfAccessMode: 2, // SET_ACCESS + grfAccessMode: access_mode, grfInheritance: inheritance, Trustee: TRUSTEE_W { pMultipleTrustee: std::ptr::null_mut(), @@ -605,6 +629,27 @@ pub unsafe fn ensure_allow_mask_aces_with_inheritance( sids, allow_mask, /*disallow_mask*/ 0, + SET_ACCESS, + inheritance, + ) +} + +/// Ensure read/execute grants without replacing existing entries or overriding denies. +/// Returns true if any ACE was added. +/// +/// # Safety +/// Caller must pass valid SID pointers and an existing path. +pub unsafe fn grant_read_execute_aces( + path: &Path, + sids: &[*mut c_void], + inheritance: u32, +) -> Result { + ensure_allow_mask_aces_with_inheritance_impl( + path, + sids, + FILE_GENERIC_READ | FILE_GENERIC_EXECUTE, + /*disallow_mask*/ 0, + GRANT_ACCESS, inheritance, ) } @@ -638,6 +683,7 @@ pub unsafe fn ensure_allow_write_aces(path: &Path, sids: &[*mut c_void]) -> Resu sids, WRITE_ALLOW_MASK, FILE_DELETE_CHILD, + SET_ACCESS, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, ) } diff --git a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs index f80efe4d12..95ca3fe473 100644 --- a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs +++ b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs @@ -344,28 +344,42 @@ fn lock_sandbox_dir( let system_sid = resolve_sid("SYSTEM")?; let admins_sid = resolve_sid("Administrators")?; let real_sid = resolve_sid(real_user)?; - let entries = [ + let inherited = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + let mut entries = vec![ ( sandbox_group_sid.to_vec(), sandbox_group_mask, sandbox_group_access_mode, + inherited, ), ( system_sid, FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE, GRANT_ACCESS, + inherited, ), ( admins_sid, FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE, GRANT_ACCESS, + inherited, + ), + ( + real_sid.clone(), + real_user_mask & !WRITE_DAC, + GRANT_ACCESS, + inherited, ), - (real_sid, real_user_mask, GRANT_ACCESS), ]; + // Permission maintenance belongs to the trusted caller on this directory, + // not to the helper files and directories that inherit its content access. + if real_user_mask & WRITE_DAC != 0 { + entries.push((real_sid, WRITE_DAC, GRANT_ACCESS, 0)); + } unsafe { let mut eas: Vec = Vec::new(); let mut sids: Vec<*mut c_void> = Vec::new(); - for (sid_bytes, mask, access_mode) in entries.iter().map(|(s, m, a)| (s, *m, *a)) { + for (sid_bytes, mask, access_mode, inheritance) in &entries { let sid_str = string_from_sid_bytes(sid_bytes).map_err(anyhow::Error::msg)?; let sid_w = to_wide(OsStr::new(&sid_str)); let mut psid: *mut c_void = std::ptr::null_mut(); @@ -377,9 +391,9 @@ fn lock_sandbox_dir( } sids.push(psid); eas.push(EXPLICIT_ACCESS_W { - grfAccessPermissions: mask, - grfAccessMode: access_mode, - grfInheritance: OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE, + grfAccessPermissions: *mask, + grfAccessMode: *access_mode, + grfInheritance: *inheritance, Trustee: TRUSTEE_W { pMultipleTrustee: std::ptr::null_mut(), MultipleTrusteeOperation: 0, @@ -816,7 +830,9 @@ fn lock_sandbox_bin_dir(payload: &Payload, sandbox_group_sid: &[u8]) -> Result<( sandbox_group_sid, GRANT_ACCESS, FILE_GENERIC_READ | FILE_GENERIC_EXECUTE, - FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE, + // Elevated provisioning may own this directory as Administrators. + // The following ordinary refresh must be able to retain its protected ACL. + FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE | WRITE_DAC, DaclInheritance::Protected, payload.mode, ) diff --git a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/setup_runtime_bin.rs b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/setup_runtime_bin.rs index 176ef07504..cdd3a77bc5 100644 --- a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/setup_runtime_bin.rs +++ b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/setup_runtime_bin.rs @@ -1,10 +1,14 @@ use std::ffi::c_void; use std::io::Write; use std::os::windows::fs::MetadataExt as _; +use std::path::Path; use std::path::PathBuf; +use anyhow::Context; use anyhow::Result; +use anyhow::ensure; use codex_windows_sandbox::ensure_allow_mask_aces_with_inheritance; +use codex_windows_sandbox::grant_read_execute_aces; use codex_windows_sandbox::path_mask_allows; use windows_sys::Win32::Security::CONTAINER_INHERIT_ACE; use windows_sys::Win32::Security::OBJECT_INHERIT_ACE; @@ -22,8 +26,9 @@ pub(super) fn ensure_codex_app_runtime_paths_readable( log: &mut dyn Write, ) -> Result<()> { let read_execute_mask = FILE_GENERIC_READ | FILE_GENERIC_EXECUTE; + let local_app_data = local_app_data_root(); let runtime_paths = runtime_paths( - local_app_data_root(), + local_app_data.clone(), std::env::var_os("USERPROFILE").map(PathBuf::from), ); @@ -89,6 +94,93 @@ pub(super) fn ensure_codex_app_runtime_paths_readable( )?; } } + if let Some(local_app_data) = local_app_data { + let runtime_root = local_app_data.join("OpenAI").join("Codex").join("runtimes"); + if let Err(err) = ensure_runtime_tree_readable(&runtime_root, sandbox_group_psid) { + let message = format!("runtime read/execute validation failed: {err:#}"); + super::log_line(log, &message)?; + refresh_errors.push(message); + } + } + Ok(()) +} + +fn ensure_runtime_tree_readable( + runtime_root: &Path, + sandbox_group_psid: *mut c_void, +) -> Result<()> { + for ancestor in runtime_root.ancestors() { + let metadata = match std::fs::symlink_metadata(ancestor) { + Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(()), + result => result + .with_context(|| format!("inspect runtime ancestor {}", ancestor.display()))?, + }; + if !metadata.is_dir() || metadata.file_attributes() & FILE_ATTRIBUTE_REPARSE_POINT != 0 { + return Ok(()); + } + } + + let read_execute_mask = FILE_GENERIC_READ | FILE_GENERIC_EXECUTE; + let mut paths = vec![runtime_root.to_path_buf()]; + while let Some(path) = paths.pop() { + let metadata = match std::fs::symlink_metadata(&path) { + Err(err) if err.kind() == std::io::ErrorKind::NotFound => continue, + result => result.with_context(|| format!("inspect runtime path {}", path.display()))?, + }; + if metadata.file_attributes() & FILE_ATTRIBUTE_REPARSE_POINT != 0 { + continue; + } + + // A readable parent does not prove that existing runtime children inherited its ACL. + let access_result = unsafe { + grant_read_execute_aces( + &path, + &[sandbox_group_psid], + if metadata.is_dir() { + OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE + } else { + 0 + }, + ) + } + .and_then(|changed| { + if changed { + ensure!( + path_mask_allows( + &path, + &[sandbox_group_psid], + read_execute_mask, + /*require_all_bits*/ true, + )?, + "runtime read/execute access still missing" + ); + } + Ok(()) + }); + if let Err(err) = access_result { + if std::fs::symlink_metadata(&path) + .is_err_and(|err| err.kind() == std::io::ErrorKind::NotFound) + { + continue; + } + return Err(err).with_context(|| { + format!("validate runtime read/execute access on {}", path.display()) + }); + } + if metadata.is_dir() { + let entries = match std::fs::read_dir(&path) { + Err(err) if err.kind() == std::io::ErrorKind::NotFound => continue, + result => result + .with_context(|| format!("enumerate runtime directory {}", path.display()))?, + }; + for entry in entries { + match entry { + Err(err) if err.kind() == std::io::ErrorKind::NotFound => continue, + result => paths.push(result?.path()), + } + } + } + } Ok(()) } diff --git a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/setup_runtime_bin_tests.rs b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/setup_runtime_bin_tests.rs index ad8aa7c3e4..14ab1bd05a 100644 --- a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/setup_runtime_bin_tests.rs +++ b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win/setup_runtime_bin_tests.rs @@ -1,6 +1,124 @@ +use super::ensure_runtime_tree_readable; use super::runtime_paths; +use codex_windows_sandbox::LocalSid; +use codex_windows_sandbox::add_deny_read_ace; +use codex_windows_sandbox::add_deny_write_ace; +use codex_windows_sandbox::ensure_allow_mask_aces_with_inheritance; +use codex_windows_sandbox::path_mask_allows; use pretty_assertions::assert_eq; +use std::fs; use std::path::PathBuf; +use windows_sys::Win32::Storage::FileSystem::DELETE; +use windows_sys::Win32::Storage::FileSystem::FILE_APPEND_DATA; +use windows_sys::Win32::Storage::FileSystem::FILE_GENERIC_EXECUTE; +use windows_sys::Win32::Storage::FileSystem::FILE_GENERIC_READ; +use windows_sys::Win32::Storage::FileSystem::FILE_WRITE_DATA; +use windows_sys::Win32::Storage::FileSystem::WRITE_DAC; + +#[test] +fn repairs_children_when_runtime_root_already_has_read_execute_access() { + let runtime = tempfile::tempdir().expect("runtime directory"); + let node = runtime.path().join("bin/node.exe"); + let module = runtime.path().join("sky/dist/project/index.js"); + for path in [&node, &module] { + fs::create_dir_all(path.parent().expect("parent")).expect("runtime subdirectory"); + fs::write(path, b"runtime content").expect("runtime file"); + } + let sandbox_sid = LocalSid::from_string("S-1-5-21-10-20-30-40").expect("test SID"); + let read_execute_mask = FILE_GENERIC_READ | FILE_GENERIC_EXECUTE; + unsafe { + ensure_allow_mask_aces_with_inheritance( + runtime.path(), + &[sandbox_sid.as_ptr()], + read_execute_mask, + /*inheritance*/ 0, + ) + } + .expect("grant root-only read/execute access"); + assert!( + path_mask_allows( + runtime.path(), + &[sandbox_sid.as_ptr()], + read_execute_mask, + /*require_all_bits*/ true, + ) + .expect("root access") + ); + for path in [&node, &module] { + assert!( + !path_mask_allows( + path, + &[sandbox_sid.as_ptr()], + read_execute_mask, + /*require_all_bits*/ true, + ) + .expect("child access before repair") + ); + } + + let denied_directory = runtime.path().join("denied"); + fs::create_dir(&denied_directory).expect("denied directory"); + assert!( + unsafe { add_deny_read_ace(&denied_directory, sandbox_sid.as_ptr()) } + .expect("deny directory reads") + ); + let denied_child = denied_directory.join("private.js"); + fs::write(&denied_child, b"private runtime content").expect("denied child"); + let write_denied_file = runtime.path().join("read-only.js"); + fs::write(&write_denied_file, b"read-only runtime content").expect("write-denied file"); + assert!( + unsafe { add_deny_write_ace(&write_denied_file, sandbox_sid.as_ptr()) } + .expect("deny runtime writes") + ); + + for _ in 0..2 { + ensure_runtime_tree_readable(runtime.path(), sandbox_sid.as_ptr()) + .expect("repair runtimes"); + for path in [&denied_directory, &denied_child] { + assert!( + !unsafe { add_deny_read_ace(path, sandbox_sid.as_ptr()) } + .expect("read denial must survive repair") + ); + assert!( + !path_mask_allows( + path, + &[sandbox_sid.as_ptr()], + read_execute_mask, + /*require_all_bits*/ false, + ) + .expect("repair must not add an allow ahead of inherited denial") + ); + } + assert!( + !unsafe { add_deny_write_ace(&write_denied_file, sandbox_sid.as_ptr()) } + .expect("write denial must survive repair") + ); + for path in [ + node.as_path(), + module.as_path(), + module.parent().expect("module directory"), + ] { + assert!( + path_mask_allows( + path, + &[sandbox_sid.as_ptr()], + read_execute_mask, + /*require_all_bits*/ true, + ) + .expect("child access after repair") + ); + assert!( + !path_mask_allows( + path, + &[sandbox_sid.as_ptr()], + FILE_WRITE_DATA | FILE_APPEND_DATA | DELETE | WRITE_DAC, + /*require_all_bits*/ false, + ) + .expect("repair must not grant write or ACL management") + ); + } + } +} #[test] fn runtime_paths_include_desktop_parent_and_primary_runtime_roots() { diff --git a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win_acl_tests.rs b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win_acl_tests.rs index df39cfdd18..0edce4aab6 100644 --- a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win_acl_tests.rs +++ b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win_acl_tests.rs @@ -7,6 +7,7 @@ use super::GRANT_ACCESS; use super::Payload; use super::SETUP_VERSION; use super::SetupMode; +use super::WRITE_DAC; use super::convert_string_sid_to_sid; use super::lock_sandbox_bin_dir; use super::lock_sandbox_dir; @@ -43,7 +44,11 @@ fn provision_only_locks_plain_directory_via_handle() { #[test] fn lock_sandbox_dir_blocks_inherited_write_for_runner_files() { - for setup_mode in [SetupMode::Full, SetupMode::ProvisionOnly] { + for setup_mode in [ + SetupMode::Full, + SetupMode::InteractiveProvision, + SetupMode::ProvisionOnly, + ] { let temp = tempfile::tempdir().expect("tempdir"); let workspace = temp.path().join("workspace"); let sandbox_bin = workspace.join(".sandbox-bin"); @@ -74,6 +79,8 @@ fn lock_sandbox_dir_blocks_inherited_write_for_runner_files() { ); let real_user = std::env::var("USERNAME").unwrap_or_else(|_| "Administrators".to_string()); + let real_sid = resolve_sid(&real_user).expect("resolve real user SID"); + let real_psid = sid_bytes_to_psid(&real_sid).expect("convert real user SID"); let payload = Payload { version: SETUP_VERSION, offline_username: String::new(), @@ -95,16 +102,52 @@ fn lock_sandbox_dir_blocks_inherited_write_for_runner_files() { let new_runner = sandbox_bin.join("new-runner.exe"); fs::write(&new_runner, b"new").expect("create new runner"); - for path in [&sandbox_bin, &existing_runner, &new_runner] { + let child_dir = sandbox_bin.join("child"); + fs::create_dir(&child_dir).expect("create child directory"); + + // Repeated refresh must retain the right seeded by privileged setup. + lock_sandbox_bin_dir(&payload, &sandbox_group_sid).expect("refresh sandbox bin"); + lock_sandbox_bin_dir(&payload, &sandbox_group_sid).expect("repeat refresh sandbox bin"); + assert!( + path_mask_allows( + &sandbox_bin, + &[real_psid], + WRITE_DAC, + /*require_all_bits*/ true + ) + .expect("check caller can maintain directory permissions") + ); + for path in [&existing_runner, &new_runner, &child_dir] { + assert!( + !path_mask_allows( + path, + &[real_psid], + WRITE_DAC, + /*require_all_bits*/ false + ) + .expect("check permission maintenance does not inherit to helpers") + ); + } + + for path in [&sandbox_bin, &existing_runner, &new_runner, &child_dir] { assert!( !path_mask_allows( path, &[workspace_psid], - FILE_GENERIC_WRITE | DELETE, + FILE_GENERIC_WRITE | DELETE | WRITE_DAC, /*require_all_bits*/ false, ) .expect("check protected path write and delete access") ); + assert!( + !path_mask_allows( + path, + &[sandbox_group_psid], + WRITE_DAC, + /*require_all_bits*/ false + ) + .expect("check sandbox cannot maintain permissions") + ); assert!( path_mask_allows( path, @@ -117,6 +160,7 @@ fn lock_sandbox_dir_blocks_inherited_write_for_runner_files() { } unsafe { + LocalFree(real_psid as HLOCAL); LocalFree(workspace_psid as HLOCAL); LocalFree(sandbox_group_psid as HLOCAL); } diff --git a/codex-rs/windows-sandbox-rs/src/desktop_tests.rs b/codex-rs/windows-sandbox-rs/src/desktop_tests.rs index 2c8f35c961..318707e625 100644 --- a/codex-rs/windows-sandbox-rs/src/desktop_tests.rs +++ b/codex-rs/windows-sandbox-rs/src/desktop_tests.rs @@ -7,6 +7,7 @@ use crate::setup::SandboxSetupRequest; use crate::setup::SetupRootOverrides; use crate::spawn_prep::legacy_session_capability_roots; use crate::spawn_prep::prepare_legacy_session_security; +use crate::winutil::current_account_name; use anyhow::Result; use codex_protocol::models::PermissionProfile; use codex_protocol::permissions::NetworkSandboxPolicy; @@ -20,10 +21,6 @@ use std::os::windows::io::FromRawHandle; use std::os::windows::io::OwnedHandle; use std::path::Path; use tempfile::TempDir; -use windows_sys::Win32::NetworkManagement::NetManagement::DNLEN; -use windows_sys::Win32::NetworkManagement::NetManagement::UNLEN; -use windows_sys::Win32::Security::Authentication::Identity::GetUserNameExW; -use windows_sys::Win32::Security::Authentication::Identity::NameSamCompatible; #[test] fn private_desktop_rejects_interactive_and_injected_names() { @@ -219,16 +216,6 @@ fn legacy_desktop_reuses_only_equivalent_permissions() -> Result<()> { Ok(()) } -fn current_account_name() -> Result { - // Bazel does not provide USERDOMAIN or USERNAME in the test environment. - let mut account = [0; (DNLEN + UNLEN + 2) as usize]; - let mut length = account.len() as u32; - if unsafe { GetUserNameExW(NameSamCompatible, account.as_mut_ptr(), &mut length) } == 0 { - return Err(std::io::Error::last_os_error().into()); - } - Ok(String::from_utf16(&account[..length as usize])?) -} - fn workspace_permissions(workspace: &Path) -> Result { ResolvedWindowsSandboxPermissions::try_from_permission_profile_for_workspace_roots( &PermissionProfile::workspace_write_with( diff --git a/codex-rs/windows-sandbox-rs/src/lib.rs b/codex-rs/windows-sandbox-rs/src/lib.rs index e83a42a59f..5b16de0609 100644 --- a/codex-rs/windows-sandbox-rs/src/lib.rs +++ b/codex-rs/windows-sandbox-rs/src/lib.rs @@ -170,6 +170,8 @@ pub use acl::ensure_allow_write_aces; #[cfg(target_os = "windows")] pub use acl::fetch_dacl_handle; #[cfg(target_os = "windows")] +pub use acl::grant_read_execute_aces; +#[cfg(target_os = "windows")] pub use acl::path_has_standard_user_mutation_allow; #[cfg(target_os = "windows")] pub use acl::path_has_trusted_system_owner; diff --git a/codex-rs/windows-sandbox-rs/src/setup.rs b/codex-rs/windows-sandbox-rs/src/setup.rs index 1e84b6fef4..031a944798 100644 --- a/codex-rs/windows-sandbox-rs/src/setup.rs +++ b/codex-rs/windows-sandbox-rs/src/setup.rs @@ -33,6 +33,7 @@ use crate::setup_error::extract_failure; use crate::setup_error::failure; use crate::setup_error::read_setup_error_report; use crate::ssh_config_dependencies::ssh_config_dependency_paths; +use crate::winutil::current_account_name; use anyhow::Result; use anyhow::anyhow; use base64::Engine; @@ -348,7 +349,7 @@ fn run_setup_refresh_inner( proxy_ports: offline_proxy_settings.proxy_ports, allow_local_binding: offline_proxy_settings.allow_local_binding, otel: None, - real_user: std::env::var("USERNAME").unwrap_or_else(|_| "Administrators".to_string()), + real_user: current_account_name()?, mode: SetupMode::Full, refresh_only: true, }; @@ -1065,7 +1066,7 @@ fn run_elevated_setup_inner( format!("failed to create sandbox dir {}: {err}", sbx_dir.display()), ) })?; - let payload = elevated_provisioning_payload(&request, offline_proxy_settings_override); + let payload = elevated_provisioning_payload(&request, offline_proxy_settings_override)?; let needs_elevation = !is_elevated().map_err(|err| { failure( SetupErrorCode::OrchestratorElevationCheckFailed, @@ -1078,10 +1079,10 @@ fn run_elevated_setup_inner( fn elevated_provisioning_payload( request: &SandboxSetupRequest<'_>, offline_proxy_settings_override: Option<&OfflineProxySettings>, -) -> ElevationPayload { +) -> Result { let offline_proxy_settings = offline_proxy_settings_for_request(request, offline_proxy_settings_override); - ElevationPayload { + Ok(ElevationPayload { version: SETUP_VERSION, offline_username: OFFLINE_USERNAME.to_string(), online_username: ONLINE_USERNAME.to_string(), @@ -1093,11 +1094,11 @@ fn elevated_provisioning_payload( deny_write_paths: Vec::new(), proxy_ports: offline_proxy_settings.proxy_ports, allow_local_binding: offline_proxy_settings.allow_local_binding, - real_user: std::env::var("USERNAME").unwrap_or_else(|_| "Administrators".to_string()), + real_user: current_account_name()?, otel: codex_otel::global_statsig_metrics_settings(), mode: SetupMode::InteractiveProvision, refresh_only: false, - } + }) } pub fn run_elevated_provisioning_setup( @@ -1600,7 +1601,8 @@ mod tests { let payload = super::elevated_provisioning_payload( &request, /*offline_proxy_settings_override*/ None, - ); + ) + .expect("elevated provisioning payload"); assert_eq!(payload.command_cwd, codex_home); assert_eq!(payload.read_roots, Vec::::new()); diff --git a/codex-rs/windows-sandbox-rs/src/winutil.rs b/codex-rs/windows-sandbox-rs/src/winutil.rs index 502d9024bf..711e2eab79 100644 --- a/codex-rs/windows-sandbox-rs/src/winutil.rs +++ b/codex-rs/windows-sandbox-rs/src/winutil.rs @@ -6,6 +6,7 @@ use windows_sys::Win32::Foundation::ERROR_INSUFFICIENT_BUFFER; use windows_sys::Win32::Foundation::GetLastError; use windows_sys::Win32::Foundation::HLOCAL; use windows_sys::Win32::Foundation::LocalFree; +use windows_sys::Win32::NetworkManagement::NetManagement::DNLEN; use windows_sys::Win32::NetworkManagement::NetManagement::LOCALGROUP_INFO_1; use windows_sys::Win32::NetworkManagement::NetManagement::NERR_Success; use windows_sys::Win32::NetworkManagement::NetManagement::NERR_UserNotFound; @@ -13,8 +14,11 @@ use windows_sys::Win32::NetworkManagement::NetManagement::NetApiBufferFree; use windows_sys::Win32::NetworkManagement::NetManagement::NetLocalGroupAdd; use windows_sys::Win32::NetworkManagement::NetManagement::NetUserGetInfo; use windows_sys::Win32::NetworkManagement::NetManagement::NetUserSetInfo; +use windows_sys::Win32::NetworkManagement::NetManagement::UNLEN; use windows_sys::Win32::NetworkManagement::NetManagement::USER_INFO_1; use windows_sys::Win32::NetworkManagement::NetManagement::USER_INFO_1008; +use windows_sys::Win32::Security::Authentication::Identity::GetUserNameExW; +use windows_sys::Win32::Security::Authentication::Identity::NameSamCompatible; use windows_sys::Win32::Security::Authorization::ConvertSidToStringSidW; use windows_sys::Win32::Security::Authorization::ConvertStringSidToSidW; use windows_sys::Win32::Security::CopySid; @@ -29,6 +33,16 @@ use windows_sys::Win32::System::Diagnostics::Debug::FormatMessageW; pub const SANDBOX_USERS_GROUP: &str = "CodexSandboxUsers"; const SANDBOX_USERS_GROUP_COMMENT: &str = "Codex sandbox internal group (managed)"; +pub(crate) fn current_account_name() -> Result { + // Sandbox launchers can filter USERNAME, so resolve the caller from its Windows token. + let mut account = [0; (DNLEN + UNLEN + 2) as usize]; + let mut length = account.len() as u32; + if unsafe { GetUserNameExW(NameSamCompatible, account.as_mut_ptr(), &mut length) } == 0 { + return Err(std::io::Error::last_os_error()).context("resolve current Windows account"); + } + Ok(String::from_utf16(&account[..length as usize])?) +} + pub fn to_wide>(s: S) -> Vec { let mut v: Vec = s.as_ref().encode_wide().collect(); v.push(0); diff --git a/third_party/voice/BUILD.bazel b/third_party/voice/BUILD.bazel index 3cf29ebde6..b3c5f0930e 100644 --- a/third_party/voice/BUILD.bazel +++ b/third_party/voice/BUILD.bazel @@ -133,6 +133,30 @@ alias( visibility = ["//visibility:public"], ) +# Explicitly select the installed pkgconf and pinned CMake in Windows voice CI. +native_tool_toolchain( + name = "windows_pkg_config_tool", + env = {"PKG_CONFIG": "$(execpath :pkg_config)"}, + path = "$(execpath :pkg_config)", + target = ":pkg_config", +) + +toolchain( + name = "windows_pkg_config_toolchain", + exec_compatible_with = ["@platforms//os:windows"], + toolchain = ":windows_pkg_config_tool", + toolchain_type = "@rules_foreign_cc//toolchains:pkgconfig_toolchain", + visibility = ["//visibility:public"], +) + +toolchain( + name = "windows_cmake_toolchain", + exec_compatible_with = ["@platforms//os:windows"], + toolchain = "@cmake-3.31.8-windows-x86_64//:cmake_tool", + toolchain_type = "@rules_foreign_cc//toolchains:cmake_toolchain", + visibility = ["//visibility:public"], +) + filegroup( name = "archives", srcs = [ diff --git a/third_party/voice/NOTICE.md b/third_party/voice/NOTICE.md index b6557717f7..c5b79744a8 100644 --- a/third_party/voice/NOTICE.md +++ b/third_party/voice/NOTICE.md @@ -1,6 +1,6 @@ # Native voice libraries in Codex releases -The macOS Codex release package includes dynamically linked GStreamer and GLib +Codex release packages with voice include dynamically linked GStreamer and GLib libraries and selected plugins, plus their native library dependencies. These components have their own copyrights and licenses. Their notices accompany this file in `licenses/`: `LGPL-2.1.txt` for GStreamer and GLib, @@ -12,6 +12,6 @@ The exact upstream versions, source archive URLs and SHA-256 digests are in projection and package scripts are in the public Codex source tree under `third_party/voice/`. The source commit for this package is recorded in `manifest.json`. The native libraries remain separate dynamic libraries in -`lib/` and `plugins/`; replacing them requires compatible binaries and valid -macOS code signatures. Build tools listed in `sources.json` are build inputs, -not bundled runtime libraries. +platform-specific runtime directories. Replacements must be compatible with +the package and, on macOS, have valid code signatures. Build tools listed in +`sources.json` are build inputs, not bundled runtime libraries. diff --git a/third_party/voice/README.md b/third_party/voice/README.md index d79e3de68d..48ea1fa46c 100644 --- a/third_party/voice/README.md +++ b/third_party/voice/README.md @@ -258,11 +258,14 @@ The module does not download that installed tree or accept compiler licenses. After provisioning, a native PowerShell invocation is: ```powershell +$hostArch = $env:PROCESSOR_ARCHITEW6432 +if (-not $hostArch) { $hostArch = $env:PROCESSOR_ARCHITECTURE } bazel build //third_party/voice:native_link_windows_x86_64 ` --platforms=//:local_windows_msvc ` --inject_repository="voice_windows_tools=$env:VOICE_WINDOWS_BAZEL_REPOSITORY" ` --//third_party/voice:windows_installed_tools=@voice_windows_tools//:tools ` - --action_env="SystemRoot=$env:SystemRoot" --host_action_env="SystemRoot=$env:SystemRoot" + --action_env="SystemRoot=$env:SystemRoot" --host_action_env="SystemRoot=$env:SystemRoot" ` + --action_env="PROCESSOR_ARCHITECTURE=$hostArch" --host_action_env="PROCESSOR_ARCHITECTURE=$hostArch" ``` Use `native_link_windows_aarch64` on native ARM64 Windows. Existing MSVC license diff --git a/third_party/voice/bazel_windows.py b/third_party/voice/bazel_windows.py index f14941d041..5cd172fb5a 100644 --- a/third_party/voice/bazel_windows.py +++ b/third_party/voice/bazel_windows.py @@ -64,9 +64,13 @@ def main(): environment, _ = build_environment( document, inputs["target"], {"python": Path(sys.executable)} ) - # Keep executor scratch directories, never its developer tool search path. + # Keep host identity and scratch directories, never developer tool search paths. environment.update( - {name: os.environ[name] for name in ("TMP", "TEMP") if name in os.environ} + { + name: os.environ[name] + for name in ("TMP", "TEMP", "PROCESSOR_ARCHITECTURE") + if name in os.environ + } ) home = temporary / "home" home.mkdir() diff --git a/third_party/voice/release_runtime.py b/third_party/voice/release_runtime.py index 6cb0f74efc..6b705ca314 100644 --- a/third_party/voice/release_runtime.py +++ b/third_party/voice/release_runtime.py @@ -1,4 +1,4 @@ -"""Stage verified macOS voice libraries and seal their post-signing release receipt.""" +"""Stage verified voice libraries and seal their public-release receipt.""" import argparse import json @@ -10,8 +10,13 @@ from runtime import digest def stage(source: Path, destination: Path, target: str) -> None: - if target not in {"aarch64-apple-darwin", "x86_64-apple-darwin"}: - raise ValueError("public voice runtime requires a macOS target") + if target not in { + "aarch64-apple-darwin", + "x86_64-apple-darwin", + "aarch64-unknown-linux-gnu", + "x86_64-unknown-linux-gnu", + }: + raise ValueError("unsupported public release voice runtime target") source = source.resolve(strict=True) files = runtime_files(source, target) destination.mkdir() diff --git a/third_party/voice/test_assemble_package.py b/third_party/voice/test_assemble_package.py index 2eb4999671..7758bd4b12 100644 --- a/third_party/voice/test_assemble_package.py +++ b/third_party/voice/test_assemble_package.py @@ -276,6 +276,38 @@ class AssembleTests(unittest.TestCase): ) self.assertEqual(manifest["appVersion"], version) + def test_linux_release_pairs_musl_app_with_gnu_voice_runtime(self): + self.commit = "b" * 40 + target = "aarch64-unknown-linux-gnu" + runtime, _ = self.make_runtime(target) + staged = self.root / "staged" + stage(runtime, staged, target) + seal(staged, target) + for version in ("0.154.0-alpha.8", "0.154.0-beta.2", "0.154.0"): + with self.subTest(version=version): + self.metadata["version"] = version + (self.package / "codex-package.json").write_text( + json.dumps(self.metadata) + ) + output = self.root / f"linux-{version}" + assemble( + self.package, + self.helper, + target, + self.commit, + output, + runtime=staged, + release_version=version, + ) + voice = output / "codex-resources/voice" + manifest = json.loads((voice / "manifest.json").read_text()) + self.assertEqual(manifest["appTarget"], "aarch64-unknown-linux-musl") + self.assertEqual(manifest["voiceTarget"], target) + self.assertEqual( + manifest["sha256"]["codex-resources/voice/runtime.json"], + digest(staged / "runtime.json"), + ) + def test_rejects_invalid_runtime_receipts_before_creating_package(self): runtime, original = self.make_runtime() changes = [ diff --git a/third_party/voice/test_bazel_windows.py b/third_party/voice/test_bazel_windows.py index 945c7e270c..1bb4296e62 100644 --- a/third_party/voice/test_bazel_windows.py +++ b/third_party/voice/test_bazel_windows.py @@ -5,13 +5,56 @@ import errno import json from pathlib import Path import tempfile +from types import SimpleNamespace import unittest +from unittest.mock import patch + +import bazel_windows from bazel_copy import copy_payloads from bazel_windows import selected_inputs class WindowsInputsTests(unittest.TestCase): + def test_adapter_preserves_host_architecture_without_developer_path(self): + with tempfile.TemporaryDirectory() as directory: + config = Path(directory) / "action.json" + config.write_text("{}") + for architecture in ("AMD64", "ARM64"): + environment = {"PROCESSOR_ARCHITECTURE": architecture, "PATH": "unsafe"} + with ( + self.subTest(architecture=architecture), + patch.object( + bazel_windows, "os", SimpleNamespace(environ=environment) + ), + patch.object( + bazel_windows.sys, "argv", ["driver", "unknown", str(config)] + ), + patch.object( + bazel_windows, + "selected_inputs", + return_value={"target": "unused"}, + ), + patch.object( + bazel_windows, + "build_environment", + return_value=({"PATH": "declared"}, {}), + ), + ): + with self.assertRaisesRegex( + ValueError, "unknown Windows native action" + ): + bazel_windows.main() + self.assertEqual( + environment, + { + "PROCESSOR_ARCHITECTURE": architecture, + "PATH": "declared", + "HOME": environment["HOME"], + "USERPROFILE": environment["HOME"], + }, + ) + def setUp(self): temporary = tempfile.TemporaryDirectory() self.addCleanup(temporary.cleanup) diff --git a/third_party/voice/windows_native.bzl b/third_party/voice/windows_native.bzl index e1a135319e..51c9968dd5 100644 --- a/third_party/voice/windows_native.bzl +++ b/third_party/voice/windows_native.bzl @@ -25,6 +25,9 @@ def _windows_tools_impl(ctx): system_root = ctx.configuration.default_shell_env.get("SystemRoot") if not system_root: fail("Pass --action_env=SystemRoot= as a fixed value") + host_architecture = ctx.configuration.default_shell_env.get("PROCESSOR_ARCHITECTURE") + if not host_architecture: + fail("Pass --action_env=PROCESSOR_ARCHITECTURE= as a fixed value") msvc = ctx.attr.msvc[DirectoryInfo] sdk = ctx.attr.sdk[DirectoryInfo] tools = { @@ -68,7 +71,11 @@ def _windows_tools_impl(ctx): python = python, manifest = manifests[0], installed_files = installed, - environment = {"SystemRoot": system_root, "SYSTEMROOT": system_root}, + environment = { + "SystemRoot": system_root, + "SYSTEMROOT": system_root, + "PROCESSOR_ARCHITECTURE": host_architecture, + }, inputs = { "schemaVersion": 1, "target": ctx.attr.target,