Skip to content

Commit 15598bb

Browse files
Update User Permitted in Namespace Logic
With this change the "user permitted in namespace" logic now properly indicates what namespaces a user is allowed to access and which they can't (i.e. because the install doesn't have access to that namespace, or the user themselves does not have permissions to access that namespace). Therefore, commands like 'pgo show namespace' now return the proper results.
1 parent 2a52720 commit 15598bb

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

apiserver/root.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/crunchydata/postgres-operator/tlsutil"
3737
"github.com/crunchydata/postgres-operator/util"
3838
log "github.com/sirupsen/logrus"
39-
"k8s.io/api/core/v1"
39+
v1 "k8s.io/api/core/v1"
4040
"k8s.io/apimachinery/pkg/api/resource"
4141
"k8s.io/client-go/kubernetes"
4242
"k8s.io/client-go/rest"
@@ -583,33 +583,34 @@ func UserIsPermittedInNamespace(username, requestedNS string) (bool, bool) {
583583

584584
}
585585

586-
//get the pgouser Secret for this username
587-
userSecretName := "pgouser-" + username
588-
userSecret, found, err := kubeapi.GetSecret(Clientset, userSecretName, PgoNamespace)
589-
if !found {
590-
uAccess = false
591-
log.Error(err)
592-
log.Errorf("could not find pgouser Secret for username %s", username)
593-
return iAccess, uAccess
594-
}
586+
if iAccess {
587+
//get the pgouser Secret for this username
588+
userSecretName := "pgouser-" + username
589+
userSecret, found, err := kubeapi.GetSecret(Clientset, userSecretName, PgoNamespace)
590+
if !found {
591+
uAccess = false
592+
log.Error(err)
593+
log.Errorf("could not find pgouser Secret for username %s", username)
594+
return iAccess, uAccess
595+
}
595596

596-
nsstring := string(userSecret.Data["namespaces"])
597-
nsList := strings.Split(nsstring, ",")
598-
for _, v := range nsList {
599-
ns := strings.TrimSpace(v)
600-
if ns == requestedNS {
597+
nsstring := string(userSecret.Data["namespaces"])
598+
nsList := strings.Split(nsstring, ",")
599+
for _, v := range nsList {
600+
ns := strings.TrimSpace(v)
601+
if ns == requestedNS {
602+
uAccess = true
603+
return iAccess, uAccess
604+
}
605+
}
606+
607+
//handle the case of a user in pgouser with "" (all) namespaces
608+
if nsstring == "" {
601609
uAccess = true
602610
return iAccess, uAccess
603611
}
604612
}
605613

606-
//handle the case of a user in pgouser with "" (all) namespaces
607-
if nsstring == "" {
608-
uAccess = true
609-
return iAccess, uAccess
610-
}
611-
612-
uAccess = false
613614
return iAccess, uAccess
614615
}
615616

0 commit comments

Comments
 (0)