Skip to content

Commit 5d24633

Browse files
committed
add better serviceprincipal detection
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent df2aa70 commit 5d24633

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

main.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,9 @@ func startAzureReport() {
134134
log.Infof("searching for ServicePrincipal information")
135135
authSettings, _ := auth.GetSettingsFromEnvironment()
136136

137-
if authSettings.GetMSI().ClientID != "" {
138-
spnInfo := log.Fields{
139-
"clientId": authSettings.GetMSI().ClientID,
140-
}
141-
log.WithFields(spnInfo).Infof("using ServicePrincipal in ENV vars")
142-
}
143-
137+
// spn detection
144138
if spnToken, err := authSettings.GetMSI().ServicePrincipalToken(); err == nil {
139+
// msi detected
145140
if err := spnToken.EnsureFresh(); err != nil {
146141
log.Panic(err)
147142
}
@@ -170,6 +165,23 @@ func startAzureReport() {
170165
log.WithFields(spnInfo).Info("found MSI ServicePrincipal in auth token")
171166
}
172167
}
168+
} else {
169+
// env settings
170+
spnInfo := log.Fields{}
171+
172+
if val := os.Getenv("AZURE_CLIENT_ID"); val != "" {
173+
spnInfo["clientid"] = val
174+
}
175+
176+
if val := os.Getenv("AZURE_TENANT_ID"); val != "" {
177+
spnInfo["tenantid"] = val
178+
}
179+
180+
if len(spnInfo) > 0 {
181+
log.WithFields(spnInfo).Infof("using ServicePrincipal in ENV vars")
182+
} else {
183+
log.WithFields(spnInfo).Infof("unable to detect ServicePrincipal")
184+
}
173185
}
174186

175187
log.Infof("starting Azure access report")

0 commit comments

Comments
 (0)