feat(session): Classify resources for audit events

This commit is contained in:
Timothy Messier authored and Johan Brandhorst-Satzkorn committed 2022-04-20 13:32:32 -04:00
1 parent 38a3960047
commit 006fa3a85a
6 files changed
+230 -68

No files matched your search

+2
View File
@@ -177,6 +177,8 @@ protobuild:
@protoc-go-inject-tag -input=./internal/gen/controller/api/services/credential_library_service.pb.go
@protoc-go-inject-tag -input=./sdk/pbs/controller/api/resources/roles/role.pb.go
@protoc-go-inject-tag -input=./internal/gen/controller/api/services/role_service.pb.go
@protoc-go-inject-tag -input=./sdk/pbs/controller/api/resources/sessions/session.pb.go
@protoc-go-inject-tag -input=./internal/gen/controller/api/services/session_service.pb.go
# these protos, services and openapi artifacts are purely for testing purposes
@protoc-go-inject-tag -input=./internal/gen/testing/event/event.pb.go
@@ -28,7 +28,7 @@ type GetSessionRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" class:"public"` // @gotags: `class:"public"`
}
func (x *GetSessionRequest) Reset() {
@@ -122,9 +122,9 @@ type ListSessionsRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ScopeId string `protobuf:"bytes,1,opt,name=scope_id,json=scopeId,proto3" json:"scope_id,omitempty"`
Recursive bool `protobuf:"varint,20,opt,name=recursive,proto3" json:"recursive,omitempty"`
Filter string `protobuf:"bytes,30,opt,name=filter,proto3" json:"filter,omitempty"`
ScopeId string `protobuf:"bytes,1,opt,name=scope_id,json=scopeId,proto3" json:"scope_id,omitempty" class:"public"` // @gotags: `class:"public"`
Recursive bool `protobuf:"varint,20,opt,name=recursive,proto3" json:"recursive,omitempty" class:"public"` // @gotags: `class:"public"`
Filter string `protobuf:"bytes,30,opt,name=filter,proto3" json:"filter,omitempty" class:"public"` // @gotags: `class:"public"`
}
func (x *ListSessionsRequest) Reset() {
@@ -232,8 +232,8 @@ type CancelSessionRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Version uint32 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" class:"public"` // @gotags: `class:"public"`
Version uint32 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty" class:"public"` // @gotags: `class:"public"`
}
func (x *CancelSessionRequest) Reset() {
@@ -9,106 +9,106 @@ import "controller/api/resources/scopes/v1/scope.proto";
message WorkerInfo {
// The address of the worker.
string address = 10;
string address = 10; // @gotags: `class:"public"`
}
message SessionState {
// The status of the Session, e.g. "pending", "active", "canceling", "terminated".
string status = 10;
string status = 10; // @gotags: `class:"public"`
// Output only. The time the Session entered this state.
google.protobuf.Timestamp start_time = 20 [json_name = "start_time"];
google.protobuf.Timestamp start_time = 20 [json_name = "start_time"]; // @gotags: `class:"public"`
// Output only. The time the Session stopped being in this state.
google.protobuf.Timestamp end_time = 30 [json_name = "end_time"];
google.protobuf.Timestamp end_time = 30 [json_name = "end_time"]; // @gotags: `class:"public"`
}
// Connection contains information about a specific connection in a session
message Connection {
// client_tcp_address of the connection
string client_tcp_address = 3;
string client_tcp_address = 3; // @gotags: `class:"public"`
// client_tcp_port of the connection
uint32 client_tcp_port = 4;
uint32 client_tcp_port = 4; // @gotags: `class:"public"`
// endpoint_tcp_address of the connection
string endpoint_tcp_address = 5;
string endpoint_tcp_address = 5; // @gotags: `class:"public"`
// endpoint_tcp_port of the connection
uint32 endpoint_tcp_port = 6;
uint32 endpoint_tcp_port = 6; // @gotags: `class:"public"`
// bytes_up of the connection
uint64 bytes_up = 7;
uint64 bytes_up = 7; // @gotags: `class:"public"`
// bytes_down of the connection
uint64 bytes_down = 8;
uint64 bytes_down = 8; // @gotags: `class:"public"`
// closed_reason of the conneciont
string closed_reason = 9;
string closed_reason = 9; // @gotags: `class:"public"`
}
// Session contains all fields related to a Session resource
message Session {
// Output only. The ID of the Session.
string id = 10;
string id = 10; // @gotags: `class:"public"`
// Output only. The ID of the Target that created this Session.
string target_id = 20 [json_name = "target_id"];
string target_id = 20 [json_name = "target_id"]; // @gotags: `class:"public"`
// Output only. Scope information for this resource.
resources.scopes.v1.ScopeInfo scope = 30;
// Output only. The time this resource was created.
google.protobuf.Timestamp created_time = 60 [json_name = "created_time"];
google.protobuf.Timestamp created_time = 60 [json_name = "created_time"]; // @gotags: `class:"public"`
// Output only. The time this resource was last updated.
google.protobuf.Timestamp updated_time = 70 [json_name = "updated_time"];
google.protobuf.Timestamp updated_time = 70 [json_name = "updated_time"]; // @gotags: `class:"public"`
// Version is used when canceling this Session to ensure that the operation is acting on a known session state.
uint32 version = 80;
uint32 version = 80; // @gotags: `class:"public"`
// Output only. Type of the Session (e.g. tcp).
string type = 90;
string type = 90; // @gotags: `class:"public"`
// Output only. After this time the connection will be expired, e.g. forcefully terminated.
google.protobuf.Timestamp expiration_time = 100 [json_name = "expiration_time"];
google.protobuf.Timestamp expiration_time = 100 [json_name = "expiration_time"]; // @gotags: `class:"public"`
// Output only. The ID of the Auth Token used to authenticate.
string auth_token_id = 110 [json_name = "auth_token_id"];
string auth_token_id = 110 [json_name = "auth_token_id"]; // @gotags: `class:"public"`
// Output only. The ID of the User that requested the Session.
string user_id = 120 [json_name = "user_id"];
string user_id = 120 [json_name = "user_id"]; // @gotags: `class:"public"`
// Output only. The Host Set sourcing the Host for this Session.
string host_set_id = 130 [json_name = "host_set_id"];
string host_set_id = 130 [json_name = "host_set_id"]; // @gotags: `class:"public"`
// Output only. The Host used by the Session.
string host_id = 140 [json_name = "host_id"];
string host_id = 140 [json_name = "host_id"]; // @gotags: `class:"public"`
// Output only. The Scope of the Session.
string scope_id = 150 [json_name = "scope_id"];
string scope_id = 150 [json_name = "scope_id"]; // @gotags: `class:"public"`
// Output only. The endpoint of the Session; that is, the address to which the worker is proxying data.
string endpoint = 160;
string endpoint = 160; // @gotags: `class:"public"`
// Output only. The states of this Session in descending order from the current state to the first.
repeated SessionState states = 170;
// Output only. The current status of this Session.
string status = 180;
string status = 180; // @gotags: `class:"public"`
// Output only. Worker information given to the client.
repeated WorkerInfo worker_info = 190 [json_name = "worker_info"];
// Output only. The certificate generated for the session. Raw DER bytes.
bytes certificate = 200;
bytes certificate = 200; // @gotags: `class:"public"`
// Output only. If the session is terminated, this provides a short description as to why.
string termination_reason = 210 [json_name = "termination_reason"];
string termination_reason = 210 [json_name = "termination_reason"]; // @gotags: `class:"public"`
// Output only. The available actions on this resource for this user.
repeated string authorized_actions = 300 [json_name="authorized_actions"];
repeated string authorized_actions = 300 [json_name="authorized_actions"]; // @gotags: `class:"public"`
// Output only. The associated connections with this session.
repeated Connection connections = 310;
@@ -52,7 +52,7 @@ service SessionService {
}
message GetSessionRequest {
string id = 1;
string id = 1; // @gotags: `class:"public"`
}
message GetSessionResponse {
@@ -60,9 +60,9 @@ message GetSessionResponse {
}
message ListSessionsRequest {
string scope_id = 1;
bool recursive = 20 [json_name="recursive"];
string filter = 30 [json_name="filter"];
string scope_id = 1; // @gotags: `class:"public"`
bool recursive = 20 [json_name="recursive"]; // @gotags: `class:"public"`
string filter = 30 [json_name="filter"]; // @gotags: `class:"public"`
}
message ListSessionsResponse {
@@ -70,8 +70,8 @@ message ListSessionsResponse {
}
message CancelSessionRequest {
string id = 1;
uint32 version = 2;
string id = 1; // @gotags: `class:"public"`
uint32 version = 2; // @gotags: `class:"public"`
}
message CancelSessionResponse {
@@ -0,0 +1,160 @@
package sessions_test
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/hashicorp/boundary/sdk/pbs/controller/api"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/sessions"
"github.com/hashicorp/boundary/sdk/wrapper"
"github.com/hashicorp/eventlogger"
"github.com/hashicorp/eventlogger/filters/encrypt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"
)
func TestSessions(t *testing.T) {
ctx := context.Background()
now := time.Now()
pbNow := timestamppb.Now()
wrapper := wrapper.TestWrapper(t)
testEncryptingFilter := api.NewEncryptFilter(t, wrapper)
testEncryptingFilter.FilterOperationOverrides = map[encrypt.DataClassification]encrypt.FilterOperation{
// Use HMAC for sensitive fields for easy test comparisons
encrypt.SensitiveClassification: encrypt.HmacSha256Operation,
}
tests := []struct {
name string
in *eventlogger.Event
want *eventlogger.Event
}{
{
name: "session",
in: &eventlogger.Event{
Type: "test",
CreatedAt: now,
Payload: &pb.Session{
Id: "id",
TargetId: "target_id",
Scope: &scopes.ScopeInfo{
Id: "scope-id",
Type: "scope-type",
Name: "scope-name",
Description: "scope-description",
ParentScopeId: "scope-parent_scope_id",
},
CreatedTime: pbNow,
UpdatedTime: pbNow,
Version: 0,
Type: "type",
ExpirationTime: pbNow,
AuthTokenId: "auth_token_id",
UserId: "user_id",
HostSetId: "host_set_id",
HostId: "host_id",
ScopeId: "scope_id",
Endpoint: "endpoint",
States: []*pb.SessionState{
{
Status: "status",
StartTime: pbNow,
EndTime: pbNow,
},
},
Status: "status",
WorkerInfo: []*pb.WorkerInfo{
{
Address: "worker-address",
},
},
Certificate: []byte("certificate"),
TerminationReason: "termination_reason",
AuthorizedActions: []string{"action-1"},
Connections: []*pb.Connection{
{
ClientTcpAddress: "client_tcp_address",
ClientTcpPort: 0,
EndpointTcpAddress: "endpoint_tcp_address",
EndpointTcpPort: 0,
BytesUp: 0,
BytesDown: 0,
ClosedReason: "closed_reason",
},
},
},
},
want: &eventlogger.Event{
Type: "test",
CreatedAt: now,
Payload: &pb.Session{
Id: "id",
TargetId: "target_id",
Scope: &scopes.ScopeInfo{
Id: "scope-id",
Type: "scope-type",
Name: "scope-name",
Description: "scope-description",
ParentScopeId: "scope-parent_scope_id",
},
CreatedTime: pbNow,
UpdatedTime: pbNow,
Version: 0,
Type: "type",
ExpirationTime: pbNow,
AuthTokenId: "auth_token_id",
UserId: "user_id",
HostSetId: "host_set_id",
HostId: "host_id",
ScopeId: "scope_id",
Endpoint: "endpoint",
States: []*pb.SessionState{
{
Status: "status",
StartTime: pbNow,
EndTime: pbNow,
},
},
Status: "status",
WorkerInfo: []*pb.WorkerInfo{
{
Address: "worker-address",
},
},
Certificate: []byte("certificate"),
TerminationReason: "termination_reason",
AuthorizedActions: []string{"action-1"},
Connections: []*pb.Connection{
{
ClientTcpAddress: "client_tcp_address",
ClientTcpPort: 0,
EndpointTcpAddress: "endpoint_tcp_address",
EndpointTcpPort: 0,
BytesUp: 0,
BytesDown: 0,
ClosedReason: "closed_reason",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, err := testEncryptingFilter.Process(ctx, tt.in)
require.NoError(err)
require.NotNil(got)
gotJSON, err := json.Marshal(got)
require.NoError(err)
wantJSON, err := json.Marshal(tt.want)
require.NoError(err)
assert.JSONEq(string(wantJSON), string(gotJSON))
})
}
}
@@ -28,7 +28,7 @@ type WorkerInfo struct {
unknownFields protoimpl.UnknownFields
// The address of the worker.
Address string `protobuf:"bytes,10,opt,name=address,proto3" json:"address,omitempty"`
Address string `protobuf:"bytes,10,opt,name=address,proto3" json:"address,omitempty" class:"public"` // @gotags: `class:"public"`
}
func (x *WorkerInfo) Reset() {
@@ -76,11 +76,11 @@ type SessionState struct {
unknownFields protoimpl.UnknownFields
// The status of the Session, e.g. "pending", "active", "canceling", "terminated".
Status string `protobuf:"bytes,10,opt,name=status,proto3" json:"status,omitempty"`
Status string `protobuf:"bytes,10,opt,name=status,proto3" json:"status,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The time the Session entered this state.
StartTime *timestamppb.Timestamp `protobuf:"bytes,20,opt,name=start_time,proto3" json:"start_time,omitempty"`
StartTime *timestamppb.Timestamp `protobuf:"bytes,20,opt,name=start_time,proto3" json:"start_time,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The time the Session stopped being in this state.
EndTime *timestamppb.Timestamp `protobuf:"bytes,30,opt,name=end_time,proto3" json:"end_time,omitempty"`
EndTime *timestamppb.Timestamp `protobuf:"bytes,30,opt,name=end_time,proto3" json:"end_time,omitempty" class:"public"` // @gotags: `class:"public"`
}
func (x *SessionState) Reset() {
@@ -143,19 +143,19 @@ type Connection struct {
unknownFields protoimpl.UnknownFields
// client_tcp_address of the connection
ClientTcpAddress string `protobuf:"bytes,3,opt,name=client_tcp_address,json=clientTcpAddress,proto3" json:"client_tcp_address,omitempty"`
ClientTcpAddress string `protobuf:"bytes,3,opt,name=client_tcp_address,json=clientTcpAddress,proto3" json:"client_tcp_address,omitempty" class:"public"` // @gotags: `class:"public"`
// client_tcp_port of the connection
ClientTcpPort uint32 `protobuf:"varint,4,opt,name=client_tcp_port,json=clientTcpPort,proto3" json:"client_tcp_port,omitempty"`
ClientTcpPort uint32 `protobuf:"varint,4,opt,name=client_tcp_port,json=clientTcpPort,proto3" json:"client_tcp_port,omitempty" class:"public"` // @gotags: `class:"public"`
// endpoint_tcp_address of the connection
EndpointTcpAddress string `protobuf:"bytes,5,opt,name=endpoint_tcp_address,json=endpointTcpAddress,proto3" json:"endpoint_tcp_address,omitempty"`
EndpointTcpAddress string `protobuf:"bytes,5,opt,name=endpoint_tcp_address,json=endpointTcpAddress,proto3" json:"endpoint_tcp_address,omitempty" class:"public"` // @gotags: `class:"public"`
// endpoint_tcp_port of the connection
EndpointTcpPort uint32 `protobuf:"varint,6,opt,name=endpoint_tcp_port,json=endpointTcpPort,proto3" json:"endpoint_tcp_port,omitempty"`
EndpointTcpPort uint32 `protobuf:"varint,6,opt,name=endpoint_tcp_port,json=endpointTcpPort,proto3" json:"endpoint_tcp_port,omitempty" class:"public"` // @gotags: `class:"public"`
// bytes_up of the connection
BytesUp uint64 `protobuf:"varint,7,opt,name=bytes_up,json=bytesUp,proto3" json:"bytes_up,omitempty"`
BytesUp uint64 `protobuf:"varint,7,opt,name=bytes_up,json=bytesUp,proto3" json:"bytes_up,omitempty" class:"public"` // @gotags: `class:"public"`
// bytes_down of the connection
BytesDown uint64 `protobuf:"varint,8,opt,name=bytes_down,json=bytesDown,proto3" json:"bytes_down,omitempty"`
BytesDown uint64 `protobuf:"varint,8,opt,name=bytes_down,json=bytesDown,proto3" json:"bytes_down,omitempty" class:"public"` // @gotags: `class:"public"`
// closed_reason of the conneciont
ClosedReason string `protobuf:"bytes,9,opt,name=closed_reason,json=closedReason,proto3" json:"closed_reason,omitempty"`
ClosedReason string `protobuf:"bytes,9,opt,name=closed_reason,json=closedReason,proto3" json:"closed_reason,omitempty" class:"public"` // @gotags: `class:"public"`
}
func (x *Connection) Reset() {
@@ -246,45 +246,45 @@ type Session struct {
unknownFields protoimpl.UnknownFields
// Output only. The ID of the Session.
Id string `protobuf:"bytes,10,opt,name=id,proto3" json:"id,omitempty"`
Id string `protobuf:"bytes,10,opt,name=id,proto3" json:"id,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The ID of the Target that created this Session.
TargetId string `protobuf:"bytes,20,opt,name=target_id,proto3" json:"target_id,omitempty"`
TargetId string `protobuf:"bytes,20,opt,name=target_id,proto3" json:"target_id,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. Scope information for this resource.
Scope *scopes.ScopeInfo `protobuf:"bytes,30,opt,name=scope,proto3" json:"scope,omitempty"`
// Output only. The time this resource was created.
CreatedTime *timestamppb.Timestamp `protobuf:"bytes,60,opt,name=created_time,proto3" json:"created_time,omitempty"`
CreatedTime *timestamppb.Timestamp `protobuf:"bytes,60,opt,name=created_time,proto3" json:"created_time,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The time this resource was last updated.
UpdatedTime *timestamppb.Timestamp `protobuf:"bytes,70,opt,name=updated_time,proto3" json:"updated_time,omitempty"`
UpdatedTime *timestamppb.Timestamp `protobuf:"bytes,70,opt,name=updated_time,proto3" json:"updated_time,omitempty" class:"public"` // @gotags: `class:"public"`
// Version is used when canceling this Session to ensure that the operation is acting on a known session state.
Version uint32 `protobuf:"varint,80,opt,name=version,proto3" json:"version,omitempty"`
Version uint32 `protobuf:"varint,80,opt,name=version,proto3" json:"version,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. Type of the Session (e.g. tcp).
Type string `protobuf:"bytes,90,opt,name=type,proto3" json:"type,omitempty"`
Type string `protobuf:"bytes,90,opt,name=type,proto3" json:"type,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. After this time the connection will be expired, e.g. forcefully terminated.
ExpirationTime *timestamppb.Timestamp `protobuf:"bytes,100,opt,name=expiration_time,proto3" json:"expiration_time,omitempty"`
ExpirationTime *timestamppb.Timestamp `protobuf:"bytes,100,opt,name=expiration_time,proto3" json:"expiration_time,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The ID of the Auth Token used to authenticate.
AuthTokenId string `protobuf:"bytes,110,opt,name=auth_token_id,proto3" json:"auth_token_id,omitempty"`
AuthTokenId string `protobuf:"bytes,110,opt,name=auth_token_id,proto3" json:"auth_token_id,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The ID of the User that requested the Session.
UserId string `protobuf:"bytes,120,opt,name=user_id,proto3" json:"user_id,omitempty"`
UserId string `protobuf:"bytes,120,opt,name=user_id,proto3" json:"user_id,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The Host Set sourcing the Host for this Session.
HostSetId string `protobuf:"bytes,130,opt,name=host_set_id,proto3" json:"host_set_id,omitempty"`
HostSetId string `protobuf:"bytes,130,opt,name=host_set_id,proto3" json:"host_set_id,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The Host used by the Session.
HostId string `protobuf:"bytes,140,opt,name=host_id,proto3" json:"host_id,omitempty"`
HostId string `protobuf:"bytes,140,opt,name=host_id,proto3" json:"host_id,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The Scope of the Session.
ScopeId string `protobuf:"bytes,150,opt,name=scope_id,proto3" json:"scope_id,omitempty"`
ScopeId string `protobuf:"bytes,150,opt,name=scope_id,proto3" json:"scope_id,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The endpoint of the Session; that is, the address to which the worker is proxying data.
Endpoint string `protobuf:"bytes,160,opt,name=endpoint,proto3" json:"endpoint,omitempty"`
Endpoint string `protobuf:"bytes,160,opt,name=endpoint,proto3" json:"endpoint,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The states of this Session in descending order from the current state to the first.
States []*SessionState `protobuf:"bytes,170,rep,name=states,proto3" json:"states,omitempty"`
// Output only. The current status of this Session.
Status string `protobuf:"bytes,180,opt,name=status,proto3" json:"status,omitempty"`
Status string `protobuf:"bytes,180,opt,name=status,proto3" json:"status,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. Worker information given to the client.
WorkerInfo []*WorkerInfo `protobuf:"bytes,190,rep,name=worker_info,proto3" json:"worker_info,omitempty"`
// Output only. The certificate generated for the session. Raw DER bytes.
Certificate []byte `protobuf:"bytes,200,opt,name=certificate,proto3" json:"certificate,omitempty"`
Certificate []byte `protobuf:"bytes,200,opt,name=certificate,proto3" json:"certificate,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. If the session is terminated, this provides a short description as to why.
TerminationReason string `protobuf:"bytes,210,opt,name=termination_reason,proto3" json:"termination_reason,omitempty"`
TerminationReason string `protobuf:"bytes,210,opt,name=termination_reason,proto3" json:"termination_reason,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The available actions on this resource for this user.
AuthorizedActions []string `protobuf:"bytes,300,rep,name=authorized_actions,proto3" json:"authorized_actions,omitempty"`
AuthorizedActions []string `protobuf:"bytes,300,rep,name=authorized_actions,proto3" json:"authorized_actions,omitempty" class:"public"` // @gotags: `class:"public"`
// Output only. The associated connections with this session.
Connections []*Connection `protobuf:"bytes,310,rep,name=connections,proto3" json:"connections,omitempty"`
}