Skip to content

Commit 951e92e

Browse files
authored
more intuitive policies (#59)
1 parent cc5c51d commit 951e92e

File tree

6 files changed

+11
-19
lines changed

6 files changed

+11
-19
lines changed

.air.toml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,14 @@ args_bin = ["--configFile", "./conf/dev.conf.toml"]
77
bin = "./tmp/main"
88
cmd = "go build -buildvcs=false -o ./tmp/main ./api/."
99
delay = 1000
10-
exclude_dir = [
11-
"assets",
12-
"tmp",
13-
"vendor",
14-
"testdata",
15-
"simulator",
16-
"website",
17-
"img",
18-
"keydb",
19-
]
10+
exclude_dir = ["assets", "tmp", "vendor", "testdata", "website", "img", "keydb"]
2011
exclude_file = []
2112
exclude_regex = ["_test.go"]
2213
exclude_unchanged = false
2314
follow_symlink = false
2415
full_bin = ""
2516
include_dir = []
26-
include_ext = ["go", "tpl", "tmpl", "html"]
17+
include_ext = ["go", "py"]
2718
kill_delay = "0s"
2819
log = "build-errors.log"
2920
send_interrupt = false

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
- THORN_ENCRYPTION_KEY=#.9U#JW#XbB12345
1111
- THORN_ENCRYPTION_SECRET=abc&1*~#^2^#s0^=)^^7%b34
1212
- THORN_SIGNING_KEY=secret
13-
- THORN_DEV_MODE=false
13+
- THORN_DEV_MODE=true
1414
- THORN_LOG_LEVEL=debug
1515
- THORN_LOG_SINK=stdout
1616
- THORN_LOG_FORMAT=text

simulator/ecommerce.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
effect="allow",
5454
actions=["read"],
5555
resources=[
56-
"/collections/customers/*/masked/*",
56+
"/collections/customers/records/*/*.masked",
5757
],
5858
),
5959
expected_statuses=[201, 409],
@@ -66,7 +66,7 @@
6666
effect="allow",
6767
actions=["read"],
6868
resources=[
69-
"/collections/customers/*/plain/*",
69+
"/collections/customers/records/*/*.plain",
7070
],
7171
),
7272
expected_statuses=[201, 409],

simulator/pci.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
effect="allow",
4444
actions=["read"],
4545
resources=[
46-
"/collections/credit_cards/*/masked/*",
46+
"/collections/credit_cards/records/*/*.masked",
4747
],
4848
),
4949
expected_statuses=[201, 409],
@@ -56,7 +56,7 @@
5656
effect="allow",
5757
actions=["read"],
5858
resources=[
59-
"/collections/credit_cards/*/plain/*",
59+
"/collections/credit_cards/records/*/*.plain",
6060
],
6161
),
6262
expected_statuses=[201, 409],

vault/policy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ func matchRune(pattern, str []rune) bool {
1010
case '*':
1111
return matchRune(pattern[1:], str) ||
1212
(len(str) > 0 && matchRune(pattern, str[1:]))
13+
case '.':
14+
return matchRune(pattern[2:], str) ||
15+
(len(str) > 0 && matchRune(pattern, str[1:]))
1316
}
1417
str = str[1:]
1518
pattern = pattern[1:]

vault/vault.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@ type Vault struct {
8282
Signer Signer
8383
}
8484

85-
// TODO: These probably should be renamed to have _PATH
8685
const (
8786
COLLECTIONS_PPATH = "/collections"
8887
PRINCIPALS_PPATH = "/principals"
8988
RECORDS_PPATH = "/records"
9089
POLICIES_PPATH = "/policies"
91-
FIELDS_PPATH = "/fields"
9290
)
9391

9492
type VaultDB interface {
@@ -263,7 +261,7 @@ func (vault Vault) GetRecords(
263261
// TODO: This is horribly inefficient, we should be able to do this in one go using ValidateActions(...)
264262
for _, recordID := range recordIDs {
265263
for field, format := range returnFormats {
266-
_request := Request{principal, PolicyActionRead, fmt.Sprintf("%s/%s%s/%s/%s%s/%s", COLLECTIONS_PPATH, collectionName, RECORDS_PPATH, recordID, format, FIELDS_PPATH, field)}
264+
_request := Request{principal, PolicyActionRead, fmt.Sprintf("%s/%s%s/%s/%s.%s", COLLECTIONS_PPATH, collectionName, RECORDS_PPATH, recordID, field, format)}
267265
allowed, err := vault.ValidateAction(ctx, _request)
268266
if err != nil {
269267
return nil, err

0 commit comments

Comments
 (0)