Skip to content

Commit 51647a0

Browse files
authored
Merge pull request #8 from ncode/juliano/development
update dev env
2 parents 3f81867 + d973a4e commit 51647a0

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

configs/development/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ ENV ARCH=arm64
88

99
# Install necessary packages
1010
RUN dnf update -y && \
11+
dnf install -y oracle-epel-release-el9 && \
1112
dnf install -y \
1213
curl \
1314
unzip \
1415
socat \
1516
nc \
17+
busybox \
1618
tcpdump \
1719
bind-utils \
1820
iproute \

configs/development/README.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Once the development environment is running:
169169
```bash
170170
curl http://127.0.0.1:8080
171171
```
172-
This should return "Hello, World!", confirming that the NAT is working correctly and the job's HTTP server is accessible.
172+
This should return the content of the queries gainst google dns, confirming that the NAT is working correctly and the job's HTTP server is accessible.
173173

174174
4. Check the job logs in the Nomad UI. You should see:
175175
- Successful DNS queries to 8.8.8.8 (Google's primary DNS server)
@@ -181,11 +181,51 @@ This behavior demonstrates that the CNI Outbound Plugin is correctly applying th
181181

182182
## The cni-outbound-job
183183

184-
The `cni-outbound-job.hcl` file defines a Nomad job that:
185-
- Sets up a simple HTTP server on port 8080
184+
The `cni-outbound-job.hcl` file defines a Nomad job named "dig-outbound-job" that:
185+
186+
- Sets up a simple HTTP server using busybox httpd on port 8080
186187
- Performs periodic DNS lookups to 8.8.8.8 and 8.8.4.4
188+
- Writes the output of these DNS lookups to an HTML file served by the HTTP server
189+
190+
Here are the key components of the job:
191+
192+
1. **Network Configuration**:
193+
- Uses the CNI network mode with "my-network" configuration
194+
- Sets up a static port 8080
195+
196+
2. **Task Configuration**:
197+
- Uses the `exec` driver to run a bash script
198+
- The script is defined inline using a template
199+
200+
3. **Script Functionality**:
201+
- Sets up a busybox httpd server on port 8080
202+
- Creates a web root directory and an initial index.html file
203+
- Performs DNS lookups in a loop:
204+
- Queries google.com using 8.8.8.8 (Google's primary DNS)
205+
- Queries google.com using 8.8.4.4 (Google's secondary DNS)
206+
- Writes the output of these queries to the index.html file
207+
- Sleeps for 60 seconds between lookups
208+
209+
This job helps verify the CNI Outbound Plugin's functionality by demonstrating allowed and blocked outbound traffic. You can observe the results by:
210+
211+
1. Accessing the HTTP server at `http://127.0.0.1:8080`
212+
2. Checking the job logs in the Nomad UI
213+
214+
You should see:
215+
- Successful DNS queries to 8.8.8.8
216+
- Failed DNS queries to 8.8.4.4
217+
218+
This behavior confirms that the CNI Outbound Plugin is correctly applying the outbound rules:
219+
- Allowing traffic to 8.8.8.8
220+
- Blocking traffic to 8.8.4.4
221+
222+
To run this job:
223+
224+
```bash
225+
NOMAD_ADDR=http://127.0.0.1:4646 nomad job run cni-outbound-job.hcl
226+
```
187227

188-
This job helps verify the CNI Outbound Plugin's functionality by demonstrating allowed and blocked outbound traffic.
228+
After running the job, you can monitor its progress and results through the Nomad UI or by accessing the HTTP server it sets up.
189229

190230
## Network Troubleshooting
191231

configs/development/cni-outbound-job.hcl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ job "dig-outbound-job" {
2525
2626
# Define the port to listen on
2727
PORT=8080
28+
WEBROOT="/tmp/webroot"
29+
OUTPUTFILE="$WEBROOT/index.html"
2830
29-
# Create the HTTP response
30-
response="HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\nHello, World!"
31+
# Ensure WEBROOT exists
32+
mkdir -p $WEBROOT
3133
32-
# Start the socat HTTP server in a subshell
33-
(
34-
while true; do
35-
echo -e "$response" | socat TCP-LISTEN:$PORT,fork,reuseaddr -
36-
done
37-
) &
34+
# Ensure OUTPUTFILE exists and has initial content
35+
echo "Initializing..." > $OUTPUTFILE
36+
37+
# Start the busybox httpd server
38+
busybox httpd -f -p $PORT -h $WEBROOT &
3839
3940
# Main loop for DNS lookups
4041
while true; do
@@ -44,7 +45,7 @@ job "dig-outbound-job" {
4445
echo "against 8.8.4.4"
4546
dig +short google.com @8.8.4.4
4647
sleep 60 # Wait for 60 seconds before next lookup
47-
done
48+
done > $OUTPUTFILE
4849
EOT
4950
}
5051

0 commit comments

Comments
 (0)