Skip to content

Commit 2141346

Browse files
committed
Fix for #GH-8
1 parent cb0f475 commit 2141346

File tree

7 files changed

+11
-12
lines changed

7 files changed

+11
-12
lines changed

analyagents/src/main/java/io/sentrius/agent/analysis/agents/sessions/SessionAnalyticsAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public List<TerminalCommand> parseAndSaveCommands(
103103
TerminalLogs terminalLog,
104104
TerminalSessionMetadata sessionMetadata) {
105105
// Split output into individual commands (Assume each command ends with a newline or specific delimiter)
106-
String[] commands = terminalLog.getOutput().split("\n");
106+
String[] commands = terminalLog.getOutput().split("\r\n|\r|\n");
107107

108108
// Parse each command
109109
List<TerminalCommand> terminalCommands = Arrays.stream(commands)

analyagents/src/main/resources/application.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ spring.security.oauth2.client.registration.keycloak.redirect-uri=http://192.168.
5757
spring.security.oauth2.client.registration.keycloak.scope=openid,profile,email
5858

5959
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://192.168.1.162:8180/realms/sentrius
60-
spring.security.oauth2.client.provider.keycloak.issuer-uri=http://192.168.1.162:8180/realms/sentrius
60+
spring.security.oauth2.client.provider.keycloak.issuer-uri=http://192.168.1.162:8180/realms/sentrius
61+
# for testing analytics agents
62+
#agents.session-analytics.enabled=true

api/src/main/java/io/sentrius/sso/controllers/api/AuditApiController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public List<SessionLogDTO> listSessions(HttpServletRequest request, HttpServletR
8484
@LimitAccess(sshAccess = {SSHAccessEnum.CAN_MANAGE_SYSTEMS})
8585
public ResponseEntity<String> getTerminalOutput(HttpServletRequest request, HttpServletResponse response, @RequestParam("sessionId") String sessionId)
8686
throws GeneralSecurityException {
87-
log.info("Connecting to SSH server {}", sessionId);
8887
var sessionIdStr = cryptoService.decrypt(sessionId);
8988
var sessionIdLong = Long.parseLong(sessionIdStr);
9089

api/src/main/java/io/sentrius/sso/websocket/SshListenerService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ public void startListeningToSshServer(String terminalSessionId, WebSocketSession
6464

6565
var connectedSystem = sessionTrackingService.getConnectedSession(sessionIdLong);
6666

67-
for(var trigger : connectedSystem.getSessionStartupActions()){
68-
69-
}
7067
log.info("Starting to listen to SSH server for session: {}", terminalSessionId);
68+
7169
activeSessions.putIfAbsent(terminalSessionId, session);
7270

7371
connectedSystem.setWebsocketSessionId(session.getId());

core/src/main/java/io/sentrius/sso/automation/auditing/AccessTokenAuditor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ public void setSynchronousRules(List<AccessTokenEvaluator> synchronousRules)
144144
}
145145
}
146146
}
147+
// async runner as user types
147148
runner = new AsyncAccessTokenAuditor(ztatService, asyncRules, connectedSystem, sessionTrackingService);
148149
executorService.submit(runner);
149150

151+
// async runner as user types, only to evaluate full commands
150152
fullRunner = new AsyncAccessTokenAuditor(ztatService, asyncFullRules, connectedSystem, sessionTrackingService);
151153
executorService.submit(fullRunner);
152154
}

core/src/main/java/io/sentrius/sso/core/services/terminal/SessionTrackingService.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ public void addToOutput(ConnectedSystem connectedSystem, char[] value, int offse
148148
}
149149
if (systemOptions.enableInternalAudit) {
150150
sessionAuditService.audit(connectedSystem, serverResponse);
151-
// SessionAuditDB.getInstance().audit(SessionIdentifier.from(schSession.getUser(),
152-
// schSession, sessionId, Long.valueOf(instanceId)), serverResponse);
153-
// systemAuditLogger.info(gson.toJson(new AuditWrapper(schSession.getUser(),
154-
// serverResponse)));
155-
// SessionAuditDB.insertTerminalLog(con, serverResponse);
156151
}
157152
}
158153
else {
@@ -231,7 +226,9 @@ public List<Session.TerminalMessage> getOutput(ConnectedSystem connectedSystem,
231226

232227
if (systemOptions.enableInternalAudit) {
233228
if (output.getOutputMessage() != null) {
234-
sessionAuditService.audit(connectedSystem, output.getOutputMessage().getCommand());
229+
// this should already be audited when client types
230+
// fix for issue GH-8, where we saw duplicate messages.
231+
// sessionAuditService.audit(connectedSystem, output.getOutputMessage().getCommand());
235232
}
236233
}
237234
if (output.getOutputMessage() != null) {

core/src/main/java/io/sentrius/sso/core/utils/SecureShellTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void execute(SessionOutput sessionOutput, InputStream outFromChannel) {
3333

3434
while (!Thread.currentThread().isInterrupted() && !sessionOutput.getConnectedSystem().getSession().getClosed()) {
3535
if (br.ready() && (read = br.read(buff)) != -1) {
36+
log.info("Read {} bytes from channel {}", read, new String(buff,0,read));
3637
sessionOutputService.addToOutput(
3738
sessionOutput.getConnectedSystem(), buff, 0, read);
3839
}

0 commit comments

Comments
 (0)