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

Basic programmability #60

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
69419d5
Move dispatch and install skeleton from logging to basic
achamayou May 15, 2024
776e4a3
Add install endpoint
achamayou May 16, 2024
6100881
Split out base class
achamayou May 16, 2024
9dbf253
wip
achamayou May 16, 2024
c13b3f0
Merge branch 'main' into basic_programmability
achamayou May 16, 2024
413ef31
Merge branch 'main' into basic_programmability
achamayou May 20, 2024
86bd884
Merge branch 'main' into basic_programmability
achamayou May 20, 2024
80b9fbd
Move enough headers that we can instantiate an interpreter factory in…
achamayou May 21, 2024
6d6fd52
More exports
achamayou May 21, 2024
e12722f
Some headers not needed in app space
achamayou May 21, 2024
11bfe8f
Merge branch 'main' into basic_programmability
achamayou May 21, 2024
57665c6
One last file plus format
achamayou May 21, 2024
6aa8840
reuse_policy
achamayou May 21, 2024
997cc12
Move RequestExtension from js_generic to public includes
achamayou May 21, 2024
5a372fe
Yes, we know, it's an extension
achamayou May 21, 2024
72ee1d4
Merge branch 'main' into basic_programmability
achamayou May 22, 2024
ca437fa
modules
achamayou May 22, 2024
9733d85
Merge branch 'basic_programmability' of https://github.com/achamayou/…
achamayou May 22, 2024
fbe0654
fmt
achamayou May 22, 2024
0dcdbc5
.
achamayou May 22, 2024
2fd1e56
Base module resolution
achamayou May 22, 2024
0e229a1
Merge branch 'main' into basic_programmability
achamayou May 23, 2024
325deba
fmt
achamayou May 23, 2024
7c550d5
Wrapped enum
achamayou May 23, 2024
099e78d
Merge branch 'main' into basic_programmability
achamayou May 23, 2024
b62e535
Interpreter flush, module prefixing
achamayou May 24, 2024
ec54bdc
Bytecode gen
achamayou May 24, 2024
50b29c6
That was just pointlessly confusing, let's not do that
achamayou May 24, 2024
7f9f55c
namespace
achamayou May 24, 2024
523f804
Templated paths and doc
achamayou May 24, 2024
cfbf401
growth mindset
achamayou May 24, 2024
48c5bdc
Split endpoint from install API
achamayou May 24, 2024
08f86c7
Merge branch 'main' into basic_programmability
achamayou May 24, 2024
edf8ba5
Test update
achamayou May 24, 2024
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
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ set(CCF_JS_SOURCES
${CCF_DIR}/src/js/extensions/ccf/network.cpp
${CCF_DIR}/src/js/extensions/ccf/node.cpp
${CCF_DIR}/src/js/extensions/ccf/rpc.cpp
${CCF_DIR}/src/js/extensions/ccf/request.cpp
)

if(COMPILE_TARGET STREQUAL "sgx")
Expand Down Expand Up @@ -590,9 +591,7 @@ elseif(COMPILE_TARGET STREQUAL "virtual")
set(JS_SNP_ATTESTATION_VIRTUAL js_snp_attestation.virtual)
endif()

set(JS_GENERIC_SOURCES ${CCF_DIR}/src/apps/js_generic/js_generic_base.cpp
${CCF_DIR}/src/apps/js_generic/request_extension.cpp
)
set(JS_GENERIC_SOURCES ${CCF_DIR}/src/apps/js_generic/js_generic_base.cpp)
if(COMPILE_TARGET STREQUAL "sgx")
add_enclave_library(js_generic_base.enclave ${JS_GENERIC_SOURCES})
target_link_libraries(js_generic_base.enclave PUBLIC ccf.enclave)
Expand Down Expand Up @@ -1424,6 +1423,11 @@ if(BUILD_TESTS)
${CMAKE_SOURCE_DIR}/samples/apps/logging/js
)

add_e2e_test(
NAME programmability
PYTHON_SCRIPT ${CMAKE_SOURCE_DIR}/tests/programmability.py
)

# This test uses large requests (so too slow for SAN)
if(NOT SAN)
add_e2e_test(
Expand Down
39 changes: 39 additions & 0 deletions include/ccf/bundle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#pragma once

#include "ccf/ds/json.h"
#include "ccf/endpoint.h"

#include <map>
#include <string>

namespace ccf::js
{
struct Metadata
{
std::map<
std::string,
std::map<std::string, ccf::endpoints::EndpointProperties>>
endpoints;
};
DECLARE_JSON_TYPE(Metadata);
DECLARE_JSON_REQUIRED_FIELDS(Metadata, endpoints);

struct Bundle
{
std::map<std::string, std::string> modules;
Metadata metadata;
};

DECLARE_JSON_TYPE(Bundle);
DECLARE_JSON_REQUIRED_FIELDS(Bundle, modules, metadata);

struct BundleWrapper
{
Bundle bundle;
};

DECLARE_JSON_TYPE(BundleWrapper);
DECLARE_JSON_REQUIRED_FIELDS(BundleWrapper, bundle);
}
7 changes: 7 additions & 0 deletions include/ccf/claims_digest.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ namespace ccf
{
ds::json::fill_schema<ClaimsDigest::Digest>(schema);
}

static ClaimsDigest empty_claims()
{
ClaimsDigest cd;
cd.set(ClaimsDigest::Digest::Representation());
return cd;
}
}
34 changes: 33 additions & 1 deletion include/ccf/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,39 @@ namespace ccf::endpoints
return fmt::format("{} {}", verb.c_str(), uri_path);
}
};
}

namespace kv::serialisers
{
template <>
struct BlitSerialiser<ccf::endpoints::EndpointKey>
{
static SerialisedEntry to_serialised(
const ccf::endpoints::EndpointKey& endpoint_key)
{
auto str =
fmt::format("{} {}", endpoint_key.verb.c_str(), endpoint_key.uri_path);
return SerialisedEntry(str.begin(), str.end());
}

static ccf::endpoints::EndpointKey from_serialised(
const SerialisedEntry& data)
{
std::string str{data.begin(), data.end()};
auto i = str.find(' ');
if (i == std::string::npos)
{
throw std::logic_error("invalid encoding of endpoint key");
}
auto verb = str.substr(0, i);
auto uri_path = str.substr(i + 1);
return {uri_path, verb};
}
};
}

namespace ccf::endpoints
{
DECLARE_JSON_TYPE(EndpointKey);
DECLARE_JSON_REQUIRED_FIELDS(EndpointKey, uri_path, verb);

Expand Down Expand Up @@ -467,4 +499,4 @@ struct formatter<ccf::endpoints::ForwardingRequired>
return format_to(ctx.out(), "{}", s);
}
};
FMT_END_NAMESPACE
FMT_END_NAMESPACE
150 changes: 150 additions & 0 deletions include/ccf/endpoints/authentication/js.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.

#include "ccf/endpoint.h"
#include "ccf/endpoints/authentication/all_of_auth.h"

namespace ccf
{
using NamedAuthPolicies =
std::unordered_map<std::string, std::shared_ptr<ccf::AuthnPolicy>>;

static inline NamedAuthPolicies& auth_policies_by_name()
{
static NamedAuthPolicies policies;
if (policies.empty())
{
policies.emplace(
ccf::UserCertAuthnPolicy::SECURITY_SCHEME_NAME,
ccf::user_cert_auth_policy);

policies.emplace(
ccf::MemberCertAuthnPolicy::SECURITY_SCHEME_NAME,
ccf::member_cert_auth_policy);

policies.emplace(
ccf::JwtAuthnPolicy::SECURITY_SCHEME_NAME, ccf::jwt_auth_policy);

policies.emplace(
ccf::UserCOSESign1AuthnPolicy::SECURITY_SCHEME_NAME,
ccf::user_cose_sign1_auth_policy);

policies.emplace(
ccf::EmptyAuthnPolicy::SECURITY_SCHEME_NAME, ccf::empty_auth_policy);
}

return policies;
}

static inline std::shared_ptr<ccf::AuthnPolicy> get_policy_by_name(
const std::string& name)
{
auto& policies = auth_policies_by_name();
auto it = policies.find(name);
if (it == policies.end())
{
return nullptr;
}

return it->second;
}

template <typename T>
static inline constexpr char const* get_policy_name_from_ident(const T*)
{
if constexpr (std::is_same_v<T, ccf::UserCertAuthnIdentity>)
{
return ccf::UserCertAuthnPolicy::SECURITY_SCHEME_NAME;
}
else if constexpr (std::is_same_v<T, ccf::MemberCertAuthnIdentity>)
{
return ccf::MemberCertAuthnPolicy::SECURITY_SCHEME_NAME;
}
else if constexpr (std::is_same_v<T, ccf::JwtAuthnIdentity>)
{
return ccf::JwtAuthnPolicy::SECURITY_SCHEME_NAME;
}
else if constexpr (std::is_same_v<T, ccf::UserCOSESign1AuthnIdentity>)
{
return ccf::UserCOSESign1AuthnPolicy::SECURITY_SCHEME_NAME;
}
else if constexpr (std::is_same_v<T, ccf::MemberCOSESign1AuthnIdentity>)
{
return ccf::MemberCOSESign1AuthnPolicy::SECURITY_SCHEME_NAME;
}
else if constexpr (std::is_same_v<T, ccf::EmptyAuthnIdentity>)
{
return ccf::EmptyAuthnPolicy::SECURITY_SCHEME_NAME;
}
else
{
return nullptr;
}
}

static inline void instantiate_authn_policies(
ccf::endpoints::EndpointDefinition& endpoint)
{
for (const auto& policy_desc : endpoint.properties.authn_policies)
{
if (policy_desc.is_string())
{
const auto policy_name = policy_desc.get<std::string>();
auto policy = get_policy_by_name(policy_name);
if (policy == nullptr)
{
throw std::logic_error(
fmt::format("Unknown auth policy: {}", policy_name));
}
endpoint.authn_policies.push_back(std::move(policy));
}
else
{
if (policy_desc.is_object())
{
const auto it = policy_desc.find("all_of");
if (it != policy_desc.end())
{
if (it.value().is_array())
{
std::vector<std::shared_ptr<ccf::AuthnPolicy>>
constituent_policies;
for (const auto& val : it.value())
{
if (!val.is_string())
{
constituent_policies.clear();
break;
}

const auto policy_name = val.get<std::string>();
auto policy = get_policy_by_name(policy_name);
if (policy == nullptr)
{
throw std::logic_error(
fmt::format("Unknown auth policy: {}", policy_name));
}
constituent_policies.push_back(std::move(policy));
}

if (!constituent_policies.empty())
{
endpoint.authn_policies.push_back(
std::make_shared<ccf::AllOfAuthnPolicy>(
constituent_policies));
continue;
}
}
}
}

// Any failure in above checks falls through to this detailed error.
throw std::logic_error(fmt::format(
"Unsupported auth policy. Policies must be either a string, or an "
"object containing an \"all_of\" key with list-of-strings value. "
"Unsupported value: {}",
policy_desc.dump()));
}
}
}
}
File renamed without changes.
8 changes: 4 additions & 4 deletions src/js/core/context.h → include/ccf/js/core/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "ccf/js/core/runtime.h"
#include "ccf/js/core/wrapped_value.h"
#include "ccf/js/extensions/extension_interface.h"
#include "ccf/js/tx_access.h"
#include "ccf/pal/locking.h"
#include "js/core/runtime.h"
#include "js/core/wrapped_value.h"
#include "js/extensions/extension_interface.h"
#include "js/tx_access.h"

#include <chrono>
#include <quickjs/quickjs-exports.h>
Expand Down
2 changes: 1 addition & 1 deletion src/js/core/runtime.h → include/ccf/js/core/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "kv/kv_types.h"
#include "ccf/tx.h"

#include <chrono>
#include <quickjs/quickjs.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "js/core/context.h"
#include "js/core/wrapped_value.h"
#include "ccf/js/core/context.h"
#include "ccf/js/core/wrapped_value.h"

#include <quickjs/quickjs.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "js/core/constants.h"
#include "ccf/js/core/constants.h"

#include <quickjs/quickjs.h>
#include <string>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma once

#include "ccf/base_endpoint_registry.h"
#include "js/extensions/extension_interface.h"
#include "ccf/js/extensions/extension_interface.h"

namespace ccf::js::extensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "js/extensions/extension_interface.h"
#include "ccf/js/extensions/extension_interface.h"

namespace ccf::js::extensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "js/extensions/extension_interface.h"
#include "ccf/js/extensions/extension_interface.h"

namespace ccf::js::extensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "ccf/js/extensions/extension_interface.h"
#include "ccf/tx.h"
#include "js/extensions/extension_interface.h"

namespace ccf::js::extensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma once

#include "ccf/historical_queries_interface.h"
#include "js/extensions/extension_interface.h"
#include "ccf/js/extensions/extension_interface.h"

#include <quickjs/quickjs.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "ccf/js/extensions/extension_interface.h"
#include "ccf/node/host_processes_interface.h"
#include "js/extensions/extension_interface.h"

namespace ccf::js::extensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache 2.0 License.
#pragma once

#include "ccf/js/extensions/extension_interface.h"
#include "ccf/tx.h"
#include "js/extensions/extension_interface.h"

#include <memory>

Expand Down
Loading
Loading