Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Added an aad_prefix option
Browse files Browse the repository at this point in the history
  • Loading branch information
cpressland committed Mar 25, 2022
1 parent 656d9c1 commit 8b7425c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package main

import (
"context"
"os"
"strings"
"time"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
msgraph "github.com/yaegashi/msgraph.go/beta"
"github.com/yaegashi/msgraph.go/msauth"
"golang.org/x/oauth2"
"os"
"strings"
"time"

rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -19,6 +20,8 @@ import (

const CHECK_INTERVAL = 5 * time.Minute

var aadPrefix = true

func main() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
log.Info().Msg("Started Azure CRB manager")
Expand All @@ -35,6 +38,10 @@ func main() {
if len(groupID) == 0 {
log.Fatal().Msgf("Environment variable AZURE_AD_GROUP_ID missing")
}
prefix := os.Getenv("AAD_PREFIX")
if len(prefix) == 0 {
aadPrefix = false
}

for {
// Get AAD users
Expand Down Expand Up @@ -173,6 +180,16 @@ func DeleteCRBsFromKube(aadUsers, kubeUsers map[string]string) error {
return nil
}

func prefix(email string) string {
var response string
if aadPrefix {
response = "aad:" + email
} else {
response = email
}
return response
}

func AddCRBsToKube(aadUsers, kubeUsers map[string]string) error {
config, err := rest.InClusterConfig()
if err != nil {
Expand Down Expand Up @@ -207,7 +224,7 @@ func AddCRBsToKube(aadUsers, kubeUsers map[string]string) error {
{
APIGroup: "rbac.authorization.k8s.io",
Kind: "User",
Name: "aad:" + email,
Name: prefix(email),
},
},
RoleRef: rbacv1.RoleRef{
Expand Down

0 comments on commit 8b7425c

Please sign in to comment.