Skip to content

Commit ccce780

Browse files
authored
Add revoke-self command (#5)
* Add `revoke-self` command * Change machine type * fix YAML * add `when: always` to `revoke-self` command
1 parent 1da0d43 commit ccce780

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

.circleci/test-deploy.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ filters: &filters
99

1010
jobs:
1111
integration-test:
12-
machine: true
12+
machine:
13+
image: ubuntu-2004:current
1314
steps:
1415
- checkout
1516
- run:
@@ -53,7 +54,18 @@ jobs:
5354
- orb-hashicorp-vault-cli/auth-oidc:
5455
vault-address: "http://localhost:8200"
5556
vault-role: "circleci-orb-dev"
56-
- run: vault kv get -field=test secret/circleci/orb
57+
- run:
58+
name: Get secret
59+
command: vault kv get -field=test secret/circleci/orb
60+
- orb-hashicorp-vault-cli/revoke-self
61+
- run:
62+
name: Get secret (should fail)
63+
command: |
64+
ret=$(set -e; vault kv get -field=test secret/circleci/orb &&:) &&:
65+
if [ $? -eq 0 ]; then
66+
exit 1
67+
fi
68+
exit 0
5769
workflows:
5870
test-deploy:
5971
jobs:

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
A custom CircleCI Orb for HashiCorp Vault CLI.
77

8-
This Orb provides two [commands](https://circleci.com/docs/2.0/orb-concepts/#commands) as below:
8+
This Orb provides a few [commands](https://circleci.com/docs/2.0/orb-concepts/#commands) as below:
99

1010
| Command | Description | Documentation |
1111
| ---| --- | --- |
1212
| `install` | Install Vault binary to the current executor environment. | [link](https://circleci.com/developer/orbs/orb/smaeda-ks/orb-hashicorp-vault-cli#commands-install) |
1313
| `auth-oidc` | Authenticate with Vault using OIDC and obtain a token. Upon successful authentication, the obtained token will be set to the `VAULT_TOKEN` environment variable using `$BASH_ENV`. | [link](https://circleci.com/developer/orbs/orb/smaeda-ks/orb-hashicorp-vault-cli#commands-auth-oidc) |
14+
| `revoke-self` | Revoke the token set to the `VAULT_TOKEN` environment variable against the Vault instance set to the `VAULT_ADDR` environment variable. | [link](https://circleci.com/developer/orbs/orb/smaeda-ks/orb-hashicorp-vault-cli#commands-revoke-self) |
1415

1516
## Example Orb usage
1617

@@ -40,6 +41,8 @@ usage:
4041
# so it can be referenced by subsequent steps within the job
4142
FOO=$(vault kv get -field=password secret/circleci/dev)
4243
echo "export SECRET_FOO=${FOO}" >> $BASH_ENV
44+
# Revoke Vault token after finishing all steps
45+
- orb-hashicorp-vault-cli/revoke-self
4346
workflows:
4447
use-my-orb:
4548
jobs:

src/commands/revoke-self.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
description: |
2+
Revoke a Token (Self).
3+
This command attempts to revoke the token set to the `VAULT_TOKEN` environment variable against the Vault instance set to the `VAULT_ADDR` environment variable. These environment variables are assumed to be already set by the `auth-oidc` command in the previous steps. When the token is revoked, all dynamic secrets generated with it are also revoked.
4+
steps:
5+
- run:
6+
when: always
7+
name: Revoke Vault token
8+
command: |
9+
if [ ! "$(which vault)" ]; then
10+
echo "vault is not installed. Please use install command first."
11+
exit 1
12+
fi
13+
14+
vault token revoke -self

src/examples/auth-oidc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ usage:
2323
# so it can be referenced by subsequent steps within the job
2424
FOO=$(vault kv get -field=foo secret/circleci/orb)
2525
echo "export SECRET_FOO=${FOO}" >> $BASH_ENV
26+
# Revoke Vault token after finishing all steps
27+
- orb-hashicorp-vault-cli/revoke-self
2628
workflows:
2729
use-my-orb:
2830
jobs:

0 commit comments

Comments
 (0)