declension / squeeze-alexa

Squeezebox integration for Amazon Alexa
GNU General Public License v3.0
59 stars 20 forks source link

"Operation not permitted" when connecting Lambda to IPv6 addresses #42

Closed luciano-fiandesio closed 6 years ago

luciano-fiandesio commented 6 years ago

When launching the Lambda, I get the following error:

{
  "stackTrace": [
    [
      "/var/task/handler.py",
      22,
      "lambda_handler",
      "return sqa.handle(event, context)"
    ],
    [
      "/var/task/squeezealexa/main.py",
      65,
      "handle",
      "return super(SqueezeAlexa, self).handle(event, context)"
    ],
    [
      "/var/task/squeezealexa/alexa/handlers.py",
      49,
      "handle",
      "return self.on_intent(request, session)"
    ],
    [
      "/var/task/squeezealexa/main.py",
      106,
      "on_intent",
      "pid = self.player_id_from(intent)"
    ],
    [
      "/var/task/squeezealexa/main.py",
      339,
      "player_id_from",
      "srv = self.get_server()"
    ],
    [
      "/var/task/squeezealexa/main.py",
      92,
      "get_server",
      "verify_hostname=VERIFY_SERVER_HOSTNAME)"
    ],
    [
      "/var/task/squeezealexa/ssl_wrap.py",
      61,
      "__init__",
      "self._ssl_sock = context.wrap_socket(socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0),"
    ],
    [
      "/usr/lib64/python2.7/socket.py",
      191,
      "__init__",
      "_sock = _realsocket(family, type, proto)"
    ]
  ],
  "errorType": "error",
  "errorMessage": "[Errno 1] Operation not permitted"
}

Please, note that I had to slightly modify the code to support IPv6 (my internet provider does not support port forwarding on IPv4...).

This is basically the line I have changed:

context.wrap_socket(socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)

Any idea if this error may be related to my change or to the high port number I'm connecting to?

declension commented 6 years ago

Hmm, weird. But I haven't tried IPv6

Any idea if this error may be related to my change or to the high port number I'm connecting to?

How high? Though really it's only if it's low (<1024) I'd expect permissions problems; so maybe it's IPv6 then.

Do the tests pass? Perhaps try writing a new test that first creates the socket with socket.socket(socket.AF_INET6) and then wraps it, and debug to see what the errors are. Unless of course this always works locally and never on AWS... but that would be useful to know too.

luciano-fiandesio commented 6 years ago

Yes, the local_test.sh script works. It looks like AWS Lambda does not really support IPv6, but I would have expected another error, see this thread: https://forums.aws.amazon.com/thread.jspa?messageID=771807&#771807

declension commented 6 years ago

Yes, but I fear this seems to be the case according to this SO post too.

Looks like EC2 in VPCs can do IPv6 though, so worst case you could host the Python code on this (with a minimal wrapper, or maybe Serverless AWS or something), but that's a costly way round I guess

luciano-fiandesio commented 6 years ago

Yeah, I will experiment with Serverless. Thanks for following up, I guess you can close the issue?

declension commented 6 years ago

See also now #50