Skip to content

Commit c5274db

Browse files
Fix HAB_AUTH_TOKEN for systemd-spawned Habitat processes
Configure token in /hab/etc/cli.toml so it persists for all Habitat processes including those spawned by systemd during chef-automate deploy. Previously the token was only passed as an environment variable to the docker exec command, but systemd services don't inherit these variables. Signed-off-by: Peter Arsenault <parsenau@progress.com>
1 parent 2cd9328 commit c5274db

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

  • .github/actions/automate-container-scan

.github/actions/automate-container-scan/run.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,26 @@ deploy_automate() {
109109
fail "sysctl configuration failed"
110110
fi
111111

112+
# Configure Habitat authentication if token provided
113+
if [[ -n "${HAB_AUTH_TOKEN:-}" ]]; then
114+
log "HAB_AUTH_TOKEN provided - configuring Habitat authentication"
115+
# Create Habitat CLI config directory and config file with auth token
116+
# This ensures the token is available to all hab processes, including those spawned by systemd
117+
docker exec -w /root "${CONTAINER_ID}" bash -c "mkdir -p /hab/etc && cat > /hab/etc/cli.toml <<EOF
118+
auth_token = \"${HAB_AUTH_TOKEN}\"
119+
EOF" > "${LOGS_DIR}/hab-config.log" 2>&1 || log "WARNING: Failed to configure Habitat auth (may not be critical)"
120+
121+
# Also set as environment variable for immediate processes
122+
docker exec -w /root "${CONTAINER_ID}" bash -c "echo 'export HAB_AUTH_TOKEN=${HAB_AUTH_TOKEN}' >> /root/.bashrc" \
123+
>> "${LOGS_DIR}/hab-config.log" 2>&1 || true
124+
fi
125+
112126
# Deploy Automate (this takes 10-15 minutes)
113127
log "Deploying Automate (this may take 10-15 minutes)..."
114128
log "Progress will be logged to ${LOGS_DIR}/deploy.log"
115129

116-
# Build docker exec command with optional HAB_AUTH_TOKEN
117-
local docker_exec_cmd="docker exec -w /root"
118-
if [[ -n "${HAB_AUTH_TOKEN:-}" ]]; then
119-
log "HAB_AUTH_TOKEN provided - enabling Habitat authentication"
120-
docker_exec_cmd="${docker_exec_cmd} -e HAB_AUTH_TOKEN=${HAB_AUTH_TOKEN}"
121-
fi
122-
docker_exec_cmd="${docker_exec_cmd} ${CONTAINER_ID} timeout 1800 chef-automate deploy --channel ${CHANNEL} --skip-preflight config.toml --accept-terms-and-mlsa"
130+
# Run deploy command
131+
local docker_exec_cmd="docker exec -w /root ${CONTAINER_ID} timeout 1800 chef-automate deploy --channel ${CHANNEL} --skip-preflight config.toml --accept-terms-and-mlsa"
123132

124133
# Run deploy with timeout and capture output
125134
# tee streams output to Actions log in real-time while also writing to file

0 commit comments

Comments
 (0)