@@ -286,7 +286,7 @@ func GetNamespace(clientset *kubernetes.Clientset, username, requestedNS string)
286286 iAccess , uAccess , err := UserIsPermittedInNamespace (username , requestedNS )
287287 if err != nil {
288288 return requestedNS , fmt .Errorf ("Error when determining whether user [%s] is allowed access to " +
289- "namespace [%s]: %w " , username , requestedNS , err )
289+ "namespace [%s]: %s " , username , requestedNS , err . Error () )
290290 }
291291 if iAccess == false {
292292 errMsg := fmt .Sprintf ("namespace [%s] is not part of the Operator installation" , requestedNS )
@@ -367,38 +367,45 @@ func ValidateNodeLabel(nodeLabel string) error {
367367// UserIsPermittedInNamespace returns installation access and user access.
368368// Installation access means a namespace belongs to this Operator installation.
369369// User access means this user has access to a namespace.
370- func UserIsPermittedInNamespace (username , requestedNS string ) (iAccess , uAccess bool , err error ) {
370+ func UserIsPermittedInNamespace (username , requestedNS string ) (bool , bool , error ) {
371371
372- if err = ns .ValidateNamespacesWatched (Clientset , NamespaceOperatingMode (), InstallationName ,
373- requestedNS ); err != nil && ! errors .Is (err , ns .ErrNamespaceNotWatched ) {
374- return
375- }
376- iAccess = true
372+ var iAccess , uAccess bool
377373
378- //get the pgouser Secret for this username
379- userSecretName := "pgouser-" + username
380- userSecret , err := kubeapi .GetSecret (Clientset , userSecretName , PgoNamespace )
381- if err != nil {
382- log .Errorf ("could not get pgouser secret %s: %s" , username , err .Error ())
383- return
374+ if err := ns .ValidateNamespacesWatched (Clientset , NamespaceOperatingMode (), InstallationName ,
375+ requestedNS ); err != nil {
376+ if ! errors .Is (err , ns .ErrNamespaceNotWatched ) {
377+ return false , false , err
378+ }
379+ } else {
380+ iAccess = true
384381 }
385382
386- // handle the case of a user in pgouser with "" (all) namespaces, otherwise check the
387- // namespaces config in the user secret
388- nsstring := string (userSecret .Data ["namespaces" ])
389- if nsstring == "" {
390- uAccess = true
391- } else {
392- nsList := strings .Split (nsstring , "," )
393- for _ , v := range nsList {
394- ns := strings .TrimSpace (v )
395- if ns == requestedNS {
396- uAccess = true
383+ if iAccess {
384+ //get the pgouser Secret for this username
385+ userSecretName := "pgouser-" + username
386+ userSecret , err := kubeapi .GetSecret (Clientset , userSecretName , PgoNamespace )
387+ if err != nil {
388+ log .Errorf ("could not get pgouser secret %s: %s" , username , err .Error ())
389+ return false , false , err
390+ }
391+
392+ // handle the case of a user in pgouser with "" (all) namespaces, otherwise check the
393+ // namespaces config in the user secret
394+ nsstring := string (userSecret .Data ["namespaces" ])
395+ if nsstring == "" {
396+ uAccess = true
397+ } else {
398+ nsList := strings .Split (nsstring , "," )
399+ for _ , v := range nsList {
400+ ns := strings .TrimSpace (v )
401+ if ns == requestedNS {
402+ uAccess = true
403+ }
397404 }
398405 }
399406 }
400407
401- return
408+ return iAccess , uAccess , nil
402409}
403410
404411// WriteTLSCert is a legacy method that writes the server certificate and key to
0 commit comments