简体   繁体   中英

Invoke server with PowerShell to run python script: can't open file [Errno 13] Permission denied

I understand this is a permission's issue but I can't tell where.

Basically I have a PowerShell script that gets some info from a user locally, then sends it to an API via python. The API I am posting to for some reason can't take JSON from PowerShell properly (thinks it's malformed no matter what you do) so I am using python to do the last bit.

The call has to come from our server ip so I have to pass the info to the server & python file and invoke the server to call the API. I do so with:

Invoke-Command -ComputerName $servername -ScriptBlock {python.exe "PATH TO .PY" -id $using:CaseID -tag $using:serviceTag -m $using:message}

I get:

C:\PATH-TO\python.exe: can't open file 'PATH TO .PY': [Errno 13] Permission denied

The python file is on a network share. I've tried giving the "everyone" group read/write to the folder to see the outcome but it is still the same.

My only thought comes down to what user is the scriptblock running under when the server executes, and if I need to provide credentials.

As comments stated, it was infamous PowerShell double hop issue.

Server A (me) invoking Server B to run the script on "Server C" (The network share).

The reason I say "Server C" is because the network share was attached to Server B itself. I used the direct path instead of the network share path in the script block and everything worked. Basically Server A to B at that point.

Before, I was going to go the route of passing credentials (not a fan of Credssp), but even this did not work when I passed them.

Best doc for this was here: https://docs.microsoft.com/en-us/archive/blogs/ashleymcglone/powershell-remoting-kerberos-double-hop-solved-securely

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM