-
Notifications
You must be signed in to change notification settings - Fork 1
feat(DEV-1582): New fetch-github-token-js action #8
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
Open
chrisnavar
wants to merge
38
commits into
main
Choose a base branch
from
new-js-action
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,224
−12
Open
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
de2338e
Add fetch-github-token-js GitHub Action
chrisnavar 83e837a
Refactor Vault authentication to use axios and JWT
chrisnavar 035f375
Add token revoke post step to GitHub Action
chrisnavar 192e6ff
Remove Vault token handling from GitHub token scripts
chrisnavar cf0bfb8
Add success log after GitHub token revocation
chrisnavar 3246d65
Create README.md
chrisnavar ed93ec3
Update README.md
chrisnavar e5e29bb
Refactor token revoke logic and update node version
chrisnavar 7807607
Update README.md
chrisnavar 667675a
Update fetch-github-token-js/README.md
chrisnavar ea4733b
Merge branch 'new-js-action' of https://github.com/elastic/ci-gh-acti…
chrisnavar c1056e0
Update dependencies and Node.js engine requirements
chrisnavar e5210b2
Add GitHub Actions context and Octokit integration
chrisnavar 39b11be
Update workflow context to use workflow instead of workflow_ref
chrisnavar 037bf17
Remove unused GitHub Actions dependencies
chrisnavar eb34f01
Update Vault login and GitHub API usage
chrisnavar 1d29950
Remove Octokit usage and verify token with gh CLI
chrisnavar 3c9072f
Replace gh CLI token verification with Octokit API call
chrisnavar 72e4b17
Fix Octokit usage for authenticated requests
chrisnavar 16749d4
Rename revoke input to skip-token-revoke
chrisnavar b5cd626
Add unit test workflow and improve token fetch action
chrisnavar 6186847
Switch to fetch API and update Vault token handling
chrisnavar 56932bf
Remove unused dist chunk files and update build
chrisnavar 7658798
Remove axios request for Vault token fetch
chrisnavar 547b732
Run tests for all package directories in workflow
chrisnavar 1e2b853
Refactor build output for ESM compatibility
chrisnavar 16d6bdb
Update run-unit-tests.yml
chrisnavar 88e8032
Update run-unit-tests.yml
chrisnavar ff3085f
Update run-unit-tests.yml
chrisnavar a9fac27
Update run-unit-tests.yml
chrisnavar 114c799
Migrate fetch-github-token-js to fetch-github-token
chrisnavar eb41789
Update README.md
chrisnavar b9fecf6
Update README.md
chrisnavar 6a1085b
Update test-fetch_token.yaml
chrisnavar fdab423
Change default for skip-token-revoke to false
chrisnavar b46cf9f
Refactor Vault GitHub token action for modularity
chrisnavar b0694b8
Mask GitHub token using core.setSecret
chrisnavar c3679c0
Refactor fetch-github-token to composite action
chrisnavar 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,30 @@ | ||
| name: Run Unit Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '24' | ||
| - name: Find and test all packages | ||
| run: | | ||
| find . -type f -name package.json -not -path "*/dist/*" -print0 | while IFS= read -r -d '' file; do | ||
| dir=$(dirname "$file") | ||
| echo "Testing in $dir" | ||
| cd "$dir" || continue | ||
| if [ -f package.json ] && grep -q '"test"' package.json; then | ||
| npm install | ||
| npm test | ||
| else | ||
| echo "No test script found in $dir, skipping..." | ||
| fi | ||
| cd - > /dev/null || exit 1 | ||
| done |
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
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
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 |
|---|---|---|
| @@ -1,89 +1,21 @@ | ||
| name: Get Ephemeral GitHub Token from CI Vault | ||
| description: 'Fetch an ephemeral GitHub token from Vault using OIDC authentication' | ||
|
|
||
| inputs: | ||
| vault-instance: | ||
| description: 'Vault instance to connect to (ci-prod or ci-dev)' | ||
| required: true | ||
| vault-role: | ||
| description: 'Vault role to assume for GitHub token retrieval' | ||
| description: 'Vault role to assume for GitHub token retrieval. If not provided, it will be generated based on the workflow ref of the GH Action.' | ||
| required: false | ||
| default: '' | ||
| # skip-token-revoke: | ||
| # description: 'Revoke the Vault token on exit' | ||
| # default: false | ||
| skip-token-revoke: | ||
| description: 'If true, skip revoking the GitHub token on exit' | ||
| required: false | ||
| default: 'false' | ||
| outputs: | ||
| token: | ||
| description: GitHub App installation access token. | ||
| value: ${{ steps.vault-action.outputs.token }} | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Set Vault Address | ||
| shell: bash | ||
| id: vault-address | ||
| env: | ||
| VAULT_INSTANCE: ${{ inputs.vault-instance }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| if [[ "$VAULT_INSTANCE" == "ci-dev" ]]; then | ||
| echo "url=https://vault-ci.dev.elastic.dev" >> "$GITHUB_OUTPUT" | ||
| echo "Vault address set to CI-DEV." | ||
| elif [[ "$VAULT_INSTANCE" == "ci-prod" ]]; then | ||
| echo "url=https://vault-ci-prod.elastic.dev" >> "$GITHUB_OUTPUT" | ||
| echo "Vault address set to CI-PROD." | ||
| else | ||
| echo "::error title=Input Validation Failed::Invalid vault instance: $VAULT_INSTANCE. Must be 'ci-dev' or 'ci-prod'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Retrieve GitHub Workflow Ref and generate Vault Role name (vault-role input overrides this if provided) | ||
| shell: bash | ||
| id: vault-role | ||
| if: ${{ inputs.vault-role == '' }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| echo "Workflow ref: $GITHUB_WORKFLOW_REF" | ||
| WORKFLOW_REF_BASE="${GITHUB_WORKFLOW_REF%@*}" | ||
| echo "Workflow ref base for role generation: $WORKFLOW_REF_BASE" | ||
| # Generate role name using SHA-256 hash of workflow ref base | ||
| WORKFLOW_HASH=$(echo -n "$WORKFLOW_REF_BASE" | sha256sum | cut -c1-12) | ||
| VAULT_ROLE="token-policy-$WORKFLOW_HASH" | ||
| echo "Generated role name: $VAULT_ROLE" | ||
| echo "role=$VAULT_ROLE" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: "Diagnostic: Log Final Vault Parameters" | ||
| shell: bash | ||
| env: | ||
| VAULT_ADDR: ${{ steps.vault-address.outputs.url }} | ||
| VAULT_ROLE: ${{ inputs.vault-role == '' && steps.vault-role.outputs.role || inputs.vault-role }} | ||
| run: | | ||
| echo "--- Vault Action Input Parameters ---" | ||
| echo "VAULT_ADDR (URL): $VAULT_ADDR" | ||
| echo "VAULT_ROLE: $VAULT_ROLE" | ||
| echo "Vault Secrets Path Expected: github/token/$VAULT_ROLE" | ||
| echo "-------------------------------------" | ||
|
|
||
| - name: Use Vault Action to login and retrieve Ephemeral GitHub Token | ||
| id: vault-action | ||
| env: | ||
| VAULT_ROLE: ${{ inputs.vault-role == '' && steps.vault-role.outputs.role || inputs.vault-role }} | ||
| uses: hashicorp/vault-action@4c06c5ccf5c0761b6029f56cfb1dcf5565918a3b # v3.4.0 | ||
| with: | ||
| url: ${{ steps.vault-address.outputs.url }} | ||
| role: ${{ env.VAULT_ROLE }} | ||
| path: github-oidc | ||
| method: jwt | ||
| jwtGithubAudience: vault | ||
| exportEnv: false | ||
| secrets: | | ||
| github/token/${{ env.VAULT_ROLE }} token | ||
|
|
||
| - name: Token status check | ||
| shell: bash | ||
| run: gh auth status | ||
| env: | ||
| GH_TOKEN: ${{ steps.vault-action.outputs.token }} | ||
| using: 'node24' | ||
| main: 'dist/main.js' | ||
| post: 'dist/revoke.js' | ||
Oops, something went wrong.
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.