-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from luhring/same-vpc
Same VPC
- Loading branch information
Showing
85 changed files
with
1,945 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,73 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
# This script takes an argument for which OS to build for: darwin, linux, or windows. | ||
# If no argument is provided, the script builds for all three. | ||
|
||
# To build for a specific version, set the `REACH_VERSION` variable to something like "2.0.1" before running the script. | ||
|
||
set -e | ||
|
||
export REACH_VERSION=${REACH_VERSION:-"0.0.0"} | ||
export SPECIFIED_OS="" | ||
|
||
if [[ -z "$1" ]] | ||
then | ||
export SPECIFIED_OS="$1" | ||
fi | ||
|
||
set -u | ||
|
||
export CGO_ENABLED=0 | ||
export GOARCH=amd64 | ||
export REACH_DIR_DARWIN=$(printf "reach_%s_darwin_amd64" $REACH_VERSION) | ||
export REACH_DIR_LINUX=$(printf "reach_%s_linux_amd64" $REACH_VERSION) | ||
export REACH_DIR_WINDOWS=$(printf "reach_%s_windows_amd64" $REACH_VERSION) | ||
|
||
mkdir -p ./build | ||
set -x | ||
|
||
function build_for_os { | ||
local GOOS="$1" | ||
local REACH_EXECUTABLE | ||
|
||
GOOS=darwin go build -a -tags netgo -o "./build/$REACH_DIR_DARWIN/reach" | ||
GOOS=linux go build -a -tags netgo -o "./build/$REACH_DIR_LINUX/reach" | ||
GOOS=windows go build -a -tags netgo -o "./build/$REACH_DIR_WINDOWS/reach.exe" | ||
if [[ "$GOOS" == "windows" ]] | ||
then | ||
REACH_EXECUTABLE="reach.exe" | ||
else | ||
REACH_EXECUTABLE="reach" | ||
fi | ||
|
||
cp -nv ./LICENSE ./README.md "./build/$REACH_DIR_DARWIN" | ||
cp -nv ./LICENSE ./README.md "./build/$REACH_DIR_LINUX" | ||
cp -nv ./LICENSE ./README.md "./build/$REACH_DIR_WINDOWS" | ||
local REACH_DIR_FOR_OS | ||
REACH_DIR_FOR_OS=$(printf "reach_%s_%s_amd64" "$REACH_VERSION" "$GOOS") | ||
|
||
mkdir -p "./$REACH_DIR_FOR_OS" | ||
|
||
GOOS=$GOOS go build -a -v -tags netgo -o "./$REACH_DIR_FOR_OS/$REACH_EXECUTABLE" .. | ||
cp -nv ../LICENSE ../README.md "./$REACH_DIR_FOR_OS/" | ||
|
||
if [[ "$GOOS" == "windows" ]] | ||
then | ||
zip "$REACH_DIR_FOR_OS.zip" "./$REACH_DIR_FOR_OS"/* | ||
openssl dgst -sha256 "./$REACH_DIR_FOR_OS.zip" >> ./checksums.txt | ||
else | ||
tar -cvzf "$REACH_DIR_FOR_OS.tar.gz" "./$REACH_DIR_FOR_OS"/* | ||
openssl dgst -sha256 "./$REACH_DIR_FOR_OS.tar.gz" >> ./checksums.txt | ||
fi | ||
} | ||
|
||
rm -rf ./build | ||
mkdir -p ./build | ||
|
||
pushd ./build | ||
tar -cvzf $REACH_DIR_DARWIN.tar.gz ./$REACH_DIR_DARWIN/* | ||
tar -cvzf $REACH_DIR_LINUX.tar.gz ./$REACH_DIR_LINUX/* | ||
tar -cvzf $REACH_DIR_WINDOWS.tar.gz ./$REACH_DIR_WINDOWS/* | ||
if [[ ! -z "$SPECIFIED_OS" ]] | ||
then | ||
build_for_os "$SPECIFIED_OS" | ||
else | ||
for CURRENT_OS in "darwin" "linux" "windows" | ||
do | ||
build_for_os "$CURRENT_OS" | ||
done | ||
fi | ||
|
||
openssl dgst -sha256 ./$REACH_DIR_DARWIN.tar.gz >> ./checksums.txt | ||
openssl dgst -sha256 ./$REACH_DIR_LINUX.tar.gz >> ./checksums.txt | ||
openssl dgst -sha256 ./$REACH_DIR_WINDOWS.tar.gz >> ./checksums.txt | ||
set +x | ||
|
||
cat ./checksums.txt | ||
popd | ||
|
||
set +eux | ||
set +eu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/mgutz/ansi" | ||
|
||
"github.com/luhring/reach/reach" | ||
) | ||
|
||
func doAssertReachable(analysis reach.Analysis) { | ||
if analysis.PassesAssertReachable() { | ||
exitSuccessfulAssertion("source is able to reach destination") | ||
} else { | ||
exitFailedAssertion("one or more forward or return paths of network traffic is obstructed") | ||
} | ||
} | ||
|
||
func doAssertNotReachable(analysis reach.Analysis) { | ||
if analysis.PassesAssertNotReachable() { | ||
exitSuccessfulAssertion("source is unable to reach destination") | ||
} else { | ||
exitFailedAssertion("source is able to send network traffic to destination") | ||
} | ||
} | ||
|
||
func exitFailedAssertion(text string) { | ||
failedMessage := ansi.Color("assertion failed:", "red+b") | ||
secondaryMessage := ansi.Color(text, "red") | ||
_, _ = fmt.Fprintf(os.Stderr, "\n%v %v\n", failedMessage, secondaryMessage) | ||
|
||
os.Exit(2) | ||
} | ||
|
||
func exitSuccessfulAssertion(text string) { | ||
succeededMessage := ansi.Color("assertion succeeded:", "green+b") | ||
secondaryMessage := ansi.Color(text, "green") | ||
_, _ = fmt.Fprintf(os.Stderr, "\n%v %v\n", succeededMessage, secondaryMessage) | ||
|
||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/luhring/reach/reach" | ||
) | ||
|
||
func printMergedResultsWarning() { | ||
const mergedResultsWarning = "WARNING: Reach detected more than one network path between the source and destination. Reach calls these paths \"network vectors\". The analysis result shown above is the merging of all network vectors' analysis results. The impact that infrastructure configuration has on actual network reachability might vary based on the way hosts are configured to use their network interfaces, and Reach is unable to access any configuration internal to a host. To see the network reachability across individual network vectors, run the command again with '--" + vectorsFlag + "'.\n" | ||
_, _ = fmt.Fprint(os.Stderr, "\n"+mergedResultsWarning) | ||
} | ||
|
||
func warnIfAnyVectorHasRestrictedReturnTraffic(vectors []reach.NetworkVector) { | ||
for _, v := range vectors { | ||
if !v.ReturnTraffic.All() { | ||
const restrictedVectorReturnTraffic = "WARNING: One or more of the analyzed network vectors has restrictions on network traffic allowed to return from the destination to the source. For details, run the command again with '--" + vectorsFlag + "'.\n" | ||
_, _ = fmt.Fprintf(os.Stderr, "\n"+restrictedVectorReturnTraffic) | ||
|
||
return | ||
} | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
reach/acceptance/data/tf/ec2_instance_source_and_destination.tf
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.