Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for using azure cleanroom in tests #214

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 10 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "KMS Dev",
"build": {
"dockerfile": "Dockerfile.devcontainer",
"context": ".."
},
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"enableNonRootDocker": "true",
"moby": "true"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/node:1": {}
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/powershell:1": {
"modules": "powershell-yaml"
},
"ghcr.io/devcontainers/features/azure-cli:1": {
"version": "2.61.0",
"extensions": "confcom,managedccfs"
}
},
"customizations": {
"vscode": {
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/endpoint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
env: [local]
env: [ccf/sandbox-local]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -42,9 +42,4 @@ jobs:
- name: Run System Tests
env:
TEST_ENVIRONMENT: ${{ matrix.env }}
run: |
if [[ "$TEST_ENVIRONMENT" == "cloud" ]]; then
pytest -sv -n auto test/system-test/test_${{ inputs.endpoint }}.py
else
pytest -sv test/system-test/test_${{ inputs.endpoint }}.py
fi
run: pytest -sv test/system-test/test_${{ inputs.endpoint }}.py
35 changes: 15 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,32 @@ setup: ## Setup proposals and generate an initial key

stop-host: ## 🏃 Stop the host
@echo -e "\e[34m$@\e[0m" || true
sudo lsof -t -i :8000 | xargs -r sudo kill -9
source ./scripts/ccf/sandbox-local/down.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These scripts force the usage of containers. So running KMS locally will no longer be possible. By the way, this is how I do my dev work. What are the limitations going forward?
In development you start frequently KMS. Containers have this persistent state behavior of you don't completely remove them. Meaning rebuilding of the container for every dev step.

Copy link
Collaborator Author

@DomAyre DomAyre Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using CCF only from the container is indeed a choice we need to make carefully, my reasoning for supporting this choice are:

  • It mimics how the real system will behave (i.e. Run CCF network somewhere else, and apply KMS code/policies/etc to it)
  • It allows us to have a much simpler dev environment as you don't need to work on top of the CCF dev container or install CCF manually
  • It makes running against KMS on different styles of CCF network trivial (sandbox locally, sandbox in aci, mCCF while it lasts, azure-cleanroom etc.)

I believe the considerations you raise aren't bad enough to outweigh the benefits for the following reasons:

  • Persistent state: Using docker compose down cleans up for you, I've never had trouble with it
  • Rebuilding:
    • Since the container image is just the official CCF dev image (i.e. no KMS code), it doesn't typically change while developing the KMS
    • In my experience starting or recreating the container takes ~5 seconds, building the kms code often takes longer
    • If you don't mind keeping the current KV/ledger of a running KMS this scheme even lets you update the code without stopping or recreating the CCF network

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much work would it be to support Ronny's way of working as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible, we would need:

  • A local environment with virtual CCF installed and all it's dependencies
    • See the changes to devcontainer.json, requires developing inside the ccf/dev container or complex setup
  • We can then add /scripts/ccf/sandbox-local-non-container/ directory with up and down scripts
    • We would need a some extra code to handle the lifecycle stuff which docker compose does for us in this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I see that as a pain, and I don't see any benefits vs just starting the off the shelf CCF container and treating it like every other use case of CCF


stop-idp: ## 🏃 Stop the idp
@echo -e "\e[34m$@\e[0m" || true
sudo lsof -t -i :3000 | xargs -r sudo kill -9
source ./scripts/jwt-issuer/down.sh

stop-all: stop-host stop-idp # Stop all services
@echo -e "\e[34m$@\e[0m" || true

# idp commands to issue JWT
start-idp: ## 🏃 Start the idp for testing jwt
@echo -e "\e[34m$@\e[0m" || true
mkdir -p ${KMS_WORKSPACE}
cd test/utils/jwt && KMS_WORKSPACE=${KMS_WORKSPACE} nohup npm run start > nohup.out 2>&1 &
./scripts/wait_idp_ready.sh
source ./scripts/jwt-issuer/up.sh

# Start hosting the application using `sandbox.sh` and enable custom JWT authentication
start-host: stop-host ## 🏃 Start the CCF network using Sandbox.sh
@echo -e "\e[34m$@\e[0m" || true
$(CCFSB)/sandbox.sh --js-app-bundle ./dist/ --initial-member-count ${MEMBER_COUNT} --initial-user-count 1 --constitution ./governance/constitution/kms_actions.js -v --http2
MEMBER_COUNT=${MEMBER_COUNT} source ./scripts/ccf/sandbox-local/up.sh && \
source ./scripts/kms/js-app-set.sh && \
source ./scripts/kms/constitution-set.sh ./governance/constitution/kms_actions.js

start-host-idp: stop-host stop-idp start-idp build ## 🏃 Start the CCF network && idp using Sandbox.sh
start-host-idp: stop-host stop-idp start-idp start-host ## 🏃 Start the CCF network && idp using Sandbox.sh
@echo -e "\e[34m$@\e[0m" || true
@echo "Executing: $(COMMAND)"
if [ "$(RUN_BACK)" = "true" ]; then \
env -i PATH=${PATH} KMS_WORKSPACE=${KMS_WORKSPACE} $(CCFSB)/sandbox.sh --js-app-bundle ./dist/ --initial-member-count ${MEMBER_COUNT} --initial-user-count 1 --constitution ./governance/constitution/kms_actions.js --jwt-issuer ${KMS_WORKSPACE}/proposals/set_jwt_issuer_test_sandbox.json -v --http2 \
${CCF_SANDBOX_EXTRA_ARGS} & \
else \
env -i PATH=${PATH} KMS_WORKSPACE=${KMS_WORKSPACE} $(CCFSB)/sandbox.sh --js-app-bundle ./dist/ --initial-member-count ${MEMBER_COUNT} --initial-user-count 1 --constitution ./governance/constitution/kms_actions.js --jwt-issuer ${KMS_WORKSPACE}/proposals/set_jwt_issuer_test_sandbox.json -v --http2 \
${CCF_SANDBOX_EXTRA_ARGS}; \
fi
MEMBER_COUNT=${MEMBER_COUNT} source ./scripts/ccf/sandbox-local/up.sh > /dev/null 2>&1 && \
source ./scripts/kms/jwt-issuer-trust.sh

demo: stop-all start-host-idp ## 🎬 Demo the KMS Application in the Sandbox
@echo -e "\e[34m$@\e[0m" || true
Expand Down Expand Up @@ -168,36 +163,36 @@ jwt-issuer-up:
@WORKSPACE=${KMS_WORKSPACE} \
DEPLOYMENT_ENV=${DEPLOYMENT_ENV} \
IMAGE_TAG=${IMAGE_TAG} \
./scripts/jwt-issuer-up.sh
./scripts/jwt-issuer/up.sh

jwt-issuer-down:
@DEPLOYMENT_ENV=${DEPLOYMENT_ENV} \
./scripts/jwt-issuer-down.sh
./scripts/jwt-issuer/down.sh

jwt-issuer-trust:
@WORKSPACE=${KMS_WORKSPACE} \
KMS_URL=${KMS_URL} \
DEPLOYMENT_ENV=${DEPLOYMENT_ENV} \
./scripts/jwt-issuer-trust.sh
./scripts/kms/jwt-issuer-trust.sh

# Manage KMS -------------------------------------------------------------------

js-app-set:
@WORKSPACE=${KMS_WORKSPACE} \
KMS_URL=${KMS_URL} \
./scripts/js-app-set.sh
./scripts/kms/js-app-set.sh

constitution-set:
@WORKSPACE=${KMS_WORKSPACE} \
KMS_URL=${KMS_URL} \
CONSTITUTION_PATH=./governance/constitution/kms_actions.js \
./scripts/constitution-set.sh
./scripts/kms/constitution-set.sh

release-policy-set:
@WORKSPACE=${KMS_WORKSPACE} \
KMS_URL=${KMS_URL} \
RELEASE_POLICY_PROPOSAL=$(release-policy-proposal) \
./scripts/release-policy-set.sh
./scripts/kms/release-policy-set.sh

test-system:
@pytest -s test/system-test/$(filter-out $@,$(MAKECMDGOALS))
Expand Down
30 changes: 30 additions & 0 deletions scripts/ccf/propose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

ccf-propose() {
set -e

echo "Proposing: $1"
echo " to $KMS_URL"
echo " cert: $KMS_SERVICE_CERT_PATH"
echo " as $KMS_MEMBER_CERT_PATH"
ccf_cose_sign1 \
--content $1 \
--signing-cert ${KMS_MEMBER_CERT_PATH} \
--signing-key ${KMS_MEMBER_PRIVK_PATH} \
--ccf-gov-msg-type proposal \
--ccf-gov-msg-created_at $(date -Is) \
| curl $KMS_URL/gov/proposals -k -H "Content-Type: application/cose" \
--data-binary @- \
-s \
--cacert $KMS_SERVICE_CERT_PATH -w '\n' \
| jq

set +e
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
ccf-propose "$@"
fi
20 changes: 20 additions & 0 deletions scripts/ccf/sandbox-local/down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

ccf-sandbox-local-down() {
set -e

REPO_ROOT="$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../../..")"
docker compose -f $REPO_ROOT/services/docker-compose.yml down ccf-sandbox --remove-orphans

unset KMS_URL
unset KMS_SERVICE_CERT_PATH
unset KMS_MEMBER_CERT_PATH
unset KMS_MEMBER_PRIVK_PATH

set +e
}

ccf-sandbox-local-down
33 changes: 33 additions & 0 deletions scripts/ccf/sandbox-local/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

ccf-sandbox-local-up() {
set -e

REPO_ROOT="$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../../..")"

export WORKSPACE="$(realpath ${WORKSPACE:-$REPO_ROOT/workspace})"
mkdir -p $WORKSPACE
docker compose -f $REPO_ROOT/services/docker-compose.yml build ccf-sandbox > /dev/null 2>&1
docker compose -f $REPO_ROOT/services/docker-compose.yml up ccf-sandbox --wait
sudo chown $USER:$USER -R $WORKSPACE

export KMS_URL="https://127.0.0.1:8000"
export KMS_SERVICE_CERT_PATH="$WORKSPACE/sandbox_common/service_cert.pem"
export KMS_MEMBER_CERT_PATH="$WORKSPACE/sandbox_common/member0_cert.pem"
export KMS_MEMBER_PRIVK_PATH="$WORKSPACE/sandbox_common/member0_privk.pem"

set +e
}

ccf-sandbox-local-up

jq -n '{
WORKSPACE: env.WORKSPACE,
KMS_URL: env.KMS_URL,
KMS_SERVICE_CERT_PATH: env.KMS_SERVICE_CERT_PATH,
KMS_MEMBER_CERT_PATH: env.KMS_MEMBER_CERT_PATH,
KMS_MEMBER_PRIVK_PATH: env.KMS_MEMBER_PRIVK_PATH
}'
19 changes: 0 additions & 19 deletions scripts/constitution-set.sh

This file was deleted.

26 changes: 0 additions & 26 deletions scripts/js-app-set.sh

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/jwt-issuer-down.sh

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/jwt-issuer-trust.sh

This file was deleted.

14 changes: 0 additions & 14 deletions scripts/jwt-issuer-up.sh

This file was deleted.

8 changes: 8 additions & 0 deletions scripts/jwt-issuer/down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

set -e

docker compose -f services/docker-compose.yml down jwt-issuer --remove-orphans
13 changes: 13 additions & 0 deletions scripts/jwt-issuer/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

set -e

REPO_ROOT="$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../..")"
export WORKSPACE=$(realpath ${WORKSPACE:-$REPO_ROOT/workspace})

docker compose -f services/docker-compose.yml up jwt-issuer --wait

sudo chown $USER:$USER -R $WORKSPACE
30 changes: 30 additions & 0 deletions scripts/kms/constitution-set.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

constitution-set() {
set -e

REPO_ROOT="$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../..")"
CONSTITUTION_PATH=$1

# Get the current constitution
curl -k $KMS_URL/gov/service/constitution?api-version=2024-07-01 > $WORKSPACE/proposals/constitution.js

# Append the consitution given
cat "$CONSTITUTION_PATH" >> $WORKSPACE/proposals/constitution.js

# Construct the proposal
jq --arg constitution "$(tr -s ' ' < "$WORKSPACE/proposals/constitution.js")" \
'.actions[0].args.constitution = $constitution' \
$REPO_ROOT/governance/proposals/set_constitution.json > $WORKSPACE/proposals/set_constitution.json

# Submit the proposal
source $REPO_ROOT/scripts/ccf/propose.sh
ccf-propose $WORKSPACE/proposals/set_constitution.json

set +e
}

constitution-set "$@"
12 changes: 12 additions & 0 deletions scripts/kms/endpoints/heartbeat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

heartbeat() {
curl $KMS_URL/app/heartbeat \
--cacert $KMS_SERVICE_CERT_PATH \
-w '\n%{http_code}\n'
}

heartbeat
Loading