Skip to content

Commit 041cdc0

Browse files
committed
Added 1Password
1 parent 5711b1d commit 041cdc0

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

src/1password-cli/NOTES.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## OS & Architecture Support
2+
3+
- Debian/Ubuntu Linux distributions with the `apt` package manager.
4+
- `amd64`, `arm64`, and `arm/v7` architectures are supported.
5+
6+
## Configuration
7+
8+
There are two options for using this implementation of the 1Password CLI:
9+
10+
1. [Use service accounts with 1Password CLI](https://developer.1password.com/docs/service-accounts/use-with-1password-cli)
11+
2. [Use 1Password CLI with a Connect server](https://developer.1password.com/docs/connect/connect-cli)
12+
13+
Both require using environment variables. The following are examples of how to set the environment variables for `devcontainer.json`based on which option (from above) is used:
14+
15+
### Service Account
16+
17+
```json
18+
"features": {
19+
"ghcr.io/jmcombs/devcontainer-features/google-cloud-sdk:latest": {},
20+
"ghcr.io/jmcombs/devcontainer-features/ngrok:latest": {}
21+
},
22+
...
23+
"containerEnv": {
24+
"OP_SERVICE_ACCOUNT_TOKEN": "thisismyserviceaccount",
25+
"OP_CONNECT_HOST": "thisismyconnecthost",
26+
"OP_CONNECT_TOKEN": "thisismyconnecttoken"
27+
}
28+
```
29+
30+
### Connect Server
31+
32+
```json
33+
"features": {
34+
"ghcr.io/jmcombs/devcontainer-features/google-cloud-sdk:latest": {},
35+
"ghcr.io/jmcombs/devcontainer-features/ngrok:latest": {}
36+
},
37+
...
38+
"containerEnv": {
39+
"OP_CONNECT_HOST": "thisismyconnecthost",
40+
"OP_CONNECT_TOKEN": "thisismyconnecttoken"
41+
}
42+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "1password-cli",
3+
"id": "1password-cli",
4+
"version": "1.0.0",
5+
"description": "Installs the 1Password CLI inside of your devcontainer. You can also pass in a 1Password token to authenticate with 1Password.",
6+
"installsAfter": ["ghcr.io/devcontainers/features/common-utils"]
7+
}

src/1password-cli/install.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Extract 1Password information from environment variables
5+
OP_SERVICE_ACCOUNT_TOKEN=${OPSERVICEACCOUNTTOKEN:-}
6+
7+
check_dependencies() {
8+
for dep in "$@"; do
9+
if ! command -v "$dep" >/dev/null 2>&1; then
10+
echo "error: $dep is not installed, attempting to install..."
11+
if command -v apt-get >/dev/null 2>&1; then
12+
apt-get update && apt-get install --no-install-recommends -y "$dep"
13+
else
14+
echo "error: cannot install $dep, please install it manually" >&2
15+
exit 1
16+
fi
17+
fi
18+
done
19+
}
20+
21+
install_1pcli() {
22+
# Add the key for the 1Password apt repository:
23+
curl -sS https://downloads.1password.com/linux/keys/1password.asc | \
24+
gpg --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg
25+
26+
# Add the 1Password apt repository:
27+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/1password-archive-keyring.gpg] https://downloads.1password.com/linux/debian/$(dpkg --print-architecture) stable main" |
28+
tee /etc/apt/sources.list.d/1password.list
29+
30+
# Add the debsig-verify policy:
31+
mkdir -p /etc/debsig/policies/AC2D62742012EA22/
32+
curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | \
33+
tee /etc/debsig/policies/AC2D62742012EA22/1password.pol && \
34+
mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22 && \
35+
curl -sS https://downloads.1password.com/linux/keys/1password.asc | \
36+
gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg
37+
38+
# Install the 1Password CLI:
39+
apt update && apt install 1password-cli
40+
}
41+
42+
set_op_service_account_token() {
43+
if [ -z "$OP_SERVICE_ACCOUNT_TOKEN" ] ; then
44+
echo "OP_SERVICE_ACCOUNT_TOKEN is not set. Skipping 1Password Service Account Token setup."
45+
return 0
46+
fi
47+
export $OP_SERVICE_ACCOUNT_TOKEN
48+
}
49+
50+
check_dependencies curl ca-certificates
51+
install_1pcli
52+
set_op_service_account_token
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library bundled with the devcontainer CLI
6+
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
7+
# Provides the 'check' and 'reportResults' commands.
8+
source dev-container-features-test-lib
9+
10+
# Check if the environment variables are set and match the expected values
11+
check "OP_SERVICE_ACCOUNT_TOKEN is set" [ "$OP_SERVICE_ACCOUNT_TOKEN" = "thisismyserviceaccount" ]
12+
check "OP_CONNECT_HOST is set" [ "$OP_CONNECT_HOST" = "thisismyconnecthost" ]
13+
check "OP_CONNECT_TOKEN is set" [ "$OP_CONNECT_TOKEN" = "thisismyconnecttoken" ]
14+
15+
# Report results
16+
# If any of the checks above exited with a non-zero exit code, the test will fail.
17+
reportResults

test/1password-cli/scenarios.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"1password-variable-test": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
4+
"features": {
5+
"1password-cli": {}
6+
},
7+
"containerEnv": {
8+
"OP_SERVICE_ACCOUNT_TOKEN": "thisismyserviceaccount",
9+
"OP_CONNECT_HOST": "thisismyconnecthost",
10+
"OP_CONNECT_TOKEN": "thisismyconnecttoken"
11+
}
12+
}
13+
}

test/1password-cli/test.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library bundled with the devcontainer CLI
6+
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
7+
# Provides the 'check' and 'reportResults' commands.
8+
source dev-container-features-test-lib
9+
10+
# Feature-specific tests
11+
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
12+
# check <LABEL> <cmd> [args...]
13+
check "op installation" command -v op
14+
check "op version" op --version
15+
16+
# Report results
17+
# If any of the checks above exited with a non-zero exit code, the test will fail.
18+
reportResults

0 commit comments

Comments
 (0)