[#1601] util: Correctly parse 'root' name for container resources
All checks were successful
DCO action / DCO (pull_request) Successful in 44s
Vulncheck / Vulncheck (pull_request) Successful in 1m12s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m40s
Build / Build Components (pull_request) Successful in 1m56s
Tests and linters / Run gofumpt (pull_request) Successful in 21s
Tests and linters / Staticcheck (pull_request) Successful in 1m51s
Tests and linters / Lint (pull_request) Successful in 2m36s
Tests and linters / Tests (pull_request) Successful in 3m57s
Tests and linters / Tests with -race (pull_request) Successful in 4m56s
Tests and linters / gopls check (pull_request) Successful in 4m59s

* Convert `root/*` to `//`;
* Add unit-test case for parses to check parsing correctness.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2025-01-15 14:19:56 +03:00
parent eff95bd632
commit 4cb509e0e1
2 changed files with 10 additions and 1 deletions

View file

@ -261,7 +261,7 @@ func parseResource(lexeme string, isObj bool) (string, error) {
} else {
if lexeme == "*" {
return nativeschema.ResourceFormatAllContainers, nil
} else if lexeme == "/*" {
} else if lexeme == "/*" || lexeme == "root/*" {
return nativeschema.ResourceFormatRootContainers, nil
} else if strings.HasPrefix(lexeme, "/") && len(lexeme) > 1 {
lexeme = lexeme[1:]

View file

@ -43,6 +43,15 @@ func TestParseAPERule(t *testing.T) {
Resources: policyengine.Resources{Names: []string{nativeschema.ResourceFormatRootObjects}},
},
},
{
name: "Valid rule for all containers in explicit root namespace",
rule: "allow Container.Put root/*",
expectRule: policyengine.Rule{
Status: policyengine.Allow,
Actions: policyengine.Actions{Names: []string{nativeschema.MethodPutContainer}},
Resources: policyengine.Resources{Names: []string{nativeschema.ResourceFormatRootContainers}},
},
},
{
name: "Valid rule for all objects in root namespace and container",
rule: "allow Object.Put /cid/*",