forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
etcdctl/ctlv3: auth: slash and wildcard permissions
Implement wildcards for get, pul and del. When '*' or '/' is the last symbol in a key, the key is converted to a prefix range. Also: fix many fencepost bugs fixed in the range merge code, including one incorrect test in auth/range_perm_cache_test.go Fixes etcd-io#6359
- Loading branch information
Showing
4 changed files
with
166 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2016 The etcd Authors | ||
// | ||
// 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. | ||
|
||
package auth | ||
|
||
import ( | ||
"bytes" | ||
) | ||
|
||
// isPrefixWithSlash returns true if and only if | ||
// a) both prefix and path are single keys; and | ||
// b) prefix ends in `/`; and | ||
// c) path starts with prefix. | ||
func isPrefixWithSlash(path, prefix *rangePerm) bool { | ||
|
||
if len(prefix.end) != 0 || len(path.end) != 0 { | ||
return false // not single keys | ||
} | ||
lenpre := len(prefix.begin) | ||
if lenpre == 0 { | ||
return false | ||
} | ||
if prefix.begin[lenpre-1] != '/' { | ||
return false | ||
} | ||
return bytes.HasPrefix(path.begin, prefix.begin) | ||
} | ||
|
||
// isPrefixPlusWildcard returns true if and only if | ||
// a) both prefix and path are single keys; and | ||
// b) prefix ends in `*`; and | ||
// c) path starts with prefix up until the `*`. | ||
func isPrefixPlusWildcard(path, prefix *rangePerm) bool { | ||
|
||
if len(prefix.end) != 0 || len(path.end) != 0 { | ||
return false // not single keys | ||
} | ||
lenpre := len(prefix.begin) | ||
if lenpre == 0 { | ||
return false | ||
} | ||
if prefix.begin[lenpre-1] != '*' { | ||
return false | ||
} | ||
return bytes.HasPrefix(path.begin, prefix.begin[:(lenpre-1)]) | ||
} |
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