Skip to content

Commit

Permalink
Conditionally call non MSI auth when interacting with keyvault (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred-sun authored Feb 28, 2022
1 parent 094fff8 commit 199c7ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugins/modules/azure_rm_keyvaultkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def get_keyvault_client(self):
return KeyVaultClient(credentials)
except Exception:
self.log("Get KeyVaultClient from service principal")
else:
try:
self.log("Get KeyVaultClient from MSI")
credentials = MSIAuthentication(resource='https://vault.azure.net')
return KeyVaultClient(credentials)
except Exception:
self.log("Get KeyVaultClient from service principal")

# Create KeyVault Client using KeyVault auth class and auth_callback
def auth_callback(server, resource, scope):
Expand Down
7 changes: 7 additions & 0 deletions plugins/modules/azure_rm_keyvaultkey_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ def get_keyvault_client(self):
return KeyVaultClient(credentials)
except Exception:
self.log("Get KeyVaultClient from service principal")
else:
try:
self.log("Get KeyVaultClient from MSI")
credentials = MSIAuthentication(resource='https://vault.azure.net')
return KeyVaultClient(credentials)
except Exception:
self.log("Get KeyVaultClient from service principal")

# Create KeyVault Client using KeyVault auth class and auth_callback
def auth_callback(server, resource, scope):
Expand Down
7 changes: 7 additions & 0 deletions plugins/modules/azure_rm_keyvaultsecret.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ def get_keyvault_client(self):
return KeyVaultClient(credentials)
except Exception:
self.log("Get KeyVaultClient from service principal")
else:
try:
self.log("Get KeyVaultClient from MSI")
credentials = MSIAuthentication(resource='https://vault.azure.net')
return KeyVaultClient(credentials)
except Exception:
self.log("Get KeyVaultClient from service principal")

# Create KeyVault Client using KeyVault auth class and auth_callback
def auth_callback(server, resource, scope):
Expand Down
7 changes: 7 additions & 0 deletions plugins/modules/azure_rm_keyvaultsecret_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ def get_keyvault_client(self):
return KeyVaultClient(credentials)
except Exception:
self.log("Get KeyVaultClient from service principal")
else:
try:
self.log("Get KeyVaultClient from MSI")
credentials = MSIAuthentication(resource='https://vault.azure.net')
return KeyVaultClient(credentials)
except Exception:
self.log("Get KeyVaultClient from service principal")

# Create KeyVault Client using KeyVault auth class and auth_callback
def auth_callback(server, resource, scope):
Expand Down

0 comments on commit 199c7ee

Please sign in to comment.