Skip to content

Commit 547bea3

Browse files
vdyederrickstolee
authored andcommitted
release: add signing step for .deb package
- sign using Azure-stored certificates & client - sign on Windows agent via python script - job skipped if credentials for accessing certificate aren't present
1 parent 6e865b5 commit 547bea3

File tree

2 files changed

+158
-2
lines changed

2 files changed

+158
-2
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import json
2+
import os
3+
import glob
4+
import pprint
5+
import subprocess
6+
import sys
7+
8+
esrp_tool = os.path.join("esrp", "tools", "EsrpClient.exe")
9+
10+
AAD_ID = "38aa33bc-a7e7-4007-bfb2-e8b17f04aadc"
11+
WORKSPACE = os.environ['GITHUB_WORKSPACE'].strip()
12+
ARTIFACTS_DIR = os.environ['ARTIFACTS_DIR'].strip()
13+
14+
def main():
15+
source_root_location = os.path.join(WORKSPACE, ARTIFACTS_DIR, "unsigned")
16+
destination_location = os.path.join(WORKSPACE, ARTIFACTS_DIR)
17+
18+
files = glob.glob(os.path.join(source_root_location, "*.deb"))
19+
20+
print("Found files:")
21+
pprint.pp(files)
22+
23+
if len(files) < 1 or not files[0].endswith(".deb"):
24+
print("Error: cannot find .deb to sign")
25+
exit(1)
26+
27+
file_to_sign = os.path.basename(files[0])
28+
29+
auth_json = {
30+
"Version": "1.0.0",
31+
"AuthenticationType": "AAD_CERT",
32+
"TenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
33+
"ClientId": AAD_ID,
34+
"AuthCert": {
35+
"SubjectName": f"CN={AAD_ID}.microsoft.com",
36+
"StoreLocation": "LocalMachine",
37+
"StoreName": "My",
38+
},
39+
"RequestSigningCert": {
40+
"SubjectName": f"CN={AAD_ID}",
41+
"StoreLocation": "LocalMachine",
42+
"StoreName": "My",
43+
}
44+
}
45+
46+
input_json = {
47+
"Version": "1.0.0",
48+
"SignBatches": [
49+
{
50+
"SourceLocationType": "UNC",
51+
"SourceRootDirectory": source_root_location,
52+
"DestinationLocationType": "UNC",
53+
"DestinationRootDirectory": destination_location,
54+
"SignRequestFiles": [
55+
{
56+
"CustomerCorrelationId": "01A7F55F-6CDD-4123-B255-77E6F212CDAD",
57+
"SourceLocation": file_to_sign,
58+
"DestinationLocation": os.path.join("signed", file_to_sign),
59+
}
60+
],
61+
"SigningInfo": {
62+
"Operations": [
63+
{
64+
"KeyCode": "CP-450779-Pgp",
65+
"OperationCode": "LinuxSign",
66+
"Parameters": {},
67+
"ToolName": "sign",
68+
"ToolVersion": "1.0",
69+
}
70+
]
71+
}
72+
}
73+
]
74+
}
75+
76+
policy_json = {
77+
"Version": "1.0.0",
78+
"Intent": "production release",
79+
"ContentType": "Debian package",
80+
}
81+
82+
configs = [
83+
("auth.json", auth_json),
84+
("input.json", input_json),
85+
("policy.json", policy_json),
86+
]
87+
88+
for filename, data in configs:
89+
with open(filename, 'w') as fp:
90+
json.dump(data, fp)
91+
92+
# Run ESRP Client
93+
esrp_out = "esrp_out.json"
94+
result = subprocess.run(
95+
[esrp_tool, "sign",
96+
"-a", "auth.json",
97+
"-i", "input.json",
98+
"-p", "policy.json",
99+
"-o", esrp_out,
100+
"-l", "Verbose"],
101+
cwd=WORKSPACE)
102+
103+
if result.returncode != 0:
104+
print("Failed to run ESRPClient.exe")
105+
sys.exit(1)
106+
107+
if os.path.isfile(esrp_out):
108+
print("ESRP output json:")
109+
with open(esrp_out, 'r') as fp:
110+
pprint.pp(json.load(fp))
111+
112+
signed_file = os.path.join(destination_location, "signed", file_to_sign)
113+
if os.path.isfile(signed_file):
114+
print(f"Success!\nSigned {signed_file}")
115+
116+
if __name__ == "__main__":
117+
main()

.github/workflows/build-git-installers.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ jobs:
1818
outputs:
1919
tag_name: ${{ steps.tag.outputs.name }} # The full name of the tag, e.g. v2.32.0.vfs.0.0
2020
tag_version: ${{ steps.tag.outputs.version }} # The version number (without preceding "v"), e.g. 2.32.0.vfs.0.0
21+
deb_signable: ${{ steps.deb.outputs.signable }} # Whether the credentials needed to sign the .deb package are available
2122
steps:
2223
- name: Determine tag to build
2324
run: |
2425
echo "::set-output name=name::${GITHUB_REF#refs/tags/}"
2526
echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
2627
id: tag
28+
- name: Determine whether signing certificates are present
29+
run: echo "::set-output name=signable::$([[ $AZ_SUB != '' && $AZ_CREDS != '' ]] && echo 'true' || echo 'false')"
30+
id: deb
2731
- name: Clone git
2832
uses: actions/checkout@v2
2933
- name: Validate the tag identified with trigger
@@ -297,7 +301,7 @@ jobs:
297301
path: artifacts
298302
# End build Mac OSX installers
299303

300-
# Build unsigned Ubuntu package
304+
# Build & sign Ubuntu package
301305
ubuntu_build:
302306
runs-on: ubuntu-latest
303307
needs: prereqs
@@ -373,4 +377,39 @@ jobs:
373377
with:
374378
name: deb-package-unsigned
375379
path: artifacts/
376-
# End build unsigned Ubuntu package
380+
ubuntu_sign-artifacts:
381+
runs-on: windows-latest # Must be run on Windows due to ESRP executable OS compatibility
382+
needs: [ubuntu_build, prereqs]
383+
if: needs.prereqs.outputs.deb_signable == 'true'
384+
env:
385+
ARTIFACTS_DIR: artifacts
386+
steps:
387+
- name: Clone repository
388+
uses: actions/checkout@v2
389+
- name: Download unsigned packages
390+
uses: actions/download-artifact@v2
391+
with:
392+
name: deb-package-unsigned
393+
path: ${{ env.ARTIFACTS_DIR }}/unsigned
394+
- uses: azure/login@v1
395+
with:
396+
creds: ${{ secrets.AZURE_CREDENTIALS }}
397+
- name: Download ESRP client
398+
run: |
399+
az storage blob download --subscription "${{ secrets.AZURE_SUBSCRIPTION }}" --account-name gitcitoolstore -c tools -n microsoft.esrpclient.1.2.47.nupkg -f esrp.zip
400+
Expand-Archive -Path esrp.zip -DestinationPath .\esrp
401+
- name: Install ESRP certificates
402+
run: |
403+
az keyvault secret download --subscription "${{ secrets.AZURE_SUBSCRIPTION }}" --vault-name "git-client-ci-kv" --name "microsoft-git-publisher-ssl-cert" -f ssl_cert.pfx
404+
Import-PfxCertificate ssl_cert.pfx -CertStoreLocation Cert:\LocalMachine\My
405+
az keyvault secret download --subscription "${{ secrets.AZURE_SUBSCRIPTION }}" --vault-name "git-client-ci-kv" --name "microsoft-git-publisher-esrp-payload-cert" -f payload_cert.pfx
406+
Import-PfxCertificate payload_cert.pfx -CertStoreLocation Cert:\LocalMachine\My
407+
- uses: actions/setup-python@v2
408+
- name: Run ESRP client
409+
run: python .github/scripts/sign-debian-packages.py
410+
- name: Upload signed artifact
411+
uses: actions/upload-artifact@v2
412+
with:
413+
name: deb-package-signed
414+
path: ${{ env.ARTIFACTS_DIR }}/signed
415+
# End build & sign Ubuntu package

0 commit comments

Comments
 (0)