Skip to content

Conversation

@dgellow
Copy link
Contributor

@dgellow dgellow commented Jan 14, 2026

Summary

Harden the stainless-builds.yml workflow for safe use with pull_request_target. This workflow runs in a privileged context even for fork PRs, so we need to ensure untrusted PR code cannot be exploited.

Changes to integration-tests.yml

  • Add matrix_json input: when provided, skips generate_ci_matrix.py execution entirely
  • Add disable_cache input: disables all caching mechanisms when true
  • Set UV_NO_CACHE=1 environment variable when disable_cache is true (prevents uv from reading/writing package cache)
  • Disable npm caching via package-manager-cache: false when disable_cache is true
  • Change composite action references from ./.github/actions/* to llamastack/llama-stack/.github/actions/*@main so they're loaded from the trusted main branch, not from PR checkout

Changes to stainless-builds.yml

  • Pass matrix_json with hardcoded stainless test config (matches ci_matrix.json "stainless" key)
  • Pass disable_cache: true to enable all cache poisoning mitigations
  • Update security documentation comment

Security Model

Threat Mitigation
generate_ci_matrix.py code execution Skipped via matrix_json input
Composite actions from PR checkout Full repo paths @main
uv package cache poisoning UV_NO_CACHE=1 env var
npm cache poisoning package-manager-cache: false

Backwards Compatibility

These changes only affect behavior when matrix_json or disable_cache inputs are explicitly passed. Normal pull_request, push, and workflow_dispatch triggers are unaffected.

Test plan

We would need to merge and test when the workflows are updated in main

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 14, 2026
@dgellow dgellow marked this pull request as draft January 14, 2026 21:17
@raghotham
Copy link
Member

It might be better to split the workflow into two?

https://openssf.org/blog/2024/08/12/mitigating-attack-vectors-in-github-workflows/

@dgellow dgellow force-pushed the sam/python-caching-issue branch from c8fd5d8 to eae255c Compare January 22, 2026 16:37
@dgellow dgellow force-pushed the sam/python-caching-issue branch from eae255c to 8b08f0e Compare January 22, 2026 17:25
Comment on lines 108 to 130
run-replay-mode-tests:
needs: generate-matrix
# Always run even if generate-matrix was skipped (when matrix_json is provided)
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
# When disable_cache is true, set UV_NO_CACHE to prevent uv from using cached packages.
# This is a security measure for pull_request_target contexts to prevent cache poisoning.
env:
UV_NO_CACHE: ${{ inputs.disable_cache == true }}
name: ${{ format('Integration Tests ({0}, {1}, {2}, client={3}, {4})', matrix.client, matrix.config.setup, matrix.python-version, matrix.client-version, matrix.config.suite) }}

strategy:
fail-fast: false
matrix:
client: [library, docker, server]
# Use Python 3.13 only on nightly schedule (daily latest client test), otherwise use 3.12
python-version: ${{ github.event.schedule == '0 0 * * *' && fromJSON('["3.12", "3.13"]') || fromJSON('["3.12"]') }}
node-version: [22]
client-version: ${{ (github.event.schedule == '0 0 * * *' || github.event.inputs.test-all-client-versions == 'true' || inputs.test-all-client-versions == true) && fromJSON('["published", "latest"]') || fromJSON('["latest"]') }}
# Test configurations: Generated from CI_MATRIX in tests/integration/ci_matrix.json
# See scripts/generate_ci_matrix.py for generation logic
config: ${{ fromJSON(needs.generate-matrix.outputs.matrix).include }}
# Test configurations: Either from matrix_json input or generated from ci_matrix.json
config: ${{ fromJSON(inputs.matrix_json || needs.generate-matrix.outputs.matrix).include }}

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
Copy link
Contributor Author

@dgellow dgellow Jan 22, 2026

Choose a reason for hiding this comment

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

I think that's orthogonal to security concerns from this specific PR, and I would prefer to not expand its scope

- Add matrix_json input to skip generate_ci_matrix.py execution
- Add disable_cache input to prevent cache poisoning
- Change composite action refs to use full repo paths (@main)
- Set UV_NO_CACHE env var when disable_cache is true
- Disable npm caching when disable_cache is true
- Update stainless-builds.yml to pass hardcoded matrix and disable_cache
@dgellow dgellow force-pushed the sam/python-caching-issue branch from 8b08f0e to 0215954 Compare January 22, 2026 17:28
if: ${{ matrix.client == 'server' }}
id: setup-ts-client
uses: ./.github/actions/setup-typescript-client
uses: llamastack/llama-stack/.github/actions/setup-typescript-client@306e43f882fdfbaf877f989f0c1ea900c6348055
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we would use @main here, but that's forbidden via pre-commit checks. That sha will need to be updated whenever the .github/actions/setup-typescript-client is updated.

- name: Run tests
if: ${{ matrix.config.allowed_clients == null || contains(matrix.config.allowed_clients, matrix.client) }}
uses: ./.github/actions/run-and-record-tests
uses: llamastack/llama-stack/.github/actions/run-and-record-tests@306e43f882fdfbaf877f989f0c1ea900c6348055
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we would use @main here, but that's forbidden via pre-commit checks. That sha will need to be updated whenever the .github/actions/run-and-record-tests is updated.

- name: Setup test environment
if: ${{ matrix.config.allowed_clients == null || contains(matrix.config.allowed_clients, matrix.client) }}
uses: ./.github/actions/setup-test-environment
uses: llamastack/llama-stack/.github/actions/setup-test-environment@306e43f882fdfbaf877f989f0c1ea900c6348055
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we would use @main here, but that's forbidden via pre-commit checks. That sha will need to be updated whenever the .github/actions/setup-test-environment is updated.

Copy link
Collaborator

@cdoern cdoern left a comment

Choose a reason for hiding this comment

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

nothing glaring here, this looks like the right design! will do a more in depth review when I am back from PTO (monday or maybe on Sunday)

@dgellow dgellow marked this pull request as ready for review January 22, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants