Skip to content

Commit

Permalink
Support TLS CA
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirianni committed Feb 28, 2024
1 parent 0dac64d commit dcabac6
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
44 changes: 35 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@ jobs:
- name: Install ShellCheck
run: sudo apt-get install shellcheck

- name: Run ShellCheck
- name: Run ShellCheck entrypoint.sh
run: shellcheck -x -s bash entrypoint.sh

- name: Run ShellCheck test script
run: shellcheck -x -s bash .github/workflows/scripts/*.sh

test:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
# This matrix allows us to test multiple bindplane versions.
# When writing back to the repo, we write to directories based
# on the bindplane version.
bindplane_versions:
- 1.40.0
- 1.37.0
- 1.45.0
- latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -50,6 +55,19 @@ jobs:
- name: Print Runner IP
run: echo $MAIN_IP

- name: Generate TLS Certs
run: ./.github/workflows/scripts/tls.sh
env:
MAIN_IP: ${{ env.MAIN_IP }}

- name: Set CA certificate
run: |
{
echo 'TLS_CA_CERT<<EOF'
cat step/ca.crt
echo EOF
} >> "$GITHUB_ENV"
- name: Pull BindPlane
run: docker pull ghcr.io/observiq/bindplane-ee:${{ matrix.bindplane_versions }}

Expand All @@ -60,22 +78,27 @@ jobs:
--name bindplane \
-e BINDPLANE_USERNAME=admin \
-e BINDPLANE_PASSWORD=admin \
-e BINDPLANE_REMOTE_URL=http://${MAIN_IP}:3001 \
-e BINDPLANE_REMOTE_URL=https://${MAIN_IP}:3001 \
-e BINDPLANE_SESSION_SECRET=2c23c9d3-850f-4062-a5c8-3f9b814ae144 \
-e BINDPLANE_SECRET_KEY=8a5353f7-bbf4-4eea-846d-a6d54296b781 \
-e BINDPLANE_LOG_OUTPUT=stdout \
-e BINDPLANE_ACCEPT_EULA=true \
-e BINDPLANE_TLS_CERT=/bindplane.crt \
-e BINDPLANE_TLS_KEY=/bindplane.key \
-p 3001:3001 \
-v $(pwd)/step/bindplane.crt:/bindplane.crt \
-v $(pwd)/step/bindplane.key:/bindplane.key \
-v $(pwd)/step/ca.crt:/ca.crt \
ghcr.io/observiq/bindplane-ee:${{ matrix.bindplane_versions }}
- name: Wait for BindPlane
uses: nick-fields/retry@v2
with:
timeout_minutes: 1
polling_interval_seconds: 5
max_attempts: 10
polling_interval_seconds: 2
max_attempts: 3
shell: bash
command: docker exec bindplane /bindplane get agent
command: docker exec bindplane /bindplane get agent --tls-ca /ca.crt

- name: Run BindPlane Action
# This should be replaced with a release action.
Expand Down Expand Up @@ -103,12 +126,15 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
enable_otel_config_write_back: true
enable_auto_rollout: true
# Generally this would come from a secret, but the certificate
# was created in this workflow.
tls_ca_cert: ${{ env.TLS_CA_CERT }}

- name: Get Resources
if: always()
run: |
docker exec bindplane /bindplane get destinations
docker exec bindplane /bindplane get configurations
docker exec bindplane /bindplane get destinations --tls-ca /ca.crt
docker exec bindplane /bindplane get configurations --tls-ca /ca.crt
- name: Debug Container Logs
if: always()
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/scripts/tls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -e

if [ -z "$MAIN_IP" ]; then
echo "MAIN_IP is not set"
exit 1
fi

curl -L -s -o step.tar.gz \
https://dl.step.sm/gh-release/cli/gh-release-header/v0.22.0/step_linux_0.22.0_amd64.tar.gz
tar -xzf step.tar.gz
mv step_0.22.0/bin/step /usr/local/bin/step
rm -f step.tar.gz
rm -rf step_0.22.0

mkdir step/
chmod -R 0755 step/

step certificate create \
ca.internal \
step/ca.crt step/ca.key \
--profile root-ca \
--no-password \
--insecure \
--not-after=8760h

step certificate create \
bindplane.internal \
step/bindplane.crt step/bindplane.key \
--san "${MAIN_IP}" \
--profile leaf \
--not-after 2160h \
--no-password \
--insecure \
--ca step/ca.crt \
--ca-key step/ca.key

chmod 0644 step/*
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ inputs:
enable_auto_rollout:
description: 'When enabled, the action will trigger a rollout for all configurations that have been updated'
default: false
tls_ca_cert:
description: 'The CA certificate to use when connecting to BindPlane OP'

runs:
using: 'docker'
Expand All @@ -49,3 +51,4 @@ runs:
- ${{ inputs.token }}
- ${{ inputs.enable_auto_rollout }}
- ${{ inputs.configuration_output_branch }}
- ${{ inputs.tls_ca_cert }}
9 changes: 8 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ configuration_output_dir=${9}
token=${10}
enable_auto_rollout=${11}
configuration_output_branch=${12}
tls_ca_cert=${13}

# This branch name will be compared to target_branch to determine if the action
# should apply or write back configurations.
Expand All @@ -24,7 +25,7 @@ echo "Current branch is $BRANCH_NAME"
install_bindplane_cli() {
curl -Ls \
-o bindplane.zip \
https://storage.googleapis.com/bindplane-op-releases/bindplane/latest/bindplane-ee-linux-amd64.zip
https://storage.googleapis.com/bindplane-op-releases/bindplane/1.46.0/bindplane-ee-linux-amd64.zip

mkdir -p ~/bin
export PATH=$PATH:~/bin
Expand Down Expand Up @@ -68,6 +69,12 @@ validate() {
profile_args="$profile_args --api-key $bindplane_api_key"
fi

if [ -n "$tls_ca_cert" ]; then
echo "tls_ca_cert is set, adding to profile."
echo "$tls_ca_cert" > ca.pem
profile_args="$profile_args --tls-ca ca.pem"
fi

# configuration_output_dir, target_branch, and token are only required
# when enable_otel_config_write_back is true.
if [ "$enable_otel_config_write_back" = true ]; then
Expand Down

0 comments on commit dcabac6

Please sign in to comment.