Skip to content

Commit 3debd68

Browse files
authored
Merge pull request #4 from RouL/feature_vault
[CHANGE] New feature "vault"
2 parents 3848c53 + 56d1c83 commit 3debd68

File tree

7 files changed

+163
-0
lines changed

7 files changed

+163
-0
lines changed

src/vault/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# HashiCorp Vault (vault)
3+
4+
Installs the HashiCorp Vault binary.
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/RouL/devcontainer-features/vault:1": {}
11+
}
12+
```
13+
14+
## Options
15+
16+
| Options Id | Description | Type | Default Value |
17+
|-----|-----|-----|-----|
18+
| version | Provides the version to be installed. Defaults to newest available version. | string | - |
19+
20+
21+
22+
---
23+
24+
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/RouL/devcontainer-features/blob/main/src/vault/devcontainer-feature.json). Add additional notes to a `NOTES.md`._

src/vault/devcontainer-feature.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "vault",
3+
"version": "1.0.0",
4+
"name": "HashiCorp Vault",
5+
"description": "Installs the HashiCorp Vault binary.",
6+
"options": {
7+
"version": {
8+
"description": "Provides the version to be installed. Defaults to newest available version.",
9+
"type": "string",
10+
"default": ""
11+
}
12+
}
13+
}

src/vault/install.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/sh
2+
set -e
3+
4+
SERVER_BASE="${SERVER_BASE}"
5+
SERVER_API="${SERVER_API}"
6+
SERVER_IDENTITY="${SERVER_IDENTITY}"
7+
8+
REQUIRED_PACKAGES="curl unzip sudo ca-certificates jq gpg"
9+
TARGET_PATH=/usr/local/bin/vault
10+
11+
# check: https://developer.hashicorp.com/well-architected-framework/operational-excellence/verify-hashicorp-binary#verify-pgp-key-id-and-fingerprint
12+
GPG_FINGERPRINT="C874011F0AB405110D02105534365D9472D7468F"
13+
14+
PRODUCT="vault"
15+
OS="linux"
16+
17+
error() {
18+
echo "$1" >&2
19+
echo "Exiting..." >&2
20+
exit 1
21+
}
22+
23+
apt_get_update()
24+
{
25+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
26+
echo "Running apt-get update..."
27+
apt-get update -y
28+
fi
29+
}
30+
31+
check_packages() {
32+
if ! dpkg -s "$@" > /dev/null 2>&1; then
33+
apt_get_update
34+
apt-get -y install --no-install-recommends "$@"
35+
fi
36+
}
37+
38+
arch_detect() {
39+
if [ "$(uname -m)" = "x86_64" ]; then
40+
ARCH="amd64"
41+
elif [ "$(uname -m)" = "aarch64" ]; then
42+
ARCH="arm64"
43+
else
44+
error "Unsupported architecture: $(uname -m)"
45+
fi
46+
}
47+
48+
export DEBIAN_FRONTEND=noninteractive
49+
50+
check_packages $REQUIRED_PACKAGES
51+
52+
CURRENT_TAG="$(curl -L https://api.github.com/repos/hashicorp/vault/releases/latest | jq --raw-output '.tag_name')"
53+
CURRENT_VERSION="${CURRENT_TAG#v}"
54+
VERSION="${VERSION:-$CURRENT_VERSION}"
55+
56+
arch_detect
57+
58+
install() {
59+
# create gpg env for signature validation
60+
export GNUPGHOME=./.gnupg
61+
gpg --no-tty --quick-generate-key --batch --passphrase "" [email protected]
62+
curl -L --remote-name https://www.hashicorp.com/.well-known/pgp-key.txt
63+
gpg --no-tty --import pgp-key.txt
64+
gpg --no-tty --quick-sign-key $GPG_FINGERPRINT # trust HashiCorp Key
65+
66+
# download vault, sha256 sums and signature
67+
curl -L --remote-name https://releases.hashicorp.com/"${PRODUCT}"/"${VERSION}"/"${PRODUCT}"_"${VERSION}"_"${OS}_${ARCH}".zip
68+
curl -L --remote-name https://releases.hashicorp.com/"${PRODUCT}"/"${VERSION}"/"${PRODUCT}"_"${VERSION}"_SHA256SUMS
69+
curl -L --remote-name https://releases.hashicorp.com/"${PRODUCT}"/"${VERSION}"/"${PRODUCT}"_"${VERSION}"_SHA256SUMS.sig
70+
71+
# verify integrity
72+
gpg --no-tty --verify ${PRODUCT}_${VERSION}_SHA256SUMS.sig ${PRODUCT}_${VERSION}_SHA256SUMS
73+
sha256sum --check --ignore-missing ${PRODUCT}_${VERSION}_SHA256SUMS
74+
75+
unzip "${PRODUCT}"_"${VERSION}"_"${OS}_${ARCH}".zip
76+
rm -f "${PRODUCT}"_"${VERSION}"_"${OS}_${ARCH}".zip LICENSE.txt "${PRODUCT}"_"${VERSION}"_SHA256SUMS "${PRODUCT}"_"${VERSION}"_SHA256SUMS.sig
77+
78+
chmod a+x vault
79+
mv vault $TARGET_PATH
80+
}
81+
82+
echo "(*) Installing HashiCorp Vault binary..."
83+
84+
install
85+
86+
# Clean up
87+
rm -rf /var/lib/apt/lists/*
88+
rm -rf .gnupg
89+
90+
echo "Done!"

test/vault/scenarios.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version-1_17_6": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
4+
"features": {
5+
"vault": {
6+
"version": "1.17.6"
7+
}
8+
}
9+
},
10+
"version-1_10_11-ent": {
11+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
12+
"features": {
13+
"vault": {
14+
"version": "1.10.11+ent"
15+
}
16+
}
17+
}
18+
}

test/vault/test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "vault --version" bash -c "vault --version | grep -E '^Vault v[1-9][0-9]*\\.[0-9]+\\.[0-9]+ '"

test/vault/version-1_10_11-ent.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "vault --version" bash -c "vault --version | grep -E '^Vault v1\\.10\\.11\+ent '"

test/vault/version-1_17_6.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "vault --version" bash -c "vault --version | grep -E '^Vault v1\\.17\\.6 '"

0 commit comments

Comments
 (0)