-
Notifications
You must be signed in to change notification settings - Fork 140
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
optionally revoke token at the end of workflow run #501
Open
kevinschoonover
wants to merge
8
commits into
hashicorp:main
Choose a base branch
from
kevinschoonover:kschoon/token-revoke
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.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2e4d53b
initial commit
kevinschoonover 4f749bb
test commit
kevinschoonover e683ccd
add revoke token github action tests
kevinschoonover 6ea4df8
update
kevinschoonover 42ebb9c
add changelog
kevinschoonover d303421
remove dist/revoke
kevinschoonover 2fff630
revokeKey -> revokeToken
kevinschoonover dfd6e99
revoke docker-compose changes
kevinschoonover 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
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -59,3 +59,36 @@ jobs: | |
echo | ||
cat secrets.json | ||
jq -c . < secrets.json | ||
revoke-token: | ||
name: revoke-token | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | ||
|
||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
with: | ||
node-version: '16.14.0' | ||
|
||
- name: NPM Install | ||
run: npm ci | ||
|
||
- name: NPM Build | ||
run: npm run build | ||
|
||
- name: Setup Vault | ||
run: node ./integrationTests/e2e/setup.js | ||
env: | ||
VAULT_HOST: localhost | ||
VAULT_PORT: 8200 | ||
|
||
- name: Import Secrets | ||
id: import-secrets | ||
# use the local changes | ||
uses: ./ | ||
# run against a specific version of vault-action | ||
# uses: hashicorp/[email protected] | ||
with: | ||
url: http://localhost:8200 | ||
method: token | ||
token: testtoken | ||
revokeToken: true |
This file contains 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 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 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,118 @@ | ||
jest.mock('@actions/core'); | ||
jest.mock('@actions/core/lib/command'); | ||
const core = require('@actions/core'); | ||
|
||
const got = require('got'); | ||
const { when } = require('jest-when'); | ||
|
||
const { revokeToken, getDefaultOptions, VAULT_TOKEN_STATE } = require('../../src/action'); | ||
const { retrieveToken } = require('../../src/auth'); | ||
|
||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`; | ||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}` | ||
|
||
describe('authenticate with userpass', () => { | ||
const username = `testUsername`; | ||
const password = `testPassword`; | ||
beforeAll(async () => { | ||
try { | ||
// Verify Connection | ||
await got(`${vaultUrl}/v1/secret/config`, { | ||
headers: { | ||
'X-Vault-Token': vaultToken, | ||
}, | ||
}); | ||
|
||
await got(`${vaultUrl}/v1/secret/data/userpass-test`, { | ||
method: 'POST', | ||
headers: { | ||
'X-Vault-Token': vaultToken, | ||
}, | ||
json: { | ||
data: { | ||
secret: 'SUPERSECRET_WITH_USERPASS', | ||
}, | ||
}, | ||
}); | ||
|
||
// Enable userpass | ||
try { | ||
await got(`${vaultUrl}/v1/sys/auth/userpass`, { | ||
method: 'POST', | ||
headers: { | ||
'X-Vault-Token': vaultToken | ||
}, | ||
json: { | ||
type: 'userpass' | ||
}, | ||
}); | ||
} catch (error) { | ||
const { response } = error; | ||
if (response.statusCode === 400 && response.body.includes("path is already in use")) { | ||
// Userpass might already be enabled from previous test runs | ||
} else { | ||
throw error; | ||
} | ||
} | ||
|
||
// Create policies | ||
await got(`${vaultUrl}/v1/sys/policies/acl/userpass-test`, { | ||
method: 'POST', | ||
headers: { | ||
'X-Vault-Token': vaultToken | ||
}, | ||
json: { | ||
"name": "userpass-test", | ||
"policy": `path \"auth/userpass/*\" {\n capabilities = [\"read\", \"list\"]\n}\npath \"auth/userpass/users/${username}\"\n{\n capabilities = [\"create\", \"read\", \"update\", \"delete\", \"list\"]\n}\n\npath \"secret/data/*\" {\n capabilities = [\"list\"]\n}\npath \"secret/metadata/*\" {\n capabilities = [\"list\"]\n}\n\npath \"secret/data/userpass-test\" {\n capabilities = [\"read\", \"list\"]\n}\npath \"secret/metadata/userpass-test\" {\n capabilities = [\"read\", \"list\"]\n}\n` | ||
}, | ||
}); | ||
|
||
// Create user | ||
await got(`${vaultUrl}/v1/auth/userpass/users/${username}`, { | ||
method: 'POST', | ||
headers: { | ||
'X-Vault-Token': vaultToken | ||
}, | ||
json: { | ||
password: `${password}`, | ||
policies: 'userpass-test' | ||
}, | ||
}); | ||
} catch (err) { | ||
console.warn('Create user in userpass', err.response.body); | ||
throw err; | ||
} | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
|
||
when(core.getInput) | ||
.calledWith('method', expect.anything()) | ||
.mockReturnValueOnce('userpass'); | ||
when(core.getInput) | ||
.calledWith('username', expect.anything()) | ||
.mockReturnValueOnce(username); | ||
when(core.getInput) | ||
.calledWith('password', expect.anything()) | ||
.mockReturnValueOnce(password); | ||
// also queried by revokeToken | ||
when(core.getInput) | ||
.calledWith('url', expect.anything()) | ||
.mockReturnValue(`${vaultUrl}`); | ||
when(core.getInput) | ||
.calledWith('revokeToken', expect.anything()) | ||
.mockReturnValueOnce('true'); | ||
}); | ||
|
||
it('revoke token', async () => { | ||
const defaultOptions = getDefaultOptions(); | ||
const vaultToken = await retrieveToken("userpass", got.extend(defaultOptions)); | ||
when(core.getState).calledWith(VAULT_TOKEN_STATE).mockReturnValue(vaultToken); | ||
await revokeToken() | ||
// token is now revoked so we can't revoke again | ||
await expect(revokeToken()) | ||
.rejects | ||
.toThrow('failed to revoke vault token. code: ERR_NON_2XX_3XX_RESPONSE, message: Response code 403 (Forbidden), vaultResponse: {"errors":["permission denied"]}'); | ||
}) | ||
}); |
This file contains 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 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 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,11 @@ | ||
const core = require('@actions/core'); | ||
const { revokeToken } = require('./action'); | ||
|
||
(async () => { | ||
try { | ||
await revokeToken() | ||
} catch (error) { | ||
core.setOutput("errorMessage", error.message); | ||
core.setFailed(error.message); | ||
} | ||
})(); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to know whether fail on revoke can also be switched off with some flag, something like
ignoreFailureRevokeToken
.