-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Per document access control #4673
base: main
Are you sure you want to change the base?
Changes from all commits
11302dd
3d225cc
d182a9c
973c407
3231b08
10525e9
5cb4b09
a76a1a9
033683b
698f268
8a0d901
eb2f0e4
26e6c78
db803af
12abedf
0109b04
6cc46f4
c4f51b7
66bbefa
6fd27aa
c105296
1bb8f00
0a43ca9
afc4aaa
88e7a90
99d1945
70e3934
bd643de
0005e36
b9b057c
fdfa229
f7747d7
f258df4
a97c7d7
ad41b24
82eb860
0f6e2f7
66fdc2a
16680e7
e96415a
7f46c70
2b53bce
441dc28
8ec3a0e
f8586a8
f6e409f
5bc6d1b
88dd94a
3db3dde
c3cdc60
fa31ba9
c76b511
f3a0110
42638d6
6cec6b6
b6b61a0
92dc3d1
fae4a03
d0eecff
6d1d1fa
072d467
b1c6308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,8 @@ | |
-record(doc_info, { | ||
id = <<"">>, | ||
high_seq = 0, | ||
revs = [] % rev_info | ||
revs = [], % rev_info | ||
access = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
}). | ||
|
||
-record(size_info, { | ||
|
@@ -80,7 +81,8 @@ | |
update_seq = 0, | ||
deleted = false, | ||
rev_tree = [], | ||
sizes = #size_info{} | ||
sizes = #size_info{}, | ||
access = [] | ||
}). | ||
|
||
-record(httpd, { | ||
|
@@ -124,7 +126,8 @@ | |
|
||
% key/value tuple of meta information, provided when using special options: | ||
% couch_db:open_doc(Db, Id, Options). | ||
meta = [] | ||
meta = [], | ||
access = [] | ||
}). | ||
|
||
|
||
|
@@ -210,7 +213,8 @@ | |
ptr, | ||
seq, | ||
sizes = #size_info{}, | ||
atts = [] | ||
atts = [], | ||
access = [] | ||
}). | ||
|
||
-record (fabric_changes_acc, { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
% Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
% use this file except in compliance with the License. You may obtain a copy of | ||
% the License at | ||
% | ||
% http://www.apache.org/licenses/LICENSE-2.0 | ||
% | ||
% Unless required by applicable law or agreed to in writing, software | ||
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
% License for the specific language governing permissions and limitations under | ||
% the License. | ||
|
||
-module(couch_access_native_proc). | ||
-behavior(gen_server). | ||
|
||
-export([ | ||
start_link/0, | ||
set_timeout/2, | ||
prompt/2 | ||
]). | ||
|
||
-export([ | ||
init/1, | ||
terminate/2, | ||
handle_call/3, | ||
handle_cast/2, | ||
handle_info/2, | ||
code_change/3 | ||
]). | ||
|
||
-record(st, { | ||
indexes = [], | ||
% TODO: make configurable | ||
timeout = 5000 | ||
}). | ||
|
||
start_link() -> | ||
gen_server:start_link(?MODULE, [], []). | ||
|
||
set_timeout(Pid, TimeOut) when is_integer(TimeOut), TimeOut > 0 -> | ||
gen_server:call(Pid, {set_timeout, TimeOut}). | ||
|
||
prompt(Pid, Data) -> | ||
gen_server:call(Pid, {prompt, Data}). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is a 5 second timeout appropriate here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it probably needs to be configurable like other query server timeouts |
||
|
||
init(_) -> | ||
{ok, #st{}}. | ||
|
||
terminate(_Reason, _St) -> | ||
ok. | ||
|
||
handle_call({set_timeout, TimeOut}, _From, St) -> | ||
{reply, ok, St#st{timeout = TimeOut}}; | ||
handle_call({prompt, [<<"reset">>]}, _From, St) -> | ||
{reply, true, St#st{indexes = []}}; | ||
handle_call({prompt, [<<"reset">>, _QueryConfig]}, _From, St) -> | ||
{reply, true, St#st{indexes = []}}; | ||
handle_call({prompt, [<<"add_fun">>, IndexInfo]}, _From, St) -> | ||
{reply, true, St}; | ||
handle_call({prompt, [<<"map_doc">>, Doc]}, _From, St) -> | ||
{reply, map_doc(St, mango_json:to_binary(Doc)), St}; | ||
handle_call({prompt, [<<"reduce">>, _, _]}, _From, St) -> | ||
{reply, null, St}; | ||
handle_call({prompt, [<<"rereduce">>, _, _]}, _From, St) -> | ||
{reply, null, St}; | ||
handle_call({prompt, [<<"index_doc">>, Doc]}, _From, St) -> | ||
{reply, [[]], St}; | ||
handle_call(Msg, _From, St) -> | ||
{stop, {invalid_call, Msg}, {invalid_call, Msg}, St}. | ||
|
||
handle_cast(garbage_collect, St) -> | ||
erlang:garbage_collect(), | ||
{noreply, St}; | ||
handle_cast(Msg, St) -> | ||
{stop, {invalid_cast, Msg}, St}. | ||
|
||
handle_info(Msg, St) -> | ||
{stop, {invalid_info, Msg}, St}. | ||
|
||
code_change(_OldVsn, St, _Extra) -> | ||
{ok, St}. | ||
|
||
% Return value is an array of arrays, first dimension is the different indexes | ||
% [0] will be by-access-id // for this test, later we should make this by-access | ||
% -seq, since that one we will always need, and by-access-id can be opt-in. | ||
% the second dimension is the number of emit kv pairs: | ||
% [ // the return value | ||
% [ // the first view | ||
% ['k1', 'v1'], // the first k/v pair for the first view | ||
% ['k2', 'v2'] // second, etc. | ||
% ], | ||
% [ // second view | ||
% ['l1', 'w1'] // first k/v par in second view | ||
% ] | ||
% ] | ||
% {"id":"account/bongel","key":"account/bongel","value":{"rev":"1-967a00dff5e02add41819138abb3284d"}}, | ||
|
||
map_doc(_St, {Doc}) -> | ||
case couch_util:get_value(<<"_access">>, Doc) of | ||
undefined -> | ||
% do not index this doc | ||
[[], []]; | ||
Access when is_list(Access) -> | ||
Id = couch_util:get_value(<<"_id">>, Doc), | ||
Rev = couch_util:get_value(<<"_rev">>, Doc), | ||
Seq = couch_util:get_value(<<"_seq">>, Doc), | ||
Deleted = couch_util:get_value(<<"_deleted">>, Doc, false), | ||
BodySp = couch_util:get_value(<<"_body_sp">>, Doc), | ||
% by-access-id | ||
ById = | ||
case Deleted of | ||
false -> | ||
lists:map( | ||
fun(UserOrRole) -> | ||
[ | ||
[[UserOrRole, Id], Rev] | ||
] | ||
end, | ||
Access | ||
); | ||
_True -> | ||
[[]] | ||
end, | ||
|
||
% by-access-seq | ||
BySeq = lists:map( | ||
fun(UserOrRole) -> | ||
[ | ||
[[UserOrRole, Seq], [{rev, Rev}, {deleted, Deleted}, {body_sp, BodySp}]] | ||
] | ||
end, | ||
Access | ||
), | ||
ById ++ BySeq; | ||
_Else -> | ||
[[], []] | ||
end. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is too generic for me,
per_doc_access_denied
or something similarly descriptive please.