-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: handle docker network host #7278
fix: handle docker network host #7278
Conversation
8f08387
to
9cf44b4
Compare
My bad, seems like black was not applied properly. I'll fix it. |
ab2952b
to
11f0f1b
Compare
11f0f1b
to
50829ea
Compare
Tests should be fixed now |
Hi @GuillaumeDesforges, thanks for opening the PR. We will review if these changes have any side effects and get back to you. |
Thanks for raising this PR @GuillaumeDesforges! I've gave a quick test, however I saw that with
The other concern we have with this change is exposing RIE port to the host network interface. RIE was never designed to expose its ports to the host system, it might have some issues when an attacker gets access to these exposed ports.
We would rather recommend running your services and lambda function in a network that you manage, which is not the host network. |
Hi @mndeveci, thanks for testing the changes.
I am surprised you get a timeout, it works fine on my end. 👀
I do not know waht RIE is, and the risks from having it bound to a port accessible on host. |
RIE is the Lambda Runtime Interface Emulator SAM CLI uses under the hood to invoke the lambda function locally. It is supposed to work between SAM CLI and the execution itself. However, when we set the network mode to "host" it is exposing RIE to the host system, which raises the above concerns. For your use case, are there any blockers that prevents you set up a custom network between your container and use it with |
I have documented my use case in the issue mentioned: #4236 (comment) |
You have said previously
A way to improve this would be to prevent accessing RIE from outside the host machine. IIRC binding RIE on 127.0.0.1:8080 (loopback) and not 0.0.0.0:8080 should suffice on Linux. |
Yeap I saw your use case, but are there any blockers for your to use another (custom) network, rather than the host one in your compose file? Something like this;
|
Indeed, I can remove binding the postgres service to the host network, and specify to SAM CLI's Example: services:
database:
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
volumes:
- ./tmp/compose/database/data:/var/lib/postgresql/data Then Then sam build && sam local invoke MyHandler -e src/test/resources/events/event.json --docker-network my-project_default So for my use case, I am fine. However, that means one would have to always have the database running/bound to a docker network, which may not always be easy nor desirable. In case anyone in the future needs these changes, you can use Nix to get it with the following overlay (tested on final: prev: {
aws-sam-cli = prev.aws-sam-cli.overrideAttrs (oldAttrs: {
patches = (oldAttrs.patches or [ ]) ++ [
# Apply fix for https://github.com/aws/aws-sam-cli/issues/4236
./aws-sam-cli.7278.patch
];
});
} and patch aws-sam-cli.7278.patch
|
After a discussion and careful consideration within our Team, we believe the right approach is to create a network instead of using the "host" network mode. Enabling "host" network mode will likely bring out other issues as @mndeveci suggested above. With that, we have decided not to merge this PR. Thank you for your contribution. We appreciate the effort and time you spent in this PR. Your input is valuable to us, and we encourage you to continue contributing. If you have any questions or need further clarification, please feel free to reach out. Thank you again for your understanding and for being a part of our community! |
Which issue(s) does this change fix?
Fixes #4236.
Why is this change necessary?
PR #669 allowed usage of the host network for Docker containers, but that feature was removed in PR #5279.
How does it address the issue?
This change reintroduces setting
network_mode
tohost
whendocker_network
ishost
, and adds some additional debug logging to ease debugging.What side effects does this change have?
None AFAIK.
Mandatory Checklist
PRs will only be reviewed after checklist is complete
make pr
passesmake update-reproducible-reqs
if dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.