Skip to content
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

Add Ports field to app spec #47706

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions lib/config/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,19 @@ app_service:
name: "TCP app with only end port",
outErr: require.Error,
},
{
inConfigString: `
app_service:
enabled: true
apps:
- name: foo
uri: "tcp://127.0.0.1"
tcp_ports:
- port: 78787
`,
name: "TCP app with port bigger than 65535",
outErr: require.Error,
},
}

for _, tt := range tests {
Expand Down
10 changes: 5 additions & 5 deletions lib/config/fileconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2081,11 +2081,11 @@ type AppAWS struct {
// PortRange can be used to describe a single port in which case the Port field is the port and the
// EndPort field is 0.
type PortRange struct {
// Port describes the start of the range. It must be between 1-65535.
Port uint32 `yaml:"port"`
// EndPort describes the end of the range, inclusive. It must be between 2-65535 and be greater
// than Port when describing a port range. When describing a single port, it must be set to 0.
EndPort uint32 `yaml:"end_port,omitempty"`
// Port describes the start of the range. It must be greater than 0.
Port uint16 `yaml:"port"`
ravicious marked this conversation as resolved.
Show resolved Hide resolved
// EndPort describes the end of the range, inclusive. When describing a port range, it must be
// greater than 2 and be greater than Port. When describing a single port, it must be set to 0.
EndPort uint16 `yaml:"end_port,omitempty"`
}

// Proxy is a `proxy_service` section of the config file:
Expand Down
4 changes: 2 additions & 2 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6772,8 +6772,8 @@ func makeApplicationTCPPorts(servicePorts []servicecfg.PortRange) []*types.PortR
ports := make([]*types.PortRange, 0, len(servicePorts))
for _, portRange := range servicePorts {
ports = append(ports, &types.PortRange{
Port: portRange.Port,
EndPort: portRange.EndPort,
Port: uint32(portRange.Port),
EndPort: uint32(portRange.EndPort),
})
}
return ports
Expand Down
4 changes: 2 additions & 2 deletions lib/service/servicecfg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ type CORS struct {
// EndPort field is 0.
type PortRange struct {
// Port describes the start of the range. It must be between 1-65535.
Port uint32
Port uint16
// EndPort describes the end of the range, inclusive. It must be between 2-65535 and be greater
// than Port when describing a port range. When describing a single port, it must be set to 0.
EndPort uint32
EndPort uint16
}

// CheckAndSetDefaults validates an application.
Expand Down
21 changes: 5 additions & 16 deletions lib/service/servicecfg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,13 @@ func TestCheckAppTCPPorts(t *testing.T) {
check: hasNoErr(),
},
{
name: "valid non-TCP app with ports ignored",
// Ports are validated only for TCP apps to allow for some forwards compatibility.
// If HTTP apps support port ranges in the future, old versions of Teleport shouldn't hard
// fail to make downgrades easier.
name: "valid non-TCP app with invalid ports ignored",
uri: "http://localhost:8000",
tcpPorts: []PortRange{
PortRange{Port: 123456789},
PortRange{Port: 0},
PortRange{Port: 10, EndPort: 2},
},
check: hasNoErr(),
Expand All @@ -251,27 +254,13 @@ func TestCheckAppTCPPorts(t *testing.T) {
},
check: hasErrTypeBadParameter(),
},
{
name: "port bigger than 65535",
tcpPorts: []PortRange{
PortRange{Port: 78787},
},
check: hasErrTypeBadParameter(),
},
{
name: "end port smaller than 2",
tcpPorts: []PortRange{
PortRange{Port: 5, EndPort: 1},
},
check: hasErrTypeBadParameterAndContains("end port must be between"),
},
{
name: "end port bigger than 65535",
tcpPorts: []PortRange{
PortRange{Port: 1, EndPort: 78787},
},
check: hasErrTypeBadParameter(),
},
{
name: "end port smaller than port",
tcpPorts: []PortRange{
Expand Down
Loading