|
| 1 | +# Testing Egress Policies Dynamic Module |
| 2 | + |
| 3 | +Quick guide to compile and test your dynamic module with Envoy. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Rust toolchain (`rustc`, `cargo`) |
| 8 | +- Envoy proxy (`brew install envoyproxy/envoy/envoy` on macOS) |
| 9 | +- `dig` command for DNS testing |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +```bash |
| 14 | +# 1. Build the module |
| 15 | +cd rust |
| 16 | +cargo build --release |
| 17 | + |
| 18 | +# 2. Start Envoy (from parent directory) |
| 19 | +cd .. |
| 20 | +./run-envoy.sh |
| 21 | + |
| 22 | +# 3. In another terminal, test it |
| 23 | +./test-egress.sh |
| 24 | +``` |
| 25 | + |
| 26 | +## Manual Steps |
| 27 | + |
| 28 | +### 1. Build Module |
| 29 | + |
| 30 | +```bash |
| 31 | +cd rust |
| 32 | +cargo build --release |
| 33 | +# Output: target/release/librust_module.dylib (macOS) or .so (Linux) |
| 34 | +``` |
| 35 | + |
| 36 | +### 2. Set Environment |
| 37 | + |
| 38 | +```bash |
| 39 | +export ENVOY_DYNAMIC_MODULES_SEARCH_PATH=/Users/govadia/Desktop/dynamic-modules-examples/rust/target/release |
| 40 | +``` |
| 41 | + |
| 42 | +### 3. Start Envoy |
| 43 | + |
| 44 | +```bash |
| 45 | +envoy -c envoy-egress-test.yaml --log-level info |
| 46 | +``` |
| 47 | + |
| 48 | +**Expected logs:** |
| 49 | +``` |
| 50 | +[info] Initialized VirtualIpCache with base IP 10.10.0.0 |
| 51 | +[info] DnsGateway initialized with 2 policies |
| 52 | +``` |
| 53 | + |
| 54 | +### 4. Test DNS Gateway |
| 55 | + |
| 56 | +```bash |
| 57 | +# Query a matching domain |
| 58 | +dig @127.0.0.1 -p 5353 api.aws.com +short |
| 59 | +# Expected: 10.10.0.0 |
| 60 | + |
| 61 | +# Query another domain |
| 62 | +dig @127.0.0.1 -p 5353 cdn.example.com +short |
| 63 | +# Expected: 10.10.0.1 |
| 64 | + |
| 65 | +# Query same domain again (cached) |
| 66 | +dig @127.0.0.1 -p 5353 api.aws.com +short |
| 67 | +# Expected: 10.10.0.0 (same IP) |
| 68 | +``` |
| 69 | + |
| 70 | +### 5. Check Envoy Stats |
| 71 | + |
| 72 | +```bash |
| 73 | +curl http://127.0.0.1:9901/stats | grep -E "(dns|virtual|policy)" |
| 74 | +``` |
| 75 | + |
| 76 | +## Configuration |
| 77 | + |
| 78 | +### DNS Gateway Config |
| 79 | + |
| 80 | +The DNS gateway is configured in `envoy-egress-test.yaml`: |
| 81 | + |
| 82 | +```yaml |
| 83 | +config: |
| 84 | + base_ip: "10.10.0.0" # Start allocating from this IP |
| 85 | + policies: |
| 86 | + - domain: "*.aws.com" # Wildcard pattern |
| 87 | + metadata: |
| 88 | + upstream_cluster: "aws_cluster" |
| 89 | + tunneling_hostname: "tunnel.aws.com" |
| 90 | +``` |
| 91 | +
|
| 92 | +### How It Works |
| 93 | +
|
| 94 | +1. **DNS Query** (port 5353): |
| 95 | + - Client queries `api.aws.com` |
| 96 | + - DNS gateway matches `*.aws.com` policy |
| 97 | + - Allocates virtual IP `10.10.0.0` |
| 98 | + - Returns DNS A record with virtual IP |
| 99 | + |
| 100 | +2. **TCP Connection** (port 17100): |
| 101 | + - Client connects to `10.10.0.0:17100` |
| 102 | + - Hostname lookup filter gets virtual IP |
| 103 | + - Looks up policy from cache |
| 104 | + - Stores metadata in FilterState |
| 105 | + - TCP proxy uses metadata for routing |
| 106 | + |
| 107 | +## Debugging |
| 108 | + |
| 109 | +### Check Module Loading |
| 110 | + |
| 111 | +```bash |
| 112 | +# Envoy should log module initialization |
| 113 | +grep "dynamic_modules" envoy.log |
| 114 | +``` |
| 115 | + |
| 116 | +### Check Allocated IPs |
| 117 | + |
| 118 | +```bash |
| 119 | +# Query admin endpoint |
| 120 | +curl http://127.0.0.1:9901/stats | grep allocated |
| 121 | +``` |
| 122 | + |
| 123 | +### Enable Debug Logging |
| 124 | + |
| 125 | +```bash |
| 126 | +envoy -c envoy-egress-test.yaml --log-level debug |
| 127 | +``` |
| 128 | + |
| 129 | +### Common Issues |
| 130 | + |
| 131 | +**Module not found:** |
| 132 | +``` |
| 133 | +ENVOY_DYNAMIC_MODULES_SEARCH_PATH not set or incorrect |
| 134 | +``` |
| 135 | +**Solution:** Set to the directory containing your `.dylib` or `.so` file |
| 136 | +
|
| 137 | +**No DNS response:** |
| 138 | +``` |
| 139 | +Domain doesn't match any policy pattern |
| 140 | +``` |
| 141 | +**Solution:** Check policy patterns in config |
| 142 | +
|
| 143 | +**Config parse error:** |
| 144 | +``` |
| 145 | +Invalid JSON in config field |
| 146 | +``` |
| 147 | +**Solution:** Validate JSON syntax in the `config:` section |
| 148 | +
|
| 149 | +## Integration Test |
| 150 | +
|
| 151 | +Run the full integration test: |
| 152 | +
|
| 153 | +```bash |
| 154 | +./test-egress.sh |
| 155 | +``` |
| 156 | + |
| 157 | +This tests: |
| 158 | +- ✅ DNS allocation for new domains |
| 159 | +- ✅ Cache hits for repeated queries |
| 160 | +- ✅ Policy matching with wildcards |
| 161 | +- ✅ Non-matching domains (no response) |
| 162 | + |
| 163 | +## Next Steps |
| 164 | + |
| 165 | +- Add more policy patterns |
| 166 | +- Implement TCP routing based on metadata |
| 167 | +- Add monitoring/metrics |
| 168 | +- Deploy to production environment |
0 commit comments