Skip to content

Commit

Permalink
moving guard against setting both SSH configs to the RPC calls indivi…
Browse files Browse the repository at this point in the history
…dually
  • Loading branch information
eriktate committed Dec 5, 2024
1 parent b897de1 commit 0d932f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 12 additions & 0 deletions lib/auth/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,10 @@ func (g *GRPCServer) CreateRole(ctx context.Context, req *authpb.CreateRoleReque
return nil, trace.Wrap(err)
}

if req.Role.GetOptions().SSHPortForwarding != nil && req.Role.GetOptions().PortForwarding != nil {
return nil, trace.BadParameter("options define both 'port_forwarding' and 'ssh_port_forwarding', only one can be set")
}

if err = services.ValidateRole(req.Role); err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -2087,6 +2091,10 @@ func (g *GRPCServer) UpdateRole(ctx context.Context, req *authpb.UpdateRoleReque
return nil, trace.Wrap(err)
}

if req.Role.GetOptions().SSHPortForwarding != nil && req.Role.GetOptions().PortForwarding != nil {
return nil, trace.BadParameter("options define both 'port_forwarding' and 'ssh_port_forwarding', only one can be set")
}

if err = services.ValidateRole(req.Role); err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -2114,6 +2122,10 @@ func (g *GRPCServer) UpsertRoleV2(ctx context.Context, req *authpb.UpsertRoleReq
return nil, trace.Wrap(err)
}

if req.Role.GetOptions().SSHPortForwarding != nil && req.Role.GetOptions().PortForwarding != nil {
return nil, trace.BadParameter("options define both 'port_forwarding' and 'ssh_port_forwarding', only one can be set")
}

if err = services.ValidateRole(req.Role); err != nil {
return nil, trace.Wrap(err)
}
Expand Down
4 changes: 0 additions & 4 deletions lib/services/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ func ValidateRole(r types.Role, opts ...validateRoleOption) error {
opt(&options)
}

if r.GetOptions().SSHPortForwarding != nil && r.GetOptions().PortForwarding != nil {
return trace.BadParameter("options define both 'port_forwarding' and 'ssh_port_forwarding', only one can be set")
}

if err := CheckAndSetDefaults(r); err != nil {
return trace.Wrap(err)
}
Expand Down
13 changes: 0 additions & 13 deletions lib/services/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,19 +832,6 @@ func TestValidateRole(t *testing.T) {
},
},
},
{
name: "invalid port forwarding config",
spec: types.RoleSpecV6{
Options: types.RoleOptions{
PortForwarding: types.NewBoolOption(true),
SSHPortForwarding: &types.SSHPortForwarding{},
},
Allow: types.RoleConditions{
Logins: []string{`{{external["http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname"]}}`},
},
},
expectError: trace.BadParameter("options define both 'port_forwarding' and 'ssh_port_forwarding', only one can be set"),
},
{
name: "invalid role condition login syntax",
spec: types.RoleSpecV6{
Expand Down

0 comments on commit 0d932f2

Please sign in to comment.