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

Don’t downgrade SSH port forwarding in roles for clients 17.1.0 and above #50645

Merged
merged 2 commits into from
Jan 8, 2025
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
15 changes: 6 additions & 9 deletions lib/auth/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2019,21 +2019,18 @@ func maybeDowngradeRole(ctx context.Context, role *types.RoleV6) (*types.RoleV6,
return role, nil
}

var minSupportedSSHPortForwardingVersions = map[int64]semver.Version{
17: {Major: 17, Minor: 1, Patch: 0},
}
var minSupportedSSHPortForwardingVersion = semver.Version{Major: 17, Minor: 1, Patch: 0}

func maybeDowngradeRoleSSHPortForwarding(role *types.RoleV6, clientVersion *semver.Version) *types.RoleV6 {
sshPortForwarding := role.GetOptions().SSHPortForwarding
if sshPortForwarding == nil || (sshPortForwarding.Remote == nil && sshPortForwarding.Local == nil) {
return role
}

minSupportedVersion, ok := minSupportedSSHPortForwardingVersions[clientVersion.Major]
if ok {
if supported, err := utils.MinVerWithoutPreRelease(clientVersion.String(), minSupportedVersion.String()); supported || err != nil {
return role
}
if supported, err := utils.MinVerWithoutPreRelease(
clientVersion.String(),
minSupportedSSHPortForwardingVersion.String()); supported || err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current PR description states:

Don’t downgrade SSH port forwarding in roles for v18.0+

However, the minSupportedSSHPortForwardingVersion is actually set to Major: 17, Minor: 1, meaning the change ensures SSH port forwarding is not downgraded starting from version 17.1.0 and upwards, not just for v18.0+.

To make the description clearer and more accurate, could you update it to:

Don’t downgrade SSH port forwarding in roles for clients 17.1.0 and above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks :)

return role
}

role = apiutils.CloneProtoMsg(role)
Expand All @@ -2044,7 +2041,7 @@ func maybeDowngradeRoleSSHPortForwarding(role *types.RoleV6, clientVersion *semv
role.SetOptions(options)
reason := fmt.Sprintf(`Client version %q does not support granular SSH port forwarding. Role %q will be downgraded `+
`to simple port forwarding rules instead. In order to support granular SSH port forwarding, all clients must be `+
`updated to version %q or higher.`, clientVersion, role.GetName(), minSupportedVersion)
`updated to version %q or higher.`, clientVersion, role.GetName(), minSupportedSSHPortForwardingVersion)
if role.Metadata.Labels == nil {
role.Metadata.Labels = make(map[string]string, 1)
}
Expand Down
6 changes: 3 additions & 3 deletions lib/auth/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4741,23 +4741,23 @@ func TestRoleVersions(t *testing.T) {
{
desc: "up to date - enabled",
clientVersions: []string{
"17.1.0", "17.1.0-dev", "",
"17.1.0", "17.1.0-dev", "18.0.0-dev", "19.0.0", "",
},
inputRole: enabledRole,
expectedRole: enabledRole,
},
{
desc: "up to date - disabled",
clientVersions: []string{
"17.1.0", "17.1.0-dev", "",
"17.1.0", "17.1.0-dev", "18.0.0-dev", "19.0.0", "",
},
inputRole: disabledRole,
expectedRole: disabledRole,
},
{
desc: "up to date - undefined",
clientVersions: []string{
"17.1.0", "17.1.0-dev", "",
"17.1.0", "17.1.0-dev", "18.0.0-dev", "19.0.0", "",
},
inputRole: undefinedRole,
expectedRole: undefinedRole,
Expand Down
Loading