Skip to content

feat(devcontainer): enhance firewall with hybrid static/dynamic IP management#5609

Open
sakumoto-shota wants to merge 2 commits intoanthropics:mainfrom
sakumoto-shota:feature/hybrid-domain-firewall
Open

feat(devcontainer): enhance firewall with hybrid static/dynamic IP management#5609
sakumoto-shota wants to merge 2 commits intoanthropics:mainfrom
sakumoto-shota:feature/hybrid-domain-firewall

Conversation

@sakumoto-shota
Copy link
Copy Markdown

@sakumoto-shota sakumoto-shota commented Aug 12, 2025

Summary

This PR enhances the DevContainer firewall configuration to better handle modern CDN
and load-balanced services by implementing a hybrid approach for IP management.

Changes

  • Hybrid IP Management:

    • GitHub continues using Meta API for comprehensive CIDR ranges (static IPSet)
    • Other services use dynamic DNS resolution with TTL support (dynamic IPSet)
  • Automatic Updates:

    • IPs expire after 600 seconds (configurable)
    • Automatic refresh script runs every 5 minutes via cron
    • Domain list passed as arguments to refresh script (no duplication)
  • Improved Maintainability:

    • Domain list managed as shell array in single location
    • Clear separation between static and dynamic IP management
    • Reduced verbose logging while keeping essential error messages
  • User-configurable Domain Whitelist (new):

    • Users can add custom allowed domains via WHITELIST_DOMAINS env var (space-separated)
    • Merged with the default DYNAMIC_DOMAINS list at container startup
    • Passed into the container via devcontainer.json using ${localEnv:WHITELIST_DOMAINS:}
    • Example: export WHITELIST_DOMAINS="pypi.org files.pythonhosted.org"

Testing

Tested in Docker container with the following results:

  • GitHub API: ✅ Accessible (47 CIDR ranges loaded)
  • NPM Registry: ✅ Accessible
  • Anthropic API: ✅ Accessible
  • External sites (Google, Example.com): ✅ Properly blocked
  • Dynamic IP refresh: ✅ Working with domain arguments
  • TTL expiry: ✅ IPs auto-expire after 600s
  • WHITELIST_DOMAINS: ✅ Custom domains correctly merged (unset/empty/single/multiple)

Backward Compatibility

  • Fully backward compatible
  • WHITELIST_DOMAINS is optional — if unset or empty, behavior is unchanged
  • Cleans up legacy allowed-domains IPSet if exists
  • Error handling remains the same
  • All existing functionality preserved

IFS=$'\n\t' # Stricter word splitting

# Configuration - Domain list as shell array for easy maintenance
declare -a DYNAMIC_DOMAINS=(
Copy link
Copy Markdown

@MarkS-AL MarkS-AL Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow additional domains, eg "pypi.org" to be passed in externally, eg via WHITELIST_DOMAINS env var?
Concat the user whitelist with this list of domain names?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply — it's been a while since this was raised!

Great suggestion. I've now added support for a WHITELIST_DOMAINS environment variable. Users can pass additional domains (space-separated) which get merged with the default DYNAMIC_DOMAINS list at container startup.

Usage example:

export WHITELIST_DOMAINS="pypi.org files.pythonhosted.org"

The env var is passed into the container via devcontainer.json using ${localEnv:WHITELIST_DOMAINS:}, so it's fully optional and backward compatible — if unset or empty, behavior is unchanged.

…nagement

- Implement dual IPSet approach (static for GitHub, dynamic for others)
- Add automatic DNS refresh with TTL support (600s default)
- Improve maintainability with single domain array configuration
- Pass domains as arguments to refresh script (avoid duplication)
- Reduce verbose logging while keeping error messages
…AINS env var

Allow users to add additional allowed domains externally by setting the
WHITELIST_DOMAINS environment variable (space-separated). These are merged
with the default DYNAMIC_DOMAINS list at container startup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants