Skip to content

FR: Support granular API permissions on a per host basis via allowfrom  #28

Closed

Description

@nathang21

Describe the feature request
Naturally many services require access to the docket socket, and while socket proxy is an excellent solution, to achieve minimal permissions for each each service would require a seperate sidecar for each. Multiple hostname support in #15 is great, but they all have to share the same permissions. While socket-proxy is very lightweight, i'm not a huge fan of running this many sidecar containers in general.

In my case I have 8 services, and would need 8 sidecars, some of these are read-only, while others also write. If interested, here are the 8 I use now:
ofelia, dozzle, watchtower, autoheal, beszel, boinc, dockwatch, portainer.

I realize supporting this would add complexity, but my ideal solution would be to have allow a separate configuration for each rest API Method on a per host (ip/hostname) basis. I suspect adjusting the configuration via environment variables or an configuration file would be required to make this maintainable.

I could imagine something like this:

allowfrom:
  - dozzle:
      allowGET=
  - ofelia:
      allowGET=
      allowPOST=
      allowDELETE=
...

Are you open to supporting this use case?

Activity

  1. wollomatic commented on Aug 14, 2024

    @wollomatic
    Owner

    Hi @nathang21,

    thanks for Your suggestion. Indeed, using one instance of socket-proxy for multiple services is a popular topic.

    A yaml file would allow configuring this without breaking existing installations. Just give me a few days :)

    Also, thanks for the list of the services you'd like to use. I only get to know how others use socket-proxy through feedback. So this is very important to me.

  2. nathang21 commented on Aug 14, 2024

    @nathang21
    Author

    Fantastic, thanks for the quick turnaround. Happy to help test when the time comes if needed.

    If it helps, I'm also considering to add this soon, which has a native docker service discovery integration that requires the socket as well. https://github.com/gethomepage/homepage

  3. wollomatic commented on Aug 14, 2024

    @wollomatic
    Owner

    Thanks for the additional information. BTW, I tested homepage by myself because of a question here: gethomepage/homepage#3266 (reply in thread)

  4. nathang21 commented on Sep 9, 2024

    @nathang21
    Author

    Thanks for sharing the homepage requirements!

    Just wanted to check back in, looking forward to harding my services with this.

  5. self-assigned this
    on Sep 11, 2024
  6. wollomatic commented on Sep 14, 2024

    @wollomatic
    Owner

    Sorry for the delayed answer. I plan to get it done this month.

  7. MarshallTPS commented on Jun 30, 2025

    @MarshallTPS

    Any chance this could still be added
    I would prefer to run just 1 instance of the socket-proxy

  8. wollomatic commented on Jun 30, 2025

    @wollomatic
    Owner

    Well, it seems to be a very long month, but yes

  9. chrishoage commented on Jul 27, 2025

    @chrishoage

    Since this project by its very nature requires access to the raw socket exposed by Docker it could be interesting to instead use a similar approach to Traefik and use labels to control configuration.

    One could imagine a label or set of labels applied to a service that could be read by socket-proxy.

    These labels would inform socket-proxy as to what containers should be allowed which requests. By extension if a container does not have the required labels that container is denied access even if it is on the same internal docker network as socket-proxy.

    Again relying on the information already available to socket-proxy through the docker socket it could restrict access via IP address gained through inspecting the container via the docker API. This could be further restricted through labels if necessary (but I could see this being unneeded complexity)

    This approach could be a clean solution that wouldn't necessarily introduce any new configuration files and would also not require maintaining the configuration file for new services as they appear.

    Of course a configuration file still may be prudent since these labels must be transformed into runtime configuration objects anyway.

  10. amanda-wee commented on Oct 4, 2025

    @amanda-wee
    Contributor

    @wollomatic would you be open to @chrishoage's suggestion of using labels? I was intrigued by the idea and have a proof of concept running, though I'm still working on automatically updating the configuration when containers are started after the socket proxy has started by checking for the relevant Docker events. I expect that you'll want to retain -allowfrom with hostnames, but it effectively does replace that.

  11. amanda-wee commented on Oct 5, 2025

    @amanda-wee
    Contributor

    Here's my proof of concept:
    https://github.com/amanda-wee/socket-proxy/tree/per-container-allowlists

    I added a dependency on the Docker API SDK for Go. If necessary, it should be possible to rework the code to do without that dependency, but before that I would like some feedback about whether the labels idea is acceptable.

  12. edekeijzer commented on Oct 10, 2025

    @edekeijzer

    Here's my proof of concept: https://github.com/amanda-wee/socket-proxy/tree/per-container-allowlists

    I added a dependency on the Docker API SDK for Go. If necessary, it should be possible to rework the code to do without that dependency, but before that I would like some feedback about whether the labels idea is acceptable.

    @amanda-wee I have built your fork and are trying to test it, but I do not get it running with -proxycontainername, it will tell me the container cannot be found. (it should point to its own container name to retrieve its network, right?)

  13. amanda-wee commented on Oct 10, 2025

    @amanda-wee
    Contributor

    @edekeijzer yes, I have been testing with a name explicitly specified in compose.yaml as container_name: beszel-socket-proxy, and just tried with leaving it out and using the service name (socket-proxy, or dockerproxy in the examples) and it seems to work too, as did using the name printed when starting the container (beszel-socket-proxy-1 in my case as I was running it under the beszel project).

    EDIT: oh, okay. I think I understand what's happening once I add in a bit more logging on the config initialisation: it looks like when the socket-proxy container starts, the Docker API might not have its data ready yet, and so it returns no matching container summaries, which in turn stops the container as I treat that as an error, and then my compose restarts it... and this time it does have the data ready, so it returns it correctly. I didn't notice because I had my focus on the network names rather than on the early error message. I've pushed a commit that adds retry logic to that part.

  14. edekeijzer commented on Oct 12, 2025

    @edekeijzer

    @amanda-wee your conclusion seems correct, it didn't start most of the time but sometimes it did. Rebuilt with your latest commit and it starts correctly every time now.
    Anything you would like to have tested? I've put Watchtower behind it and will do Traefik later today.

  15. wollomatic commented on Oct 12, 2025

    @wollomatic
    Owner

    @amanda-wee, thank you very much for your contribution — I really appreciate it!
    Also, thanks @edekeijzer for testing.
    I’m a bit under the weather with the flu right now, so I’ll get back to you in a few days.

  16. amanda-wee commented on Oct 14, 2025

    @amanda-wee
    Contributor

    @edekeijzer thanks for testing. I guess the core is checking that the per-container allowlists come into effect correctly for the given containers, whether the socket proxy starts before or after these containers.

    In my own testing with Beszel, I ran into the problem that Beszel attempted to access the Docker API to check Docker version before its allowlist came into effect, so that query got blocked. Unfortunately, it only ran once, so subsequent Docker API access attempts failed as they depended on the version info. I think this needed to be fixed in Beszel, and the maintainer agreed, but it's possible that this kind of assumption of success could be a drawback of the label processing. In Beszel's case, using the default allowlist to allow version info queries is a reasonable workaround, so it was not a dealbreaker.

    @wollomatic no worries, I'm travelling until the weekend so I'm just waiting for you and interested socket-proxy users to provide feedback. I guess the important decisions from you would be whether you even want to implement the per-container allowlists in this way, and if so, if you want to keep the Docker Go SDK client and types dependency.

  17. amanda-wee commented on Oct 22, 2025

    @amanda-wee
    Contributor

    @wollomatic I have created another branch from my per-container-allowlists branch for investigating integrating the parts of the Docker SDK for Go needed to get the functionality to work. See:
    https://github.com/amanda-wee/socket-proxy/tree/per-container-allowlists-integrate-sdk

    This would eliminate the dependency, and is structured to reduce the difficulty of porting over future improvements and bug fixes to that SDK.

    @edekeijzer did your testing uncover any problems that I should fix?

    Thanks!

  18. edekeijzer commented on Oct 23, 2025

    @edekeijzer

    @amanda-wee it's been running with Traefik, Watchtower and Gitea ACT Runner for two weeks now and I haven't seen any issues.
    What would be nice to have, is adding the generic permissions to the granular permissions, I have to add things like get for info, ping or version and allow.head \/.* to each container.
    Another nice to have would be a log for 'learning', so you'd either set the entire socket-proxy to learning, or add all permissions to a container and then show a deduplicated list of all endpoints that an IP address has used. (this is not specific to your label implementation, it would make implementing the proxy least-privileged much easier)

  19. amanda-wee commented on Oct 23, 2025

    @amanda-wee
    Contributor

    it's been running with Traefik, Watchtower and Gitea ACT Runner for two weeks now and I haven't seen any issues.

    Awesome. I haven't seen issues with Beszel either, also when testing with the integrated Docker client.

    What would be nice to have, is adding the generic permissions to the granular permissions, I have to add things like get for info, ping or version and allow.head /.* to each container.

    This should be a separate feature, methinks. I imagine there could be an allowed request "minimal preset" like what you mentioned that could be built on, and a "readonly preset" that would be more restrictive than -allowGET=.* (basically the idea of 11notes/docker-socket-proxy). Of course, there's also the argument that maybe wollomatic/socket-proxy's wiki just needs more examples.

    Another nice to have would be a log for 'learning', so you'd either set the entire socket-proxy to learning, or add all permissions to a container and then show a deduplicated list of all endpoints that an IP address has used.

    You can already do this by setting the log level to debug as successful requests will get logged at debug level with method, path, and IP address, just that they aren't deduplicated.

  20. amanda-wee commented on Oct 28, 2025

    @amanda-wee
    Contributor

    I've made some optimisations to reduce the number of Docker API calls and data received from the Docker API, and merged the whole Docker SDK integration into my original per-container-allowlists branch to go back to the claim in the README of socket-proxy being "without any external dependencies".

    @wollomatic It will be quite a big pull request in terms of number of files and the changes to config.go, but if you have no objections, I'll create a pull request and see how it goes from there.

  21. amanda-wee commented on Oct 28, 2025

    @amanda-wee
    Contributor

    @wollomatic great, here's the pull request!
    #69

  22. vnghia commented on Dec 16, 2025

    @vnghia

    Hello. This is a great idea. I have a more restrictive setup that I would like to know if we could also support it. For each service, I have one isolated bridge network, for example:

    • service 1 + database 1 + reverse proxy => bridge 1
    • service 2 + reverse proxy (with hostname alias to service 1) => bridge 2
    • socket-proxy + reverse proxy => bridge 3

    And then service 2 can ping service 1 by using the hostname instead of normal container name and port.

    Furthermore, I also expose socket-proxy to the outer world (via VPN and mTLS at reverse proxy level). This means socket-proxy only see the reverse-proxy in the end. Do you have any suggestion about how I could have this granular API permissions without spawning more than one socket-proxy instances ?

    Thank you very much!

  23. amanda-wee commented on Dec 17, 2025

    @amanda-wee
    Contributor

    @vnghia my pending per-container allowlists implementation depends on the socket proxy container being in a Docker network with each container that uses it. How you accomplish that is up to you.

    The second part is presently unsupported since the socket proxy needs to be able to identify containers, and how it does so for per-container allowlists is by using the Docker Engine API on the same host. Therefore, containers on an external host are beyond such identification.

    Functionality could be added to allow a (trusted) reverse proxy to forward Docker Engine API requests while identifying the source container that is possibly on an external host, e.g., perhaps the reverse proxy could send a designated header containing the container name or other unique identifier. But I think that my current work on per-container allowlists is already large and complex enough that we should not add additional features to it at this time. I would wait for the current per-container allowlists functionality to be merged to main and released, and to have received wider feedback.

  24. wollomatic commented on Dec 17, 2025

    @wollomatic
    Owner

    Thanks @amanda-wee for answering. I think I'll release the new version this weekend.

  25. vnghia commented on Dec 17, 2025

    @vnghia

    I see, thank you very much for your work on this feature @amanda-wee! I think the header is the right approach but I concur that we could revisit this feature later.

  26. wollomatic commented on Jan 17, 2026

    @wollomatic
    Owner

    Thank you all for your patience and thank you @amanda-wee for the awesome work. The new version is released now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions