Repository navigation
324 lines (300 loc) · 14.5 KB
/
Copy pathrun-cli-e2e-tests.yml
File metadata and controls
324 lines (300 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
name: CLI E2EE Tests
on:
pull_request:
types: [opened, synchronize]
workflow_dispatch:
workflow_call:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
name: CLI End-to-End Testing
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: "1.26.11"
- name: Install dependencies
run: go get .
- name: Build the CLI
run: go build -o infisical-cli
- name: Checkout infisical repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: infisical/infisical
path: infisical
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
docker system prune -af
df -h
- name: Test with the Go CLI
run: go test -v -timeout 30m -count=1 github.com/infisical/cli/e2e-tests/proxy github.com/infisical/cli/e2e-tests/relay
working-directory: ./e2e
env:
INFISICAL_BACKEND_DIR: ${{ github.workspace }}/infisical/backend
INFISICAL_LICENSE_KEY: ${{ secrets.INFISICAL_LICENSE_KEY }}
INFISICAL_CLI_EXECUTABLE: ${{ github.workspace }}/infisical-cli
CLI_E2E_DEFAULT_RUN_METHOD: subprocess
agent-test:
runs-on: ubuntu-latest
name: Agent End-to-End Testing
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: "1.26.11"
- name: Install dependencies
run: go get .
- name: Build the CLI
run: go build -o infisical-cli
- name: Checkout infisical repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: infisical/infisical
path: infisical
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
docker system prune -af
df -h
- name: Test Certificate Agent
run: go test -v -timeout 30m -count=1 github.com/infisical/cli/e2e-tests/agent
working-directory: ./e2e
env:
INFISICAL_LICENSE_KEY: ${{ secrets.INFISICAL_LICENSE_KEY }}
INFISICAL_BACKEND_DIR: ${{ github.workspace }}/infisical/backend
INFISICAL_CLI_EXECUTABLE: ${{ github.workspace }}/infisical-cli
CLI_E2E_DEFAULT_RUN_METHOD: subprocess
# The Linux PAM job can't catch macOS failures: Rust embeds bitcode there as __LLVM,__bitcode
# sections, which strip-llvm-bitcode.sh has to remove before Go 1.26.11 accepts the bridge.
rdp-build-macos:
runs-on: macos-latest
name: RDP Bridge Build (macOS)
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: "1.26.11"
- name: Cache cargo registry + target
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: |
~/.cargo/registry
~/.cargo/git
packages/pam/handlers/rdp/native/target
key: rdp-bridge-cargo-${{ runner.os }}-${{ hashFiles('packages/pam/handlers/rdp/native/Cargo.lock') }}
restore-keys: rdp-bridge-cargo-${{ runner.os }}-
- name: Install pinned Rust toolchain
working-directory: packages/pam/handlers/rdp/native
run: rustup show active-toolchain
- name: Build Rust RDP bridge
working-directory: packages/pam/handlers/rdp/native
run: cargo build --release
- name: Strip LLVM bitcode from the RDP bridge
working-directory: packages/pam/handlers/rdp/native
run: ./strip-llvm-bitcode.sh target/release
- name: Build the CLI with the RDP bridge
run: CGO_ENABLED=1 go build -tags rdp -o infisical-cli
- name: Run the CLI
run: ./infisical-cli --version
pam-test:
runs-on: ubuntu-latest
name: PAM End-to-End Testing
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: "1.26.11"
- name: Install dependencies
run: go get .
- name: Cache cargo registry + target
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: |
~/.cargo/registry
~/.cargo/git
packages/pam/handlers/rdp/native/target
key: rdp-bridge-cargo-${{ runner.os }}-${{ hashFiles('packages/pam/handlers/rdp/native/Cargo.lock') }}
restore-keys: rdp-bridge-cargo-${{ runner.os }}-
- name: Install pinned Rust toolchain
working-directory: packages/pam/handlers/rdp/native
run: rustup show active-toolchain
- name: Build Rust RDP bridge
working-directory: packages/pam/handlers/rdp/native
run: cargo build --release
- name: Strip LLVM bitcode from the RDP bridge
working-directory: packages/pam/handlers/rdp/native
run: ./strip-llvm-bitcode.sh target/release
- name: Build the CLI
run: CGO_ENABLED=1 go build -tags rdp -o infisical-cli
- name: Install RDP test dependencies
run: |
sudo apt-get update && sudo apt-get install -y --no-install-recommends freerdp3-x11 xvfb
Xvfb :99 -screen 0 1024x768x24 &
echo "DISPLAY=:99" >> "$GITHUB_ENV"
- name: Checkout infisical repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: infisical/infisical
path: infisical
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
docker system prune -af
df -h
- name: Test PAM Resources
run: go test -v -timeout 30m -count=1 github.com/infisical/cli/e2e-tests/pam
working-directory: ./e2e
env:
INFISICAL_BACKEND_DIR: ${{ github.workspace }}/infisical/backend
INFISICAL_LICENSE_KEY: ${{ secrets.INFISICAL_LICENSE_KEY }}
INFISICAL_CLI_EXECUTABLE: ${{ github.workspace }}/infisical-cli
CLI_E2E_DEFAULT_RUN_METHOD: subprocess
os-specific-test:
runs-on: ${{ matrix.os }}
name: OS-Specific Testing (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-2022]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: "1.26.11"
- name: Build the CLI
run: go build -o infisical-cli${{ runner.os == 'Windows' && '.exe' || '' }}
# --exit-code 0 so leaks in test fixtures don't fail the job; a failed git scan still exits 1.
- name: Run infisical scan
run: ./infisical-cli scan -v --exit-code 0
# -vet=off: packages/cmd/run.go has existing printf vet failures.
# TestProcessTemplate is the Windows regression check for backslash source-paths in agent templates.
- name: Run agent unit tests
run: go test -vet=off -count=1 -run 'TestProcessTemplate|AgentService|AgentSystemd|RevokeCredentials|PathsVisibleToSystemd' ./packages/cmd/ ./packages/agent/
# The agent points at a closed port, so auth keeps failing and being retried and the service stays up.
# Auth failing on the network rather than on reading ./client-id proves relative paths resolve from the config's directory.
- name: Test agent service (systemd)
if: runner.os == 'Linux'
run: |
set -euo pipefail
# the shared systemd unit runs `infisical agent start` from PATH, makes /home inaccessible and has its own /tmp and /var/tmp
sudo cp ./infisical-cli /usr/local/bin/infisical
dir=/etc/infisical/agents/ci
sudo mkdir -p "$dir"
echo "client-id" | sudo tee "$dir/client-id" > /dev/null
echo "client-secret" | sudo tee "$dir/client-secret" > /dev/null
printf '%s\n' 'infisical:' ' address: "http://127.0.0.1:1"' 'auth:' ' type: "universal-auth"' ' config:' ' client-id: "./client-id"' ' client-secret: "./client-secret"' | sudo tee "$dir/agent-config.yaml" > /dev/null
# the service logs to the systemd journal
journal() { sudo journalctl -u ci-agent.service --no-pager; }
# a config under /home is refused, since the service could not read it
cp "$dir/agent-config.yaml" "$RUNNER_TEMP/agent-config.yaml"
if sudo ./infisical-cli agent service install ci-agent --config "$RUNNER_TEMP/agent-config.yaml"; then
echo "install accepted a config under /home"
exit 1
fi
# a name systemd already uses would override that service
if sudo ./infisical-cli agent service install systemd-journald --config "$dir/agent-config.yaml"; then
echo "install accepted the name of a system service"
exit 1
fi
test ! -e /etc/systemd/system/systemd-journald.service
sudo ./infisical-cli agent service install ci-agent --config "$dir/agent-config.yaml"
# the service runs as root, so it runs its own copy of the config that only root can change
test "$(sudo stat -c '%U %a' /etc/infisical/agents/ci-agent.service-config.yaml)" = "root 600"
sudo cmp "$dir/agent-config.yaml" /etc/infisical/agents/ci-agent.service-config.yaml
# Type=notify: start only returns once the agent reported it is ready
sudo ./infisical-cli agent service start ci-agent
systemctl is-active --quiet ci-agent
for _ in $(seq 1 60); do
grep -q "unable to authenticate" <(journal) && break
sleep 1
done
journal
grep -q "unable to authenticate" <(journal)
if grep -q "unable to get client id" <(journal); then
echo "client-id was not resolved from the config directory"
exit 1
fi
sudo ./infisical-cli agent service stop ci-agent
if systemctl is-active --quiet ci-agent; then
echo "service is still active after stop"
exit 1
fi
sudo ./infisical-cli agent service uninstall ci-agent
test ! -e /etc/systemd/system/ci-agent.service
test ! -e /etc/infisical/agents/ci-agent.env.conf
test ! -e /etc/infisical/agents/ci-agent.service-config.yaml
- name: Test agent service (Windows Service Control Manager)
if: runner.os == 'Windows'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
$dir = Join-Path $env:RUNNER_TEMP 'agent-service'
New-Item -ItemType Directory -Force -Path $dir | Out-Null
Set-Content -Path (Join-Path $dir 'client-id') -Value 'client-id'
Set-Content -Path (Join-Path $dir 'client-secret') -Value 'client-secret'
Set-Content -Path (Join-Path $dir 'agent-config.yaml') -Value @"
infisical:
address: "http://127.0.0.1:1"
auth:
type: "universal-auth"
config:
client-id: "./client-id"
client-secret: "./client-secret"
"@
$config = Join-Path $dir 'agent-config.yaml'
$log = Join-Path $env:ProgramData 'Infisical\Agent\ci-agent.log'
$exe = './infisical-cli.exe'
$serviceDir = Join-Path $env:ProgramFiles 'Infisical\Agent\ci-agent'
& $exe agent service install ci-agent --config $config
# the service runs as LocalSystem: it runs its own copies of infisical.exe and the config, and what it runs, obeys
# and logs is closed to standard users
$configCopy = Join-Path $serviceDir 'service-config.yaml'
$binary = (Get-CimInstance Win32_Service -Filter "Name='ci-agent'").PathName
if ($binary -notlike "*$serviceDir\infisical.exe*--config*$configCopy*") { throw "the service does not run its own copies of infisical.exe and the config: $binary" }
if ((Get-FileHash $configCopy).Hash -ne (Get-FileHash $config).Hash) { throw 'the config copy differs from the config' }
foreach ($path in @($configCopy, (Split-Path $log), (Split-Path (Split-Path $log)), $serviceDir)) {
if ((Get-Acl $path).Access | Where-Object { $_.IdentityReference -match 'Users' }) { throw "$path is still accessible to standard users" }
}
& $exe agent service start ci-agent
if ((Get-Service ci-agent).Status -ne 'Running') { throw 'service is not running after start' }
$deadline = (Get-Date).AddSeconds(60)
while (-not ((Test-Path $log) -and (Select-String -Path $log -Pattern 'unable to authenticate' -Quiet))) {
if ((Get-Date) -gt $deadline) { throw 'the agent did not log an authentication attempt' }
Start-Sleep -Seconds 1
}
Get-Content $log
if (Select-String -Path $log -Pattern 'unable to get client id' -Quiet) { throw 'client-id was not resolved from the config directory' }
# errors are copied into the Application event log under the service name
$errors = Get-WinEvent -FilterHashtable @{ LogName = 'Application'; ProviderName = 'ci-agent'; Level = 2 } -MaxEvents 5
$errors | Format-List TimeCreated, Message
& $exe agent service stop ci-agent
if ((Get-Service ci-agent).Status -ne 'Stopped') { throw 'service did not stop' }
& $exe agent service uninstall ci-agent
# the SCM removes a deleted service once the last handle to it closes
$deadline = (Get-Date).AddSeconds(15)
while (Get-Service ci-agent -ErrorAction SilentlyContinue) {
if ((Get-Date) -gt $deadline) { throw 'service still exists after uninstall' }
Start-Sleep -Seconds 1
}
if (Test-Path $serviceDir) { throw "uninstall left $serviceDir behind" }