Skip to content

Added EC2 Metadata Service Access Flag #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions cmd/gvproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@ import (
)

var (
debug bool
mtu int
endpoints arrayFlags
vpnkitSocket string
qemuSocket string
bessSocket string
stdioSocket string
vfkitSocket string
forwardSocket arrayFlags
forwardDest arrayFlags
forwardUser arrayFlags
forwardIdentify arrayFlags
sshPort int
pidFile string
pcapFile string
exitCode int
logFile string
servicesEndpoint string
debug bool
mtu int
endpoints arrayFlags
vpnkitSocket string
qemuSocket string
bessSocket string
stdioSocket string
vfkitSocket string
forwardSocket arrayFlags
forwardDest arrayFlags
forwardUser arrayFlags
forwardIdentify arrayFlags
sshPort int
pidFile string
pcapFile string
exitCode int
logFile string
servicesEndpoint string
ec2MetadataAccess bool
)

const (
Expand Down Expand Up @@ -78,6 +79,7 @@ func main() {
flag.StringVar(&pidFile, "pid-file", "", "Generate a file with the PID in it")
flag.StringVar(&logFile, "log-file", "", "Output log messages (logrus) to a given file path")
flag.StringVar(&servicesEndpoint, "services", "", "Exposes the same HTTP API as the --listen flag, without the /connect endpoint")
flag.BoolVar(&ec2MetadataAccess, "ec2-metadata-access", false, "Permits access to EC2 Metadata Service (TCP only)")
flag.Parse()

if version.ShowVersion() {
Expand Down Expand Up @@ -262,7 +264,8 @@ func main() {
VpnKitUUIDMacAddresses: map[string]string{
"c3d68012-0208-11ea-9fd7-f2189899ab08": "5a:94:ef:e4:0c:ee",
},
Protocol: protocol,
Protocol: protocol,
Ec2MetadataAccess: ec2MetadataAccess,
}

groupErrs.Go(func() error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/services/forwarder/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (

const linkLocalSubnet = "169.254.0.0/16"

func TCP(s *stack.Stack, nat map[tcpip.Address]tcpip.Address, natLock *sync.Mutex) *tcp.Forwarder {
func TCP(s *stack.Stack, nat map[tcpip.Address]tcpip.Address, natLock *sync.Mutex, ec2MetadataAccess bool) *tcp.Forwarder {
return tcp.NewForwarder(s, 0, 10, func(r *tcp.ForwarderRequest) {
localAddress := r.ID().LocalAddress

if linkLocal().Contains(localAddress) {
if (!ec2MetadataAccess) && linkLocal().Contains(localAddress) {
r.Complete(true)
return
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type Configuration struct {

// Protocol to be used. Only for /connect mux
Protocol Protocol

// EC2 Metadata Service Access
Ec2MetadataAccess bool
}

type Protocol string
Expand Down
2 changes: 1 addition & 1 deletion pkg/virtualnetwork/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func addServices(configuration *types.Configuration, s *stack.Stack, ipPool *tap
var natLock sync.Mutex
translation := parseNATTable(configuration)

tcpForwarder := forwarder.TCP(s, translation, &natLock)
tcpForwarder := forwarder.TCP(s, translation, &natLock, configuration.Ec2MetadataAccess)
s.SetTransportProtocolHandler(tcp.ProtocolNumber, tcpForwarder.HandlePacket)
udpForwarder := forwarder.UDP(s, translation, &natLock)
s.SetTransportProtocolHandler(udp.ProtocolNumber, udpForwarder.HandlePacket)
Expand Down
Loading