Add check for namespace label openfaas=true

This commit adds the checks that the namespace supplied by the user has
the `openfaas=true` label. Without this check the user can
deploy/update/read functions in any namespace  using the CLI.

The UI is not effected because it calls the listnamesaces endpoint,
which has the check for the label

Signed-off-by: Alistair Hey <alistair@heyal.co.uk>
This commit is contained in:
Alistair Hey
2021-09-16 08:31:05 +01:00
committed by Alex Ellis
parent 195e81f595
commit 12b5e8ca7f
9 changed files with 123 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package handlers
import (
"context"
"errors"
"fmt"
"log"
"strings"
@ -32,6 +33,17 @@ type Function struct {
// ListFunctions returns a map of all functions with running tasks on namespace
func ListFunctions(client *containerd.Client, namespace string) (map[string]*Function, error) {
// Check if namespace exists, and it has the openfaas label
nsValid, err := validateNamespace(client, namespace)
if err != nil {
return nil, err
}
if !nsValid {
return nil, errors.New("namespace not valid")
}
ctx := namespaces.WithNamespace(context.Background(), namespace)
functions := make(map[string]*Function)