|
| 1 | +name: Integration |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +jobs: |
| 10 | + integration: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - uses: actions/setup-go@v5 |
| 19 | + with: |
| 20 | + go-version-file: go.mod |
| 21 | + cache: true |
| 22 | + |
| 23 | + - name: Build |
| 24 | + run: make build |
| 25 | + |
| 26 | + - name: Install age |
| 27 | + run: | |
| 28 | + GOBIN=/usr/local/bin go install filippo.io/age/cmd/age-keygen@v1.3.1 |
| 29 | + GOBIN=/usr/local/bin go install filippo.io/age/cmd/age@v1.3.1 |
| 30 | +
|
| 31 | + # ----------------------------------------------------------------------- |
| 32 | + # Setup: generate keys, config, and sealed secrets |
| 33 | + # ----------------------------------------------------------------------- |
| 34 | + - name: Generate age identity |
| 35 | + run: age-keygen -o /tmp/identity.txt |
| 36 | + |
| 37 | + - name: Write botlockbox config |
| 38 | + run: | |
| 39 | + cat > /tmp/botlockbox.yaml <<'EOF' |
| 40 | + listen: "127.0.0.1:8080" |
| 41 | + secrets_file: /tmp/secrets.age |
| 42 | + rules: |
| 43 | + - name: github-api |
| 44 | + match: |
| 45 | + hosts: |
| 46 | + - "api.github.com" |
| 47 | + inject: |
| 48 | + headers: |
| 49 | + Authorization: "Bearer {{secrets.github_token}}" |
| 50 | + EOF |
| 51 | +
|
| 52 | + - name: Seal GITHUB_TOKEN into secrets.age |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + run: | |
| 56 | + printf 'github_token: "%s"\n' "$GITHUB_TOKEN" \ |
| 57 | + | ./bin/botlockbox seal \ |
| 58 | + --config /tmp/botlockbox.yaml \ |
| 59 | + --identity /tmp/identity.txt |
| 60 | +
|
| 61 | + # ----------------------------------------------------------------------- |
| 62 | + # Start proxy |
| 63 | + # ----------------------------------------------------------------------- |
| 64 | + - name: Start botlockbox serve |
| 65 | + run: | |
| 66 | + ./bin/botlockbox serve \ |
| 67 | + --config /tmp/botlockbox.yaml \ |
| 68 | + --identity /tmp/identity.txt \ |
| 69 | + --ca-cert /tmp/botlockbox-ca.pem \ |
| 70 | + --pidfile /tmp/botlockbox.pid & |
| 71 | +
|
| 72 | + - name: Wait for proxy to be ready |
| 73 | + run: | |
| 74 | + for i in $(seq 1 40); do |
| 75 | + if nc -z 127.0.0.1 8080 2>/dev/null; then |
| 76 | + echo "Proxy is ready (attempt $i)" |
| 77 | + exit 0 |
| 78 | + fi |
| 79 | + sleep 0.25 |
| 80 | + done |
| 81 | + echo "Proxy did not become ready in time" >&2 |
| 82 | + exit 1 |
| 83 | +
|
| 84 | + - name: Trust botlockbox CA system-wide |
| 85 | + run: | |
| 86 | + sudo cp /tmp/botlockbox-ca.pem /usr/local/share/ca-certificates/botlockbox.crt |
| 87 | + sudo update-ca-certificates |
| 88 | +
|
| 89 | + # ----------------------------------------------------------------------- |
| 90 | + # Tests |
| 91 | + # ----------------------------------------------------------------------- |
| 92 | + |
| 93 | + # Baseline: unauthenticated request WITHOUT the proxy → 401 |
| 94 | + - name: Baseline - unauthenticated request returns 401 |
| 95 | + run: | |
| 96 | + STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://api.github.com/user) |
| 97 | + echo "Status without proxy: $STATUS" |
| 98 | + [ "$STATUS" = "401" ] |
| 99 | +
|
| 100 | + # Core test: botlockbox injects the real token even when gh carries a dummy token. |
| 101 | + # GH_TOKEN=dummy forces gh to send "Authorization: Bearer dummy", which the |
| 102 | + # proxy overwrites with the sealed real token before forwarding to GitHub. |
| 103 | + - name: Proxy injects real token - gh api /user succeeds with dummy GH_TOKEN |
| 104 | + env: |
| 105 | + GH_TOKEN: dummy-credential |
| 106 | + HTTPS_PROXY: http://127.0.0.1:8080 |
| 107 | + run: | |
| 108 | + LOGIN=$(gh api /user --jq '.login') |
| 109 | + echo "Logged in as: $LOGIN" |
| 110 | + [ -n "$LOGIN" ] |
| 111 | +
|
| 112 | + # Verify the injected identity matches the token owner |
| 113 | + - name: Proxy injects real token - curl returns valid user JSON |
| 114 | + run: | |
| 115 | + RESPONSE=$(curl -s \ |
| 116 | + --proxy http://127.0.0.1:8080 \ |
| 117 | + --cacert /tmp/botlockbox-ca.pem \ |
| 118 | + https://api.github.com/user) |
| 119 | + echo "$RESPONSE" | python3 -c " |
| 120 | + import sys, json |
| 121 | + data = json.load(sys.stdin) |
| 122 | + assert 'login' in data, f'missing login field: {data}' |
| 123 | + print('login:', data['login']) |
| 124 | + " |
| 125 | +
|
| 126 | + # Confirm without proxy the dummy token is rejected → 401 |
| 127 | + - name: Dummy token without proxy returns 401 |
| 128 | + run: | |
| 129 | + STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ |
| 130 | + -H "Authorization: Bearer dummy-credential" \ |
| 131 | + https://api.github.com/user) |
| 132 | + echo "Status with dummy token (no proxy): $STATUS" |
| 133 | + [ "$STATUS" = "401" ] |
| 134 | +
|
| 135 | + # ----------------------------------------------------------------------- |
| 136 | + # Reload test |
| 137 | + # ----------------------------------------------------------------------- |
| 138 | + - name: Reload secrets via SIGHUP |
| 139 | + run: | |
| 140 | + # Re-seal with the same token (simulates a rotation) |
| 141 | + printf 'github_token: "%s"\n' "$GITHUB_TOKEN" \ |
| 142 | + | ./bin/botlockbox seal \ |
| 143 | + --config /tmp/botlockbox.yaml \ |
| 144 | + --identity /tmp/identity.txt |
| 145 | +
|
| 146 | + # Signal reload |
| 147 | + ./bin/botlockbox reload --pidfile /tmp/botlockbox.pid |
| 148 | + sleep 1 |
| 149 | +
|
| 150 | + # Proxy must still serve requests correctly after reload |
| 151 | + LOGIN=$(GH_TOKEN=dummy-credential HTTPS_PROXY=http://127.0.0.1:8080 \ |
| 152 | + gh api /user --jq '.login') |
| 153 | + echo "After reload, logged in as: $LOGIN" |
| 154 | + [ -n "$LOGIN" ] |
| 155 | + env: |
| 156 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments