Skip to content

Commit

Permalink
Several changes
Browse files Browse the repository at this point in the history
  • Loading branch information
catttam committed Jan 26, 2024
1 parent 440c634 commit 436a60d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
6 changes: 4 additions & 2 deletions pkg/handlers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ func MakeCreateHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand
c.String(http.StatusInternalServerError, fmt.Sprintln("Missing EGI user uid"))
}

mc, mcParsed := mcUntyped.(auth.MultitenancyConfig)
mc, mcParsed := mcUntyped.(*auth.MultitenancyConfig)
uid, uidParsed := uidOrigin.(string)

if !mcParsed {
c.String(http.StatusInternalServerError, fmt.Sprintf("Error parsing multitenancy config: %v", mcParsed))
}

createLogger.Println("Multitenancy config: ", &mc)

if !uidParsed {
c.String(http.StatusInternalServerError, fmt.Sprintf("Error parsing uid origin: %v", uidParsed))
}
Expand All @@ -90,7 +92,7 @@ func MakeCreateHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand
if err != nil {
c.String(http.StatusBadRequest, fmt.Sprintln(err))
}
service.Labels["uid"] = uid
service.Labels["uid"] = auth.FormatUID(uid)
service.AllowedUsers = append(service.AllowedUsers, uid)
createLogger.Println("Creating service for user: ", uid)
break
Expand Down
28 changes: 20 additions & 8 deletions pkg/utils/auth/multitenancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,19 @@ func (mc *MultitenancyConfig) ClearCache() {
}

func (mc *MultitenancyConfig) UserExists(uid string) bool {
for _, id := range mc.usersCache {
if id == uid {
return true
if len(mc.usersCache) < 1 {
// If the cache is empty check if a secret for the uid exists
secret_name := FormatUID(uid)
_, err := mc.kubeClientset.CoreV1().Secrets(ServicesNamespace).Get(context.TODO(), secret_name, metav1.GetOptions{})
if err != nil {
return false
}
return true
} else {
for _, id := range mc.usersCache {
if id == uid {
return true
}
}
}
return false
Expand All @@ -88,13 +98,9 @@ func (mc *MultitenancyConfig) CheckUsersInCache(uids []string) []string {

func (mc *MultitenancyConfig) CreateSecretForOIDC(uid string, sk string) error {

uidr, _ := regexp.Compile("[0-9a-z]+@")
idx := uidr.FindStringIndex(uid)
secret_name := uid[0 : idx[1]-1]

secret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secret_name,
Name: FormatUID(uid),
Namespace: ServicesNamespace,
},
StringData: map[string]string{
Expand Down Expand Up @@ -123,3 +129,9 @@ func GenerateRandomKey(length int) (string, error) {
}
return base64.RawURLEncoding.EncodeToString(key), nil
}

func FormatUID(uid string) string {
uidr, _ := regexp.Compile("[0-9a-z]+@")
idx := uidr.FindStringIndex(uid)
return uid[0 : idx[1]-1]
}
2 changes: 1 addition & 1 deletion pkg/utils/auth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func getOIDCMiddleware(kubeClientset *kubernetes.Clientset, minIOAdminClient *ut
}
oidcLogger.Printf("User %s already exists", uid)
c.Set("uidOrigin", uid)
c.Set("multitenancyConfig", mc)
c.Set("multitenancyConfig", &mc)
c.Next()
}
}
Expand Down

0 comments on commit 436a60d

Please sign in to comment.