I have a simple page that asks for an account name, a button click will call a script that calls get-aduser, and display the output in a textbox.
This worked in 4.3.2 and causes an “not authorized” error upon Invoke-PSUScript after update to 4.3.3. It works again after a downgrade to 4.3.2.
All I found in the logs is:
[01:18:21 ERR][App][AD] Failed to execute script. NotAuthorized
Details:
Host: Windows Server 2016 on VMware
Powershell: 7.4.2
PSU installed via: install-module universal, install-psuserver
added a self-signed certificate and https on 443.
PSU runs as service / local system
The script getaduser.ps1 is listed in Automation/Scripts.
Environment is set to Windows PowerShell 5.1
It resides in the Repository folder.
It works nicely when called directly from the scripts page in both PSU versions
It loads the credentials needed to access AD from an xml file.
which credentials?
It does not need that in 4.3.2.
PSU runs under system, so it cannot access AD.
I know I could probably launch the script with credentials.
But theoretically it should just run anyway.
The error tells me that PSU is not allowed to start the script at all.
And if there would be issues with the credentials for get-aduser, I would get a nice error message.
This is the default mode when running PSU cmdlets in PSU but it uses a couple things, like Connect-PSUServer state, and some built in variables, to determine if that’s the case. -Integrated forces it.
I’m unaware of changes between .2 and .3 in this regard but we could open an issue to investigate.
We don’t have ours tied to AD, and ours was installed via MSI, but I modified your example App to essentially just launch one of our scripts via the button, and it executed without any error about permissions. There are some other differences with our setup to how you have yours (such as both the App and script are set to use Agent for their environment), so I’m going to make some more samples to test with that better reflect your scenario as close as I can.
Thank you.
I will try that as well, just need to understand first what “agent” means.
I am still new.
AD does not like Agent:
[error] The running command stopped because the preference variable “ErrorActionPreference” or common parameter is set to Stop: Module ‘C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ActiveDirectory\ActiveDirectory.psd1’ supports PowerShell edition ‘Desktop’ and cannot be loaded implicitly using the Windows Compatibility feature because it is disabled in the settings file. Use ‘Import-Module -UseWindowsPowerShell’ to load this module with Windows PowerShell or ‘Import-Module -SkipEditionCheck’ to try to load the module with the current PowerShell.
You will probably have to set your environment to PowerShell 7 or WIndows PowerShell 5.1 for the ActiveDirectory module to work. I haven’t tested, but that seems likely.
Since this is a POC, I have no license yet.
I only have 2 users (identities) created.
One with Administrator role,
one with User role.
4.3.2
The script launch works with Administrator role.
And it does work with just User role.
4.3.3
The script will not launch with just User role.
The Execute role needs to be set as well.
Yes, confirmed.
Adding the Execute role to a user (identity) and logging out and back in solves the issue.
It seems 4.3.3 behaves here different than 4.3.2, where 4.3.2 did not need the Execute role on identities to run a script.
Mmh.
Maybe that is not yet it.
It seems that the identity with the User and Execute role can access the admin pages.
That was not possible without the Execute role.
I still think something broke in 4.3.3
I’ve opened an issue to track this. I haven’t been able to reproduce the NotAuthorized error so I will need some system logs from someone, if possible.
4.3.2
2 identities set up.
One with Administrator role.
Another with User role.
Behavior:
Administrator can get into admin pages and do all.
User can’t get into admin pages, but can have scripts executed by app web pages.
(invoke-psuscript)
Then update to 4.3.3 via Update-PSUServer -LatestVersion.
Behavior:
Administrator can get into admin pages and do all. (no change)
User can’t get into admin pages.
User CANNOT have scripts executed by app web pages anymore.
Change to fix this:
Added Execute role to User.
User can have scripts executed by app web pages again.
New issue:
NOW User can access admin pages as well, what should not be possible.
If you provided the execute role to the user, then they will be able to access the admin console.
I realize now why this is happening and should be able to work around this in v4.3.4. I may ask for you to test a nightly build just to verify my assumption is correct.
We have some new controls in v5 that will make this much simpler to configure because scripts just have a role property you can set.
running the nightly build 4.3.4 and removing the “execute” role from the user, shows the same result as before: “Failed to execute script. Not authorized”
There must be a code change between 4.3.2 and 4.3.3, because this worked in 4.3.2 and still does when I downgrade.