Skip to content

Commit 84c50c7

Browse files
feat(azure-trusted-signing): add action (#1290)
* feat(azure-trusted-signing): Add action Add a composite action that signs files using Azure Trusted Signing. * feat(azure-trusted-signing): Run prettier Fix formatting for prettier. * feat(azure-trusted-signing): fix errors - Fix incorrect syntax for default URL. - Fix incorrect secrets access. * feat(azure-trusted-signing): fix sign path Execute the file, not the directory it's in. * feat(azure-trusted-signing): fix command Add missing `code` prefix. * feat(azure-trusted-signing): Docs fixes Apply Copilot suggestions. * feat(azure-trusted-signing): update release-please Add new action to release-please configuration.
1 parent 2e039c2 commit 84c50c7

File tree

4 files changed

+289
-0
lines changed

4 files changed

+289
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
<!-- TODO Confirm format/version/date -->
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# azure-trusted-signing
2+
3+
This is a composite GitHub Action used to sign files using [Azure Trusted Signing][azure-trusted-signing].
4+
5+
> [!IMPORTANT]
6+
> This GitHub Action is only supported on Windows-based GitHub Actions runners.
7+
8+
## Example
9+
10+
<!-- markdownlint-disable MD013 -->
11+
<!-- x-release-please-start-version -->
12+
13+
```yaml
14+
name: CI
15+
on:
16+
push:
17+
branches: ["main"]
18+
tags: ["v*"]
19+
pull_request:
20+
workflow_dispatch:
21+
22+
jobs:
23+
package:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Setup .NET
28+
uses: actions/setup-dotnet@v4
29+
30+
- name: Build NuGet packages
31+
run: dotnet pack --configuration Release --output ./artifacts
32+
33+
- name: Upload artifacts
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: artifacts
37+
path: ./artifacts
38+
39+
sign:
40+
needs: [package]
41+
runs-on: windows-latest
42+
if: github.event.repository.fork == false && startsWith(github.ref, 'refs/tags/')
43+
44+
environment:
45+
name: azure-trusted-signing
46+
47+
outputs:
48+
artifact-name: ${{ steps.sign-artifacts.outputs.artifact-name }}
49+
50+
permissions:
51+
contents: read
52+
id-token: write
53+
54+
steps:
55+
- name: Get secrets for Azure Trusted Signing
56+
uses: grafana/shared-workflows/actions/get-vault-secrets@get-vault-secrets/v1.3.0
57+
id: get-signing-secrets
58+
with:
59+
export_env: false
60+
repo_secrets: |
61+
client-id=azure-trusted-signing:client-id
62+
subscription-id=azure-trusted-signing:subscription-id
63+
tenant-id=azure-trusted-signing:tenant-id
64+
65+
- name: Sign artifacts
66+
uses: grafana/shared-workflows/actions/azure-trusted-signing@azure-trusted-signing/v0.1.0
67+
id: sign-artifacts
68+
with:
69+
application-description: "My Awesome application"
70+
artifact-to-sign: "artifacts"
71+
azure-client-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).client-id }}
72+
azure-subscription-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).subscription-id }}
73+
azure-tenant-id: ${{ fromJSON(steps.get-signing-secrets.outputs.secrets).tenant-id }}
74+
signed-artifact-name: "signed-artifacts"
75+
76+
release:
77+
needs: [sign]
78+
runs-on: ubuntu-latest
79+
80+
steps:
81+
- name: Download signed packages
82+
uses: actions/download-artifact@v5
83+
with:
84+
name: ${{ needs.sign.outputs.artifact-name }}
85+
86+
- name: Release
87+
run: echo "Do something with the signed artifacts"
88+
```
89+
90+
<!-- x-release-please-end-version -->
91+
<!-- markdownlint-enable MD013 -->
92+
93+
## Inputs
94+
95+
### Required
96+
97+
| **Name** | **Description** |
98+
| :------------------------ | :------------------------------------------------------------------------------------------------------ |
99+
| `application-description` | The description of the application to sign the file(s) for. |
100+
| `artifact-to-sign` | The name of the GitHub Actions workflow artifact from the current workflow run to sign the contents of. |
101+
| `azure-client-id` | The client ID to use to authenticate with Azure. |
102+
| `azure-subscription-id` | The subscription ID to use to authenticate with Azure. |
103+
| `azure-tenant-id` | The tenant ID to use to authenticate with Azure. |
104+
| `signed-artifact-name` | The name of the GitHub Actions workflow artifact to upload the signed files to. |
105+
106+
### Optional
107+
108+
| **Name** | **Description** | **Default** |
109+
| :------------------------- | :------------------------------------------------------------------------------- | :----------------------------------------------------- |
110+
| `application-url` | The URL of the application to sign the file(s) for. | The URL of the GitHub repository running the workflow. |
111+
| `file-filter` | The path filter of which files to sign from the artifact. | `'**/*'` |
112+
| `file-list` | The path to a file containing paths of files to sign or to exclude from signing. | - |
113+
| `publisher-name` | The name of the publisher of the application the signed file(s) belong to. | `'Grafana Labs'` |
114+
| `trusted-signing-account` | The name of the Azure Trusted Signing account to use. | - |
115+
| `trusted-signing-endpoint` | The endpoint URL of the Azure Trusted Signing service to use. | - |
116+
| `trusted-signing-profile` | The name of the Azure Trusted Signing profile to use. | - |
117+
118+
## Outputs
119+
120+
| **Name** | **Description** |
121+
| :-------------- | :------------------------------------------------------------------------------ |
122+
| `artifact-name` | The name of the GitHub Actions workflow artifact containing the signed file(s). |
123+
124+
[azure-trusted-signing]: https://learn.microsoft.com/azure/trusted-signing/
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: Azure Trusted Signing
2+
description: Signs files in a GitHub Actions artifact using Azure Trusted Signing
3+
4+
inputs:
5+
application-description:
6+
description: "The description of the application to sign the file(s) for."
7+
required: true
8+
application-url:
9+
description: "The optional URL of the application to sign the file(s) for. Defaults to the current GitHub repository URL."
10+
required: false
11+
default: ${{ format('{0}/{1}', github.server_url, github.repository) }}
12+
artifact-to-sign:
13+
description: "The name of the GitHub Actions workflow artifact from the current workflow run to sign the contents of."
14+
required: true
15+
azure-client-id:
16+
description: "The client ID to use to authenticate with Azure."
17+
required: true
18+
azure-subscription-id:
19+
description: "The subscription ID to use to authenticate with Azure."
20+
required: true
21+
azure-tenant-id:
22+
description: "The tenant ID to use to authenticate with Azure."
23+
required: true
24+
file-filter:
25+
description: "The optional path filter of which files to sign from the artifact. Defaults to all files."
26+
required: false
27+
default: "**/*"
28+
file-list:
29+
description: "The optional path to a file containing paths of files to sign or to exclude from signing."
30+
required: false
31+
publisher-name:
32+
description: 'The optional name of the publisher of the application the signed file(s) belong to. Defaults to "Grafana Labs".'
33+
required: false
34+
default: "Grafana Labs"
35+
signed-artifact-name:
36+
description: "The name of the GitHub Actions workflow artifact to upload the signed files to."
37+
required: true
38+
trusted-signing-account:
39+
description: "The optional name of the Azure Trusted Signing account to use."
40+
required: false
41+
default: "grafana-premium-eastus"
42+
trusted-signing-endpoint:
43+
description: "The optional endpoint URL of the Azure Trusted Signing service to use."
44+
required: false
45+
default: "https://eus.codesigning.azure.net/"
46+
trusted-signing-profile:
47+
description: "The optional name of the Azure Trusted Signing profile to use."
48+
required: false
49+
default: "grafana-production"
50+
outputs:
51+
artifact-name:
52+
description: "The name of the GitHub Actions workflow artifact containing the signed file(s)."
53+
value: ${{ inputs.signed-artifact-name }}
54+
55+
runs:
56+
using: composite
57+
steps:
58+
- name: Verify runner operating system
59+
shell: pwsh
60+
run: |
61+
if (${env:RUNNER_OS} -ne "Windows") {
62+
Write-Output "::error::This action can only be used on Windows runners."
63+
exit 1
64+
}
65+
66+
- name: Get staging path
67+
id: get-staging-path
68+
shell: pwsh
69+
run: |
70+
$stagingPath = Join-Path -Path ${env:RUNNER_TEMP} -ChildPath (New-Guid).ToString()
71+
"staging-path=$stagingPath" >> ${env:GITHUB_OUTPUT}
72+
73+
- name: Download artifact
74+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
75+
with:
76+
name: ${{ inputs.artifact-to-sign }}
77+
path: ${{ steps.get-staging-path.outputs.staging-path }}
78+
79+
- name: Setup .NET SDK
80+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
81+
with:
82+
# renovate: datasource=dotnet-version depName=dotnet-sdk
83+
dotnet-version: "8.0.413"
84+
85+
- name: Install Sign CLI tool
86+
id: install-sign-tool
87+
shell: pwsh
88+
env:
89+
# renovate: datasource=nuget depName=sign
90+
DOTNET_SIGN_VERSION: "0.9.1-beta.25379.1"
91+
run: |
92+
$toolPath = Join-Path -Path ${env:RUNNER_TEMP} -ChildPath (New-Guid).ToString()
93+
New-Item -ItemType Directory -Path $toolPath | Out-Null
94+
95+
dotnet tool install --tool-path $toolPath sign --version ${env:DOTNET_SIGN_VERSION}
96+
97+
if ($LASTEXITCODE -ne 0) {
98+
Write-Output "::error::Failed to install Sign CLI tool"
99+
exit 1
100+
}
101+
102+
"sign-tool=$toolPath" >> ${env:GITHUB_OUTPUT}
103+
104+
- name: Azure log in
105+
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
106+
with:
107+
client-id: ${{ inputs.azure-client-id }}
108+
subscription-id: ${{ inputs.azure-subscription-id }}
109+
tenant-id: ${{ inputs.azure-tenant-id }}
110+
111+
- name: Sign files
112+
shell: pwsh
113+
env:
114+
APPLICATION_DESCRIPTION: ${{ inputs.application-description }}
115+
APPLICATION_URL: ${{ inputs.application-url }}
116+
BASE_DIRECTORY: ${{ steps.get-staging-path.outputs.staging-path }}
117+
FILE_FILTER: ${{ inputs.file-filter }}
118+
FILE_LIST: ${{ inputs.file-list }}
119+
PUBLISHER_NAME: ${{ inputs.publisher-name }}
120+
SIGN_CLI_PATH: ${{ steps.install-sign-tool.outputs.sign-tool }}
121+
TRUSTED_SIGNING_ACCOUNT: ${{ inputs.trusted-signing-account }}
122+
TRUSTED_SIGNING_ENDPOINT: ${{ inputs.trusted-signing-endpoint }}
123+
TRUSTED_SIGNING_PROFILE: ${{ inputs.trusted-signing-profile }}
124+
VERBOSITY: ${{ runner.debug == '1' && 'Debug' || 'Error' }}
125+
run: |
126+
$signArgs = @(
127+
${env:FILE_FILTER},
128+
"--base-directory", ${env:BASE_DIRECTORY},
129+
"--application-name", ${env:APPLICATION_DESCRIPTION},
130+
"--publisher-name", ${env:PUBLISHER_NAME},
131+
"--description", ${env:APPLICATION_DESCRIPTION},
132+
"--description-url", ${env:APPLICATION_URL},
133+
"--trusted-signing-account", ${env:TRUSTED_SIGNING_ACCOUNT},
134+
"--trusted-signing-certificate-profile", ${env:TRUSTED_SIGNING_PROFILE},
135+
"--trusted-signing-endpoint", ${env:TRUSTED_SIGNING_ENDPOINT},
136+
"--verbosity", ${env:VERBOSITY}
137+
)
138+
139+
if (-Not [string]::IsNullOrEmpty(${env:FILE_LIST})) {
140+
$signArgs += "--file-list"
141+
$signArgs += ${env:FILE_LIST}
142+
}
143+
144+
$signTool = Join-Path -Path ${env:SIGN_CLI_PATH} -ChildPath "sign"
145+
146+
& $signTool code trusted-signing $signArgs
147+
148+
if ($LASTEXITCODE -ne 0) {
149+
Write-Output "::error::Failed to sign files with Azure Trusted Signing"
150+
exit 1
151+
}
152+
153+
- name: Upload signed artifacts
154+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
155+
with:
156+
name: ${{ inputs.signed-artifact-name }}
157+
path: ${{ steps.get-staging-path.outputs.staging-path }}
158+
if-no-files-found: error

release-please-config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
"package-name": "aws-auth",
6262
"extra-files": ["README.md"]
6363
},
64+
"actions/azure-trusted-signing": {
65+
"package-name": "azure-trusted-signing",
66+
"extra-files": ["README.md"]
67+
},
6468
"actions/build-push-to-dockerhub": {
6569
"package-name": "build-push-to-dockerhub",
6670
"extra-files": ["README.md"]

0 commit comments

Comments
 (0)