-
Notifications
You must be signed in to change notification settings - Fork 32
[Fixes: mosip/mosip-infra#1874] Add WireGuard onboarding workflow in master #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+134
−0
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5313a4d
[Fixes: mosip/mosip-infra#1874] Add WireGuard onboarding workflow in …
Ivanmeneges f9784cc
Change runner from ubuntu-latest to self-hosted
Ivanmeneges 47cdbbc
Address CodeRabbit and CodeQL review feedback for wg-onboard workflow.
Ivanmeneges 6b4e140
wg-onboard: concurrency, pull-before-commit, drop dead input
Ivanmeneges 3b341eb
wg-onboard: rebase with autostash only when tracker changed
Ivanmeneges d78b5a6
wg-onboard: use GITHUB_TOKEN for checkout, validate secrets early
Ivanmeneges 4cfd8ab
Update git pull and push commands with remote URL
Ivanmeneges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| name: WireGuard onboard environment | ||
|
|
||
| # Self-service WireGuard onboarding for a new environment. | ||
| # Allocates free WireGuard peers from the jumpserver and publishes them as | ||
| # GitHub *environment* secrets (TF_WG_CONFIG, CLUSTER_WIREGUARD_WG0/WG1) so a | ||
| # QA/dev team can run the Terraform + Helmsman workflows without DevOps. | ||
| # | ||
| # Requires .github/scripts/wg-onboard.sh (mosip/infra PR #253). | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| ENV_NAME: | ||
| description: 'Environment / branch name to onboard (becomes the GitHub environment name)' | ||
| required: true | ||
| type: string | ||
| JUMPSERVER_HOST: | ||
| description: 'Jumpserver / WireGuard VM public IP or DNS (SSH reachable)' | ||
| required: true | ||
| type: string | ||
| TICKET: | ||
| description: 'Optional ticket id to record in assigned.txt (e.g. DSD-10264)' | ||
| required: false | ||
| type: string | ||
| WG_DIR: | ||
| description: 'WireGuard env dir on the VM' | ||
| required: false | ||
| type: string | ||
| default: /home/ubuntu/wireguard_env_2026 | ||
| ALLOWED_IPS: | ||
| description: 'AllowedIPs to set in each conf' | ||
| required: false | ||
| type: string | ||
| default: 172.31.0.0/16 | ||
| DRY_RUN: | ||
| description: 'Resolve and print actions without creating env/secrets' | ||
| required: false | ||
| type: boolean | ||
| default: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: wg-onboard-${{ inputs.ENV_NAME }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| onboard: | ||
| runs-on: self-hosted | ||
| timeout-minutes: 20 | ||
| steps: | ||
| - name: Validate required secrets | ||
| run: | | ||
| missing=() | ||
| [[ -z "${{ secrets.ACTION_PAT }}" ]] && missing+=(ACTION_PAT) | ||
| [[ -z "${{ secrets.MOSIP_AWS_PEM }}" ]] && missing+=(MOSIP_AWS_PEM) | ||
| if ((${#missing[@]})); then | ||
| echo "ERROR: Missing repository secrets: ${missing[*]}" | ||
| echo "Add them under Settings → Secrets and variables → Actions for ${GITHUB_REPOSITORY}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Write SSH private key | ||
| env: | ||
| SSH_KEY: ${{ secrets.MOSIP_AWS_PEM }} | ||
| SSH_KEY_NAME: MOSIP_AWS_PEM | ||
| run: | | ||
| SSH_KEY_PATH="${RUNNER_TEMP}/jumpserver_key" | ||
| printf '%s\n' "$SSH_KEY" | tr -d '\r' > "$SSH_KEY_PATH" | ||
| chmod 600 "$SSH_KEY_PATH" | ||
| if ! ssh-keygen -l -f "$SSH_KEY_PATH" >/dev/null 2>&1; then | ||
| echo "ERROR: secret '$SSH_KEY_NAME' is not a valid private key (check format/newlines/CRLF)" | ||
| exit 1 | ||
| fi | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| echo "SSH_KEY_PATH=$SSH_KEY_PATH" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Run WireGuard onboarding | ||
| env: | ||
| GH_TOKEN: ${{ secrets.ACTION_PAT }} | ||
| GITHUB_TOKEN: ${{ secrets.ACTION_PAT }} | ||
| INPUT_ENV_NAME: ${{ inputs.ENV_NAME }} | ||
| INPUT_JUMPSERVER_HOST: ${{ inputs.JUMPSERVER_HOST }} | ||
| INPUT_WG_DIR: ${{ inputs.WG_DIR }} | ||
| INPUT_ALLOWED_IPS: ${{ inputs.ALLOWED_IPS }} | ||
| INPUT_TICKET: ${{ inputs.TICKET }} | ||
| INPUT_DRY_RUN: ${{ inputs.DRY_RUN }} | ||
| GITHUB_REPOSITORY: ${{ github.repository }} | ||
| run: | | ||
| chmod +x .github/scripts/wg-onboard.sh | ||
| args=( | ||
| --env "$INPUT_ENV_NAME" | ||
| --host "$INPUT_JUMPSERVER_HOST" | ||
| --ssh-key "$SSH_KEY_PATH" | ||
| --repo "$GITHUB_REPOSITORY" | ||
| --wg-dir "$INPUT_WG_DIR" | ||
| --allowed-ips "$INPUT_ALLOWED_IPS" | ||
| ) | ||
| [[ -n "$INPUT_TICKET" ]] && args+=(--ticket "$INPUT_TICKET") | ||
| [[ "$INPUT_DRY_RUN" == "true" ]] && args+=(--dry-run) | ||
| .github/scripts/wg-onboard.sh "${args[@]}" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| - name: Cleanup SSH private key | ||
| if: always() | ||
| run: rm -f "${SSH_KEY_PATH:-}" | ||
|
|
||
| - name: Commit updated peer allocation | ||
| if: ${{ inputs.DRY_RUN == false }} | ||
| env: | ||
| GH_TOKEN: ${{ secrets.ACTION_PAT }} | ||
| INPUT_ENV_NAME: ${{ inputs.ENV_NAME }} | ||
| GIT_AUTHOR_NAME: ${{ github.actor }} | ||
| GIT_AUTHOR_EMAIL: ${{ github.actor }}@users.noreply.github.com | ||
| GIT_COMMITTER_NAME: ${{ github.actor }} | ||
| GIT_COMMITTER_EMAIL: ${{ github.actor }}@users.noreply.github.com | ||
| run: | | ||
| tracker=".github/scripts/wg-peer-allocation.tsv" | ||
| if git diff --quiet -- "$tracker"; then | ||
| echo "No allocation change to commit" | ||
| else | ||
| remote_url="https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | ||
| if ! git pull --rebase --autostash "$remote_url" "${GITHUB_REF_NAME}"; then | ||
| echo "ERROR: Rebase failed (concurrent tracker update?). Resolve on ${GITHUB_REF_NAME} and re-run." | ||
| exit 1 | ||
| fi | ||
| git add "$tracker" | ||
| git commit -s -m "wg: allocate peers for environment $INPUT_ENV_NAME" | ||
| git push "$remote_url" "HEAD:${GITHUB_REF_NAME}" | ||
| fi | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.