Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 83 additions & 4 deletions .github/workflows/cli-release.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
name: CLI Release

# Builds the keepiq-cli single static binary for every supported platform.
# On a tag push it also uploads the artifacts to the GitHub release. The CLI is
# stdlib-only Go, so the matrix is a plain cross-compile — no PHP/Node needed.
# On a tag push it also uploads the artifacts to the GitHub release, with a
# SHA256SUMS file that the GitHub Action and the GitLab template check every
# download against, and pushes the container image ghcr.io/conductionnl/keepiq-cli
# at the same version. The CLI is stdlib-only Go and builds against sdk/go in
# this repository, so the matrix is a plain cross-compile — no PHP/Node needed.

on:
push:
branches: [main, development]
paths: ["cli/**"]
paths: ["cli/**", "sdk/go/**", "sdk/testdata/**", ".github/workflows/cli-release.yml"]
tags: ["cli-v*"]
pull_request:
branches: [main, development, beta]
paths: ["cli/**"]
paths: ["cli/**", "sdk/go/**", "sdk/testdata/**", ".github/workflows/cli-release.yml"]
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -72,3 +75,79 @@
uses: softprops/action-gh-release@v2
with:
files: ${{ env.ARTIFACT }}

checksums:
# One SHA256SUMS over every binary, attached to the release. On a branch or
# pull request it is built and uploaded as an artifact only (the dry run).
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/download-artifact@v4
with:
pattern: keepiq-*
merge-multiple: true
path: dist
- name: Write SHA256SUMS
working-directory: dist
run: |
sha256sum keepiq-* > SHA256SUMS
cat SHA256SUMS
test "$(wc -l < SHA256SUMS)" -eq 6
- uses: actions/upload-artifact@v4
with:
name: SHA256SUMS
path: dist/SHA256SUMS
- name: Attach to release
if: startsWith(github.ref, 'refs/tags/cli-v')
uses: softprops/action-gh-release@v2
with:
files: dist/SHA256SUMS

image:
Comment on lines +82 to +107
# ghcr.io/conductionnl/keepiq-cli: the linux binaries on a distroless static
# base, multi-arch, tagged with the release version. Pushed on a cli-v tag;
# built without pushing otherwise (the dry run).
needs: build
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: keepiq-linux-*
merge-multiple: true
path: cli/dist
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Log in to ghcr.io
if: startsWith(github.ref, 'refs/tags/cli-v')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Image tags
id: tags
run: |
version="${GITHUB_REF_NAME#cli-v}"
echo "tags=ghcr.io/conductionnl/keepiq-cli:${version},ghcr.io/conductionnl/keepiq-cli:latest" >> "$GITHUB_OUTPUT"
- uses: docker/build-push-action@v6
with:
context: cli
file: cli/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ startsWith(github.ref, 'refs/tags/cli-v') }}
load: false
tags: ${{ steps.tags.outputs.tags }}
labels: |
org.opencontainers.image.source=https://github.com/ConductionNL/keepiq
org.opencontainers.image.description=keepiq CLI, the zero-knowledge Keepiq command-line client
org.opencontainers.image.licenses=EUPL-1.2
- name: Smoke test the amd64 image
run: |
docker buildx build --platform linux/amd64 --load -t keepiq-cli:smoke -f cli/Dockerfile cli
docker run --rm keepiq-cli:smoke --version
107 changes: 107 additions & 0 deletions .github/workflows/integrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: CI integrations

# Runs the GitHub Action and the GitLab CI template against a stub Keepiq
# (sdk/testdata/stub_server.py) and a local release directory holding a CLI
# built from this commit plus its SHA256SUMS. integrations/test/run.sh covers
# both, including a tampered binary; the `action` job then uses the action the
# way a workflow does, so the masked export shows in this run's log.

on:
push:
branches: [main, development]
paths: ["integrations/**", "cli/**", "sdk/go/**", "sdk/testdata/**", ".github/workflows/integrations.yml"]
pull_request:
branches: [main, development, beta]
paths: ["integrations/**", "cli/**", "sdk/go/**", "sdk/testdata/**", ".github/workflows/integrations.yml"]
workflow_dispatch:

permissions:
contents: read

jobs:
scripts:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: python -m pip install cryptography pyyaml
- name: Build the CLI
working-directory: cli
run: CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=cli-vtest" -o "$RUNNER_TEMP/keepiq-linux-amd64" .
- run: bash integrations/test/run.sh "$RUNNER_TEMP/keepiq-linux-amd64"
- name: Lint the GitLab template
run: |
python - <<'PY'
import yaml
doc = yaml.safe_load(open("integrations/gitlab-ci/keepiq.gitlab-ci.yml"))
assert ".keepiq" in doc and doc[".keepiq"]["before_script"], "no .keepiq before_script"
assert "KEEPIQ_CLI_VERSION" in doc["variables"]
PY

action:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: python -m pip install cryptography
- name: Local release and stub Keepiq
run: |
mkdir -p "$RUNNER_TEMP/release/cli-vtest"
(cd cli && CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=cli-vtest" -o "$RUNNER_TEMP/release/cli-vtest/keepiq-linux-amd64" .)
(cd "$RUNNER_TEMP/release/cli-vtest" && sha256sum keepiq-linux-amd64 > SHA256SUMS)
nohup python -m http.server 18088 --bind 127.0.0.1 --directory "$RUNNER_TEMP/release" > /dev/null 2>&1 &
# The password is random and lives only in the stub's memory and argv,
# so the disk check below cannot be fooled by a literal in this repo.
db_value="$(openssl rand -hex 24)"
nohup python sdk/testdata/stub_server.py --port 18089 --add "DB_PASSWORD=$db_value" --add API_TOKEN=api-token-from-keepiq > /dev/null 2>&1 &
echo "STUB_PID=$!" >> "$GITHUB_ENV"
echo "DB_HASH=$(printf %s "$db_value" | sha256sum | cut -c1-64)" >> "$GITHUB_ENV"
for _ in $(seq 50); do curl -fs http://127.0.0.1:18089/index.php/apps/keepiq/api/v1/app/.well-known/keepiq > /dev/null && break; sleep 0.2; done
{
echo 'KEEPIQ_TEST_KEY<<KEEPIQ_TEST_EOF'
python -c 'import json; print(json.load(open("sdk/testdata/machine_envelope.json"))["privateKeyPem"].strip())'
echo 'KEEPIQ_TEST_KEY_EOF'
} >> "$GITHUB_ENV"
- name: Run mode
uses: ./integrations/github-action
with:
url: http://127.0.0.1:18089/index.php
application-id: billing
private-key: ${{ env.KEEPIQ_TEST_KEY }}
secrets: DB_PASSWORD
run: test "$(printf %s "$KEEPIQ_DB_PASSWORD" | sha256sum | cut -c1-64)" = "$DB_HASH" && echo "deploy saw the password"
version: cli-vtest
download-base: http://127.0.0.1:18088
- name: No file on the runner holds the value
run: |
value="$(tr '\0' '\n' < "/proc/$STUB_PID/cmdline" | sed -n 's/^DB_PASSWORD=//p')"
test -n "$value"
if grep -rqF "$value" "$RUNNER_TEMP" "$HOME" "$GITHUB_WORKSPACE" 2>/dev/null; then
echo "::error::a file holds the secret value"; exit 1
fi
- name: Export mode
uses: ./integrations/github-action
with:
url: http://127.0.0.1:18089/index.php
application-id: billing
private-key: ${{ env.KEEPIQ_TEST_KEY }}
secrets: API_TOKEN
export-env: "true"
version: cli-vtest
download-base: http://127.0.0.1:18088
- name: A later step sees the value, and the log shows it masked
run: |
test "$KEEPIQ_API_TOKEN" = api-token-from-keepiq
echo "value: $KEEPIQ_API_TOKEN"
142 changes: 142 additions & 0 deletions .github/workflows/sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Client libraries

# Tests the Go, Python and TypeScript client libraries in sdk/ on every pull
# request that touches them, against the shared vectors in sdk/testdata, and
# releases each one on its own tag prefix:
#
# sdk/go/vX.Y.Z Go module github.com/ConductionNL/keepiq/sdk/go (the tag is
# the release; the Go proxy serves it)
# sdk-py-vX.Y.Z keepiq-sdk on PyPI, through trusted publishing
# sdk-js-vX.Y.Z @conduction/keepiq-sdk on npm, with provenance
#
# On a pull request the package jobs build the Python distribution and the npm
# tarball without publishing them: that is the dry run.

on:
push:
branches: [main, development]
paths: ["sdk/**", ".github/workflows/sdk.yml"]
tags: ["sdk/go/v*", "sdk-py-v*", "sdk-js-v*"]
pull_request:
branches: [main, development, beta]
paths: ["sdk/**", ".github/workflows/sdk.yml"]
workflow_dispatch:

permissions:
contents: read

jobs:
go:
runs-on: ubuntu-latest
# Stdlib-only Go; the RSA-4096 key generation in the tests is the slow part.
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- working-directory: sdk/go
run: |
go vet ./...
go test ./...
- name: Go release tag matches the module
if: startsWith(github.ref, 'refs/tags/sdk/go/v')
run: |
grep -qx 'module github.com/ConductionNL/keepiq/sdk/go' sdk/go/go.mod
echo "Released ${GITHUB_REF_NAME}; consumers fetch it with go get github.com/ConductionNL/keepiq/sdk/go@${GITHUB_REF_NAME#sdk/go/}"

python:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
python: ["3.9", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- working-directory: sdk/python
run: |
python -m pip install --upgrade pip
python -m pip install cryptography pytest
python -m pytest -q

js:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- working-directory: sdk/js
run: |
npm install --no-audit --no-fund
npm run typecheck
npm test

python-package:
needs: python
runs-on: ubuntu-latest
timeout-minutes: 10
environment: ${{ startsWith(github.ref, 'refs/tags/sdk-py-v') && 'pypi' || '' }}
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build
working-directory: sdk/python
run: |
python -m pip install build
python -m build
ls -l dist
- name: Tag matches the package version
if: startsWith(github.ref, 'refs/tags/sdk-py-v')
working-directory: sdk/python
run: |
want="${GITHUB_REF_NAME#sdk-py-v}"
got="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml","rb"))["project"]["version"])')"
test "$want" = "$got" || { echo "::error::tag says $want, pyproject.toml says $got"; exit 1; }
- name: Publish to PyPI (trusted publishing)
if: startsWith(github.ref, 'refs/tags/sdk-py-v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: sdk/python/dist

js-package:
needs: js
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: https://registry.npmjs.org
- name: Build
working-directory: sdk/js
run: |
npm install --no-audit --no-fund
npm run build
npm pack --dry-run
- name: Tag matches the package version
if: startsWith(github.ref, 'refs/tags/sdk-js-v')
working-directory: sdk/js
run: |
want="${GITHUB_REF_NAME#sdk-js-v}"
got="$(node -p 'require("./package.json").version')"
test "$want" = "$got" || { echo "::error::tag says $want, package.json says $got"; exit 1; }
- name: Publish to npm with provenance
if: startsWith(github.ref, 'refs/tags/sdk-js-v')
working-directory: sdk/js
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --provenance --access public
13 changes: 13 additions & 0 deletions .gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Secret scanning configuration (gitleaks v8).
#
# sdk/testdata/ holds a throwaway RSA key and values encrypted to it. They are
# conformance vectors that every client library and the server decrypt in
# tests; the key protects nothing and is labelled TEST ONLY in each file.
title = "keepiq"

[extend]
useDefault = true

[allowlist]
description = "Test-only conformance vectors for the client libraries"
paths = ['''^sdk/testdata/''']
1 change: 1 addition & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
8 changes: 8 additions & 0 deletions cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ghcr.io/conductionnl/keepiq-cli: the static keepiq binary on a distroless base.
# Built by .github/workflows/cli-release.yml from the release binaries in
# cli/dist/ (keepiq-linux-amd64, keepiq-linux-arm64), so the image runs exactly
# the bytes listed in the release's SHA256SUMS.
FROM gcr.io/distroless/static-debian12:nonroot
ARG TARGETARCH
COPY --chmod=0755 dist/keepiq-linux-${TARGETARCH} /usr/local/bin/keepiq
ENTRYPOINT ["/usr/local/bin/keepiq"]
4 changes: 2 additions & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ omits lease reporting.

## Crypto parity

The `internal/crypto` package reimplements the browser recipe **byte-for-byte**:
The `sdk/go/crypto` package (shared with the client libraries, see `../sdk/`) reimplements the browser recipe **byte-for-byte**:

- **Private-key blob** (human unlock): base64 of `[4B version][16B salt][12B
IV][ciphertext+16B GCM tag]`. The unlock key is
Expand All @@ -107,7 +107,7 @@ The `internal/crypto` package reimplements the browser recipe **byte-for-byte**:

PBKDF2 is implemented in-house over `crypto/hmac` (RFC 8018) so the CLI has zero
external dependencies. Byte-parity is pinned by the RFC 6070 test vectors in
`internal/crypto/crypto_test.go`.
`../sdk/go/crypto/crypto_test.go`.

```sh
go test ./...
Expand Down
Loading
Loading