-
Notifications
You must be signed in to change notification settings - Fork 14
294 lines (282 loc) · 11.8 KB
/
pkg_msi.yaml
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
name: 'PKG: Microsoft Software Installer (MSI)'
on:
workflow_dispatch:
inputs:
version:
description: 'Package Version'
required: true
default: '0.0.1'
name:
description: 'Package Name'
required: false
default: 'mondoo'
skip-publish:
description: 'Skip publish?'
required: false
default: false
type: boolean
release:
types: [published]
jobs:
setup:
name: 'Setup'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
trimmed-version: ${{ steps.version.outputs.trimmed_version }}
name: ${{ steps.version.outputs.name }}
steps:
- name: Set Version (Workflow Dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
echo VERSION=${{ inputs.version }} >> $GITHUB_ENV
- name: Set Version (Release Event)
if: github.event_name == 'release'
run: |
echo VERSION=${{ github.event.release.tag_name }} >> $GITHUB_ENV
- name: Unified Version
id: version
run: |
INPUT_NAME=${{ inputs.name }}
if [[ ${INPUT_NAME} == '' ]]; then
echo "Name is empty, using default"
echo "name=mondoo" >> $GITHUB_OUTPUT
else
echo "Name: ${INPUT_NAME}"
echo "name=${INPUT_NAME}" >> $GITHUB_OUTPUT
fi
V=$(echo $VERSION | sed 's/v//')
echo "Version: $V"
echo "version=${V}" >> $GITHUB_OUTPUT
echo "trimmed_version=$(echo ${V} | sed 's/-.*//')" >> $GITHUB_OUTPUT
- name: Ensure version of cnquery and cnspec are available
run: |
curl -sL --head --fail https://github.com/mondoohq/cnquery/releases/download/v${{ steps.version.outputs.version }}/cnquery_${{ steps.version.outputs.version }}_windows_amd64.zip \
https://github.com/mondoohq/cnspec/releases/download/v${{ steps.version.outputs.version }}/cnspec_${{ steps.version.outputs.version }}_windows_amd64.zip \
https://github.com/mondoohq/cnquery/releases/download/v${{ steps.version.outputs.version }}/cnquery_${{ steps.version.outputs.version }}_windows_arm64.zip \
https://github.com/mondoohq/cnspec/releases/download/v${{ steps.version.outputs.version }}/cnspec_${{ steps.version.outputs.version }}_windows_arm64.zip
dist-prepare:
name: Prepare Distribution for Packaging
strategy:
matrix:
arch:
- amd64
- arm64
runs-on: ubuntu-latest
needs: setup
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Binaries
env:
VERSION: ${{ needs.setup.outputs.version }}
run: |
# TODO: We should check the sums here
mkdir -p dist/${{ matrix.arch }} && cd dist/${{ matrix.arch }}
curl -sSL -O https://github.com/mondoohq/cnspec/releases/download/v${VERSION}/cnspec_${VERSION}_windows_${{ matrix.arch }}.zip
unzip cnspec_${VERSION}_windows_${{ matrix.arch }}.zip
rm cnspec_${VERSION}_windows_${{ matrix.arch }}.zip
curl -sSL -O https://github.com/mondoohq/cnquery/releases/download/v${VERSION}/cnquery_${VERSION}_windows_${{ matrix.arch }}.zip
unzip cnquery_${VERSION}_windows_${{ matrix.arch }}.zip
rm cnquery_${VERSION}_windows_${{ matrix.arch }}.zip
ls -lh
- name: Upload Distribution
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.arch }}
path: dist/${{ matrix.arch }}
msi-build:
name: 'Packaging: Windows MSI'
runs-on: windows-latest
strategy:
matrix:
arch:
- amd64
- arm64
needs:
- setup
- dist-prepare
# For Version: ${{ needs.setup.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Distribution
uses: actions/download-artifact@v4
with:
name: dist-${{ matrix.arch }}
path: dist/${{ matrix.arch }}
- name: Setup Certificate
shell: bash
run: |
echo "${{ secrets.SM_CLIENT_CERT_FILE_B64 }}" | base64 --decode > /d/Certificate_pkcs12.p12
- name: Set signing variables
shell: bash
run: |
echo "SM_HOST=${{ secrets.SM_HOST }}" >> "$GITHUB_ENV"
echo "SM_API_KEY=${{ secrets.SM_API_KEY }}" >> "$GITHUB_ENV"
echo "SM_CLIENT_CERT_FILE=D:\\Certificate_pkcs12.p12" >> "$GITHUB_ENV"
echo "SM_CLIENT_CERT_PASSWORD=${{ secrets.SM_CLIENT_CERT_PASSWORD }}" >> "$GITHUB_ENV"
echo "SM_CODE_SIGNING_CERT_SHA1_HASH=${{ secrets.SM_CODE_SIGNING_CERT_SHA1_HASH }}" >> "$GITHUB_ENV"
echo "C:\Program Files (x86)\Windows Kits\10\App Certification Kit" >> $GITHUB_PATH
echo "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools" >> $GITHUB_PATH
echo "C:\Program Files\DigiCert\DigiCert One Signing Manager Tools" >> $GITHUB_PATH
- name: Setup SSM KSP on windows latest
shell: cmd
run: |
curl --retry 10 --retry-delay 60 -X GET https://one.digicert.com/signingmanager/api-ui/v1/releases/smtools-windows-x64.msi/download -H "x-api-key:%SM_API_KEY%" -o smtools-windows-x64.msi
msiexec /i smtools-windows-x64.msi /quiet /qn
smksp_registrar.exe list
smctl.exe keypair ls
C:\Windows\System32\certutil.exe -csp "DigiCert Signing Manager KSP" -key -user
smksp_cert_sync.exe
- name: Build and Sign MSI
env:
VERSION: ${{ needs.setup.outputs.trimmed-version }}
run: |
$mondooVersion = ${env:VERSION}
echo "Running build job for version ${mondooVersion}"
Copy-Item .\dist\${{ matrix.arch }}\cnquery.exe .\packages\msi\msi\
Copy-Item .\dist\${{ matrix.arch }}\cnspec.exe .\packages\msi\msi\
Copy-Item .\dist\${{ matrix.arch }}\cnquery.exe .\packages\msi\appx\
Copy-Item .\dist\${{ matrix.arch }}\cnspec.exe .\packages\msi\appx\
# build msi package
echo " - Packaging MSI..."
Set-Location -Path '.\packages\msi\'
./package.ps1 -version $mondooVersion -arch ${{ matrix.arch }}
# sign msi package
echo " - Signing MSI..."
Set-Location -Path '.\..\..'
signtool.exe sign /debug /sha1 ${{ secrets.SM_CODE_SIGNING_CERT_SHA1_HASH }} /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 .\packages\msi\mondoo_${{ matrix.arch }}.msi
Copy-Item '.\packages\msi\mondoo_${{ matrix.arch }}.msi' '.\dist\${{ matrix.arch }}'
- name: Dump Signing Log on Failure
if: failure()
run: |
echo "Dumping signing logs..."
gc $home\AppData\Local\Temp\signtool.log
echo "Dumping signing manager logs..."
gc $home\.signingmanager\logs\smctl.log
echo "Dumping signing manager KSP logs..."
gc $home\.signinmanager\logs\smksp.log
echo "Dumping signing manager KSP cert sync logs..."
gc $home\.signingmanager\logs\smksp_cert_sync.log
- name: Cleanup dist before upload
run: |
Remove-Item -Path .\dist\${{ matrix.arch }}\cnquery.exe -Force
Remove-Item -Path .\dist\${{ matrix.arch }}\cnspec.exe -Force
- name: Upload Distribution
uses: actions/upload-artifact@v4
with:
name: msi-${{ matrix.arch }}
path: dist/${{ matrix.arch }}
test-msi-install:
name: Test Signed Package
strategy:
matrix:
arch:
- amd64
# - arm64 # we currently don't have windows arm64 runners to test arm against
needs:
- setup
- msi-build
runs-on: windows-latest
steps:
- name: Download MSI Package
uses: actions/download-artifact@v4
with:
name: msi-${{ matrix.arch }}
path: dist
- name: Verify digital signature is valid
run: |
cd dist
Get-AuthenticodeSignature -FilePath .\\mondoo_${{ matrix.arch }}.msi
- name: Install artifact
run: |
cd dist
msiexec /qn /i mondoo_${{ matrix.arch }}.msi
- name: Verify the correct cnquery version is installed
run: |
$version=& 'C:\Program Files\Mondoo\cnquery.exe' version
$match=$version -like "*${{ needs.setup.outputs.version }}*"
if (-not $match) {
exit 1
}
- name: Run a basic cnquery sanity check
run: |
& 'C:\Program Files\Mondoo\cnquery.exe' run -c "os.base.packages.where(name == 'Mondoo') { name }"
- name: Verify the correct cnspec version is installed
run: |
$version=& 'C:\Program Files\Mondoo\cnspec.exe' version
$match=$version -like "*${{ needs.setup.outputs.version }}*"
if (-not $match) {
exit 1
}
- name: Run a basic cnspec sanity check
run: |
& 'C:\Program Files\Mondoo\cnspec.exe' run -c "os.base.packages.where(name == 'Mondoo') { name }"
- name: Login to edge with cnspec
run: |
& 'C:\Program Files\Mondoo\cnspec.exe' login -t "${{ secrets.INSTALL_TEST_MONDOO_REGISTRATION_TOKEN }}" --config C:\ProgramData\Mondoo\mondoo.yml
- name: Run a basic cnspec sanity check
run: |
& 'C:\Program Files\Mondoo\cnspec.exe' policy download mondoo-windows-installer -f mondoo-windows-installer.mql.yaml
& 'C:\Program Files\Mondoo\cnspec.exe' scan local --detect-cicd --score-threshold 100 -o full --policy-bundle mondoo-windows-installer.mql.yaml
- name: Logout from edge with cnspec
run: |
& 'C:\Program Files\Mondoo\cnspec.exe' logout --config C:\ProgramData\Mondoo\mondoo.yml --force
publish:
name: 'Publish: Releases'
strategy:
matrix:
arch:
- amd64
- arm64
needs:
- setup
- msi-build
- test-msi-install
if: ${{ ! inputs.skip-publish }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download MSI Package
uses: actions/download-artifact@v4
with:
name: msi-${{ matrix.arch }}
path: dist
- name: Authenticate with Google Cloud
id: gauth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{secrets.GCP_CREDENTIALS}}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Verify access to release bucket
env:
VERSION: ${{ needs.setup.outputs.version }}
run: |
gsutil ls gs://releases-us.mondoo.io/mondoo
- name: Upload static content to buckets
env:
VERSION: ${{ needs.setup.outputs.version }}
run: |
cd dist
mv mondoo_${{ matrix.arch }}.msi mondoo_${VERSION}_windows_${{ matrix.arch }}.msi
sha256sum mondoo_${VERSION}_windows_${{ matrix.arch }}.msi >> checksums.windows_${{ matrix.arch }}.txt
gsutil cp checksums.windows_${{ matrix.arch }}.txt gs://releases-us.mondoo.io/mondoo/${VERSION}/checksums.windows_${{ matrix.arch }}.txt
gsutil cp mondoo_${VERSION}_windows_${{ matrix.arch }}.msi gs://releases-us.mondoo.io/mondoo/${VERSION}/mondoo_${VERSION}_windows_${{ matrix.arch }}.msi
- name: Reindex folder on releaser.mondoo.com
uses: peter-evans/repository-dispatch@v3
env:
VERSION: ${{ needs.setup.outputs.version }}
with:
token: ${{ secrets.RELEASR_ACTION_TOKEN }}
repository: "mondoohq/releasr"
event-type: reindex
client-payload: '{
"reindex-path": "mondoo/${{ env.VERSION }}",
"bucket": "releases-us.mondoo.io"
}'
- name: Cleanup
run: |
rm -f "${{ steps.gauth.outputs.credentials_file_path }}"