CCF
Loading...
Searching...
No Matches
permissions_checks.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
7#include "ccf/js/tx_access.h"
8#include "kv/kv_types.h"
9
10namespace ccf::js
11{
12 static KVAccessPermissions check_kv_map_access(
13 TxAccess execution_context, const std::string& table_name)
14 {
15 // Enforce the restrictions described in the read_write_restrictions page in
16 // the docs. Note that table is more readable, so should be considered the
17 // source of truth for these restrictions. This code is formatted to attempt
18 // to make it clear how it maps directly to that table.
19 const auto [privacy_of_table, namespace_of_table] =
20 ccf::kv::parse_map_name(table_name);
21
22 switch (privacy_of_table)
23 {
25 {
26 // The only time private tables can be used, is on private application
27 // tables in an application context. Governance should neither read from
28 // nor write to private tables, and if private governance or internal
29 // tables exist then applications should not be able to read them.
30 if (
31 execution_context == TxAccess::APP_RW &&
32 namespace_of_table == ccf::kv::AccessCategory::APPLICATION)
33 {
35 }
36 else if (
37 execution_context == TxAccess::APP_RO &&
38 namespace_of_table == ccf::kv::AccessCategory::APPLICATION)
39 {
41 }
42 else
43 {
45 }
46 }
47
49 {
50 switch (namespace_of_table)
51 {
53 {
55 }
56
58 {
59 if (execution_context == TxAccess::GOV_RW)
60 {
62 }
63 else
64 {
66 }
67 }
68
70 {
71 switch (execution_context)
72 {
73 case (TxAccess::APP_RW):
74 {
76 }
77 case (TxAccess::APP_RO):
78 {
80 }
81 case (TxAccess::GOV_RW):
82 {
84 }
85 default:
86 {
88 }
89 }
90 }
91 }
92 }
93
95 {
96 throw std::logic_error(fmt::format(
97 "Unexpected security domain (max) for table {}", table_name));
98 }
99 }
100 }
101 static std::string explain_kv_map_access(
103 {
104 char const* table_kind = permission == KVAccessPermissions::READ_ONLY ?
105 "read-only" :
106 (permission == KVAccessPermissions::WRITE_ONLY ? "write-only" :
107 "inaccessible");
108
109 char const* exec_context = "unknown";
110 switch (access)
111 {
112 case (TxAccess::APP_RW):
113 {
114 exec_context = "application";
115 break;
116 }
117 case (TxAccess::APP_RO):
118 {
119 exec_context = "read-only application";
120 break;
121 }
122 case (TxAccess::GOV_RO):
123 {
124 exec_context = "read-only governance";
125 break;
126 }
127 case (TxAccess::GOV_RW):
128 {
129 exec_context = "read-write governance";
130 break;
131 }
132 }
133
134 static constexpr char const* access_permissions_explanation_url =
135 "https://microsoft.github.io/CCF/main/audit/"
136 "read_write_restrictions.html";
137
138 return fmt::format(
139 "This table is {} in current ({}) execution context. See {} for more "
140 "detail.",
141 table_kind,
142 exec_context,
143 access_permissions_explanation_url);
144 }
145}
Definition bundle.h:12
TxAccess
Definition tx_access.h:10
KVAccessPermissions
Definition kv_access_permissions.h:10
@ SECURITY_DOMAIN_MAX
Definition kv_types.h:258
@ PRIVATE
Definition kv_types.h:257
@ PUBLIC
Definition kv_types.h:256
@ INTERNAL
Definition kv_types.h:263
@ APPLICATION
Definition kv_types.h:265
@ GOVERNANCE
Definition kv_types.h:264