-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate auth permissions in function claims
Compare the auth permissions in the function claim with the function name and namespace the verify if the provided JWT token is authorized to invoke the function. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
- Loading branch information
Showing
44 changed files
with
1,943 additions
and
1,246 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package executor | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_isAuthorized(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want bool | ||
permissions AuthPermissions | ||
namespace string | ||
function string | ||
}{ | ||
{ | ||
name: "deny empty permission list", | ||
want: false, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{}, | ||
}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
{ | ||
name: "allow empty audience list", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"staging:env"}, | ||
}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
{ | ||
name: "allow cluster wildcard", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"*"}, | ||
}, | ||
namespace: "staging", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "allow function wildcard", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"dev:*"}, | ||
}, | ||
namespace: "dev", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "allow namespace wildcard", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"*:env"}, | ||
}, | ||
namespace: "openfaas-fn", | ||
function: "env", | ||
}, | ||
{ | ||
name: "allow function", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:env"}, | ||
}, | ||
namespace: "openfaas-fn", | ||
function: "env", | ||
}, | ||
{ | ||
name: "deny function", | ||
want: false, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:env"}, | ||
}, | ||
namespace: "openfaas-fn", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "deny namespace", | ||
want: false, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:*"}, | ||
}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
{ | ||
name: "deny namespace wildcard", | ||
want: false, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"*:figlet"}, | ||
}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
{ | ||
name: "multiple permissions allow function", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:*", "staging:env"}, | ||
}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
{ | ||
name: "multiple permissions deny function", | ||
want: false, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:figlet", "staging-*:env"}, | ||
}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
{ | ||
name: "allow audience", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:*"}, | ||
Audience: []string{"openfaas-fn:env"}, | ||
}, | ||
namespace: "openfaas-fn", | ||
function: "env", | ||
}, | ||
{ | ||
name: "deny audience", | ||
want: false, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:*"}, | ||
Audience: []string{"openfaas-fn:env"}, | ||
}, | ||
namespace: "openfaas-fn", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "allow audience function wildcard", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:figlet"}, | ||
Audience: []string{"openfaas-fn:*"}, | ||
}, | ||
namespace: "openfaas-fn", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "deny audience function wildcard", | ||
want: false, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:figlet", "dev:env"}, | ||
Audience: []string{"openfaas-fn:*"}, | ||
}, | ||
namespace: "dev", | ||
function: "env", | ||
}, | ||
{ | ||
name: "deny audience namespace wildcard", | ||
want: false, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:*", "dev:*"}, | ||
Audience: []string{"*:env"}, | ||
}, | ||
namespace: "dev", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "allow audience namespace wildcard", | ||
want: true, | ||
permissions: AuthPermissions{ | ||
Permissions: []string{"openfaas-fn:*", "dev:*"}, | ||
Audience: []string{"*:env"}, | ||
}, | ||
namespace: "openfaas-fn", | ||
function: "env", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
want := test.want | ||
got := isAuthorized(test.permissions, test.namespace, test.function) | ||
|
||
if want != got { | ||
t.Errorf("want: %t, got: %t", want, got) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.