-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yaml
More file actions
375 lines (341 loc) · 14.1 KB
/
Copy pathaction.yaml
File metadata and controls
375 lines (341 loc) · 14.1 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
---
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2025 The Linux Foundation
name: "OpenStack Bastion with Tailscale"
description: "Setup and manage an OpenStack bastion host with Tailscale VPN for secure remote access"
inputs:
# Operation Mode
operation:
description: "Operation: 'setup' to create bastion, 'teardown' to destroy bastion"
required: true
# OpenStack Credentials
openstack_auth_url:
description: "OpenStack auth URL"
required: true
openstack_project_id:
description: "OpenStack project/tenant ID"
required: true
openstack_username:
description: "OpenStack username"
required: true
openstack_password:
description: "OpenStack password (will be base64 decoded if needed)"
required: true
openstack_region:
description: "OpenStack region"
required: false
default: "ca-ymq-1"
openstack_network_id:
description: "OpenStack network UUID"
required: false
default: ""
# Bastion Configuration
bastion_flavor:
description: "OpenStack flavor for bastion instance"
required: false
default: "v3-standard-2"
bastion_image:
description: "Base image for bastion host"
required: false
default: "Ubuntu 22.04.5 LTS (x86_64) [2025-03-27]"
bastion_network:
description: "Network name for bastion host"
required: false
default: "odlci"
bastion_ssh_key:
description: "SSH key name for bastion (optional, Tailscale SSH used by default)"
required: false
default: ""
bastion_wait_timeout:
description: "Timeout in seconds to wait for bastion to be ready"
required: false
default: "600"
bastion_name:
description: "Name for the bastion instance (defaults to bastion-gh-{run_id})"
required: false
default: ""
# Tailscale Configuration (required for setup only)
# OAuth is the recommended method - requires both client_id and secret
tailscale_oauth_client_id:
description: "Tailscale OAuth client ID (recommended - requires oauth_secret)"
required: false
default: ""
tailscale_oauth_secret:
description: "Tailscale OAuth secret (recommended - requires oauth_client_id)"
required: false
default: ""
tailscale_use_ephemeral_keys:
description: "Generate ephemeral auth keys from OAuth (recommended: true, legacy: false)"
required: false
default: "true"
# Legacy auth key support - deprecated but still supported
tailscale_auth_key:
description: "Tailscale auth key (legacy - OAuth is recommended)"
required: false
default: ""
tailscale_tags:
description: "Comma-separated Tailscale tags applied to the GitHub runner (e.g., 'tag:ci') and to OAuth-generated ephemeral auth keys. Runner tagging is skipped when the runner is already connected; auth key tagging always applies"
required: false
default: "tag:ci"
bastion_tailscale_tags:
description: "Comma-separated list of Tailscale tags for the bastion VM (e.g., 'tag:bastion')"
required: false
default: "tag:bastion"
tailscale_version:
description: "Tailscale version. Ignored when the runner is already connected to Tailscale"
required: false
default: "latest"
# Options
debug_mode:
description: "Enable debug logging"
required: false
default: "false"
outputs:
bastion_ip:
description: "Tailscale IP of the bastion host"
value: ${{ steps.get-bastion-ip.outputs.bastion_ip }}
bastion_name:
description: "Name of the bastion instance"
value: ${{ steps.create-bastion.outputs.bastion_name }}
status:
description: "Status of the operation (success/failure)"
value: ${{ steps.operation-status.outputs.status }}
runs:
using: "composite"
steps:
# ========================================
# Setup Operation
# ========================================
- name: Detect existing Tailscale connection
if: inputs.operation == 'setup'
id: tailscale-state
shell: bash
run: |
# The Tailscale setup action copies fresh binaries into
# /usr/local/bin. If a tailscaled started by an earlier step in
# this job is already running, that copy fails hard with
# "Text file busy" and takes the whole job with it.
#
# Callers legitimately bring the runner onto the tailnet before
# invoking this action, so treat an existing connection as the
# one to use rather than trying to replace it.
if pgrep -x tailscaled >/dev/null 2>&1; then
echo "connected=true" >> "${GITHUB_OUTPUT}"
echo "ℹ️ Tailscale is already running on this runner; reusing the existing connection"
echo " (tailscale_version and the runner half of tailscale_tags do not apply;"
echo " tailscale_tags still tags the bastion's ephemeral auth key)"
else
echo "connected=false" >> "${GITHUB_OUTPUT}"
fi
- name: Setup Tailscale VPN (OAuth)
# yamllint disable-line rule:line-length
if: inputs.operation == 'setup' && steps.tailscale-state.outputs.connected != 'true' && inputs.tailscale_oauth_client_id != '' && inputs.tailscale_oauth_secret != ''
uses: tailscale/github-action@780049a30b6ff5c378a9e7b389d15ece7a204888 # v4.1.3
with:
oauth-client-id: ${{ inputs.tailscale_oauth_client_id }}
oauth-secret: ${{ inputs.tailscale_oauth_secret }}
version: ${{ inputs.tailscale_version }}
tags: ${{ inputs.tailscale_tags }}
hostname: github-runner-${{ github.run_id }}
args: --ssh --accept-dns=false
- name: Setup Tailscale VPN (Auth Key - Legacy)
# yamllint disable-line rule:line-length
if: inputs.operation == 'setup' && steps.tailscale-state.outputs.connected != 'true' && (inputs.tailscale_oauth_client_id == '' || inputs.tailscale_oauth_secret == '') && inputs.tailscale_auth_key != ''
uses: tailscale/github-action@780049a30b6ff5c378a9e7b389d15ece7a204888 # v4.1.3
with:
authkey: ${{ inputs.tailscale_auth_key }}
version: ${{ inputs.tailscale_version }}
hostname: github-runner-${{ github.run_id }}
args: --ssh --accept-dns=false
- name: Validate Tailscale credentials
if: inputs.operation == 'setup'
shell: bash
env:
TS_OAUTH_CLIENT_ID: ${{ inputs.tailscale_oauth_client_id }}
TS_OAUTH_SECRET: ${{ inputs.tailscale_oauth_secret }}
TS_AUTH_KEY: ${{ inputs.tailscale_auth_key }}
# yamllint disable rule:line-length
run: |
if [[ -z "$TS_OAUTH_CLIENT_ID" ]] && [[ -z "$TS_OAUTH_SECRET" ]] && [[ -z "$TS_AUTH_KEY" ]]; then
echo "❌ Error: Either tailscale_oauth_client_id+tailscale_oauth_secret OR tailscale_auth_key must be provided for setup"
exit 1
fi
if [[ -n "$TS_OAUTH_CLIENT_ID" ]] && [[ -z "$TS_OAUTH_SECRET" ]]; then
echo "❌ Error: tailscale_oauth_secret is required when tailscale_oauth_client_id is provided"
exit 1
fi
if [[ -n "$TS_OAUTH_SECRET" ]] && [[ -z "$TS_OAUTH_CLIENT_ID" ]]; then
echo "❌ Error: tailscale_oauth_client_id is required when tailscale_oauth_secret is provided"
exit 1
fi
# yamllint enable rule:line-length
- name: Verify Tailscale connection
if: inputs.operation == 'setup'
shell: bash
run: |
echo "✅ Tailscale status:"
sudo tailscale status
- name: Install OpenStack CLI
if: inputs.operation == 'setup' || inputs.operation == 'teardown'
shell: bash
run: |
pip install python-openstackclient
- name: Configure OpenStack credentials
if: inputs.operation == 'setup' || inputs.operation == 'teardown'
shell: bash
env:
OS_AUTH_URL: ${{ inputs.openstack_auth_url }}
OS_PROJECT_ID: ${{ inputs.openstack_project_id }}
OS_USERNAME: ${{ inputs.openstack_username }}
OS_PASSWORD: ${{ inputs.openstack_password }}
OS_REGION_NAME: ${{ inputs.openstack_region }}
OS_IDENTITY_API_VERSION: "3"
OS_USER_DOMAIN_NAME: "Default"
OS_PROJECT_DOMAIN_NAME: "Default"
run: |
echo "Configuring OpenStack credentials..."
# Decode base64 encoded password
PASSWORD=$(printf '%s' "${OS_PASSWORD}" | base64 -d)
export OS_PASSWORD="${PASSWORD}"
# Validate credentials
echo "Validating OpenStack credentials..."
if ! ERROR_OUTPUT=$(openstack token issue 2>&1); then
echo "❌ Error: Failed to authenticate with OpenStack"
echo "OpenStack error output:"
echo "$ERROR_OUTPUT"
exit 1
fi
echo "✅ OpenStack credentials validated"
- name: Create bastion host
if: inputs.operation == 'setup'
id: create-bastion
shell: bash
env:
# OpenStack credentials
OS_AUTH_URL: ${{ inputs.openstack_auth_url }}
OS_PROJECT_ID: ${{ inputs.openstack_project_id }}
OS_USERNAME: ${{ inputs.openstack_username }}
OS_PASSWORD: ${{ inputs.openstack_password }}
OS_REGION_NAME: ${{ inputs.openstack_region }}
OS_IDENTITY_API_VERSION: "3"
OS_USER_DOMAIN_NAME: "Default"
OS_PROJECT_DOMAIN_NAME: "Default"
# Tailscale configuration
TAILSCALE_OAUTH_CLIENT_ID: ${{ inputs.tailscale_oauth_client_id }}
TAILSCALE_OAUTH_SECRET: ${{ inputs.tailscale_oauth_secret }}
TAILSCALE_AUTH_KEY: ${{ inputs.tailscale_auth_key }}
TAILSCALE_TAGS: ${{ inputs.tailscale_tags }}
BASTION_TAILSCALE_TAGS: ${{ inputs.bastion_tailscale_tags }}
TAILSCALE_USE_EPHEMERAL_KEYS: ${{ inputs.tailscale_use_ephemeral_keys }}
# Bastion configuration
BASTION_NAME: ${{ inputs.bastion_name }}
BASTION_FLAVOR: ${{ inputs.bastion_flavor }}
BASTION_IMAGE: ${{ inputs.bastion_image }}
BASTION_NETWORK: ${{ inputs.bastion_network }}
BASTION_SSH_KEY: ${{ inputs.bastion_ssh_key }}
BASTION_WAIT_TIMEOUT: ${{ inputs.bastion_wait_timeout }}
DEBUG_MODE: ${{ inputs.debug_mode }}
# Workflow context routed via env to avoid template injection
RUN_ID: ${{ github.run_id }}
ACTION_PATH: ${{ github.action_path }}
run: |
set -euo pipefail
# Decode base64 encoded password
PASSWORD=$(printf '%s' "${OS_PASSWORD}" | base64 -d)
export OS_PASSWORD="${PASSWORD}"
# Set bastion name
BASTION_NAME="${BASTION_NAME:-bastion-gh-${RUN_ID}}"
echo "bastion_name=${BASTION_NAME}" >> "${GITHUB_OUTPUT}"
# Run setup script
"${ACTION_PATH}/scripts/setup-bastion.sh"
- name: Get bastion IP
if: inputs.operation == 'setup'
id: get-bastion-ip
shell: bash
env:
# OpenStack credentials (needed for cleanup on timeout)
OS_AUTH_URL: ${{ inputs.openstack_auth_url }}
OS_PROJECT_ID: ${{ inputs.openstack_project_id }}
OS_USERNAME: ${{ inputs.openstack_username }}
OS_PASSWORD: ${{ inputs.openstack_password }}
OS_REGION_NAME: ${{ inputs.openstack_region }}
OS_IDENTITY_API_VERSION: "3"
OS_USER_DOMAIN_NAME: "Default"
OS_PROJECT_DOMAIN_NAME: "Default"
# Bastion configuration
BASTION_NAME: ${{ steps.create-bastion.outputs.bastion_name }}
BASTION_WAIT_TIMEOUT: ${{ inputs.bastion_wait_timeout }}
# Workflow context routed via env to avoid template injection
ACTION_PATH: ${{ github.action_path }}
# yamllint disable rule:line-length
run: |
set -euo pipefail
# Decode base64 encoded password
PASSWORD=$(printf '%s' "${OS_PASSWORD}" | base64 -d)
export OS_PASSWORD="${PASSWORD}"
TIMEOUT="${BASTION_WAIT_TIMEOUT}"
ELAPSED=0
RETRY_INTERVAL=10
echo "Waiting for bastion Tailscale IP..."
while [[ $ELAPSED -lt $TIMEOUT ]]; do
# Get bastion IP from Tailscale
BASTION_IP=$(sudo tailscale status --json | jq -r ".Peer[] | select(.HostName | contains(\"${BASTION_NAME}\")) | .TailscaleIPs[0]" || echo "")
if [[ -n "$BASTION_IP" && "$BASTION_IP" != "null" ]]; then
echo "✅ Bastion Tailscale IP: ${BASTION_IP}"
echo "bastion_ip=${BASTION_IP}" >> "${GITHUB_OUTPUT}"
exit 0
fi
echo "Waiting for bastion to connect to Tailscale... (${ELAPSED}s/${TIMEOUT}s)"
sleep "${RETRY_INTERVAL}"
ELAPSED=$((ELAPSED + RETRY_INTERVAL))
done
echo "❌ Error: Timeout waiting for bastion Tailscale IP"
# Trigger automatic cleanup on timeout
if [[ -n "${BASTION_NAME}" ]]; then
echo "Triggering automatic cleanup due to timeout..."
"${ACTION_PATH}/scripts/cleanup-bastion.sh" "${BASTION_NAME}" || true
fi
exit 1
# yamllint enable rule:line-length
- name: Cleanup bastion host
if: inputs.operation == 'teardown'
shell: bash
env:
# OpenStack credentials
OS_AUTH_URL: ${{ inputs.openstack_auth_url }}
OS_PROJECT_ID: ${{ inputs.openstack_project_id }}
OS_USERNAME: ${{ inputs.openstack_username }}
OS_PASSWORD: ${{ inputs.openstack_password }}
OS_REGION_NAME: ${{ inputs.openstack_region }}
OS_IDENTITY_API_VERSION: "3"
OS_USER_DOMAIN_NAME: "Default"
OS_PROJECT_DOMAIN_NAME: "Default"
# Bastion configuration
BASTION_NAME: ${{ inputs.bastion_name }}
DEBUG_MODE: ${{ inputs.debug_mode }}
# Workflow context routed via env to avoid template injection
RUN_ID: ${{ github.run_id }}
ACTION_PATH: ${{ github.action_path }}
run: |
set -euo pipefail
# Decode base64 encoded password
PASSWORD=$(printf '%s' "${OS_PASSWORD}" | base64 -d)
export OS_PASSWORD="${PASSWORD}"
BASTION_NAME="${BASTION_NAME:-bastion-gh-${RUN_ID}}"
# Run cleanup script
"${ACTION_PATH}/scripts/cleanup-bastion.sh" "${BASTION_NAME}"
- name: Set operation status
if: always()
id: operation-status
shell: bash
run: |
if [[ "${JOB_STATUS}" == "success" ]]; then
echo "status=success" >> "${GITHUB_OUTPUT}"
else
echo "status=failure" >> "${GITHUB_OUTPUT}"
fi
env:
JOB_STATUS: ${{ job.status }}
branding:
icon: "cloud"
color: "blue"