Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication using the Service Principal Authentication Method missing in version 3.5.4? #224

Open
KorZijl opened this issue Oct 4, 2024 · 22 comments

Comments

@KorZijl
Copy link

KorZijl commented Oct 4, 2024

Hi,
we are currently using version 3.1.16 with the Service Principal Authentication Method to authenticate to different tenants to retrieve the inventory. In the tenants we've created an Enterprise App with certificate authentication and we've set the appropriate read permissions on the resources. Every weekend we run a scheduled task that calls AzureResourceInventory.ps1 with the parameters TenantID, AppId and Secret for all those tenants.

Now we're trying to move from version 3.1.16 to version 3.5.4 but after testing it seems the Service Principal Authentication Method is not available anymore. Executing Invoke-ARI with those parameters returns a lot of "Run Connect-AzAccount to login" messages and the parameters AppId and Secret aren't mentioned anymore in the updated README (https://github.com/microsoft/ARI/tree/main?tab=readme-ov-file#3-parameters).

Did we miss a breaking change alert on this authentication method? And are you willing and planning to reimplement this method?

@KorZijl KorZijl changed the title Is is impossible to use the Service Principal Authentication Method in 3.5.4? Authentication using the Service Principal Authentication Method missing in version 3.5.4? Oct 4, 2024
@Claudio-Merola
Copy link
Collaborator

Hi @KorZijl

Our idea was to initially remove the SPN support in the module version, that is why we removed from the README.

But some people have requested that functionality back and it should be working in the version 3.5.4

The parameters should be the same actually, -Appid and -Secret (the secret must be passed as plaintext).

If you are using the parameters correctly and still having issues, please send me the output of the script with the -Debug

@KorZijl
Copy link
Author

KorZijl commented Oct 7, 2024

Hi Claudio,
We're using certificate authentication so we pass the PEM-file as the secret value instead of a plaintext secret successfully using version 3.1.16.

I've executed the command below and attached the result as picture (cause the debugging output is messing up the layout):

Invoke-ARI -TenantId 419a6976-xxxx-xxxx-xxxx-xxxxxxxxxxxx -AppId 1af2daf0-xxx-xxxx-xxxx-xxxxxxxxxxxx -Secret D:\ARI\AzureResourceInventory-BASE64-ALL.pem -ReportDir D:\ARI\Exports\TESTWORKZ -ReportName ARI_TESTWORKZ -Debug

ARI

I've also tested with Powershell 7.4.5 but the error output is almost similar.

@Claudio-Merola
Copy link
Collaborator

Hello @KorZijl

In the older versions we were using the az cli, since we moved to 100% Powershell we are using different methods, I don't think this will work the same way, for the current version we are using the following method to do the SPN authentication:

https://learn.microsoft.com/en-us/powershell/module/az.accounts/connect-azaccount?view=azps-12.3.0#example-3-connect-to-azure-using-a-service-principal-account

I believe we will need to build a new parameter for certificate file authentication.

@KorZijl
Copy link
Author

KorZijl commented Oct 7, 2024

Hi Claudio,

There are examples to use certificates but they rely on the Windows certificate store (example 7) or on PFX-files (example 9):
https://learn.microsoft.com/en-us/powershell/module/az.accounts/connect-azaccount?view=azps-12.3.0#example-7-connect-using-certificates
https://learn.microsoft.com/en-us/powershell/module/az.accounts/connect-azaccount?view=azps-12.3.0#example-9-connect-using-certificate-file

I need to rethink my authentication method i guess ;)

BTW: For testing purposes i've added a client secret to the enterprise app and used that as plaintext secret but i'm still getting "Run Connect-AzAccount to login" messages.

Invoke-ARI -TenantId 419a6976-xxxx-xxxx-xxxx-xxxxxxxxxxxx -AppId 1af2daf0-xxx-xxxx-xxxx-xxxxxxxxxxxx -Secret "x-M8Q~xxxxxxx~xxxx~xx~xxxxxxxxxxxxxxxxxx" -ReportDir D:\ARI\Exports\TESTWORKZ -ReportName ARI_TESTWORKZ -Debug

ARI2

@TheOlek
Copy link

TheOlek commented Oct 9, 2024

Hello @Claudio-Merola, im having the same issue as i try to login with Service Principal and i cant connect

@Claudio-Merola
Copy link
Collaborator

Hi @TheOlek

Are you also using a certificate to authenticate?

@TheOlek
Copy link

TheOlek commented Oct 9, 2024

Hi @Claudio-Merola
Im just using
Invoke-ARI -TenantId "" -AppId "" -Secret ""

Image

@Claudio-Merola
Copy link
Collaborator

@TheOlek

Are you passing the secret as plaintext or securestring?

It has to be plaintext

@TheOlek
Copy link

TheOlek commented Oct 11, 2024

@Claudio-Merola im passing as plain text
is reader at subscription level enough?

@Claudio-Merola
Copy link
Collaborator

@TheOlek

Yes it is, can you run the command adding the -Debug and post the output here?

@TheOlek
Copy link

TheOlek commented Oct 11, 2024

@Claudio-Merola

Image
Image

@Claudio-Merola
Copy link
Collaborator

@TheOlek

I think there was a bug there.

Can you try the version 3.5.6 and see if it works?

@TheOlek
Copy link

TheOlek commented Oct 11, 2024

@Claudio-Merola im getting the same behaviour even with the new version

@Claudio-Merola
Copy link
Collaborator

@TheOlek

with the version 3.5.5 or 3.5.6?

I released version 3.5.5 and then found that bug, then I just released version 3.5.6 a few minutes after 3.5.5

@TheOlek
Copy link

TheOlek commented Oct 11, 2024

@Claudio-Merola im using 3.5.6

Image

@KorZijl
Copy link
Author

KorZijl commented Oct 15, 2024

I tested this again with 3.5.6 and encountered the same behavior as TheOlek.

@Claudio-Merola
Copy link
Collaborator

@TheOlek @KorZijl

I updated the module to the version 3.5.7

Can you guys try it using the -Debug parameter?

This version should at least give more details on what is going on during the authentication phase

@TheOlek
Copy link

TheOlek commented Oct 17, 2024

@Claudio-Merola here it is

Image

@KorZijl
Copy link
Author

KorZijl commented Oct 23, 2024

@Claudio-Merola: I've got similar output using version 3.5.7:

Image

Copy link

This Issue is stale and may be automatically close soon.

@TheOlek
Copy link

TheOlek commented Nov 22, 2024

@Claudio-Merola do you have any update on this?

@Claudio-Merola
Copy link
Collaborator

@TheOlek

This should be fixed already.

Can you try to run the following command:

$secret = "YOURSECRET"
$SecurePassword = ConvertTo-SecureString -String $Secret -AsPlainText -Force

If that command runs without issue, then ARI should be running fine, at least without the previous issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants