Skip to content

Commit

Permalink
Don't downgrade SSH port forwarding in roles for v18.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-nero committed Dec 31, 2024
1 parent b228096 commit 263ad72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
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 {
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

0 comments on commit 263ad72

Please sign in to comment.