Skip to content

Commit 5e24c54

Browse files
Merge pull request #52 from chef/peter-at-progress/hab-auth-token
Add HAB_AUTH_TOKEN support to automate-container-scan action
2 parents 59f6caf + a711c73 commit 5e24c54

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

.github/actions/automate-container-scan/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This action provides automated vulnerability scanning for Chef Automate's embedd
2020
uses: chef/common-github-actions/.github/actions/automate-container-scan@main
2121
with:
2222
channel: current
23+
license_id: ${{ secrets.GA_DOWNLOAD_GRYPE_LICENSE_ID }}
24+
hab_auth_token: ${{ secrets.HAB_AUTH_TOKEN }} # Required for dev channel
2325
out_dir: out
2426
```
2527
@@ -48,6 +50,8 @@ jobs:
4850
uses: ./common-github-actions/.github/actions/automate-container-scan
4951
with:
5052
channel: current
53+
license_id: ${{ secrets.GA_DOWNLOAD_GRYPE_LICENSE_ID }}
54+
hab_auth_token: ${{ secrets.HAB_AUTH_TOKEN }}
5155
out_dir: out
5256

5357
- name: Upload scan results
@@ -66,8 +70,12 @@ jobs:
6670
| Input | Description | Required | Default |
6771
|-------|-------------|----------|---------|
6872
| `channel` | Release channel for Chef Automate (`stable` or `current`) | No | `current` |
73+
| `license_id` | Chef download license ID (required for commercial downloads) | Yes | N/A |
74+
| `hab_auth_token` | Habitat Builder Personal Access Token for protected channels (pass via secrets) | No | `""` |
6975
| `out_dir` | Output directory for scan results and logs | No | `out` |
7076

77+
**Note on `hab_auth_token`**: This parameter is **required for the `dev` channel** and other protected Habitat channels that contain packages requiring authentication. The `current` and `stable` channels typically have public packages that don't require authentication. If you see `401 Unauthorized` errors during deployment, ensure you've provided a valid HAB_AUTH_TOKEN.
78+
7179
## Outputs
7280

7381
### Directory Structure

.github/actions/automate-container-scan/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ inputs:
1010
license_id:
1111
description: "Chef download license ID (required for commercial downloads)"
1212
required: true
13+
hab_auth_token:
14+
description: "Habitat Builder Personal Access Token for protected channels (pass via secrets)"
15+
required: false
16+
default: ""
1317
out_dir:
1418
description: "Output directory for scan results and logs"
1519
required: false
@@ -33,6 +37,7 @@ runs:
3337
CHANNEL: ${{ inputs.channel }}
3438
OUT_DIR: ${{ inputs.out_dir }}
3539
ACTION_DIR: ${{ github.action_path }}
40+
HAB_AUTH_TOKEN: ${{ inputs.hab_auth_token }}
3641

3742
branding:
3843
icon: "shield"

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,33 @@ 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

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"
132+
116133
# Run deploy with timeout and capture output
117134
# tee streams output to Actions log in real-time while also writing to file
118135
# --skip-preflight: the CLI is always downloaded from the 'current' channel (no 'dev' download URL
119136
# exists), so when deploying --channel dev the preflight CLI version check will always fail because
120137
# dev has a newer build than current. The skip is safe: the CLI is still fully capable of deploying.
121-
if docker exec -w /root "${CONTAINER_ID}" timeout 1800 chef-automate deploy --channel ${CHANNEL} --skip-preflight config.toml --accept-terms-and-mlsa \
122-
2>&1 | tee "${LOGS_DIR}/deploy.log"; then
138+
if eval "${docker_exec_cmd}" 2>&1 | tee "${LOGS_DIR}/deploy.log"; then
123139
log "Automate deployment completed successfully"
124140
else
125141
log "ERROR: Automate deployment failed or timed out"

0 commit comments

Comments
 (0)