Skip to content

Set permissions/ownership when creating a socket #94984

Closed

Description

@Dreamsorcerer

Feature or enhancement

When creating a socket with one of the asyncio methods, it should be possible to specify the correct ownership/permissions needed for good security.

Pitch

When creating a server with loop.create_unix_server(), it will create the socket with default permissions which may lack security or may not be accessible to the application that is meant to communicate via this socket.

Previous discussion

python/asyncio#426

Linked PRs

Activity

  1. kumaraditya303 commented on Sep 30, 2022

    @kumaraditya303
    Contributor

    Can't you do this by calling os.chmod after binding the socket?

  2. Dreamsorcerer commented on Sep 30, 2022

    @Dreamsorcerer
    ContributorAuthor

    Yes, see the original (archived) issue linked.

    The behaviour is not desirable, and could potentially lead to security issues. If you can create a file with the correct permissions, why would you not be able to create a named socket with the correct permissions?

    e.g. os.open allows setting the permissions on creation: https://docs.python.org/3/library/os.html#os.open

  3. gvanrossum commented on Sep 30, 2022

    @gvanrossum
    Member

    Possibly because there's no platform-independent way to do it? (I think I gleaned this from the original issue.)

    Anyway, I'd be happy to review a PR, but I'm not the expert here. @Dreamsorcerer are you interested in submitting a PR?

  4. Dreamsorcerer commented on Sep 30, 2022

    @Dreamsorcerer
    ContributorAuthor

    Not currently, got a hundred things to catch up on with aiohttp etc. Mainly just wanted to make sure the request didn't get lost. Maybe I'll get some time to come back to it at some point though.

  5. gvanrossum commented on Oct 1, 2022

    @gvanrossum
    Member

    No worries, hopefully someone else with relevant knowledge will help us out.

  6. kumaraditya303 commented on Jul 27, 2026

    @kumaraditya303
    Contributor

    @Dreamsorcerer Do you still want to pursue this further?

  7. Dreamsorcerer commented on Jul 27, 2026

    @Dreamsorcerer
    ContributorAuthor

    @Dreamsorcerer Do you still want to pursue this further?

    How do you feel about the os.chmod() proposal in the original issue? If we add the call between the bind() and listen(), then any connections before the permissions are set would be refused anyway, so that likely minimises the security implications.

  8. kumaraditya303 commented on Aug 1, 2026

    @kumaraditya303
    Contributor

    Yeah, that sounds good to me.

  9. added a commit that references this issue on Aug 3, 2026
  10. moved this from Todo to Done in asyncioon Aug 3, 2026
  11. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions