Skip to content
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
26 changes: 26 additions & 0 deletions policy/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,25 @@ var DefaultPolicies = []struct {
},
},

// FilesAdmin - provides admin access to the AIStor Files export API. Like
// memoryAdmin it carries its own action family only, so an operator who
// also manages the exported buckets combines it with an S3 policy.
{
Name: "filesAdmin",
Definition: Policy{
Version: DefaultVersion,
Statements: []Statement{
{
SID: ID(""),
Effect: Allow,
Actions: NewActionSet(Action(AllFilesActions)),
Resources: NewResourceSet(),
Conditions: condition.NewFunctions(),
},
},
},
},

// IAMAdmin - provides IAM management access (users, groups, policies,
// service accounts) but no infrastructure, diagnostics, or S3 data access.
{
Expand Down Expand Up @@ -559,6 +578,13 @@ var DefaultPolicies = []struct {
Resources: NewResourceSet(NewMemoryResource("*")),
Conditions: condition.NewFunctions(),
},
{
SID: ID(""),
Effect: Allow,
Actions: NewActionSet(Action(AllFilesActions)),
Resources: NewResourceSet(),
Conditions: condition.NewFunctions(),
},
},
},
},
Expand Down
39 changes: 39 additions & 0 deletions policy/constants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ func TestDefaultPolicyMemoryAdmin(t *testing.T) {
}
}

func TestDefaultPolicyFilesAdmin(t *testing.T) {
p, ok := findDefaultPolicy("filesAdmin")
if !ok {
t.Fatal("filesAdmin default policy not found")
}
if err := p.Validate(); err != nil {
t.Fatalf("filesAdmin policy invalid: %v", err)
}

for action := range SupportedFilesActions {
if !p.IsAllowed(Args{AccountName: "operator", Action: Action(action)}) {
t.Errorf("filesAdmin should allow %v", action)
}
}

// It carries its own action family only, like memoryAdmin.
for _, action := range []Action{GetObjectAction, Action(ServerInfoAdminAction)} {
if p.IsAllowed(Args{AccountName: "operator", Action: action, BucketName: "exports"}) {
t.Errorf("filesAdmin should NOT allow %v", action)
}
}
}

func TestDefaultPolicyConsoleAdminAllowsMemory(t *testing.T) {
args := Args{
AccountName: "admin",
Expand All @@ -164,3 +187,19 @@ func TestDefaultPolicyConsoleAdminAllowsMemory(t *testing.T) {
t.Error("readwrite should NOT allow memory:ListCortexes (sanity check)")
}
}

func TestDefaultPolicyConsoleAdminAllowsFiles(t *testing.T) {
p, ok := findDefaultPolicy("consoleAdmin")
if !ok {
t.Fatal("consoleAdmin default policy not found")
}
// Files actions take no Resource, so the statement must still validate.
if err := p.Validate(); err != nil {
t.Fatalf("consoleAdmin policy invalid: %v", err)
}
for _, action := range []FilesAction{FilesGetExportStatusAction, FilesGetExportStatsAction} {
if !p.IsAllowed(Args{AccountName: "admin", Action: Action(action)}) {
t.Errorf("consoleAdmin should allow %v", action)
}
}
}
11 changes: 6 additions & 5 deletions policy/files-action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,17 @@ func TestFilesPolicyIsAllowed(t *testing.T) {
})
}

func TestFilesActionNotGrantedByDefaultPolicies(t *testing.T) {
// No canned policy grants the Files namespace yet, consoleAdmin included:
// it is granted on its own, as the issue that introduced it asks.
func TestFilesActionGrantedOnlyByFilesAndConsoleAdmin(t *testing.T) {
// consoleAdmin drives the whole console, Files exports included, and
// filesAdmin grants the namespace on its own; no other canned policy may.
for _, dp := range DefaultPolicies {
want := dp.Name == "consoleAdmin" || dp.Name == "filesAdmin"
for action := range SupportedFilesActions {
if action == AllFilesActions {
continue
}
if dp.Definition.IsAllowed(filesArgs(action)) {
t.Errorf("default policy %q allows %v", dp.Name, action)
if got := dp.Definition.IsAllowed(filesArgs(action)); got != want {
t.Errorf("default policy %q allows %v = %v, want %v", dp.Name, action, got, want)
}
}
}
Expand Down
Loading