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

401 When Running in Docker #175

Open
DakotaWray2 opened this issue Mar 13, 2024 · 6 comments
Open

401 When Running in Docker #175

DakotaWray2 opened this issue Mar 13, 2024 · 6 comments

Comments

@DakotaWray2
Copy link

DakotaWray2 commented Mar 13, 2024

Hi and thank you very much for a wonderful tool. I've used it for many years.

When running in a docker container I am receiving 401 errors when trying to connect via NTLM. Running the same API requests through the proxy without being dockerized allows successful api returns. below you will find the docker inspect output for the container. I am running over port 4000. Any insight would be much appreciated. Thank you

[
    {
        "Id": "50e726601cb9e94d11c7f1e756446b56ddefce3e122942f95828453da3b76361",
        "Created": "2024-03-13T18:39:22.674162901Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "node",
            "./server"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 137,
            "Error": "",
            "StartedAt": "2024-03-13T18:39:23.021588852Z",
            "FinishedAt": "2024-03-13T18:44:34.592510212Z"
        },
        "Image": "",
        "ResolvConfPath": "/var/lib/docker/containers/50e726601cb9e94d11c7f1e756446b56ddefce3e122942f95828453da3b76361/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/50e726601cb9e94d11c7f1e756446b56ddefce3e122942f95828453da3b76361/hostname",
        "HostsPath": "/var/lib/docker/containers/50e726601cb9e94d11c7f1e756446b56ddefce3e122942f95828453da3b76361/hosts",
        "LogPath": "/var/lib/docker/containers/50e726601cb9e94d11c7f1e756446b56ddefce3e122942f95828453da3b76361/50e726601cb9e94d11c7f1e756446b56ddefce3e122942f95828453da3b76361-json.log",
        "Name": "/sp-rest-proxy",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "4000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "4000"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                15,
                220
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": [],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware",
                "/sys/devices/virtual/powercap"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/0e6f9beeabb71d34c9dad94db8553ba8199470c365e1a117a50df653f7d828a9-init/diff:/var/lib/docker/overlay2/zphiszza0b5g3ylim4gx4j681/diff:/var/lib/docker/overlay2/zcidjsoupq0c0kzzncl24o5hy/diff:/var/lib/docker/overlay2/ygn7w9mv7zw89j0dqou4w8jtx/diff:/var/lib/docker/overlay2/ahay74ofwh0tc5luna276l30r/diff:/var/lib/docker/overlay2/180ed930ab8755f7d82e25b0604fcccdccfe699bef69ab43178500e21c0afab9/diff:/var/lib/docker/overlay2/ee6be75d98d589826d0a8cdfd33b85008a1717527454491617aa6f478ced7670/diff:/var/lib/docker/overlay2/54e6c2fa168459341b581dfa79dfdebb93d515e02b193d528b931840ee23bc6f/diff:/var/lib/docker/overlay2/6b921c0428823f2ac512063462634ed5953686e1441f1ac2c43d9165f6f759dc/diff",
                "MergedDir": "/var/lib/docker/overlay2/0e6f9beeabb71d34c9dad94db8553ba8199470c365e1a117a50df653f7d828a9/merged",
                "UpperDir": "/var/lib/docker/overlay2/0e6f9beeabb71d34c9dad94db8553ba8199470c365e1a117a50df653f7d828a9/diff",
                "WorkDir": "/var/lib/docker/overlay2/0e6f9beeabb71d34c9dad94db8553ba8199470c365e1a117a50df653f7d828a9/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "50e726601cb9",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "4000/tcp": {},
                "8080/tcp": {}
            },
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NODE_VERSION=16.20.2",
                "YARN_VERSION=1.22.19"
            ],
            "Cmd": [
                "node",
                "./server"
            ],
            "Image": "sp-rest-proxy",
            "Volumes": null,
            "WorkingDir": "/usr/src/app",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "09acdc637742f34c75ba4b918cf6e848e6b61b592660ebb1eee39ceac7ecda08",
            "SandboxKey": "/var/run/docker/netns/09acdc637742",
            "Ports": {},
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "MacAddress": "",
                    "NetworkID": "071afe429498e618ede316976d3e05ec431da667cfa3d31cc31c0411e9e0c627",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "DriverOpts": null,
                    "DNSNames": null
                }
            }
        }
    }
]```
@DakotaWray2
Copy link
Author

Also, do you have any tips for utilizing electron in the Docker container? Thanks again

@koltyakov
Copy link
Owner

Hey @DakotaWray2, thank you for using the library.

Make sure that you don't have locally generated config/private.json file. The creds are hashed with machine ID so will end up different on the host and container.

One of the options is disabling encryption encryptPassword: false, passing static masterKey in IAuthConfigSettings, or passing creds to docker container as ENV variables.

Hope this helps.

do you have any tips for utilizing electron in the Docker container?

Sorry, no. I have not exposed any UI with Docker.

@DakotaWray2
Copy link
Author

DakotaWray2 commented Mar 15, 2024

Hi @koltyakov thanks for the response. Unfortunately I've tried all of the above recommendations plus a few more and it still comes back with 401 unauthorized :/
I have a feeling its related to a strict-origin-when-cross-origin policy and I explored utilizing the host networking but unfortunately this doesn't seem possible with Docker Desktop for Windows. If you have any other insight please let me know. Thanks again for a wonderful tool.

@koltyakov
Copy link
Owner

koltyakov commented Mar 15, 2024

Will it work for you if you just do:

docker run -p 9090:8080 --name=sharepoint --hostname=localhost -it koltyakov/sp-rest-proxy node ./server

Enter prompted credentials, which you'd know works.

Then open http://0.0.0.0:9090/.

And check /_api/web?$select=title.

Just check it on my end with an NTLM SharePoint farm across an ocean :).

image

image

@DakotaWray2
Copy link
Author

Tried the above (thank you again) but it still doesn't like the configuration somehow.
My host machine is utilizing a Cisco VPN and I've tried a few solutions to create a bridge network that forces the container to utilize the specific adapter with no success.
I should also note that my network rejects 0.0.0.0 addresses on my host but connects to localhost successfully (when running in my traditional dev setup outside the Docker container).

@DakotaWray2
Copy link
Author

DakotaWray2 commented Mar 18, 2024

I set up a container for node-sp-auth-troubleshoot and ran it with success output.

wraydak@machine MINGW64 ~/Repos/Docker/test2/node-sp-auth-troubleshoot (master)
$ docker run --name=node-proxy -it node-proxy node ./index
? SharePoint URL http://spurl
? Authentication strategy User credentials (NTLM)
? User name xxx
? Domain xxx
? Password xxx
Connecting to site: xxx

=== Success === 
 {
  headers: {
    Connection: 'Close',
    Authorization: 'NTLM __token__'
  },
  options: {
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 80,
      protocol: 'http:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: true,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      [Symbol(kCapture)]: false
    }
  }
}```

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

2 participants