Skip to content

Commit 6b22b1a

Browse files
Skip providing secrets if pipe does not exist (#395)
Otherwise restarting the devcontainer service will fail since the existing app no longer listens for secrets. We shouldn't need to wait anyways since the docker container should've already started with devcontainer up, and it should create the pipe almost instantly.
1 parent 230c1f1 commit 6b22b1a

4 files changed

Lines changed: 20 additions & 32 deletions

File tree

src/test-app-secrets/secrets.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
secrets:
22
- name: "example-secret"
3-
valueVar: "EXAMPLE_SECRET"
4-
- name: "pipe-secret"
5-
pipeVar: "PIPE_SECRET"
6-
- name: "path-secret"
7-
pathVar: "PATH_SECRET"
8-
- name: "multi-dest-secret"
9-
valueVar: "MULTI_VALUE"
10-
pathVar: "MULTI_PATH"
3+
valueVar: "SECRET_VALUE"
4+
pathVar: "SECRET_PATH"
5+
pipeVar: "SECRET_PIPE"

startupscript/butane/055-provide-secrets.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,10 @@ readonly ATTACHED_SECRETS
126126

127127
echo "Waiting for container to create named pipe..."
128128

129-
retries=0
130-
until docker exec "${CONTAINER_NAME}" sh -c "[ -p ${PIPE_PATH} ]" 2>/dev/null; do
131-
if (( retries >= 40 )); then
132-
>&2 echo "ERROR: Timed out waiting for container to create ${PIPE_PATH}"
133-
exit 1
134-
fi
135-
sleep 3
136-
(( retries++ ))
137-
done
129+
if ! docker exec "${CONTAINER_NAME}" sh -c "[ -p ${PIPE_PATH} ]" 2>/dev/null; then
130+
>&2 echo "Container not receinv secrets at ${PIPE_PATH}. Skipping secret provisioning."
131+
exit 0
132+
fi
138133

139134
# --- Build JSON secrets array for pipe delivery ---
140135
SECRETS_JSON="[]"

tests/test-app-secrets.bats

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ get_pid1_env() {
1515
! exec_in_container root test -e /tmp/secrets
1616
}
1717

18-
@test "secret: EXAMPLE_SECRET has correct value" {
19-
result="$(get_pid1_env EXAMPLE_SECRET)"
20-
[ "$result" = "test-value-secret" ]
18+
@test "secret: SECRET_VALUE has correct value" {
19+
result="$(get_pid1_env SECRET_VALUE)"
20+
[ "$result" = "secret-value" ]
2121
}
2222

23-
@test "secret: PIPE_SECRET fd can only be read once" {
24-
fd_path="$(get_pid1_env PIPE_SECRET)"
23+
@test "secret: SECRET_PIPE fd can only be read once" {
24+
fd_path="$(get_pid1_env SECRET_PIPE)"
2525
fd="${fd_path#/dev/fd/}"
2626
result="$(exec_in_container root cat "/proc/1/fd/${fd}")"
27-
[ "$result" = "test-pipe-secret" ]
27+
[ "$result" = "secret-value" ]
2828
result="$(exec_in_container root cat "/proc/1/fd/${fd}")"
2929
[ "$result" = "" ]
3030
}
3131

32-
@test "secret: PATH_SECRET fd is readable multiple times" {
33-
fd_path="$(get_pid1_env PATH_SECRET)"
32+
@test "secret: SECRET_PATH fd is readable multiple times" {
33+
fd_path="$(get_pid1_env SECRET_PATH)"
3434
fd="${fd_path#/dev/fd/}"
3535
result="$(exec_in_container root cat "/proc/1/fd/${fd}")"
36-
[ "$result" = "test-path-secret" ]
36+
[ "$result" = "secret-value" ]
3737
result="$(exec_in_container root cat "/proc/1/fd/${fd}")"
38-
[ "$result" = "test-path-secret" ]
38+
[ "$result" = "secret-value" ]
3939
}

tests/test-app-secrets.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ fi
1616
# Inject mock secrets to unblock the secret receiver
1717
echo "Injecting mock secrets..."
1818
echo '[
19-
{"type":"valueVar","value":"test-value-secret","target":"EXAMPLE_SECRET"},
20-
{"type":"pipeVar","value":"test-pipe-secret","target":"PIPE_SECRET"},
21-
{"type":"pathVar","value":"test-path-secret","target":"PATH_SECRET"},
22-
{"type":"valueVar","value":"test-multi-secret","target":"MULTI_VALUE"},
23-
{"type":"pathVar","value":"test-multi-secret","target":"MULTI_PATH"}
19+
{"type":"valueVar","value":"secret-value","target":"SECRET_VALUE"},
20+
{"type":"pathVar","value":"secret-value","target":"SECRET_PATH"},
21+
{"type":"pipeVar","value":"secret-value","target":"SECRET_PIPE"}
2422
]' | timeout 30 docker exec --user root -i "$CONTAINER_NAME" sh -c 'cat > /tmp/secrets'
2523

2624
bats tests/test-app-secrets.bats

0 commit comments

Comments
 (0)