Skip to content

[BUG] ALLOWED_HOSTS hardcodes 'mailman-web' breaking container use with host networking #549

Closed

Description

@cboylan

Tag/version of Container Images
0.4.* but I believe 0.3.* is also affected

Currently ALLOWED_HOSTS hardcodes mailman-web which means you cannot use host networking or name your containers with different names. In particular it is the gethostbyname() call that fails because mailman-web does not resolve when using host networking or when you name the container differently.

In our proof of concept deployment I was able to modify names and urls using existing environment variables for everything else that needs to know where the web container is located. This usage was the only one that required me to replace the settings.py file. In particular we cannot use settings_local.py here because the settings.py definition of ALLOWED_HOSTS is always evaluated.

I'm not sure what the best way to address this would be to maintain backward compatibility. I think the best option may be to see if mailman-web resolves and if so add both the name and IP address to ALLOWED_HOSTS otherwise leave it out. That way we can catch and handle the gethostbyname() error if the name isn't valid.

I'm happy to submit a PR to address this, but was hoping for a bit of direction on the best approach before I did that.

Activity

  1. gsontag commented on Feb 18, 2023

    @gsontag

    Just ran into this issue. Makes the image unuseable

  2. mm534 commented on Jan 16, 2024

    @mm534
    Contributor

    Also running into this when deploying to AWS Fargate. I've worked around it for now, but would be good if this line doesn't throw. It would simplify my deployment a lot. Would it be possible to make it optional? If it resolves add it in, otherwise handle the exception and not add it in?

  3. petergorla commented on Jan 16, 2024

    @petergorla

    Also running into this when deploying to AWS Fargate. I've worked around it for now, but would be good if this line doesn't throw. It would simplify my deployment a lot. Would it be possible to make it optional? If it resolves add it in, otherwise handle the exception and not add it in?

    Hey friend, would you have any documentation or crib notes that you could share regarding your Fargate deployment, please? This is exactly what I want to do, but not sure where to get started. Thanks!

  4. mm534 commented on Jan 18, 2024

    @mm534
    Contributor

    Perhaps something like - this?
    That would give a chance to override it and keep existing behavior intact? i.e. gethostbyname(os.environ.get('SOME_ENV_VAR', 'mailman-web'))

  5. maxking commented on Jan 22, 2024

    @maxking
    Owner

    That would give a chance to override it and keep existing behavior intact? i.e. gethostbyname(os.environ.get('SOME_ENV_VAR', 'mailman-web'))

    I am fine with adding another env var, MAILMAN_WEB_CONTAINER_NAME to replace mailman-web.

    You can also just update ALLOWED_HOSTS completely in your settings.py.

    Please feel free to send a PR.

  6. maxking commented on Jan 22, 2024

    @maxking
    Owner

    Actually, #681 fixes this, without adding additional env var. DJANGO_ALLOWED_HOSTS env var already allows supplementing ALLOWED_HOSTS so no point adding yet another var doing closely the same thing.

    Closing this as fixed by #681.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions