Skip to content

Commit a64d381

Browse files
tetragon/windows: Build windows bpf program
Sample commit to check building and download-ability of Windows bpf program Signed-off-by: Anadi Anadi <[email protected]>
1 parent d3e194c commit a64d381

File tree

2 files changed

+308
-0
lines changed

2 files changed

+308
-0
lines changed
+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
name: Windows Build and Smoke
2+
on:
3+
pull_request:
4+
paths-ignore:
5+
- docs/**
6+
push:
7+
branches:
8+
- main
9+
- v*
10+
paths-ignore:
11+
- docs/**
12+
jobs:
13+
windows-ebpf-prog-build:
14+
name: Build Windows process ebpf program
15+
runs-on: windows-2022
16+
timeout-minutes: 15
17+
strategy:
18+
matrix:
19+
version:
20+
- main
21+
env:
22+
GOCACHE: D:\gocache
23+
GOMODCACHE: D:\gomodcache
24+
TEMP: D:\temp
25+
CI_EFW_VERSION: 0.20.0
26+
BUILD_CONFIGURATION: Release
27+
BUILD_PLATFORM: x64
28+
29+
steps:
30+
- run: mkdir D:\temp
31+
shell: pwsh
32+
33+
- name: Set MSVC Environment Variables
34+
shell: cmd
35+
run: |
36+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
37+
powershell.exe "echo 'msvc_tools_path=%VCToolsInstallDir%' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append"
38+
powershell.exe "echo 'msvc_tools_version=%VCToolsVersion%' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append"
39+
powershell.exe "echo 'ASAN_WIN_CONTINUE_ON_INTERCEPTION_FAILURE=true' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append"
40+
powershell.exe "echo 'VCINSTALLDIR=%VCINSTALLDIR%' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append"
41+
42+
- name: Add MSBuild to PATH
43+
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce
44+
with:
45+
msbuild-architecture: x64
46+
47+
- name: Add Visual Studio LLVM to path
48+
if: steps.skip_check.outputs.should_skip != 'true'
49+
run: |
50+
echo "$env:VCINSTALLDIR\tools\llvm\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
51+
52+
- name: Check for Clang version (MSVC)
53+
if: steps.skip_check.outputs.should_skip != 'true'
54+
run:
55+
clang.exe --version
56+
57+
- name: Check clang version (LLVM)
58+
if: steps.skip_check.outputs.should_skip != 'true'
59+
shell: cmd
60+
run:
61+
'"c:\Program Files\llvm\bin\clang.exe" --version'
62+
63+
64+
- name: Download ntosebpfext
65+
id: download-ntosebpfet
66+
shell: powershell
67+
working-directory: ${{ env.TEMP }}
68+
run: |
69+
git clone --recursive https://github.com/microsoft/ntosebpfext.git
70+
cd ${{ env.TEMP }}\ntosebpfext
71+
git checkout e7dc209a8be0da2ff5d75f5772a0ee0bf4a10383
72+
73+
- name: Configuring repo for first build
74+
if: steps.skip_check.outputs.should_skip != 'true'
75+
working-directory: ${{ env.TEMP }}\ntosebpfext
76+
env:
77+
CXXFLAGS: /ZH:SHA_256 ${{ env.CXX_FLAGS }}
78+
LDFLAGS: ${{ env.LD_FLAGS }}
79+
run: |
80+
.\scripts\initialize_repo.ps1
81+
82+
- name: Build
83+
working-directory: ${{ env.TEMP }}\ntosebpfext
84+
run: msbuild -target:Tools\process_monitor_bpf:Rebuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=${{env.BUILD_PLATFORM}} /bl:${{env.BUILD_PLATFORM}}_${{env.BUILD_CONFIGURATION}}\build_logs\build.binlog ${{env.BUILD_OPTIONS}} ${{env.SOLUTION_FILE_PATH}}
85+
86+
- name: Zip Build Output
87+
working-directory: ${{ env.TEMP }}\ntosebpfext
88+
run: |
89+
Compress-Archive -Path ${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -DestinationPath .\build-${{env.BUILD_PLATFORM}}.${{env.BUILD_CONFIGURATION}}.zip
90+
91+
- name: Upload Build Output
92+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1
93+
with:
94+
working-directory: ${{ env.TEMP }}\ntosebpfext
95+
name: ntosebpfext-build-output
96+
path: ${{ env.TEMP }}\ntosebpfext\build-${{env.BUILD_PLATFORM}}.${{env.BUILD_CONFIGURATION}}.zip
97+
retention-days: 5
98+
99+
100+
windows-tetragon-build:
101+
name: Build and Uplod Windows Tetragon and Tetra Binaries
102+
runs-on: windows-2022
103+
timeout-minutes: 15
104+
strategy:
105+
matrix:
106+
version:
107+
- main
108+
109+
env:
110+
TEMP: D:\temp
111+
112+
113+
steps:
114+
115+
- run: mkdir D:\temp
116+
shell: pwsh
117+
118+
- name: Install Go
119+
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
120+
with:
121+
go-version: '1.24.2'
122+
123+
124+
- name: Checkout
125+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
126+
with:
127+
path: go/src/github.com/cilium/tetragon/
128+
129+
- name: Build and Zip tetragon Windows binaries
130+
working-directory: ${{ github.workspace }}\go\src\github.com\cilium\tetragon
131+
shell: powershell
132+
run: |
133+
go build -o .\Tetra.exe .\cmd\tetra\
134+
go build -o .\Tetragon.exe .\cmd\tetragon\
135+
Get-ChildItem
136+
New-Item -ItemType Directory -Path ${{ env.TEMP }}\Tetragon-Windows
137+
Copy-Item *.exe -Destination ${{ env.TEMP }}\Tetragon-Windows
138+
Compress-Archive -Path ${{ env.TEMP }}\Tetragon-Windows\* -DestinationPath ${{ env.TEMP }}\Tetragon-Windows.zip
139+
Get-ChildItem -Recurse ${{ env.TEMP }}
140+
141+
- name: Upload Tetragon Windows binaries
142+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1
143+
with:
144+
name: tetragon-windows-build-output
145+
path: ${{ env.TEMP }}\Tetragon-Windows.zip
146+
retention-days: 5
147+
148+
windows-Smoke-test:
149+
name: Deploy and Test tetragon for Windows
150+
runs-on: windows-2022
151+
needs:
152+
- windows-tetragon-build
153+
- windows-ebpf-prog-build
154+
timeout-minutes: 15
155+
strategy:
156+
matrix:
157+
version:
158+
- main
159+
env:
160+
TEMP: D:\temp
161+
162+
steps:
163+
- run: mkdir D:\temp
164+
shell: powershell
165+
166+
- run: mkdir D:\temp\test
167+
shell: powershell
168+
169+
- name: Download and Install eBPF for Windows
170+
shell: powershell
171+
run: |
172+
Invoke-WebRequest -Uri "https://github.com/microsoft/ebpf-for-windows/releases/download/Release-v0.21.0/ebpf-for-windows.x64.0.21.0.msi" -OutFile $env:TEMP\ebpf-for-windows.x64.0.21.0.msi
173+
174+
Start-Process -FilePath C:\Windows\system32\msiexec.exe -ArgumentList "/i ""$env:TEMP\ebpf-for-windows.x64.0.21.0.msi"" /qn INSTALLFOLDER=""C:\Program Files\ebpf-for-windows"" ADDLOCAL=eBPF_Runtime_Components"
175+
176+
- name: Download tetragon-windows-build-output
177+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
178+
with:
179+
path: ${{ env.TEMP }}\test
180+
name: tetragon-windows-build-output
181+
182+
- name: Download ntosebpfext-build-output
183+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
184+
with:
185+
path: ${{ env.TEMP }}\test
186+
name: ntosebpfext-build-output
187+
188+
- name: Checkout
189+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
190+
with:
191+
path: go/src/github.com/cilium/tetragon/
192+
193+
- name: Setup Tetragon for Windows
194+
working-directory: ${{ github.workspace }}\go\src\github.com\cilium\tetragon
195+
shell: powershell
196+
run: ${{ github.workspace }}\go\src\github.com\cilium\tetragon\install\windows\setup-windows.ps1 ${{ env.TEMP }}\test\tetragon-windows-build-output.zip ${{ env.TEMP }}\test\ntosebpfext-build-output.zip
197+
198+
- name: Run Smoke test Windows
199+
working-directory: C:\Program Files\Tetragon\cmd
200+
shell: powershell
201+
run: |
202+
# Define the path to the JSON file
203+
$jsonFilePath = "C:\Program Files\Tetragon\events.json"
204+
205+
# Define the path to the executable
206+
$tetragonProcess = "C:\Program Files\Tetragon\cmd\tetragon.exe"
207+
208+
# Start the process in the background and capture its PID
209+
$tetragonBackgroundProcess = Start-Process -FilePath "$tetragonProcess" -ArgumentList "--export-filename ""$jsonFilePath""" -RedirectStandardOutput "C:\Program Files\Tetragon\tetragon.log" -NoNewWindow -PassThru
210+
211+
Start-Sleep -Seconds 5
212+
213+
if(Get-Process -id $tetragonBackgroundProcess.Id) {
214+
Write-Host "Tetragon Running "
215+
}
216+
else {
217+
throw "Tetragon is Not Running"
218+
}
219+
220+
$notepad = Start-Process -FilePath "C:\Windows\System32\notepad.exe" -PassThru
221+
$notepadPID = $notepad.Id
222+
Write-Host "Process launched with PID: $notepadPID"
223+
224+
$searchString = "\{\""process_exec\""\:\{\""process\""\:\{\""exec_id\""\:\"".{16,30}\""\,\""pid\""\:$notepadPID\,\""uid\""\:0\,\""binary\""\:\""C:\\\\Windows\\\\system32\\\\notepad.exe\"""
225+
226+
Write-Host "Looking for regex: $searchString"
227+
# Load the JSON content
228+
$jsonContent = Get-Content -Path $jsonFilePath
229+
230+
# Search for the PID in the JSON file
231+
if ($jsonContent -match $searchString) {
232+
Write-Host "Found PID $notepadPID in JSON file: $searchString"
233+
Exit 0
234+
235+
} else {
236+
Write-Host "PID $notepadPID not found in JSON file."
237+
throw "PID not found in JSON file."
238+
}
239+
240+
241+
242+
243+
244+
245+
246+
247+
248+
249+

install/windows/setup-windows.ps1

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
param (
2+
[string]$tetragonBinariesZip, # Path to the first ZIP archive
3+
[string]$ntosebpfextZip # Path to the second ZIP archive
4+
)
5+
6+
# Function to extract a zip file
7+
function Extract-ZipFile {
8+
param (
9+
[string]$zipPath
10+
)
11+
$destinationName = [System.IO.Path]::GetFileNameWithoutExtension($zipPath)
12+
$destinationPath = Join-Path (Split-Path -Parent $zipPath)$destinationName
13+
14+
if ( (Test-Path $destinationPath)) {
15+
Remove-Item -Path $destinationPath -Recurse -Force
16+
}
17+
18+
New-Item -ItemType Directory -Path $destinationPath
19+
20+
Add-Type -AssemblyName System.IO.Compression.FileSystem
21+
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $destinationPath)
22+
}
23+
24+
# Extract the first ZIP archive
25+
$tetragonBinariesDir = Extract-ZipFile $tetragonBinariesZip
26+
Write-Host "Tetragon Binaries extracted to: $tetragonBinariesDir"
27+
28+
# Extract the second ZIP archive
29+
$ntosebpfextZipExtracted = Extract-ZipFile -zipPath $ntosebpfextZip
30+
Write-Host "ntosebpfext extracted to: $ntosebpfextZipExtracted"
31+
32+
$buildZip = Join-Path($ntosebpfextZipExtracted)"build-x64.Release.zip"
33+
Write-Host "Extracting $buildZip"
34+
$ntosebpfextZipBinaries = Extract-ZipFile -zipPath $buildZip
35+
Write-Host "Ntosebpfext archive extracted to: $ntosebpfextZipBinaries"
36+
37+
$tetragonZip = Join-Path($tetragonBinariesDir)"Tetragon-Windows.zip"
38+
Write-Host "Extracting $tetragonZip"
39+
$tetragonBinaries = Extract-ZipFile -zipPath $tetragonZip
40+
Write-Host "Tetragon archive extracted to: $tetragonBinaries"
41+
42+
43+
New-Item -ItemType Directory -Path "C:\Program Files\Tetragon\cmd" -Force
44+
New-Item -ItemType Directory -Path "C:\Program Files\Tetragon\BPF" -Force
45+
New-Item -ItemType Directory -Path "C:\Program Files\Tetragon\tetragon.tp.d" -Force
46+
47+
Copy-Item -Path $tetragonBinaries\*.exe -destination "C:\Program Files\tetragon\cmd\" -Force
48+
49+
Copy-Item -Path "$ntosebpfextZipBinaries\Release\process_monitor_km\process_monitor.sys" -destination "C:\Program Files\tetragon\BPF\" -Force
50+
51+
"$ntosebpfextZipBinaries\Release\ntos_ebpf_ext_export_program_info.exe" --clear
52+
53+
"$ntosebpfextZipBinaries\Release\ntos_ebpf_ext_export_program_info.exe"
54+
55+
sc.exe delete "ntosebpfext"
56+
57+
sc.exe create ntosebpfext type= kernel start= demand binPath= "$ntosebpfextZipBinaries\Release\ntosebpfext\ntosebpfext.sys"
58+
59+
sc.exe start ntosebpfext

0 commit comments

Comments
 (0)