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

Run release enclaves without OE DEBUG flag #1083

Merged
merged 23 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8c7acb5
Compare enclave_type with "virtual", not "debug"
eddyashton Apr 20, 2020
7c46cf1
Add a RELEASE EnclaveType in C++
eddyashton Apr 20, 2020
52365d9
Plumb through 'release' option, as default
eddyashton Apr 20, 2020
9929d61
Set -e debug for Debug builds
eddyashton Apr 20, 2020
de86679
Whoops quotes
eddyashton Apr 20, 2020
c989005
Merge branch 'master' into release_enclaves
achamayou Apr 20, 2020
f57c711
Merge branch 'master' into release_enclaves
achamayou Apr 21, 2020
c438409
Merge branch 'master' into release_enclaves
eddyashton Apr 21, 2020
16188f9
Merge remote-tracking branch 'ea/release_enclaves' into release_enclaves
eddyashton Apr 21, 2020
baebccb
Merge branch 'master' into release_enclaves
achamayou Apr 21, 2020
2e4f482
Remove Debug= lines
eddyashton Apr 21, 2020
7f51065
Produce debuggable AND release libs, all the time
eddyashton Apr 21, 2020
fdc78b0
Mangle correct extension for debuggable libs
eddyashton Apr 21, 2020
4369457
Copy correct file, remove temp dir
eddyashton Apr 21, 2020
3975a00
cmake-format
eddyashton Apr 21, 2020
36bfc44
Clarity
eddyashton Apr 21, 2020
3474933
Merge branch 'release_enclaves' of github.com:eddyashton/CCF into rel…
eddyashton Apr 21, 2020
f66ab94
Add docs
eddyashton Apr 21, 2020
9500e8c
Mention cchost arg
eddyashton Apr 21, 2020
06f7fcc
Merge branch 'master' into release_enclaves
achamayou Apr 21, 2020
9c7476d
De-editorialise
eddyashton Apr 21, 2020
fab8c9a
Merge branch 'release_enclaves' of github.com:eddyashton/CCF into rel…
eddyashton Apr 21, 2020
630716f
Use enclave_type to build lib paths everywhere
eddyashton Apr 22, 2020
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
35 changes: 34 additions & 1 deletion cmake/ccf_app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,44 @@ find_package(OpenEnclave 0.8 CONFIG REQUIRED)
# Sign a built enclave library with oesign
function(sign_app_library name app_oe_conf_path enclave_sign_key_path)
if(TARGET ${name})
# Produce a debuggable variant. This doesn't need to be 'signed', but oesign
eddyashton marked this conversation as resolved.
Show resolved Hide resolved
# also stamps the other config (heap size etc) which _are_ needed
set(DEBUG_CONF_NAME ${CMAKE_CURRENT_BINARY_DIR}/${name}.debuggable.conf)

# Need to put in a temp folder, as oesign has a fixed output path, so
# multiple calls will force unnecessary rebuilds
set(TMP_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/${name}_tmp)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.debuggable
eddyashton marked this conversation as resolved.
Show resolved Hide resolved
COMMAND cp ${app_oe_conf_path} ${DEBUG_CONF_NAME}
COMMAND echo "Debug=1" >> ${DEBUG_CONF_NAME}
COMMAND mkdir -p ${TMP_FOLDER}
COMMAND ln -s ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so
${TMP_FOLDER}/lib${name}.so
COMMAND openenclave::oesign sign -e ${TMP_FOLDER}/lib${name}.so -c
${DEBUG_CONF_NAME} -k ${enclave_sign_key_path}
COMMAND mv ${TMP_FOLDER}/lib${name}.so.signed
${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.debuggable
COMMAND rm -rf ${TMP_FOLDER}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so ${app_oe_conf_path}
${enclave_sign_key_path}
)

add_custom_target(
${name}_debuggable ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.debuggable
)

# Produce a releaseable signed variant. This is NOT debuggable - oegdb
# cannot be attached
set(SIGNED_CONF_NAME ${CMAKE_CURRENT_BINARY_DIR}/${name}.signed.conf)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so.signed
COMMAND cp ${app_oe_conf_path} ${SIGNED_CONF_NAME}
COMMAND echo "Debug=0" >> ${SIGNED_CONF_NAME}
COMMAND
openenclave::oesign sign -e ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so -c
${app_oe_conf_path} -k ${enclave_sign_key_path}
${SIGNED_CONF_NAME} -k ${enclave_sign_key_path}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/lib${name}.so ${app_oe_conf_path}
${enclave_sign_key_path}
)
Expand Down
4 changes: 4 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ if("sgx" IN_LIST COMPILE_TARGETS)
set(QUOTES_ENABLED ON)
endif()
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(TEST_ENCLAVE_TYPE -e debug)
endif()
else()
set(TEST_ENCLAVE_TYPE -e virtual)
endif()
Expand Down
1 change: 0 additions & 1 deletion samples/apps/smallbank/app/oe_sign.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Enclave settings:
Debug=1
NumHeapPages=327680
NumStackPages=1024
NumTCS=8
Expand Down
1 change: 0 additions & 1 deletion samples/apps/txregulator/app/oe_sign.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Enclave settings:
Debug=1
NumHeapPages=50000
NumStackPages=1024
NumTCS=8
Expand Down
5 changes: 5 additions & 0 deletions sphinx/source/developers/build_app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ Running the Application
$ cchost --enclave-file liblua_generic.signed.so [args]

.. note:: When deploying the ``lua_generic`` application, members should also :ref:`register the Lua application <members/open_network:Registering the Lua Application>` before the network is opened to users.

Debugging
---------

To connect a debugger to a CCF node, the configuration passed to `oesign sign` must have debugging enabled (``Debug=1``). This should be disabled for production enclaves, to ensure confidentiality is maintained. If using the ``sign_app_library`` function defined in ``ccf_app.cmake``, 2 variants will be produced for each enclave. ``name.enclave.so.debuggable`` will have debugging enabled (meaning a debugger may be attached - the optimisation level is handled indepdently), while ``name.enclave.so.signed`` produces a final debugging-disabled enclave. The produced binaries are otherwise identical.
1 change: 0 additions & 1 deletion sphinx/source/operators/recovery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ To initiate the first phase of the recovery protocol, one or several nodes shoul

$ cchost
--enclave-file /path/to/enclave_library
--enclave-type debug
--node-address node_ip:node_port
--rpc-address <ccf-node-address>
--public-rpc-address <ccf-node-public-address>
Expand Down
2 changes: 0 additions & 2 deletions sphinx/source/operators/start_network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ To create a new CCF network, the first node of the network should be started wit

$ cchost
--enclave-file /path/to/enclave_library
--enclave-type debug
--node-address node_ip:node_port
--rpc-address <ccf-node-address>
--public-rpc-address <ccf-node-public-address>
Expand Down Expand Up @@ -54,7 +53,6 @@ To add a new node to an existing opening network, other nodes should be started

$ cchost
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a Debug/Debugging section that says "if you are going to be debugging, pass this flag and make sure the config has X, and be aware of the fact that your security guarantees are null and void", perhaps with a link to doc that exists about oegdb if any (or mention oegdb otherwise).

--enclave-file /path/to/enclave_library
--enclave-type debug
--node-address node_ip:node_port
--rpc-address <ccf-node-address>
--public-rpc-address <ccf-node-public-address>
Expand Down
1 change: 0 additions & 1 deletion src/apps/batched/oe_sign.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Enclave settings:
Debug=1
NumHeapPages=50000
NumStackPages=1024
NumTCS=8
Expand Down
1 change: 0 additions & 1 deletion src/apps/js_generic/oe_sign.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Enclave settings:
Debug=1
NumHeapPages=131072
NumStackPages=1024
NumTCS=8
Expand Down
1 change: 0 additions & 1 deletion src/apps/logging/oe_sign.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Enclave settings:
Debug=1
NumHeapPages=50000
NumStackPages=1024
NumTCS=8
Expand Down
1 change: 0 additions & 1 deletion src/apps/lua_generic/oe_sign.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Enclave settings:
Debug=1
NumHeapPages=32768
NumStackPages=1024
NumTCS=8
Expand Down
9 changes: 8 additions & 1 deletion src/host/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ int main(int argc, char** argv)

enum EnclaveType
{
RELEASE,
DEBUG,
VIRTUAL
};

std::vector<std::pair<std::string, EnclaveType>> enclave_type_map = {
{"debug", EnclaveType::DEBUG}, {"virtual", EnclaveType::VIRTUAL}};
{"release", EnclaveType::RELEASE},
{"debug", EnclaveType::DEBUG},
{"virtual", EnclaveType::VIRTUAL}};

EnclaveType enclave_type;
app.add_option("-t,--enclave-type", enclave_type, "Enclave type")
Expand Down Expand Up @@ -400,6 +403,10 @@ int main(int argc, char** argv)

switch (enclave_type)
{
case EnclaveType::RELEASE:
{
break;
}
case EnclaveType::DEBUG:
{
oe_flags |= OE_ENCLAVE_FLAG_DEBUG;
Expand Down
2 changes: 1 addition & 1 deletion tests/code_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def add(parser):
)

args = infra.e2e_args.cli_args(add)
if args.enclave_type != "debug":
if args.enclave_type == "virtual":
LOG.warning("Skipping code update test with virtual enclave")
sys.exit()

Expand Down
2 changes: 1 addition & 1 deletion tests/governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def add(parser):

args = infra.e2e_args.cli_args(add=add)

if args.enclave_type != "debug":
if args.enclave_type == "virtual":
LOG.warning("This test can only run in real enclaves, skipping")
sys.exit(0)

Expand Down
4 changes: 2 additions & 2 deletions tests/infra/e2e_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def cli_args(add=lambda x: None, parser=None, accept_unknown=False):
"-e",
"--enclave-type",
help="Enclave type",
default=os.getenv("TEST_ENCLAVE", "debug"),
choices=("debug", "virtual"),
default=os.getenv("TEST_ENCLAVE", "release"),
choices=("release", "debug", "virtual"),
)
parser.add_argument(
"-l",
Expand Down
2 changes: 1 addition & 1 deletion tests/infra/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _start(
If self.debug is set to True, it will not actually start up the node, but will prompt the user to do so manually
Raises exception if failed to prepare or start the node
:param lib_name: the enclave package to load
:param enclave_type: default: debug. Choices: 'debug', 'virtual'
:param enclave_type: default: release. Choices: 'release', 'debug', 'virtual'
:param workspace: directory where node is started
:param label: label for this node (to differentiate nodes from different test runs)
:return: void
Expand Down
20 changes: 12 additions & 8 deletions tests/infra/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ def mk_new(name, contents):
mk(name, contents)


def build_lib_path(lib_name, enclave_type="debug"):
VIRTUAL_EXT = ".virtual.so"
SIGNED_EXT = ".enclave.so.signed"
def build_lib_path(lib_name, enclave_type=None):
if enclave_type == "virtual":
ext = ".virtual.so"
mode = "Virtual mode"
elif enclave_type == "debug":
ext = ".enclave.so.debuggable"
mode = "Debuggable enclave"
else:
ext = ".enclave.so.signed"
mode = "Real enclave"
if os.path.isfile(lib_name):
if enclave_type == "virtual" and VIRTUAL_EXT not in lib_name:
raise ValueError(f"Virtual mode requires {VIRTUAL_EXT} enclave image")
elif enclave_type == "debug" and SIGNED_EXT not in lib_name:
raise ValueError(f"Real enclave requires {SIGNED_EXT} enclave image")
if ext not in lib_name:
raise ValueError(f"{mode} requires {ext} enclave image")
return lib_name
else:
ext = VIRTUAL_EXT if enclave_type == "virtual" else SIGNED_EXT
# Make sure relative paths include current directory. Absolute paths will be unaffected
return os.path.join(".", os.path.normpath(f"{lib_name}{ext}"))

Expand Down
2 changes: 1 addition & 1 deletion tests/reconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_add_as_many_pending_nodes(network, args):

@reqs.description("Add node with untrusted code version")
def test_add_node_untrusted_code(network, args):
if args.enclave_type == "debug":
if args.enclave_type != "virtual":
LOG.info("Adding an invalid node (unknown code id)")
code_not_found_exception = None
try:
Expand Down