-
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
[WIP, but please review]: per-doc-access-control #4139
Closed
+2,396
−151
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9bc4dda
feat(access): add access handling to chttpd
janl ea4e3cc
feat(access): add access to couch_db internal records
janl d95945c
feat(access): handle new records in couch_doc
janl a9eb33d
feat(access): add new _users role for all authenticated users
janl 78eb8d8
feat(access): add access query server
janl cc05b2b
feat(access): expand couch_btree / bt_engine to handle access
janl ae30074
feat(access): handle access in couch_db[_updater]
janl 1d7162e
feat(access): add util functions
janl 8c3e295
feat(access): adjust existing tests
janl 9d3fe31
feat(access): add mrview machinery
janl 9af77d9
feat(access): add access tests
janl bcd3cce
feat(access): add access handling to replicator
janl 4680045
feat(access): add access handling to ddoc cache
janl 92944c3
feat(access): add access handling to fabric
janl 865e428
feat(access): additional test fixes
janl 886ab2f
fix: make tests pass again
janl 651df0a
feat(access): add global off switch
janl e1746c5
doc(access): leave todo for missing implementation detail
janl 2084d51
chore(access): remove old comment
janl 3c5bdf4
fix(access): use minimal info from prev rev
janl fa8585c
chore(access): style notes
janl 92f36af
doc(access): add todos
janl b6a7521
fix(access): opt-out switch
janl a443c03
test(access): test disable access config
janl 3776dca
fix(access): elixir tests
janl d6863a7
chore(access): erlfmt
janl 6d437e3
chore: remove comments and stale todo entries
janl 691343f
fix(access) elixir tests again
janl 5b9e274
fix: simplify
janl 207cdb3
chore: append _users role instead of prepending it
janl 9db67a9
fix: restore previous function signature
janl 841bc38
fix: add function signature change to new open_docs_rev/3
janl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
% 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}). | ||
|
||
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 -> | ||
% TODO: no comprende: should not be needed once we implement | ||
% _access field validation | ||
[[], []] | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Original Comment:
#3038 (comment)