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

Add proto services for python clients to use #170

Draft
wants to merge 75 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
eced702
Add receipt claims for put and delete
Oct 27, 2022
45784aa
Rename operation
Oct 27, 2022
6abf77b
Wire up install endpoint logic for receipt endpoint
Oct 28, 2022
6fd8c83
Extract txid from request body for receipts
Oct 28, 2022
fb57eee
Update receipt types in proto
Oct 28, 2022
0aed03d
Add leaf components to proto
Oct 28, 2022
87d351e
Fill in receipt data
Oct 28, 2022
96a5cbe
Echo etcdctl command to stderr
Oct 28, 2022
fc0c67b
Add receipts test script
Oct 28, 2022
466ac49
Disable setting claims_digest in receipt
Oct 28, 2022
7bf05b6
Fill header with committed revision for get_receipt
Oct 28, 2022
56dcb18
Fix script lint
Oct 28, 2022
a3fcc74
Quickly document receipts
Oct 28, 2022
33ced80
Re-set claims digest
Oct 28, 2022
882adc1
Format
Oct 28, 2022
d80eff6
Add license
Oct 28, 2022
35272eb
Add newline
Oct 28, 2022
ebe627e
Add receipts flow to docs
Oct 31, 2022
5fc39b2
Separate out lskv gRPC extensions
Oct 31, 2022
0f975c5
Fixup readme
Oct 31, 2022
c683894
Update readme with receipt purpose
Oct 31, 2022
7a9ad5b
Format
Oct 31, 2022
268500f
Merge branch 'main' into custom-claims
Oct 31, 2022
858dd1c
Add cmake current binary dir to proto builds
Oct 31, 2022
93af319
Try adding extra includes or lskvserver
Oct 31, 2022
8623dff
typo
heidihoward Nov 1, 2022
791840f
Use set_allocated_*
Nov 2, 2022
299cb3b
Add txn requests to receipt claims
Nov 2, 2022
c84e0f1
Populate txn requests in receipt claims
Nov 2, 2022
156ba19
Update README.md
Nov 2, 2022
5925533
Change receipt types to use string
Nov 2, 2022
b8c1f09
Format
Nov 2, 2022
fe4040f
Add responses in claims
Nov 2, 2022
c25e93b
Add macro to set custom claims
Nov 2, 2022
f154475
Merge branch 'main' into custom-claims
Nov 2, 2022
86598d9
Generate python protobuf files
Nov 2, 2022
5cdba2f
Ignore generated python pb files
Nov 2, 2022
50407ea
Automatically check receipts and responses
Nov 2, 2022
cbe0f3a
Add types
Nov 2, 2022
767f97d
Add more venv
Nov 2, 2022
fff583f
Change ci to build-virtual
Nov 2, 2022
64337b3
Merge branch 'main' into test-receipts
Nov 8, 2022
51f9630
Add grpcio-tools to requirements
Nov 8, 2022
0451016
Add EXTRA_INCLUDES for sgx
Nov 8, 2022
aae5f48
Only build pb2 for testing
Nov 8, 2022
09f81f9
Ignore pb2 files in linting and type checking
Nov 8, 2022
2ee4485
Merge branch 'main' into test-receipts
Nov 8, 2022
3f74727
Format
Nov 8, 2022
3f4ce9e
Update readme with docker info (#162)
Nov 9, 2022
ef57850
Format proto files (#163)
Nov 9, 2022
d7c6c23
Fix notice check (#164)
Nov 9, 2022
96a5186
Add google apis submodule
Nov 10, 2022
1f3a790
Add range service rpc
Nov 10, 2022
6857313
Add protobuf building with google apis
Nov 10, 2022
361964f
Include google proto dir
Nov 10, 2022
aa963bb
Fixup python protobuf build
Nov 10, 2022
1b15b3b
Generate python grpc bindings
Nov 10, 2022
1f8f089
Format proto file
Nov 10, 2022
898de18
Have proto python builds depend on the build script too
Nov 10, 2022
7314cd4
Include google proto api
Nov 10, 2022
c947bb1
Fix outputs from python grpc
Nov 10, 2022
f6abb62
Fix build
Nov 10, 2022
6b2124f
Add grpc files to gitignore
Nov 10, 2022
60e538d
Comment
Nov 10, 2022
4c8172d
Fix depends for _proto_python
Nov 10, 2022
f08a662
Fixup docker build
Nov 10, 2022
d7eeae5
Add more service definitions
Nov 10, 2022
bb46be8
Add googleapis to cgmanifest
Nov 10, 2022
7617b32
Add new python package
Nov 10, 2022
94531c3
Add python package
Nov 10, 2022
33517e1
Install protoc-gen-openapi
Nov 11, 2022
97e9c19
Add go_package and receipt Service
Nov 11, 2022
de9e4c8
Generate openapi spec
Nov 11, 2022
f34d799
Add options to generate python and openapi
Nov 11, 2022
12b6b94
Update version
Nov 11, 2022
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
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/.venv_ccf_sandbox/
/.vscode/
/3rdparty/
!/3rdparty/googleapis
/Dockerfile.*
/LICENSE
/Makefile
Expand All @@ -36,4 +37,4 @@
/scripts/
/scripts/env/
/workspace/
requirements.txt
requirements.txt
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "3rdparty/k6"]
path = 3rdparty/k6
url = https://github.com/grafana/k6.git
[submodule "3rdparty/googleapis"]
path = 3rdparty/googleapis
url = https://github.com/googleapis/googleapis
1 change: 1 addition & 0 deletions 3rdparty/googleapis
Submodule googleapis added at da380c
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the
# MIT license.
# MIT License.

cmake_minimum_required(VERSION 3.16)

Expand Down Expand Up @@ -45,16 +45,21 @@ add_ccf_app(
src/app/leases.cpp
INCLUDE_DIRS
"${CMAKE_BINARY_DIR}/proto"
"${CMAKE_BINARY_DIR}/proto/google/api"
"${CCF_DIR}/include/ccf/_private"
LINK_LIBS_ENCLAVE
etcd.enclave
lskvserver.enclave
status.enclave
annotations.enclave
http.enclave
protobuf.enclave
LINK_LIBS_VIRTUAL
etcd.virtual
lskvserver.virtual
status.virtual
annotations.virtual
http.virtual
protobuf.virtual)

if(PUBLIC_MAPS)
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile.ignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

FROM busybox
WORKDIR /build-context
COPY . .
CMD find .
CMD find .
7 changes: 4 additions & 3 deletions Dockerfile.sgx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Build
FROM mcr.microsoft.com/ccf/app/dev:3.0.0-rc1-sgx as builder

COPY CMakeLists.txt oe_sign.conf /src/
COPY src /src/src/
COPY proto /src/proto/
COPY . /src/
WORKDIR /build
RUN CC="/opt/oe_lvi/clang-10" CXX="/opt/oe_lvi/clang++-10" cmake -GNinja -DCOMPILE_TARGET=sgx /src && ninja

Expand Down
7 changes: 4 additions & 3 deletions Dockerfile.virtual
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Build
FROM mcr.microsoft.com/ccf/app/dev:3.0.0-rc1-virtual as builder

COPY CMakeLists.txt /src/
COPY src /src/src/
COPY proto /src/proto/
COPY . /src/
WORKDIR /build
RUN CC=$(command -v clang-10) CXX=$(command -v clang++-10) cmake -GNinja -DCOMPILE_TARGET=virtual /src && ninja

Expand Down
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
BUILD=build
CCF_PREFIX_VIRTUAL=/opt/ccf_virtual
CCF_PREFIX_SGX=/opt/ccf_sgx
Expand Down Expand Up @@ -40,22 +42,22 @@ install-ccf-sgx-unsafe:
/opt/ccf_sgx_unsafe/getting_started/setup_vm/run.sh /opt/ccf_sgx_unsafe/getting_started/setup_vm/app-dev.yml # Install dependencies

.PHONY: build-virtual
build-virtual:
build-virtual: .venv protoc-gen-openapi
mkdir -p $(BUILD)
cd $(BUILD) && CC=$(CC) CXX=$(CXX) cmake -DCOMPILE_TARGET=virtual -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DVERBOSE_LOGGING=OFF -DCCF_UNSAFE=OFF -GNinja ..
cd $(BUILD) && ninja
cd $(BUILD) && CC=$(CC) CXX=$(CXX) cmake -DCOMPILE_TARGET=virtual -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DVERBOSE_LOGGING=OFF -DCCF_UNSAFE=OFF -DBUILD_TESTING=ON -DGENERATE_PYTHON=ON -DGENERATE_OPENAPI=ON -GNinja ..
. .venv/bin/activate && cd $(BUILD) && ninja

.PHONY: build-virtual-unsafe
build-virtual-unsafe:
build-virtual-unsafe: .venv protoc-gen-openapi
mkdir -p $(BUILD)
cd $(BUILD) && CC=$(CC) CXX=$(CXX) cmake -DCOMPILE_TARGET=virtual -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DVERBOSE_LOGGING=ON -DCCF_UNSAFE=ON -GNinja ..
cd $(BUILD) && ninja
cd $(BUILD) && CC=$(CC) CXX=$(CXX) cmake -DCOMPILE_TARGET=virtual -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DVERBOSE_LOGGING=ON -DCCF_UNSAFE=ON -DBUILD_TESTING=ON -DGENERATE_PYTHON=ON -DGENERATE_OPENAPI=ON -GNinja ..
. .venv/bin/activate && cd $(BUILD) && ninja

.PHONY: build-sgx
build-sgx:
build-sgx: .venv protoc-gen-openapi
mkdir -p $(BUILD)
cd $(BUILD) && CC=$(OE_CC) CXX=$(OE_CXX) cmake -DCOMPILE_TARGET=sgx -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DVERBOSE_LOGGING=OFF -DCCF_UNSAFE=OFF -GNinja ..
cd $(BUILD) && ninja
cd $(BUILD) && CC=$(OE_CC) CXX=$(OE_CXX) cmake -DCOMPILE_TARGET=sgx -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DVERBOSE_LOGGING=OFF -DCCF_UNSAFE=OFF -DBUILD_TESTING=ON -DGENERATE_PYTHON=ON -DGENERATE_OPENAPI=ON -GNinja ..
. .venv/bin/activate && cd $(BUILD) && ninja

.PHONY: build-docker-virtual
build-docker-virtual:
Expand Down Expand Up @@ -115,6 +117,10 @@ patched-k6:
cp -r 3rdparty/k6 $(BUILD)/3rdparty/.
git apply --directory=$(BUILD)/3rdparty/k6 patches/k6-micro.diff

.PHONY: protoc-gen-openapi
protoc-gen-openapi:
go install github.com/google/gnostic/cmd/[email protected]

$(BIN_DIR)/benchmark: patched-etcd
cd $(BUILD)/3rdparty/etcd && go build -buildvcs=false ./tools/benchmark
mkdir -p $(BIN_DIR)
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Builds `build/liblskv.virtual.so`.
Alternatively, it is possible to build a runtime image of this application via docker:

```bash
$ docker build -t lskv-virtual -f Dockerfile.virtual .
$ make build-docker-virtual
```

### SGX (attested)
Expand All @@ -64,7 +64,7 @@ Builds `build/liblskv.enclave.so.signed`.
Alternatively, it is possible to build a runtime image of this application via docker:

```bash
$ docker build -t lskv-sgx -f Dockerfile.sgx .
$ make build-docker-sgx
```

## Build options
Expand Down Expand Up @@ -119,17 +119,21 @@ Or, for an SGX-enabled application: `$ make run-sgx` or `$ /opt/ccf_sgx/bin/sand

### With docker in Virtual mode

**Note**: A Docker image following the latest changes on the `main` branch is available as `ccfmsrc.azurecr.io/public/lskv:latest-virtual`.

```bash
$ docker run --name lskv -it --rm lskv-virtual
$ docker run --name ccfmsrc.azurecr.io/public/lskv:latest-virtual -it --rm lskv-virtual
...
2022-01-01T12:00:00.000000Z -0.000 0 [info ] ../src/node/node_state.h:1790 | Network TLS connections now accepted
# It is then possible to interact with the service
```

### With docker in SGX mode

**Note**: A Docker image following the latest changes on the `main` branch is available as `ccfmsrc.azurecr.io/public/lskv:latest-sgx`.

```bash
$ docker run --name lskv -it --rm --device /dev/sgx_enclave:/dev/sgx_enclave --device /dev/sgx_provision:/dev/sgx_provision -v /dev/sgx:/dev/sgx lskv-sgx
$ docker run --name ccfmsrc.azurecr.io/public/lskv:latest-sgx -it --rm --device /dev/sgx_enclave:/dev/sgx_enclave --device /dev/sgx_provision:/dev/sgx_provision -v /dev/sgx:/dev/sgx lskv-sgx
...
2022-01-01T12:00:00.000000Z -0.000 0 [info ] ../src/node/node_state.h:1790 | Network TLS connections now accepted
# It is then possible to interact with the service
Expand All @@ -138,6 +142,7 @@ $ docker run --name lskv -it --rm --device /dev/sgx_enclave:/dev/sgx_enclave --d
## Interacting with the store

**Note**: When running with Docker extra setup steps are currently required before interacting with the store as below, see [Running a CCF Service](https://microsoft.github.io/CCF/main/operations/start_network.html#opening-a-network-to-users).
The [`lskv_cluster.py`](./benchmark/lskv_cluster.py) may also be useful for setting up a local docker cluster.

### etcdctl (gRPC API)

Expand Down
2 changes: 2 additions & 0 deletions benchmark/k6.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { check } from "k6";
import http from "k6/http";

Expand Down
9 changes: 9 additions & 0 deletions cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"commitHash": "2fe2dd32b3827eeeeb3959aff63a6b402aab0a5a"
}
}
},
{
"component": {
"type": "git",
"git": {
"repositoryUrl": "https://github.com/googleapis/googleapis",
"commitHash": "da380c77bb87ba0f752baf07605dd1db30e1f7e1"
}
}
}
],
"Version": 1
Expand Down
62 changes: 62 additions & 0 deletions cmake/protobuf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the
# MIT License.

option(GENERATE_PYTHON "generate python protobuf and grpc bindings" OFF)

function(build_proto proto_file src_dir)
message(STATUS "Generating source files from proto file ${proto_file}")
get_filename_component(PROTO_DIR ${proto_file} DIRECTORY)
get_filename_component(PROTO_NAME ${proto_file} NAME)
get_filename_component(PROTO_NAME_WE ${proto_file} NAME_WE)

# generate cpp protoc files
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME_WE}.pb.h
${CMAKE_CURRENT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME_WE}.pb.cc
COMMAND
${PROTOC_BINARY_PATH} --proto_path=${CMAKE_CURRENT_SOURCE_DIR}
--proto_path=${CMAKE_SOURCE_DIR}/3rdparty/googleapis
--cpp_out=${CMAKE_CURRENT_BINARY_DIR} ${src_dir}/${proto_file}
COMMENT "Generate C++ source files from protobuf file ${PROTO_NAME}"
DEPENDS ${src_dir}/${proto_file})

if(${GENERATE_PYTHON})
# generate python grpc and protobuf files
add_custom_command(
OUTPUT
${CMAKE_SOURCE_DIR}/python/lskv/${PROTO_DIR}/${PROTO_NAME_WE}_pb2.py
${CMAKE_SOURCE_DIR}/python/lskv/${PROTO_DIR}/${PROTO_NAME_WE}_pb2.pyi
${CMAKE_SOURCE_DIR}/python/lskv/${PROTO_DIR}/${PROTO_NAME_WE}_pb2_grpc.py
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build.sh ${src_dir}/${proto_file}
${CMAKE_SOURCE_DIR}/python/lskv/
COMMENT "Generate Python source files from protobuf file ${PROTO_NAME}"
DEPENDS ${src_dir}/${proto_file} ${CMAKE_CURRENT_SOURCE_DIR}/build.sh)
add_custom_target(
${PROTO_NAME_WE}_proto_python ALL
DEPENDS
${CMAKE_SOURCE_DIR}/python/lskv/${PROTO_DIR}/${PROTO_NAME_WE}_pb2.py
${CMAKE_SOURCE_DIR}/python/lskv/${PROTO_DIR}/${PROTO_NAME_WE}_pb2.pyi
${CMAKE_SOURCE_DIR}/python/lskv/${PROTO_DIR}/${PROTO_NAME_WE}_pb2_grpc.py
)
endif()

set(PROTOBUF_INCLUDE_DIR ${CCF_DIR}/include/3rdparty/protobuf/src/)

if(${COMPILE_TARGET} STREQUAL "virtual")
add_host_library(
${PROTO_NAME_WE}.virtual
${CMAKE_CURRENT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME_WE}.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME_WE}.pb.h)
target_include_directories(
${PROTO_NAME_WE}.virtual PUBLIC ${PROTOBUF_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR})
else()
add_enclave_library(
${PROTO_NAME_WE}.enclave
${CMAKE_CURRENT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME_WE}.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME_WE}.pb.h)
target_include_directories(
${PROTO_NAME_WE}.enclave PUBLIC ${PROTOBUF_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR})
endif()
endfunction()
3 changes: 3 additions & 0 deletions constitution/actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

class Action {
constructor(validate, apply) {
this.validate = validate;
Expand Down
3 changes: 3 additions & 0 deletions constitution/apply.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

export function apply(proposal, proposalId) {
const proposed_actions = JSON.parse(proposal)["actions"];
for (const proposed_action of proposed_actions) {
Expand Down
3 changes: 3 additions & 0 deletions constitution/resolve.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

export function resolve(proposal, proposerId, votes) {
const memberVoteCount = votes.filter((v) => v.vote).length;

Expand Down
3 changes: 3 additions & 0 deletions constitution/validate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

export function validate(input) {
let proposal = JSON.parse(input);
let errors = [];
Expand Down
4 changes: 3 additions & 1 deletion oe_sign.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Enclave settings:
NumHeapPages=50000
NumStackPages=1024
NumTCS=8
ProductID=1
SecurityVersion=1
# The Debug setting is automatically inserted by sign_app_library in CMake, to build both debuggable and non-debuggable variants
# The Debug setting is automatically inserted by sign_app_library in CMake, to build both debuggable and non-debuggable variants
Loading