지속적 통합 및 지속적 배포CI/CD) pipelines play a pivotal role in facilitating streamlined software development. Yet, as these pipelines become increasingly crucial, the imperative to protect them from vulnerabilities becomes more pronounced. This in-depth investigation focuses on addressing a prominent risk identified in the OWASP Top-10 CI/CD Security Risks: Poisoned Pipeline Execution (PPE).
What is Poisoned Pipeline 실행(PPE)
According to OWASP Top-10 CI/CD Security Risks, “중독 Pipeline 실행 (PPE) risk refers to the ability of an attacker with access to source control systems – and without access to the build environment – to manipulate the build process by injecting malicious code/commands into the build pipeline 구성, 본질적으로 ‘poisoning’ the pipeline and running malicious code as part of the build process”
간단히 말해서, 독살당했다 Pipeline 실행(PPE)은 다음과 같은 경우에 생성됩니다. 공격자는 수정할 수 있습니다. pipeline 논리.
두 가지가있다 변종:
- 다이렉트 PPE (디-PPE): D-PPE 시나리오에서, 공격자는 CI 설정 파일을 수정합니다. 접근 권한이 있는 저장소에서 변경 사항을 적용하려면, 저장소의 보호되지 않은 원격 브랜치에 직접 변경 사항을 푸시하거나, 브랜치 또는 포크에서 변경 사항이 포함된 PR을 제출하면 됩니다. CI 이후로 pipeline 실행은 수정된 CI 구성 파일의 명령에 의해 정의되며, 공격자의 악의적인 명령은 빌드가 완료되면 빌드 노드에서 최종적으로 실행됩니다. pipeline 트리거됩니다.
- 간접 개인보호장비 (I-PPE특정 경우에는 D-PPE에 접근할 수 있는 적이 D-PPE를 사용할 수 없는 경우가 있습니다. SCM 저장소(예: 만약 pipeline CI 구성 파일은 동일한 저장소 내의 별도 보호된 브랜치에서 가져오도록 구성되어 있습니다. 이러한 시나리오에서는 독을 넣는 것보다는 pipeline 공격자는 그 자체로 참조되는 파일에 악성 코드를 삽입합니다. pipeline (예: 내부에서 참조되는 스크립트) pipeline 설정 파일)
두 경우 모두 GitHub는 수정된 내용을 실행합니다. pipeline 사전 검토나 승인이 필요 없습니다..
Early detection of PPE
How can we detect this type of vulnerability?
Let’s see this example pipeline :
name: PR CI on: pull_request: branches: [ main ] env: MY_SECRET: ${{ secrets.MY_SECRET }} jobs: pr_build_test_and_merge: runs-on: ubuntu-latest steps: # checkout PR code - name: Checkout repository uses: actions/checkout@v4 # Simulation of a compilation - name: Building ... run: | echo $MY_SECRET mkdir ./bin touch ./bin/mybin.exe # Simulation of running tests - name: Running tests ... id : run_tests run: | echo Running tests.. chmod +x runtests.sh ./runtests.sh "${{ github.event.pull_request.user.login }}" "${{ github.workflow }}" echo Tests executed. And the content of a dummy shell script (runtests.sh):
#!/usr/bin/bash echo "Executing Tests script [from user $1 at $2]" >> runtests.out exit 0 The pipeline is quite simple: its aim is to provide the reviewer with some preliminary hints for the Pull Request (PR) acceptance process:
- It’ will be triggered on 풀 리퀘스트 (i.e. whenever a PR is created)
- It checkout the PR code (i.e. the contributed code)
- It will make the build
- It will run tests on contributed code (e.g. by executing a shell script)
Steps #3 (make the build) and #4 (run test) will fail if the code does not compile or it fails to pass the tests. So, these steps act as a necessary, but not sufficient, condition to accept the PR. If successful, the repo admin will proceed to review the contributed code and, based on that, he/she will accept/reject/comment the PR.
자이제니 스캐너
제니 provides a CLI (the “자이제니 스캐너”) that can be embedded into a pipeline or run in a command-line. The Xygeni Scanner will process the pipelines to check for vulnerabilities and, if a GitHub PAT is provided, it will connect to GitHub to discover vulnerabilities at the org/repo level.
Xygeni Inventory
When we execute Xygeni Scanner on this repo, it discovers a useful set of assets (the Xygeni Inventory). The Inventory will be populated with many different types of CI/CD 자산같은 :
- The SCM 시스템 where the repo is stored
- The SCM 플러그인 installed/used
- The 코드 저장소 그 자체
- The SCM 회사조직 where the repo belongs to
- The CI/CD Pipelines and Jobs
- The CI/CD 시스템 실행 pipelines
- IaC 리소스 defined into the repo
- 외부 종속성
- 기타..
In our example, we can filter the Inventory by some specific asset type (SCM- and CICD-related assets), so we can see that:
- SCM system is GitHub Cloud
- Repo is stored in GitHub Cloud and belongs to a specific GitHub Organization
- 두 가지가있다 pipelines powered by GitHub (CI/CD 체계)
- 모든 pipeline contains one specific step
By selecting the above pipeline we can see some vulnerabilities:
- At pipeline level, it is vulnerable to both 직접 Indirect PPE.
We can see the details of those Poisoned Pipeline Execution vulnerabilities
Xygeni detects that it’s vulnerable to D-PPE because it’s triggered on a Pull Request event and there are no additional security controls, so any repo user can modify the pipeline and those modifications will be executed without any review or approval.
In the same sense, Xygeni also detects that it’s vulnerable to I-PPE because of the call to the shell script from the pipeline: any repo user can modify the shell script and those modifications will be executed without any review or approval.
더 알고 싶으십니까?
Exploiting PPE
To exploit the PPE let’s consider a scenario where there are two kinds of repo users:
- An internal user (an internal developer working on that repo), with write permissions on the repo
- An 외부 사용자 (an outsourced developer working on that repo but with read permissions on the repo), i.e. not allowed to branch the repo and forced to work on a fork.
Let’s imagine that both are malicious attackers (or impersonated by a malicious actor). The repo contains some secret and both want to steal the repo secret and send it to a hacker-controlled server. To do it, they will take advantage of the Poisoned Pipeline Execution vulnerabilities of the pipeline.
In both cases (external and internal user), they open a Pull Request with the same modifications:
- The pipeline and the shell script are modified 에 read the secret from the environment and send it to a hacker-controlled server
Modifications might be as follows:
Both users will create a Pull Request with the modifications. Upon creation of the PR, GitHub will execute both modifications (with no need of previous review or approval), resulting in the following:
Same for write and read users, in both cases D-PPE and I-PPE are executed, with the difference that the read user is not able to access the secrets. (!!!!)
This reason is because, in the case of a PR coming from a fork, GitHub does not allow access to the repo secrets. Although the read user cannot read the secrets, he/she can still run any other program. A typical attack example is creating PRs that download a crypto miner, so the GitHub runner will execute the crypto miner when executing a poisoned pipeline.
This is not a safe environment, of course!! What might the repo admin do to avoid it?
After some googling, the repo admin decides to modify the pipeline to be triggered on a 풀 리퀘스트 타겟 event. Why? Because pipelines triggered on pull_request_target do not allow executing pipeline 수정, i.e. despite any user modification the “original” pipeline 실행됩니다.
Following our example, the attack will be the same as before. What will happen then after this pipeline modification?
예상대로, D-PPE is not executed but, because I-PPE is still there, the read user is now able to access the repo secret!!!
What is the reason that the read user now has access to secrets? Although the pipeline cannot be modified, it is still possible to modify the shell script. 때 pipeline is triggered on pull_request_target, it will be executed in privileged mode so it will also be the shell script, resulting in the shell script having access to repo secrets!!
예방 조치
GitHub provides some measures to protect against malicious PRs.
지점 보호 규칙
With GitHub you can define Branch Protection Rules over selected branches.
For your protected branches, you can specify a policy that ~이 필요하다. pull request 병합하기 전에 (as well as additional conditions such as a required number of approvals, reviews from code owners, etc. )
A couple of conditions that deserves special consideration are:
- "Allow specified actors to bypass required pull requests".
- "Do not allow bypassing the above settings"
While most of the conditions add strictness to the policy, these ones relax the policy and that might entail an open door to malicious activities, for example, in the case that credentials are stolen by “privileged” actors.
Restrict GITHUB_TOKEN permissions (least-privilege)
Restrict the GitHub token permissions only to the required ones; this way, even in case the attackers succeed in compromising your pipeline, they won’t be able to do much.
Avoid string interpolation by using pipeline env variables
Whenever you use some input variables in your pipeline, be aware that they should be considered by default as “untrusted” data (their content is controlled by the end user). See Untrusted Actions and Workflows Secure Learn Github Actions.
You should always use environment variables to insert input variables inside scripts instead of using string interpolation.
Workflow runs and approval requirements
럭셔리 공개 repos, GitHub allows to specify how to work with “external” PRs.
GitHub Organization settings (“Org >> Settings >> Actions >> General”) let specify how to manage external PR’s:
By default, GitHub will require PR approval for 1st-time contributors, making malicious request attacks more complicated. Even so, the attacker might gain the project maintainers’ trust for example by contributing some innocent pull request before the real attack.
이런 의미에서 3rd option (Requiring approval for all outside collaborators) adds a higher level of control.
럭셔리 사설 repos, GitHub provides also helpful control both at the Organization- and Repo-level.
"Run Workflows from Pull Requests” (not checked by default) allows users to run workflows from fork PRs (using a GITHUB_TOKEN with read-only permissions and with no access to secrets). By selecting this option together with the last one (“Require approval for fork PRs workflows”) , you can reach a similar policy to private repos (as shown above).
As we have seen in the PPE exploit from a read user, allowing running workflows from fork pull requests is unsafe!!
The remaining options (“포크에서 워크플로우로 쓰기 토큰을 전송합니다. pull requests"및"Send secrets and variables to workflows from for pull requests") decrease the security level applied to fork PRs.
You can define this fork policy either at the Organization Level or at Repo-level. If the policy is disabled at org-level, it cannot be enabled at the repo level. But, if the policy is enabled at org-level, it can be disabled at repo-level.
요점을 되풀이하다
We hope you have seen the implications of having some pipeline vulnerable to Poisoned Pipeline Execution. It’s too easy to commit a vulnerable pipeline, and it’s difficult to write a safe one.
So it’s highly valuable to use the Xygeni Scanner to be aware of such vulnerabilities.
You cannot solve a vuln unless you are aware of its existence !!
But… There is still a pending question… How to avoid the I-PPE ?
This will be the subject of our next post 🙂 … 간접 중독 Pipeline 실행 (I-PPE) !!




