Skip to content

Commit 86c69cd

Browse files
authored
Merge pull request #173 from Infisical/feat/pam-session-real-time-log-sync
feat(pam): real-time session log sync via incremental batch uploads
2 parents ec49ef5 + 5906e97 commit 86c69cd

3 files changed

Lines changed: 309 additions & 55 deletions

File tree

packages/api/api.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const (
5454
operationCallGetPamSessionKey = "CallGetPamSessionKey"
5555
operationCallUploadPamSessionLog = "CallUploadPamSessionLog"
5656
operationCallPAMSessionTermination = "CallPAMSessionTermination"
57+
operationCallUploadPamSessionEventBatch = "CallUploadPamSessionEventBatch"
5758
operationCallGetMFASessionStatus = "CallGetMFASessionStatus"
5859
operationCallOrgRelayHeartBeat = "CallOrgRelayHeartBeat"
5960
operationCallInstanceRelayHeartBeat = "CallInstanceRelayHeartBeat"
@@ -1008,6 +1009,23 @@ func CallUploadPamSessionLogs(httpClient *resty.Client, sessionId string, reques
10081009
return nil
10091010
}
10101011

1012+
func CallUploadPamSessionEventBatch(httpClient *resty.Client, sessionId string, startOffset int64, data []byte) error {
1013+
response, err := httpClient.
1014+
R().
1015+
SetHeader("User-Agent", USER_AGENT).
1016+
SetHeader("Content-Type", "application/octet-stream").
1017+
SetBody(data).
1018+
Post(fmt.Sprintf("%v/v1/pam/sessions/%s/event-batches?startOffset=%d", config.INFISICAL_URL, sessionId, startOffset))
1019+
1020+
if err != nil {
1021+
return NewGenericRequestError(operationCallUploadPamSessionEventBatch, err)
1022+
}
1023+
if response.IsError() {
1024+
return NewAPIErrorWithResponse(operationCallUploadPamSessionEventBatch, response, nil)
1025+
}
1026+
return nil
1027+
}
1028+
10111029
func CallPAMSessionTermination(httpClient *resty.Client, sessionId string) error {
10121030
response, err := httpClient.
10131031
R().

packages/pam/pam-proxy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func HandlePAMProxy(ctx context.Context, conn *tls.Conn, pamConfig *GatewayPAMCo
158158
if err != nil {
159159
return fmt.Errorf("failed to create session logger: %w", err)
160160
}
161+
pamConfig.SessionUploader.RegisterSession(pamConfig.SessionId)
161162

162163
serverName := credentials.Host
163164
switch pamConfig.ResourceType {

0 commit comments

Comments
 (0)