Skip to content

Commit 5b94d93

Browse files
authored
feat: support portable workflow sync authentication (#114)
* feat: support portable workflow sync authentication * test: cover portable workflow sync authentication * docs: document portable workflow sync authentication * fix: keep portable sync auth in upstream patch
1 parent 9f03141 commit 5b94d93

4 files changed

Lines changed: 278 additions & 16 deletions

File tree

‎docs/cross-repository-automation.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,35 @@ The initial production validation confirmed:
112112
- `LibreCodeCoop/extract` can be checked out and updated;
113113
- managed workflows can be adopted into the lock file;
114114
- a subsequent synchronization with current hashes creates no PR.
115+
116+
117+
## Portable consumer authentication
118+
119+
The installed workflow updater does not infer authentication from the consumer's
120+
organization name. Consumers select an explicit repository variable:
121+
122+
\`WORKFLOW_SYNC_AUTH_MODE\`
123+
124+
Supported values:
125+
126+
- \`librecode-app\` — default for existing LibreCode-managed repositories. Uses
127+
\`LIBRECODE_WORKFLOW_APP_ID\` and \`LIBRECODE_WORKFLOW_APP_PRIVATE_KEY\`.
128+
- \`github-app\` — uses a consumer-owned GitHub App configured through
129+
\`WORKFLOW_SYNC_APP_ID\` and \`WORKFLOW_SYNC_APP_PRIVATE_KEY\`.
130+
- \`token\` — uses a consumer-owned repository-scoped credential stored as
131+
\`WORKFLOW_SYNC_TOKEN\`.
132+
- \`github-token\` — uses the workflow's built-in \`GITHUB_TOKEN\`.
133+
134+
A consumer-owned GitHub App is preferred for independent projects because it
135+
keeps credentials under the consumer's control while still allowing generated
136+
pull requests to trigger normal repository automation.
137+
138+
The \`github-token\` mode is intentionally explicit. GitHub suppresses workflow
139+
runs caused by most events created with the repository \`GITHUB_TOKEN\`, which
140+
means a pull request created through that mode may not trigger the consumer's
141+
normal pull-request CI. Use it only when that limitation is acceptable or when
142+
another mechanism explicitly triggers validation.
143+
144+
For GitHub App credentials, request only the repository permissions needed by
145+
the updater: Contents write, Pull requests write and Workflows write. Do not
146+
install or share the LibreCode GitHub App/private key with external consumers.

‎patches/nextcloud/sync-workflow-templates.yml.patch‎

Lines changed: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
--- upstream/vendor/nextcloud/sync-workflow-templates.yml
22
+++ workflow-templates/sync-workflow-templates.yml
3-
@@ -1,6 +1,6 @@
3+
@@ -1,13 +1,19 @@
44
# This workflow is provided via the organization template repository
55
#
66
-# https://github.com/nextcloud/.github
77
+# https://github.com/LibreCodeCoop/.github
88
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
99
#
1010
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
11-
@@ -26,9 +26,6 @@
11+
# SPDX-License-Identifier: MIT
12+
13+
-# This workflow will update all workflow templates
14+
-# Additionally it will reapply `workflow.yml.patch` files after syncing and only then commit the result
15+
+# This workflow will update all workflow templates.
16+
+# Additionally it will reapply workflow.yml.patch files after syncing and only then commit the result.
17+
+#
18+
+# Authentication is explicit through vars.WORKFLOW_SYNC_AUTH_MODE:
19+
+# - librecode-app (default): LibreCode-managed GitHub App credentials
20+
+# - github-app: consumer-owned GitHub App credentials
21+
+# - token: consumer-owned repository-scoped token
22+
+# - github-token: built-in GITHUB_TOKEN (generated PRs do not trigger normal PR workflows)
23+
name: Update workflows
24+
on:
25+
workflow_dispatch:
26+
@@ -26,9 +32,6 @@
1227
matrix:
1328
branches:
1429
- ${{ github.event.repository.default_branch }}
@@ -18,12 +33,52 @@
1833

1934
name: Update workflows in ${{ matrix.branches }}
2035

21-
@@ -42,12 +39,24 @@
36+
@@ -42,12 +45,105 @@
2237
with:
2338
require: admin
2439

25-
+ - name: Create GitHub App token
26-
+ id: app-token
40+
+ - name: Validate workflow sync authentication
41+
+ shell: bash
42+
+ env:
43+
+ AUTH_MODE: ${{ vars.WORKFLOW_SYNC_AUTH_MODE || 'librecode-app' }}
44+
+ LIBRECODE_APP_ID: ${{ vars.LIBRECODE_WORKFLOW_APP_ID }}
45+
+ LIBRECODE_APP_PRIVATE_KEY: ${{ secrets.LIBRECODE_WORKFLOW_APP_PRIVATE_KEY }}
46+
+ CONSUMER_APP_ID: ${{ vars.WORKFLOW_SYNC_APP_ID }}
47+
+ CONSUMER_APP_PRIVATE_KEY: ${{ secrets.WORKFLOW_SYNC_APP_PRIVATE_KEY }}
48+
+ CONSUMER_TOKEN: ${{ secrets.WORKFLOW_SYNC_TOKEN }}
49+
+ run: |
50+
+ set -euo pipefail
51+
+
52+
+ case "${AUTH_MODE}" in
53+
+ librecode-app)
54+
+ [[ -n "${LIBRECODE_APP_ID}" && -n "${LIBRECODE_APP_PRIVATE_KEY}" ]] || {
55+
+ echo "::error::librecode-app requires LIBRECODE_WORKFLOW_APP_ID and LIBRECODE_WORKFLOW_APP_PRIVATE_KEY"
56+
+ exit 1
57+
+ }
58+
+ ;;
59+
+ github-app)
60+
+ [[ -n "${CONSUMER_APP_ID}" && -n "${CONSUMER_APP_PRIVATE_KEY}" ]] || {
61+
+ echo "::error::github-app requires WORKFLOW_SYNC_APP_ID and WORKFLOW_SYNC_APP_PRIVATE_KEY"
62+
+ exit 1
63+
+ }
64+
+ ;;
65+
+ token)
66+
+ [[ -n "${CONSUMER_TOKEN}" ]] || {
67+
+ echo "::error::token mode requires WORKFLOW_SYNC_TOKEN"
68+
+ exit 1
69+
+ }
70+
+ ;;
71+
+ github-token)
72+
+ ;;
73+
+ *)
74+
+ echo "::error::Unsupported WORKFLOW_SYNC_AUTH_MODE: ${AUTH_MODE}"
75+
+ exit 1
76+
+ ;;
77+
+ esac
78+
+
79+
+ - name: Create LibreCode GitHub App token
80+
+ if: ${{ vars.WORKFLOW_SYNC_AUTH_MODE == '' || vars.WORKFLOW_SYNC_AUTH_MODE == 'librecode-app' }}
81+
+ id: librecode-app-token
2782
+ uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
2883
+ with:
2984
+ app-id: ${{ vars.LIBRECODE_WORKFLOW_APP_ID }}
@@ -33,6 +88,47 @@
3388
+ permission-contents: write
3489
+ permission-pull-requests: write
3590
+ permission-workflows: write
91+
+
92+
+ - name: Create consumer GitHub App token
93+
+ if: ${{ vars.WORKFLOW_SYNC_AUTH_MODE == 'github-app' }}
94+
+ id: consumer-app-token
95+
+ uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
96+
+ with:
97+
+ app-id: ${{ vars.WORKFLOW_SYNC_APP_ID }}
98+
+ private-key: ${{ secrets.WORKFLOW_SYNC_APP_PRIVATE_KEY }}
99+
+ owner: ${{ github.repository_owner }}
100+
+ repositories: ${{ github.event.repository.name }}
101+
+ permission-contents: write
102+
+ permission-pull-requests: write
103+
+ permission-workflows: write
104+
+
105+
+ - name: Resolve workflow sync token
106+
+ id: auth-token
107+
+ shell: bash
108+
+ env:
109+
+ AUTH_MODE: ${{ vars.WORKFLOW_SYNC_AUTH_MODE || 'librecode-app' }}
110+
+ LIBRECODE_APP_TOKEN: ${{ steps.librecode-app-token.outputs.token }}
111+
+ CONSUMER_APP_TOKEN: ${{ steps.consumer-app-token.outputs.token }}
112+
+ CONSUMER_TOKEN: ${{ secrets.WORKFLOW_SYNC_TOKEN }}
113+
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
+ run: |
115+
+ set -euo pipefail
116+
+
117+
+ case "${AUTH_MODE}" in
118+
+ librecode-app) token="${LIBRECODE_APP_TOKEN}" ;;
119+
+ github-app) token="${CONSUMER_APP_TOKEN}" ;;
120+
+ token) token="${CONSUMER_TOKEN}" ;;
121+
+ github-token) token="${GITHUB_TOKEN}" ;;
122+
+ *) exit 1 ;;
123+
+ esac
124+
+
125+
+ [[ -n "${token}" ]] || {
126+
+ echo "::error::Selected workflow sync authentication produced an empty token"
127+
+ exit 1
128+
+ }
129+
+
130+
+ echo "::add-mask::${token}"
131+
+ echo "token=${token}" >> "${GITHUB_OUTPUT}"
36132
+
37133
- name: Checkout workflow repository
38134
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -44,7 +140,7 @@
44140

45141
- name: Checkout app
46142
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
47-
@@ -56,86 +65,30 @@
143+
@@ -56,86 +152,30 @@
48144
path: target
49145
ref: ${{ matrix.branches }}
50146

@@ -123,11 +219,11 @@
123219
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
124220
with:
125221
- token: ${{ secrets.COMMAND_BOT_WORKFLOWS }}
126-
+ token: ${{ steps.app-token.outputs.token }}
222+
+ token: ${{ steps.auth-token.outputs.token }}
127223
commit-message: 'ci(actions): Update workflow templates from organization template repository'
128224
committer: GitHub <noreply@github.com>
129225
- author: nextcloud-command <nextcloud-command@users.noreply.github.com>
130-
+ author: librecode-workflow-automation[bot] <331658022+librecode-workflow-automation[bot]@users.noreply.github.com>
226+
+ author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
131227
path: target
132228
signoff: true
133229
branch: 'automated/noid/${{ matrix.branches }}-update-workflows'
@@ -138,7 +234,7 @@
138234
body: |
139235
- Automated update of all workflow templates from [nextcloud/.github](https://github.com/nextcloud/.github)
140236
- ${{ env.SUMMARY }}
141-
+ Automated update of all workflow templates from [LibreCodeCoop/.github](https://github.com/LibreCodeCoop/.github)
237+
+ Automated update of workflow templates from [LibreCodeCoop/.github](https://github.com/LibreCodeCoop/.github)
142238
+ ${{ steps.sync.outputs.summary }}
143239
labels: |
144240
dependencies
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
2+
# SPDX-License-Identifier: AGPL-3.0-or-later
3+
4+
from pathlib import Path
5+
import unittest
6+
7+
ROOT = Path(__file__).resolve().parents[1]
8+
TEMPLATE = ROOT / "workflow-templates" / "sync-workflow-templates.yml"
9+
10+
11+
class PortableWorkflowSyncAuthTest(unittest.TestCase):
12+
def test_template_supports_explicit_authentication_modes(self) -> None:
13+
content = TEMPLATE.read_text(encoding="utf-8")
14+
15+
self.assertIn("WORKFLOW_SYNC_AUTH_MODE", content)
16+
self.assertIn("librecode-app", content)
17+
self.assertIn("github-app", content)
18+
self.assertIn("token", content)
19+
self.assertIn("github-token", content)
20+
self.assertIn("WORKFLOW_SYNC_APP_ID", content)
21+
self.assertIn("WORKFLOW_SYNC_APP_PRIVATE_KEY", content)
22+
self.assertIn("WORKFLOW_SYNC_TOKEN", content)
23+
24+
def test_external_modes_do_not_require_librecode_credentials(self) -> None:
25+
content = TEMPLATE.read_text(encoding="utf-8")
26+
27+
self.assertIn("Create consumer GitHub App token", content)
28+
self.assertIn("vars.WORKFLOW_SYNC_AUTH_MODE == 'github-app'", content)
29+
self.assertIn('github-app) token="${CONSUMER_APP_TOKEN}"', content)
30+
self.assertIn('token) token="${CONSUMER_TOKEN}"', content)
31+
32+
def test_generated_pull_request_uses_selected_token(self) -> None:
33+
content = TEMPLATE.read_text(encoding="utf-8")
34+
35+
self.assertIn("id: auth-token", content)
36+
self.assertIn("token: ${{ steps.auth-token.outputs.token }}", content)
37+
38+
def test_github_token_limitation_is_visible_in_template(self) -> None:
39+
content = TEMPLATE.read_text(encoding="utf-8")
40+
self.assertIn(
41+
"generated PRs do not trigger normal PR workflows",
42+
content,
43+
)
44+
45+
46+
if __name__ == "__main__":
47+
unittest.main()

‎workflow-templates/sync-workflow-templates.yml‎

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
77
# SPDX-License-Identifier: MIT
88

9-
# This workflow will update all workflow templates
10-
# Additionally it will reapply `workflow.yml.patch` files after syncing and only then commit the result
9+
# This workflow will update all workflow templates.
10+
# Additionally it will reapply workflow.yml.patch files after syncing and only then commit the result.
11+
#
12+
# Authentication is explicit through vars.WORKFLOW_SYNC_AUTH_MODE:
13+
# - librecode-app (default): LibreCode-managed GitHub App credentials
14+
# - github-app: consumer-owned GitHub App credentials
15+
# - token: consumer-owned repository-scoped token
16+
# - github-token: built-in GITHUB_TOKEN (generated PRs do not trigger normal PR workflows)
1117
name: Update workflows
1218
on:
1319
workflow_dispatch:
@@ -39,8 +45,48 @@ jobs:
3945
with:
4046
require: admin
4147

42-
- name: Create GitHub App token
43-
id: app-token
48+
- name: Validate workflow sync authentication
49+
shell: bash
50+
env:
51+
AUTH_MODE: ${{ vars.WORKFLOW_SYNC_AUTH_MODE || 'librecode-app' }}
52+
LIBRECODE_APP_ID: ${{ vars.LIBRECODE_WORKFLOW_APP_ID }}
53+
LIBRECODE_APP_PRIVATE_KEY: ${{ secrets.LIBRECODE_WORKFLOW_APP_PRIVATE_KEY }}
54+
CONSUMER_APP_ID: ${{ vars.WORKFLOW_SYNC_APP_ID }}
55+
CONSUMER_APP_PRIVATE_KEY: ${{ secrets.WORKFLOW_SYNC_APP_PRIVATE_KEY }}
56+
CONSUMER_TOKEN: ${{ secrets.WORKFLOW_SYNC_TOKEN }}
57+
run: |
58+
set -euo pipefail
59+
60+
case "${AUTH_MODE}" in
61+
librecode-app)
62+
[[ -n "${LIBRECODE_APP_ID}" && -n "${LIBRECODE_APP_PRIVATE_KEY}" ]] || {
63+
echo "::error::librecode-app requires LIBRECODE_WORKFLOW_APP_ID and LIBRECODE_WORKFLOW_APP_PRIVATE_KEY"
64+
exit 1
65+
}
66+
;;
67+
github-app)
68+
[[ -n "${CONSUMER_APP_ID}" && -n "${CONSUMER_APP_PRIVATE_KEY}" ]] || {
69+
echo "::error::github-app requires WORKFLOW_SYNC_APP_ID and WORKFLOW_SYNC_APP_PRIVATE_KEY"
70+
exit 1
71+
}
72+
;;
73+
token)
74+
[[ -n "${CONSUMER_TOKEN}" ]] || {
75+
echo "::error::token mode requires WORKFLOW_SYNC_TOKEN"
76+
exit 1
77+
}
78+
;;
79+
github-token)
80+
;;
81+
*)
82+
echo "::error::Unsupported WORKFLOW_SYNC_AUTH_MODE: ${AUTH_MODE}"
83+
exit 1
84+
;;
85+
esac
86+
87+
- name: Create LibreCode GitHub App token
88+
if: ${{ vars.WORKFLOW_SYNC_AUTH_MODE == '' || vars.WORKFLOW_SYNC_AUTH_MODE == 'librecode-app' }}
89+
id: librecode-app-token
4490
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
4591
with:
4692
app-id: ${{ vars.LIBRECODE_WORKFLOW_APP_ID }}
@@ -51,6 +97,47 @@ jobs:
5197
permission-pull-requests: write
5298
permission-workflows: write
5399

100+
- name: Create consumer GitHub App token
101+
if: ${{ vars.WORKFLOW_SYNC_AUTH_MODE == 'github-app' }}
102+
id: consumer-app-token
103+
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
104+
with:
105+
app-id: ${{ vars.WORKFLOW_SYNC_APP_ID }}
106+
private-key: ${{ secrets.WORKFLOW_SYNC_APP_PRIVATE_KEY }}
107+
owner: ${{ github.repository_owner }}
108+
repositories: ${{ github.event.repository.name }}
109+
permission-contents: write
110+
permission-pull-requests: write
111+
permission-workflows: write
112+
113+
- name: Resolve workflow sync token
114+
id: auth-token
115+
shell: bash
116+
env:
117+
AUTH_MODE: ${{ vars.WORKFLOW_SYNC_AUTH_MODE || 'librecode-app' }}
118+
LIBRECODE_APP_TOKEN: ${{ steps.librecode-app-token.outputs.token }}
119+
CONSUMER_APP_TOKEN: ${{ steps.consumer-app-token.outputs.token }}
120+
CONSUMER_TOKEN: ${{ secrets.WORKFLOW_SYNC_TOKEN }}
121+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
run: |
123+
set -euo pipefail
124+
125+
case "${AUTH_MODE}" in
126+
librecode-app) token="${LIBRECODE_APP_TOKEN}" ;;
127+
github-app) token="${CONSUMER_APP_TOKEN}" ;;
128+
token) token="${CONSUMER_TOKEN}" ;;
129+
github-token) token="${GITHUB_TOKEN}" ;;
130+
*) exit 1 ;;
131+
esac
132+
133+
[[ -n "${token}" ]] || {
134+
echo "::error::Selected workflow sync authentication produced an empty token"
135+
exit 1
136+
}
137+
138+
echo "::add-mask::${token}"
139+
echo "token=${token}" >> "${GITHUB_OUTPUT}"
140+
54141
- name: Checkout workflow repository
55142
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
56143
with:
@@ -76,18 +163,18 @@ jobs:
76163
if: ${{ steps.sync.outputs.changed == 'true' }}
77164
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
78165
with:
79-
token: ${{ steps.app-token.outputs.token }}
166+
token: ${{ steps.auth-token.outputs.token }}
80167
commit-message: 'ci(actions): Update workflow templates from organization template repository'
81168
committer: GitHub <noreply@github.com>
82-
author: librecode-workflow-automation[bot] <331658022+librecode-workflow-automation[bot]@users.noreply.github.com>
169+
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
83170
path: target
84171
signoff: true
85172
branch: 'automated/noid/${{ matrix.branches }}-update-workflows'
86173
title: '[${{ matrix.branches }}] ci(actions): Update workflow templates from organization template repository'
87174
draft: ${{ steps.sync.outputs.patch_failed == 'true' }}
88175
add-paths: .github/workflows/*.yml,.github/actions-lock.txt
89176
body: |
90-
Automated update of all workflow templates from [LibreCodeCoop/.github](https://github.com/LibreCodeCoop/.github)
177+
Automated update of workflow templates from [LibreCodeCoop/.github](https://github.com/LibreCodeCoop/.github)
91178
${{ steps.sync.outputs.summary }}
92179
labels: |
93180
dependencies

0 commit comments

Comments
 (0)