From edffc7863d7691062855dc86ac5e7caa8038e31e Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 20 Sep 2020 15:53:49 -0400 Subject: [PATCH] Change connection limit to -1 for unlimited so it works with TF (#383) * Migrate connection limit unlimited value to -1 * Fix authorization check --- api/internal/genapi/parse.go | 3 + api/targets/option.gen.go | 2 +- api/targets/target.gen.go | 2 +- internal/cmd/commands/targets/tcp.go | 6 +- internal/db/migrations/postgres.gen.go | 8 +- .../db/migrations/postgres/41_targets.up.sql | 8 +- internal/gen/controller.swagger.json | 2 +- .../api/resources/targets/target.pb.go | 159 +++++++++--------- .../api/resources/targets/v1/target.proto | 2 +- .../storage/target/store/v1/target.proto | 4 +- .../handlers/targets/target_service.go | 28 ++- .../handlers/targets/target_service_test.go | 24 +-- internal/session/query.go | 4 +- internal/session/repository_session.go | 2 +- internal/session/session.go | 4 +- internal/target/options.go | 4 +- internal/target/store/target.pb.go | 12 +- internal/target/target.go | 2 +- 18 files changed, 152 insertions(+), 124 deletions(-) diff --git a/api/internal/genapi/parse.go b/api/internal/genapi/parse.go index 34ab5e94ee..4bc93d1c3f 100644 --- a/api/internal/genapi/parse.go +++ b/api/internal/genapi/parse.go @@ -87,6 +87,7 @@ var ( stringValueName = (&wrapperspb.StringValue{}).ProtoReflect().Descriptor().FullName() boolValueName = (&wrapperspb.BoolValue{}).ProtoReflect().Descriptor().FullName() uInt32ValueName = (&wrapperspb.UInt32Value{}).ProtoReflect().Descriptor().FullName() + int32ValueName = (&wrapperspb.Int32Value{}).ProtoReflect().Descriptor().FullName() structValueName = (&_struct.Struct{}).ProtoReflect().Descriptor().FullName() timestampName = (×tamppb.Timestamp{}).ProtoReflect().Descriptor().FullName() ) @@ -99,6 +100,8 @@ func messageKind(fd protoreflect.FieldDescriptor) (ptr, pkg, name string) { return "", "", "bool" case uInt32ValueName: return "", "", "uint32" + case int32ValueName: + return "", "", "int32" case structValueName: return "", "", "map[string]interface{}" case timestampName: diff --git a/api/targets/option.gen.go b/api/targets/option.gen.go index 3a55ba9d11..d53dce5e9e 100644 --- a/api/targets/option.gen.go +++ b/api/targets/option.gen.go @@ -111,7 +111,7 @@ func DefaultName() Option { } } -func WithSessionConnectionLimit(inSessionConnectionLimit uint32) Option { +func WithSessionConnectionLimit(inSessionConnectionLimit int32) Option { return func(o *options) { o.postMap["session_connection_limit"] = inSessionConnectionLimit } diff --git a/api/targets/target.gen.go b/api/targets/target.gen.go index e8131d2be4..71ea3e0fea 100644 --- a/api/targets/target.gen.go +++ b/api/targets/target.gen.go @@ -28,7 +28,7 @@ type Target struct { HostSetIds []string `json:"host_set_ids,omitempty"` HostSets []*HostSet `json:"host_sets,omitempty"` SessionMaxSeconds uint32 `json:"session_max_seconds,omitempty"` - SessionConnectionLimit uint32 `json:"session_connection_limit,omitempty"` + SessionConnectionLimit int32 `json:"session_connection_limit,omitempty"` Attributes map[string]interface{} `json:"attributes,omitempty"` responseBody *bytes.Buffer diff --git a/internal/cmd/commands/targets/tcp.go b/internal/cmd/commands/targets/tcp.go index 898aff1175..801de34b7a 100644 --- a/internal/cmd/commands/targets/tcp.go +++ b/internal/cmd/commands/targets/tcp.go @@ -89,7 +89,7 @@ func (c *TcpCommand) Flags() *base.FlagSets { f.StringVar(&base.StringVar{ Name: "session-connection-limit", Target: &c.flagSessionConnectionLimit, - Usage: "The maximum number of connections allowed for a session. 0 means unlimited.", + Usage: "The maximum number of connections allowed for a session. -1 means unlimited.", }) } } @@ -188,12 +188,12 @@ func (c *TcpCommand) Run(args []string) int { case "null": opts = append(opts, targets.DefaultSessionConnectionLimit()) default: - limit, err := strconv.ParseUint(c.flagSessionConnectionLimit, 10, 32) + limit, err := strconv.ParseInt(c.flagSessionConnectionLimit, 10, 32) if err != nil { c.UI.Error(fmt.Sprintf("Error parsing %q: %s", c.flagSessionConnectionLimit, err)) return 1 } - opts = append(opts, targets.WithSessionConnectionLimit(uint32(limit))) + opts = append(opts, targets.WithSessionConnectionLimit(int32(limit))) } targetClient := targets.NewClient(client) diff --git a/internal/db/migrations/postgres.gen.go b/internal/db/migrations/postgres.gen.go index ab8efe2e75..29589eefdf 100644 --- a/internal/db/migrations/postgres.gen.go +++ b/internal/db/migrations/postgres.gen.go @@ -3152,12 +3152,12 @@ create table target_tcp ( name text not null, -- name is not optional for a target subtype description text, default_port int, -- default_port can be null - -- max duration of the session in seconds. default of 0 equals no limit + -- max duration of the session in seconds. session_max_seconds int not null default 0 - check(session_max_seconds >= 0), - -- limit on number of session connections allowed. default of 0 equals no limit + check(session_max_seconds > 0), + -- limit on number of session connections allowed. -1 equals no limit session_connection_limit int not null default 1 - check(session_connection_limit >= 0), + check(session_connection_limit > 0 or session_connection_limit = -1), create_time wt_timestamp, update_time wt_timestamp, version wt_version, diff --git a/internal/db/migrations/postgres/41_targets.up.sql b/internal/db/migrations/postgres/41_targets.up.sql index 7664bcfbf4..695cb5784f 100644 --- a/internal/db/migrations/postgres/41_targets.up.sql +++ b/internal/db/migrations/postgres/41_targets.up.sql @@ -99,12 +99,12 @@ create table target_tcp ( name text not null, -- name is not optional for a target subtype description text, default_port int, -- default_port can be null - -- max duration of the session in seconds. default of 0 equals no limit + -- max duration of the session in seconds. session_max_seconds int not null default 0 - check(session_max_seconds >= 0), - -- limit on number of session connections allowed. default of 0 equals no limit + check(session_max_seconds > 0), + -- limit on number of session connections allowed. -1 equals no limit session_connection_limit int not null default 1 - check(session_connection_limit >= 0), + check(session_connection_limit > 0 or session_connection_limit = -1), create_time wt_timestamp, update_time wt_timestamp, version wt_version, diff --git a/internal/gen/controller.swagger.json b/internal/gen/controller.swagger.json index f9b15bcbd6..19d5ffc890 100644 --- a/internal/gen/controller.swagger.json +++ b/internal/gen/controller.swagger.json @@ -3011,7 +3011,7 @@ }, "session_connection_limit": { "type": "integer", - "format": "int64", + "format": "int32", "title": "Maximum number of connections in a session" }, "attributes": { diff --git a/internal/gen/controller/api/resources/targets/target.pb.go b/internal/gen/controller/api/resources/targets/target.pb.go index 3876482e50..d448d7671e 100644 --- a/internal/gen/controller/api/resources/targets/target.pb.go +++ b/internal/gen/controller/api/resources/targets/target.pb.go @@ -122,7 +122,7 @@ type Target struct { // Maximum total lifetime of a created session, in seconds SessionMaxSeconds *wrappers.UInt32Value `protobuf:"bytes,120,opt,name=session_max_seconds,json=sessionMaxSeconds,proto3" json:"session_max_seconds,omitempty"` // Maximum number of connections in a session - SessionConnectionLimit *wrappers.UInt32Value `protobuf:"bytes,130,opt,name=session_connection_limit,json=sessionConnectionLimit,proto3" json:"session_connection_limit,omitempty"` + SessionConnectionLimit *wrappers.Int32Value `protobuf:"bytes,130,opt,name=session_connection_limit,json=sessionConnectionLimit,proto3" json:"session_connection_limit,omitempty"` // The attributes that are applied for the specific Target type. Attributes *_struct.Struct `protobuf:"bytes,200,opt,name=attributes,proto3" json:"attributes,omitempty"` } @@ -243,7 +243,7 @@ func (x *Target) GetSessionMaxSeconds() *wrappers.UInt32Value { return nil } -func (x *Target) GetSessionConnectionLimit() *wrappers.UInt32Value { +func (x *Target) GetSessionConnectionLimit() *wrappers.Int32Value { if x != nil { return x.SessionConnectionLimit } @@ -605,7 +605,7 @@ var file_controller_api_resources_targets_v1_target_proto_rawDesc = []byte{ 0x02, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x26, 0x0a, 0x0f, 0x68, 0x6f, 0x73, 0x74, 0x5f, 0x63, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x68, 0x6f, 0x73, 0x74, 0x43, 0x61, 0x74, 0x61, - 0x6c, 0x6f, 0x67, 0x49, 0x64, 0x22, 0x96, 0x07, 0x0a, 0x06, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, + 0x6c, 0x6f, 0x67, 0x49, 0x64, 0x22, 0x95, 0x07, 0x0a, 0x06, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x5f, 0x69, 0x64, 0x12, 0x43, 0x0a, 0x05, @@ -649,80 +649,80 @@ var file_controller_api_resources_targets_v1_target_proto_rawDesc = []byte{ 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x78, 0x5f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x12, 0x11, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x61, 0x78, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x52, 0x11, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x61, - 0x78, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x12, 0x93, 0x01, 0x0a, 0x18, 0x73, 0x65, 0x73, + 0x78, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x12, 0x92, 0x01, 0x0a, 0x18, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x82, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, - 0x49, 0x6e, 0x74, 0x33, 0x32, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x3a, 0xa0, 0xda, 0x29, 0x01, - 0xc2, 0xdd, 0x29, 0x32, 0x0a, 0x18, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, - 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x16, - 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x16, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, - 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x3e, - 0x0a, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x18, 0xc8, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x42, 0x04, 0xa0, 0xda, - 0x29, 0x01, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x22, 0x86, - 0x01, 0x0a, 0x13, 0x54, 0x63, 0x70, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x41, 0x74, 0x74, 0x72, - 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x12, 0x6f, 0x0a, 0x0c, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, - 0x74, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, - 0x49, 0x6e, 0x74, 0x33, 0x32, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x2e, 0xa0, 0xda, 0x29, 0x01, - 0xc2, 0xdd, 0x29, 0x26, 0x0a, 0x17, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, - 0x2e, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x0b, 0x44, - 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x0b, 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x22, 0x26, 0x0a, 0x0a, 0x57, 0x6f, 0x72, 0x6b, 0x65, - 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, - 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, - 0x89, 0x03, 0x0a, 0x18, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x41, 0x75, 0x74, 0x68, 0x6f, - 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1d, 0x0a, 0x0a, - 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, - 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, - 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x12, 0x43, 0x0a, 0x05, 0x73, 0x63, 0x6f, - 0x70, 0x65, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, - 0x6f, 0x70, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x3e, - 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x28, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x52, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, - 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x50, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, - 0x70, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, - 0x65, 0x18, 0x78, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, - 0x63, 0x61, 0x74, 0x65, 0x12, 0x21, 0x0a, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, - 0x6b, 0x65, 0x79, 0x18, 0x82, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x70, 0x72, 0x69, 0x76, - 0x61, 0x74, 0x65, 0x5f, 0x6b, 0x65, 0x79, 0x12, 0x52, 0x0a, 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x65, - 0x72, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x96, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2f, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, - 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x73, - 0x2e, 0x76, 0x31, 0x2e, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, - 0x77, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x9d, 0x02, 0x0a, 0x14, - 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, - 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x64, - 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, - 0x64, 0x12, 0x43, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x2d, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, - 0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, - 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, - 0x05, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x3e, 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x28, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x50, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x2f, 0x0a, 0x13, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x6f, 0x6b, 0x65, - 0x6e, 0x18, 0x5a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, - 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x42, 0x55, 0x5a, 0x53, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, - 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, - 0x65, 0x73, 0x2f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x73, 0x3b, 0x74, 0x61, 0x72, 0x67, 0x65, - 0x74, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x82, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x49, + 0x6e, 0x74, 0x33, 0x32, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x3a, 0xa0, 0xda, 0x29, 0x01, 0xc2, + 0xdd, 0x29, 0x32, 0x0a, 0x18, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, + 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x16, 0x53, + 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x16, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f, + 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x3e, 0x0a, + 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x18, 0xc8, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x42, 0x04, 0xa0, 0xda, 0x29, + 0x01, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x22, 0x86, 0x01, + 0x0a, 0x13, 0x54, 0x63, 0x70, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x41, 0x74, 0x74, 0x72, 0x69, + 0x62, 0x75, 0x74, 0x65, 0x73, 0x12, 0x6f, 0x0a, 0x0c, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, + 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x55, 0x49, + 0x6e, 0x74, 0x33, 0x32, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x2e, 0xa0, 0xda, 0x29, 0x01, 0xc2, + 0xdd, 0x29, 0x26, 0x0a, 0x17, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x2e, + 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x0b, 0x44, 0x65, + 0x66, 0x61, 0x75, 0x6c, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x0b, 0x64, 0x65, 0x66, 0x61, 0x75, + 0x6c, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x22, 0x26, 0x0a, 0x0a, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, + 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, + 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x89, + 0x03, 0x0a, 0x18, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, + 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1d, 0x0a, 0x0a, 0x73, + 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x61, + 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x12, 0x43, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x70, + 0x65, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, + 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, + 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, + 0x70, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x3e, 0x0a, + 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x28, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x50, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, + 0x18, 0x78, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, + 0x61, 0x74, 0x65, 0x12, 0x21, 0x0a, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, 0x6b, + 0x65, 0x79, 0x18, 0x82, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x61, + 0x74, 0x65, 0x5f, 0x6b, 0x65, 0x79, 0x12, 0x52, 0x0a, 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x65, 0x72, + 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x96, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2f, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, 0x65, + 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x73, 0x2e, + 0x76, 0x31, 0x2e, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x77, + 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x9d, 0x02, 0x0a, 0x14, 0x53, + 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, + 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, + 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x69, 0x64, + 0x12, 0x43, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x2d, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, + 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, + 0x73, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x3e, 0x0a, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x28, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0c, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x50, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x2f, 0x0a, 0x13, 0x61, 0x75, 0x74, + 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x18, 0x5a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x42, 0x55, 0x5a, 0x53, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, + 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x6c, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x73, 0x2f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x73, 0x3b, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, + 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -749,7 +749,8 @@ var file_controller_api_resources_targets_v1_target_proto_goTypes = []interface{ (*wrappers.StringValue)(nil), // 7: google.protobuf.StringValue (*timestamp.Timestamp)(nil), // 8: google.protobuf.Timestamp (*wrappers.UInt32Value)(nil), // 9: google.protobuf.UInt32Value - (*_struct.Struct)(nil), // 10: google.protobuf.Struct + (*wrappers.Int32Value)(nil), // 10: google.protobuf.Int32Value + (*_struct.Struct)(nil), // 11: google.protobuf.Struct } var file_controller_api_resources_targets_v1_target_proto_depIdxs = []int32{ 6, // 0: controller.api.resources.targets.v1.Target.scope:type_name -> controller.api.resources.scopes.v1.ScopeInfo @@ -759,8 +760,8 @@ var file_controller_api_resources_targets_v1_target_proto_depIdxs = []int32{ 8, // 4: controller.api.resources.targets.v1.Target.updated_time:type_name -> google.protobuf.Timestamp 0, // 5: controller.api.resources.targets.v1.Target.host_sets:type_name -> controller.api.resources.targets.v1.HostSet 9, // 6: controller.api.resources.targets.v1.Target.session_max_seconds:type_name -> google.protobuf.UInt32Value - 9, // 7: controller.api.resources.targets.v1.Target.session_connection_limit:type_name -> google.protobuf.UInt32Value - 10, // 8: controller.api.resources.targets.v1.Target.attributes:type_name -> google.protobuf.Struct + 10, // 7: controller.api.resources.targets.v1.Target.session_connection_limit:type_name -> google.protobuf.Int32Value + 11, // 8: controller.api.resources.targets.v1.Target.attributes:type_name -> google.protobuf.Struct 9, // 9: controller.api.resources.targets.v1.TcpTargetAttributes.default_port:type_name -> google.protobuf.UInt32Value 6, // 10: controller.api.resources.targets.v1.SessionAuthorizationData.scope:type_name -> controller.api.resources.scopes.v1.ScopeInfo 8, // 11: controller.api.resources.targets.v1.SessionAuthorizationData.created_time:type_name -> google.protobuf.Timestamp diff --git a/internal/proto/local/controller/api/resources/targets/v1/target.proto b/internal/proto/local/controller/api/resources/targets/v1/target.proto index b390aa8b9e..96fa639be5 100644 --- a/internal/proto/local/controller/api/resources/targets/v1/target.proto +++ b/internal/proto/local/controller/api/resources/targets/v1/target.proto @@ -60,7 +60,7 @@ message Target { google.protobuf.UInt32Value session_max_seconds = 120 [(custom_options.v1.generate_sdk_option) = true, (custom_options.v1.mask_mapping) = {this:"session_max_seconds" that: "SessionMaxSeconds"}]; // Maximum number of connections in a session - google.protobuf.UInt32Value session_connection_limit = 130 [(custom_options.v1.generate_sdk_option) = true, (custom_options.v1.mask_mapping) = {this:"session_connection_limit" that: "SessionConnectionLimit"}]; + google.protobuf.Int32Value session_connection_limit = 130 [(custom_options.v1.generate_sdk_option) = true, (custom_options.v1.mask_mapping) = {this:"session_connection_limit" that: "SessionConnectionLimit"}]; // The attributes that are applied for the specific Target type. google.protobuf.Struct attributes = 200 [(custom_options.v1.generate_sdk_option) = true]; diff --git a/internal/proto/local/controller/storage/target/store/v1/target.proto b/internal/proto/local/controller/storage/target/store/v1/target.proto index 0abfb2fb4e..56234c01a8 100644 --- a/internal/proto/local/controller/storage/target/store/v1/target.proto +++ b/internal/proto/local/controller/storage/target/store/v1/target.proto @@ -52,7 +52,7 @@ message TargetView { // Maximum number of connections in a session // @inject_tag: `gorm:"default:null"` - uint32 session_connection_limit = 110; + int32 session_connection_limit = 110; } message TargetHostSet { @@ -120,7 +120,7 @@ message TcpTarget { // Maximum number of connections in a session // @inject_tag: `gorm:"default:null"` - uint32 session_connection_limit = 110 [(custom_options.v1.mask_mapping) = { + int32 session_connection_limit = 110 [(custom_options.v1.mask_mapping) = { this: "SessionConnectionLimit" that: "session_connection_limit" }]; diff --git a/internal/servers/controller/handlers/targets/target_service.go b/internal/servers/controller/handlers/targets/target_service.go index 90ddf4da9f..1af4f08673 100644 --- a/internal/servers/controller/handlers/targets/target_service.go +++ b/internal/servers/controller/handlers/targets/target_service.go @@ -652,8 +652,8 @@ func toProto(in target.Target, m []*target.TargetSet) (*pb.Target, error) { UpdatedTime: in.GetUpdateTime().GetTimestamp(), Version: in.GetVersion(), Type: target.TcpTargetType.String(), - SessionMaxSeconds: &wrapperspb.UInt32Value{Value: in.GetSessionMaxSeconds()}, - SessionConnectionLimit: &wrapperspb.UInt32Value{Value: in.GetSessionConnectionLimit()}, + SessionMaxSeconds: wrapperspb.UInt32(in.GetSessionMaxSeconds()), + SessionConnectionLimit: wrapperspb.Int32(in.GetSessionConnectionLimit()), } if in.GetDescription() != "" { out.Description = wrapperspb.String(in.GetDescription()) @@ -698,6 +698,18 @@ func validateCreateRequest(req *pbs.CreateTargetRequest) error { if req.GetItem().GetName() == nil || req.GetItem().GetName().GetValue() == "" { badFields["name"] = "This field is required." } + if req.GetItem().GetSessionConnectionLimit() != nil { + val := req.GetItem().GetSessionConnectionLimit().GetValue() + switch { + case val == -1: + case val > 0: + default: + badFields["session_connection_limit"] = "This must be -1 (unlimited) or greater than zero." + } + } + if req.GetItem().GetSessionMaxSeconds() != nil && req.GetItem().GetSessionMaxSeconds().GetValue() == 0 { + badFields["session_max_seconds"] = "This must be greater than zero." + } switch target.SubtypeFromType(req.GetItem().GetType()) { case target.TcpSubType: tcpAttrs := &pb.TcpTargetAttributes{} @@ -725,6 +737,18 @@ func validateUpdateRequest(req *pbs.UpdateTargetRequest) error { if handlers.MaskContains(req.GetUpdateMask().GetPaths(), "name") && req.GetItem().GetName().GetValue() == "" { badFields["name"] = "This field cannot be set to empty." } + if req.GetItem().GetSessionConnectionLimit() != nil { + val := req.GetItem().GetSessionConnectionLimit().GetValue() + switch { + case val == -1: + case val > 0: + default: + badFields["session_connection_limit"] = "This must be -1 (unlimited) or greater than zero." + } + } + if req.GetItem().GetSessionMaxSeconds() != nil && req.GetItem().GetSessionMaxSeconds().GetValue() == 0 { + badFields["session_max_seconds"] = "This must be greater than zero." + } switch target.SubtypeFromType(req.GetItem().GetType()) { case target.TcpSubType: tcpAttrs := &pb.TcpTargetAttributes{} diff --git a/internal/servers/controller/handlers/targets/target_service_test.go b/internal/servers/controller/handlers/targets/target_service_test.go index a6fea808ad..56301df481 100644 --- a/internal/servers/controller/handlers/targets/target_service_test.go +++ b/internal/servers/controller/handlers/targets/target_service_test.go @@ -77,8 +77,8 @@ func TestGet(t *testing.T) { Type: target.TcpTargetType.String(), HostSetIds: []string{hs[0].GetPublicId(), hs[1].GetPublicId()}, Attributes: new(structpb.Struct), - SessionMaxSeconds: &wrapperspb.UInt32Value{Value: 28800}, - SessionConnectionLimit: &wrapperspb.UInt32Value{Value: 1}, + SessionMaxSeconds: wrapperspb.UInt32(28800), + SessionConnectionLimit: wrapperspb.Int32(1), } for _, ihs := range hs { pTar.HostSets = append(pTar.HostSets, &pb.HostSet{Id: ihs.GetPublicId(), HostCatalogId: ihs.GetCatalogId()}) @@ -157,8 +157,8 @@ func TestList(t *testing.T) { Version: tar.GetVersion(), Type: target.TcpTargetType.String(), Attributes: new(structpb.Struct), - SessionMaxSeconds: &wrapperspb.UInt32Value{Value: 28800}, - SessionConnectionLimit: &wrapperspb.UInt32Value{Value: 1}, + SessionMaxSeconds: wrapperspb.UInt32(28800), + SessionConnectionLimit: wrapperspb.Int32(1), }) } @@ -308,8 +308,8 @@ func TestCreate(t *testing.T) { Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{ "default_port": structpb.NewNumberValue(2), }}, - SessionMaxSeconds: &wrapperspb.UInt32Value{Value: 28800}, - SessionConnectionLimit: &wrapperspb.UInt32Value{Value: 1}, + SessionMaxSeconds: wrapperspb.UInt32(28800), + SessionConnectionLimit: wrapperspb.Int32(1), }, }, errCode: codes.OK, @@ -458,7 +458,7 @@ func TestUpdate(t *testing.T) { Name: wrapperspb.String("name"), Description: wrapperspb.String("desc"), SessionMaxSeconds: wrapperspb.UInt32(3600), - SessionConnectionLimit: wrapperspb.UInt32(5), + SessionConnectionLimit: wrapperspb.Int32(5), }, }, res: &pbs.UpdateTargetResponse{ @@ -476,7 +476,7 @@ func TestUpdate(t *testing.T) { HostSetIds: hsIds, HostSets: hostSets, SessionMaxSeconds: wrapperspb.UInt32(3600), - SessionConnectionLimit: wrapperspb.UInt32(5), + SessionConnectionLimit: wrapperspb.Int32(5), }, }, errCode: codes.OK, @@ -507,7 +507,7 @@ func TestUpdate(t *testing.T) { HostSetIds: hsIds, HostSets: hostSets, SessionMaxSeconds: wrapperspb.UInt32(3600), - SessionConnectionLimit: wrapperspb.UInt32(5), + SessionConnectionLimit: wrapperspb.Int32(5), }, }, errCode: codes.OK, @@ -592,7 +592,7 @@ func TestUpdate(t *testing.T) { HostSetIds: hsIds, HostSets: hostSets, SessionMaxSeconds: wrapperspb.UInt32(3600), - SessionConnectionLimit: wrapperspb.UInt32(5), + SessionConnectionLimit: wrapperspb.Int32(5), }, }, errCode: codes.OK, @@ -623,7 +623,7 @@ func TestUpdate(t *testing.T) { HostSetIds: hsIds, HostSets: hostSets, SessionMaxSeconds: wrapperspb.UInt32(3600), - SessionConnectionLimit: wrapperspb.UInt32(5), + SessionConnectionLimit: wrapperspb.Int32(5), }, }, errCode: codes.OK, @@ -654,7 +654,7 @@ func TestUpdate(t *testing.T) { HostSetIds: hsIds, HostSets: hostSets, SessionMaxSeconds: wrapperspb.UInt32(3600), - SessionConnectionLimit: wrapperspb.UInt32(5), + SessionConnectionLimit: wrapperspb.Int32(5), }, }, errCode: codes.OK, diff --git a/internal/session/query.go b/internal/session/query.go index 898a749fc7..a6313e24d6 100644 --- a/internal/session/query.go +++ b/internal/session/query.go @@ -65,9 +65,9 @@ with active_session as ( where -- check that the session hasn't expired. s.expiration_time > now() and - -- check that there are still connections available. connection_limit of 0 equals unlimited connections + -- check that there are still connections available. connection_limit of -1 equals unlimited connections ( - s.connection_limit = 0 + s.connection_limit = -1 or s.connection_limit > (select count(*) from session_connection sc where sc.session_id = $1) ) and diff --git a/internal/session/repository_session.go b/internal/session/repository_session.go index bf84b317c1..a1d9bb6adc 100644 --- a/internal/session/repository_session.go +++ b/internal/session/repository_session.go @@ -335,7 +335,7 @@ func (r *Repository) AuthorizeConnection(ctx context.Context, sessionId string) type ConnectionAuthzSummary struct { ExpirationTime *timestamp.Timestamp - ConnectionLimit uint32 + ConnectionLimit int32 CurrentConnectionCount uint32 } diff --git a/internal/session/session.go b/internal/session/session.go index 99f5abb63a..5994945781 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -43,7 +43,7 @@ type ComposedOf struct { // Expiration time for the session ExpirationTime *timestamp.Timestamp // Max connections for the session - ConnectionLimit uint32 + ConnectionLimit int32 } // Session contains information about a user's session with a target @@ -87,7 +87,7 @@ type Session struct { // Endpoint Endpoint string `json:"-" gorm:"default:null"` // Maximum number of connections in a session - ConnectionLimit uint32 `json:"connection_limit,omitempty" gorm:"default:null"` + ConnectionLimit int32 `json:"connection_limit,omitempty" gorm:"default:null"` // key_id is the key ID that was used for the encryption operation. It can be // used to identify a specific version of the key needed to decrypt the value, diff --git a/internal/target/options.go b/internal/target/options.go index c7e64df20e..01f9716ca6 100644 --- a/internal/target/options.go +++ b/internal/target/options.go @@ -25,7 +25,7 @@ type options struct { withTargetType *TargetType withHostSets []string withSessionMaxSeconds uint32 - withSessionConnectionLimit uint32 + withSessionConnectionLimit int32 } func getDefaultOptions() options { @@ -107,7 +107,7 @@ func WithSessionMaxSeconds(dur uint32) Option { } } -func WithSessionConnectionLimit(limit uint32) Option { +func WithSessionConnectionLimit(limit int32) Option { return func(o *options) { o.withSessionConnectionLimit = limit } diff --git a/internal/target/store/target.pb.go b/internal/target/store/target.pb.go index 2e96f8f15e..25516ffbc9 100644 --- a/internal/target/store/target.pb.go +++ b/internal/target/store/target.pb.go @@ -67,7 +67,7 @@ type TargetView struct { SessionMaxSeconds uint32 `protobuf:"varint,100,opt,name=session_max_seconds,json=sessionMaxSeconds,proto3" json:"session_max_seconds,omitempty" gorm:"default:null"` // Maximum number of connections in a session // @inject_tag: `gorm:"default:null"` - SessionConnectionLimit uint32 `protobuf:"varint,110,opt,name=session_connection_limit,json=sessionConnectionLimit,proto3" json:"session_connection_limit,omitempty" gorm:"default:null"` + SessionConnectionLimit int32 `protobuf:"varint,110,opt,name=session_connection_limit,json=sessionConnectionLimit,proto3" json:"session_connection_limit,omitempty" gorm:"default:null"` } func (x *TargetView) Reset() { @@ -172,7 +172,7 @@ func (x *TargetView) GetSessionMaxSeconds() uint32 { return 0 } -func (x *TargetView) GetSessionConnectionLimit() uint32 { +func (x *TargetView) GetSessionConnectionLimit() int32 { if x != nil { return x.SessionConnectionLimit } @@ -284,7 +284,7 @@ type TcpTarget struct { SessionMaxSeconds uint32 `protobuf:"varint,100,opt,name=session_max_seconds,json=sessionMaxSeconds,proto3" json:"session_max_seconds,omitempty" gorm:"default:null"` // Maximum number of connections in a session // @inject_tag: `gorm:"default:null"` - SessionConnectionLimit uint32 `protobuf:"varint,110,opt,name=session_connection_limit,json=sessionConnectionLimit,proto3" json:"session_connection_limit,omitempty" gorm:"default:null"` + SessionConnectionLimit int32 `protobuf:"varint,110,opt,name=session_connection_limit,json=sessionConnectionLimit,proto3" json:"session_connection_limit,omitempty" gorm:"default:null"` } func (x *TcpTarget) Reset() { @@ -382,7 +382,7 @@ func (x *TcpTarget) GetSessionMaxSeconds() uint32 { return 0 } -func (x *TcpTarget) GetSessionConnectionLimit() uint32 { +func (x *TcpTarget) GetSessionConnectionLimit() int32 { if x != nil { return x.SessionConnectionLimit } @@ -430,7 +430,7 @@ var file_controller_storage_target_store_v1_target_proto_rawDesc = []byte{ 0x73, 0x18, 0x64, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x11, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x61, 0x78, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x12, 0x38, 0x0a, 0x18, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x6e, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x16, 0x73, 0x65, + 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x6e, 0x20, 0x01, 0x28, 0x05, 0x52, 0x16, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x99, 0x01, 0x0a, 0x0d, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x48, 0x6f, 0x73, 0x74, 0x53, 0x65, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, @@ -477,7 +477,7 @@ var file_controller_storage_target_store_v1_target_proto_rawDesc = []byte{ 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x61, 0x78, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x12, 0x70, 0x0a, 0x18, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x6e, 0x20, 0x01, 0x28, - 0x0d, 0x42, 0x36, 0xc2, 0xdd, 0x29, 0x32, 0x0a, 0x16, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x05, 0x42, 0x36, 0xc2, 0xdd, 0x29, 0x32, 0x0a, 0x16, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x18, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x16, 0x73, 0x65, 0x73, 0x73, 0x69, diff --git a/internal/target/target.go b/internal/target/target.go index f8f5da0e4b..e2631138f2 100644 --- a/internal/target/target.go +++ b/internal/target/target.go @@ -20,7 +20,7 @@ type Target interface { GetCreateTime() *timestamp.Timestamp GetUpdateTime() *timestamp.Timestamp GetSessionMaxSeconds() uint32 - GetSessionConnectionLimit() uint32 + GetSessionConnectionLimit() int32 oplog(op oplog.OpType) oplog.Metadata }