Skip to content
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

🐛 fix unexpected run of release workflow #9494

Merged

Conversation

zawakin
Copy link
Contributor

@zawakin zawakin commented Aug 19, 2023

I have discovered a bug located within .github/workflows/_release.yml which is the primary cause of continuous integration (CI) errors. The problem can be solved; therefore, I have constructed a PR to address the issue.

The Issue

Access the following link to view the exact errors: Langhain Release Workflow

The instances of these errors take place for each PR that updates pyproject.toml, excluding those specifically associated with bumping PRs.

See below for the specific error message:

Error: Error 422: Validation Failed: {"resource":"Release","code":"already_exists","field":"tag_name"}

An image of the error can be viewed here:
Image

The _release.yml document contains the following if-condition:

    if: |
        ${{ github.event.pull_request.merged == true }}
        && ${{ contains(github.event.pull_request.labels.*.name, 'release') }}

The Root Cause

The above job constantly runs as the if-condition is always identified as true.

The Logic

The if-condition can be defined as if: ${{ b1 }} && ${{ b2 }}, where b1 and b2 are boolean values. However, in terms of condition evaluation with GitHub Actions, ${{ false }} is identified as a string value, thereby rendering it as truthy as per the official documentation.

I have run some tests regarding this behavior within my forked repository. You can consult my debug PR for reference.

Here is the result of the tests:

If-Condition Outcome
if: true && ${{ false }} Execution
if: ${{ false }} Skipped
if: true && false Skipped
if: false Skipped
if: ${{ true && false }} Skipped

In view of the first and second results, we can infer that ${{ false }} can only be interpreted as true for conditions composed of some expressions.
It is consistent that the condition of if: ${{ inputs.working-directory == 'libs/langchain' }} works.

It is surprised to be skipped for the second case but it seems the spec of GitHub Actions 😓

Anyway, the PR would fix these errors, I believe 👍

Could you review this? @hwchase17 or @shoelsch , who is the author of PR.

@vercel
Copy link

vercel bot commented Aug 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Aug 19, 2023 5:31pm

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Aug 19, 2023
@baskaryan
Copy link
Collaborator

cc @obi1kenobi

@zawakin
Copy link
Contributor Author

zawakin commented Aug 19, 2023

(A little background leading to the discovery: I personally like your project and was referencing the release workflow in my personal development. I noticed that there were times when the if-condition for the PyPI release workflow was not functioning properly.)

@zawakin
Copy link
Contributor Author

zawakin commented Aug 19, 2023

Let me add one more point. Both of the following code would work,

github.event.pull_request.merged == true
&& contains(github.event.pull_request.labels.*.name, 'release')

as in this PR,

${{ github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') }}

@obi1kenobi obi1kenobi merged commit 85a1c6d into langchain-ai:master Aug 21, 2023
@obi1kenobi
Copy link
Collaborator

Thanks for the report and for the fix! 🚀

@obi1kenobi
Copy link
Collaborator

We have completed triage and remediation for this issue.

TL;DR: This was not exploited. No actions are required for users of LangChain.

The misconfiguration identified here allowed the release workflow to be triggered by an unmerged PR, which could have led to the creation of an unintended langchain or langchain-experimental release on PyPI.

Having reviewed all runs of the release workflows, we have determined that no inappropriate releases took place. We have already merged the fix as well as some additional hardening of our GitHub Actions that will make similar issues impossible in the future.

What went well:

  • GitHub prevents first-time contributors from triggering workflows without explicit opt-in from maintainers. This means that any attempts to take advantage of the misconfiguration would have had to either pass code-review or come from an account that has previously contributed to LangChain and has been approved for running workflows. It was thus not possible for a new account to trigger the release workflow without the maintainer explicitly clicking to approve the run first.

What we're improving for the future:

@zawakin
Copy link
Contributor Author

zawakin commented Aug 23, 2023

@obi1kenobi Thank you! I was really impressed with how quickly you've put together the security.md and the other actions. Wishing you continued improvement and success!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants