Skip to content
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

Intuitive Policies #59

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,14 @@ args_bin = ["--configFile", "./conf/dev.conf.toml"]
bin = "./tmp/main"
cmd = "go build -buildvcs=false -o ./tmp/main ./api/."
delay = 1000
exclude_dir = [
"assets",
"tmp",
"vendor",
"testdata",
"simulator",
"website",
"img",
"keydb",
]
exclude_dir = ["assets", "tmp", "vendor", "testdata", "website", "img", "keydb"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_ext = ["go", "py"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- THORN_ENCRYPTION_KEY=#.9U#JW#XbB12345
- THORN_ENCRYPTION_SECRET=abc&1*~#^2^#s0^=)^^7%b34
- THORN_SIGNING_KEY=secret
- THORN_DEV_MODE=false
- THORN_DEV_MODE=true
- THORN_LOG_LEVEL=debug
- THORN_LOG_SINK=stdout
- THORN_LOG_FORMAT=text
Expand Down
4 changes: 2 additions & 2 deletions simulator/ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
effect="allow",
actions=["read"],
resources=[
"/collections/customers/*/masked/*",
"/collections/customers/records/*/*.masked",
],
),
expected_statuses=[201, 409],
Expand All @@ -66,7 +66,7 @@
effect="allow",
actions=["read"],
resources=[
"/collections/customers/*/plain/*",
"/collections/customers/records/*/*.plain",
],
),
expected_statuses=[201, 409],
Expand Down
4 changes: 2 additions & 2 deletions simulator/pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
effect="allow",
actions=["read"],
resources=[
"/collections/credit_cards/*/masked/*",
"/collections/credit_cards/records/*/*.masked",
],
),
expected_statuses=[201, 409],
Expand All @@ -56,7 +56,7 @@
effect="allow",
actions=["read"],
resources=[
"/collections/credit_cards/*/plain/*",
"/collections/credit_cards/records/*/*.plain",
],
),
expected_statuses=[201, 409],
Expand Down
3 changes: 3 additions & 0 deletions vault/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ func matchRune(pattern, str []rune) bool {
case '*':
return matchRune(pattern[1:], str) ||
(len(str) > 0 && matchRune(pattern, str[1:]))
case '.':
return matchRune(pattern[2:], str) ||
(len(str) > 0 && matchRune(pattern, str[1:]))
}
str = str[1:]
pattern = pattern[1:]
Expand Down
4 changes: 1 addition & 3 deletions vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ type Vault struct {
Signer Signer
}

// TODO: These probably should be renamed to have _PATH
const (
COLLECTIONS_PPATH = "/collections"
PRINCIPALS_PPATH = "/principals"
RECORDS_PPATH = "/records"
POLICIES_PPATH = "/policies"
FIELDS_PPATH = "/fields"
)

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