diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f75acc39..484fd6bf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,6 @@ - Fixed the IP location component to accurately determine whether an IP address is public or private. - Fixed communication from/to agents using secure connections. - Fixed negative operator evaluation matching on wrong input value due to insufficient checking in correlation engine. -- Reorganized GeoIP database and threat intelligence loading into more modular functions for improved maintainability and code readability. Simplified caching, removed unused database function, and restructured rule-handling logic. Addressed minor variable renames and logging adjustments for consistency. -- Removed unused docker volume configuration for GeoIp. -- Fixed Kernel modules wheren't loaded because incorrect function call ## New Features - Introduced new standards, sections, dashboards, and visualizations to compliance reports. diff --git a/backend/src/main/java/com/park/utmstack/service/agent_manager/AgentGrpcService.java b/backend/src/main/java/com/park/utmstack/service/agent_manager/AgentGrpcService.java index b19877606..1787681b3 100644 --- a/backend/src/main/java/com/park/utmstack/service/agent_manager/AgentGrpcService.java +++ b/backend/src/main/java/com/park/utmstack/service/agent_manager/AgentGrpcService.java @@ -93,9 +93,29 @@ public AuthResponseDTO updateAgentAttributes(AgentRequestVM agentRequestVM) thro final String ctx = CLASSNAME + ".updateAgentAttributes"; try { AgentRequest req = agentRequestVM.getAgentRequest(); - Metadata customHeaders = new Metadata(); - customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agentRequestVM.getAgentKey()); - customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agentRequestVM.getId())); + + // Validating the existence of the agent. + String currentUser = SecurityUtils.getCurrentUserLogin().orElseThrow(() -> new RuntimeException("No current user login")); + Agent agent = null; + String hostname = agentRequestVM.getHostname(); + + try { + agent = blockingStub.getAgentByHostname(Hostname.newBuilder().setHostname(hostname).build()); + if (agent == null) { + String msg = String.format("%1$s: Agent %2$s could not be updated because no information was obtained from the agent", ctx, hostname); + log.error(msg); + throw new Exception(msg); + } + } catch (StatusRuntimeException e) { + if (e.getStatus().getCode() == Status.Code.NOT_FOUND) { + String msg = String.format("%1$s: Agent %2$s could not be updated because was not found", ctx, hostname); + log.error(msg); + throw new Exception(msg); + } + } + + assert agent != null; + Metadata customHeaders = getCustomHeaders(agent); Channel intercept = ClientInterceptors.intercept(grpcManagedChannel, MetadataUtils.newAttachHeadersInterceptor(customHeaders)); AgentServiceGrpc.AgentServiceBlockingStub newStub = AgentServiceGrpc.newBlockingStub(intercept); @@ -163,9 +183,8 @@ public void deleteAgent(String hostname) { AgentDelete request = AgentDelete.newBuilder().setDeletedBy(currentUser).build(); - Metadata customHeaders = new Metadata(); - customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agent.getAgentKey()); - customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agent.getId())); + assert agent != null; + Metadata customHeaders = getCustomHeaders(agent); Channel intercept = ClientInterceptors.intercept(grpcManagedChannel, MetadataUtils.newAttachHeadersInterceptor(customHeaders)); AgentServiceGrpc.AgentServiceBlockingStub newStub = AgentServiceGrpc.newBlockingStub(intercept); @@ -177,4 +196,11 @@ public void deleteAgent(String hostname) { throw new RuntimeException(msg); } } + + private Metadata getCustomHeaders (Agent agent) { + Metadata customHeaders = new Metadata(); + customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agent.getAgentKey()); + customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agent.getId())); + return customHeaders; + } } diff --git a/backend/src/main/java/com/park/utmstack/web/rest/vm/AgentRequestVM.java b/backend/src/main/java/com/park/utmstack/web/rest/vm/AgentRequestVM.java index c4b23ede4..1a724e397 100644 --- a/backend/src/main/java/com/park/utmstack/web/rest/vm/AgentRequestVM.java +++ b/backend/src/main/java/com/park/utmstack/web/rest/vm/AgentRequestVM.java @@ -1,29 +1,17 @@ package com.park.utmstack.web.rest.vm; import com.park.utmstack.service.grpc.AgentRequest; - -import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +/* +* Use this class when you need to update agent's attributes. +* To add new attributes to update, add it to the class. Actually only ip is permitted. +* */ public class AgentRequestVM { @NotEmpty private String ip; @NotEmpty private String hostname; - private String os; - private String platform; - private String version; - @NotEmpty - private String mac; - private String osMajorVersion; - private String osMinorVersion; - private String aliases; - private String addresses; - @NotEmpty - private String agentKey; - @Min(1) - private int id; public AgentRequestVM() {} @@ -32,14 +20,6 @@ public AgentRequest getAgentRequest() { return AgentRequest.newBuilder() .setIp(this.ip) .setHostname(this.hostname) - .setOs(this.os) - .setPlatform(this.platform) - .setVersion(this.version) - .setMac(this.mac) - .setOsMajorVersion(this.osMajorVersion) - .setOsMinorVersion(this.osMinorVersion) - .setAliases(this.aliases) - .setAddresses(this.addresses) .build(); } @@ -58,84 +38,4 @@ public String getHostname() { public void setHostname(String hostname) { this.hostname = hostname; } - - public String getOs() { - return os; - } - - public void setOs(String os) { - this.os = os; - } - - public String getPlatform() { - return platform; - } - - public void setPlatform(String platform) { - this.platform = platform; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getMac() { - return mac; - } - - public void setMac(String mac) { - this.mac = mac; - } - - public String getOsMajorVersion() { - return osMajorVersion; - } - - public void setOsMajorVersion(String osMajorVersion) { - this.osMajorVersion = osMajorVersion; - } - - public String getOsMinorVersion() { - return osMinorVersion; - } - - public void setOsMinorVersion(String osMinorVersion) { - this.osMinorVersion = osMinorVersion; - } - - public String getAliases() { - return aliases; - } - - public void setAliases(String aliases) { - this.aliases = aliases; - } - - public String getAddresses() { - return addresses; - } - - public void setAddresses(String addresses) { - this.addresses = addresses; - } - - public String getAgentKey() { - return agentKey; - } - - public void setAgentKey(String agentKey) { - this.agentKey = agentKey; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } } diff --git a/frontend/src/app/shared/components/utm/util/utm-agent-detail/utm-agent-detail.component.ts b/frontend/src/app/shared/components/utm/util/utm-agent-detail/utm-agent-detail.component.ts index d5515139a..6b67b9bfc 100644 --- a/frontend/src/app/shared/components/utm/util/utm-agent-detail/utm-agent-detail.component.ts +++ b/frontend/src/app/shared/components/utm/util/utm-agent-detail/utm-agent-detail.component.ts @@ -52,11 +52,8 @@ export class UtmAgentDetailComponent implements OnInit { changeIp(event: string) { this.loading = true; const agent = { - id: this.agent.id, hostname: this.agent.hostname, ip: this.agentIp, - mac: this.macs.length > 0 ? this.macs[0] : '', - agentKey: this.agent.agentKey }; this.agentManagerService.updateAgent(agent)