Skip to content

Commit 774382b

Browse files
committed
Merge remote-tracking branch 'origin/bugfix/10.5.20/update-agent-hostname' into bugfix/10.5.20/update-agent-hostname
2 parents e266901 + 3e3e582 commit 774382b

File tree

13 files changed

+120
-195
lines changed

13 files changed

+120
-195
lines changed

.github/workflows/principal-multi-env.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ jobs:
4343
backend:
4444
- 'backend/**'
4545
- 'version.yml'
46-
correlation: correlation/**
4746
frontend: frontend/**
4847
bitdefender: bitdefender/**
4948
mutate: mutate/**
@@ -74,7 +73,7 @@ jobs:
7473
strategy:
7574
fail-fast: false
7675
matrix:
77-
service: ['agent-manager', 'aws', 'backend', 'correlation', 'frontend', 'bitdefender', 'mutate', 'office365', 'log-auth-proxy', 'sophos', 'user-auditor', 'web-pdf']
76+
service: ['agent-manager', 'aws', 'backend', 'frontend', 'bitdefender', 'mutate', 'office365', 'log-auth-proxy', 'sophos', 'user-auditor', 'web-pdf']
7877
uses: ./.github/workflows/used-runner.yml
7978
with:
8079
microservice: ${{ matrix.service }}

.github/workflows/used-runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
id: get_tech
2323
run: |
2424
folder_changed="${{inputs.microservice}}"
25-
if [[ "$folder_changed" == "agent-manager" || "$folder_changed" == "aws" || "$folder_changed" == "correlation" || "$folder_changed" == "bitdefender" || "$folder_changed" == "office365" || "$folder_changed" == "sophos" || "$folder_changed" == "log-auth-proxy" ]]; then
25+
if [[ "$folder_changed" == "agent-manager" || "$folder_changed" == "aws" || "$folder_changed" == "bitdefender" || "$folder_changed" == "office365" || "$folder_changed" == "sophos" || "$folder_changed" == "log-auth-proxy" ]]; then
2626
tech="golang"
2727
elif [[ "$folder_changed" == "backend" ]]; then
2828
tech="java-11"

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# UTMStack 10.5.20 Release Notes
22
## Bug Fixes
33
- Fixed the IP location component to accurately determine whether an IP address is public or private.
4+
- Fixed communication from/to agents using secure connections.
5+
- Fixed negative operator evaluation matching on wrong input value due to insufficient checking in correlation engine.
6+
- 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.
7+
- Removed unused docker volume configuration for GeoIp.
8+
- Fixed Kernel modules wheren't loaded because incorrect function call
49

510
## New Features
611
- Introduced new standards, sections, dashboards, and visualizations to compliance reports.
7-
- Update ip address to agent
8-
- Alert generation for down data sources
12+
- Update ip address to agent.
13+
- Alert generation for down data sources.

backend/src/main/java/com/park/utmstack/service/agent_manager/AgentGrpcService.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,29 @@ public AuthResponseDTO updateAgentAttributes(AgentRequestVM agentRequestVM) thro
9393
final String ctx = CLASSNAME + ".updateAgentAttributes";
9494
try {
9595
AgentRequest req = agentRequestVM.getAgentRequest();
96-
Metadata customHeaders = new Metadata();
97-
customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agentRequestVM.getAgentKey());
98-
customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agentRequestVM.getId()));
96+
97+
// Validating the existence of the agent.
98+
String currentUser = SecurityUtils.getCurrentUserLogin().orElseThrow(() -> new RuntimeException("No current user login"));
99+
Agent agent = null;
100+
String hostname = agentRequestVM.getHostname();
101+
102+
try {
103+
agent = blockingStub.getAgentByHostname(Hostname.newBuilder().setHostname(hostname).build());
104+
if (agent == null) {
105+
String msg = String.format("%1$s: Agent %2$s could not be updated because no information was obtained from the agent", ctx, hostname);
106+
log.error(msg);
107+
throw new Exception(msg);
108+
}
109+
} catch (StatusRuntimeException e) {
110+
if (e.getStatus().getCode() == Status.Code.NOT_FOUND) {
111+
String msg = String.format("%1$s: Agent %2$s could not be updated because was not found", ctx, hostname);
112+
log.error(msg);
113+
throw new Exception(msg);
114+
}
115+
}
116+
117+
assert agent != null;
118+
Metadata customHeaders = getCustomHeaders(agent);
99119

100120
Channel intercept = ClientInterceptors.intercept(grpcManagedChannel, MetadataUtils.newAttachHeadersInterceptor(customHeaders));
101121
AgentServiceGrpc.AgentServiceBlockingStub newStub = AgentServiceGrpc.newBlockingStub(intercept);
@@ -163,9 +183,8 @@ public void deleteAgent(String hostname) {
163183

164184
AgentDelete request = AgentDelete.newBuilder().setDeletedBy(currentUser).build();
165185

166-
Metadata customHeaders = new Metadata();
167-
customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agent.getAgentKey());
168-
customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agent.getId()));
186+
assert agent != null;
187+
Metadata customHeaders = getCustomHeaders(agent);
169188

170189
Channel intercept = ClientInterceptors.intercept(grpcManagedChannel, MetadataUtils.newAttachHeadersInterceptor(customHeaders));
171190
AgentServiceGrpc.AgentServiceBlockingStub newStub = AgentServiceGrpc.newBlockingStub(intercept);
@@ -177,4 +196,11 @@ public void deleteAgent(String hostname) {
177196
throw new RuntimeException(msg);
178197
}
179198
}
199+
200+
private Metadata getCustomHeaders (Agent agent) {
201+
Metadata customHeaders = new Metadata();
202+
customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agent.getAgentKey());
203+
customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agent.getId()));
204+
return customHeaders;
205+
}
180206
}
Lines changed: 4 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
package com.park.utmstack.web.rest.vm;
22

33
import com.park.utmstack.service.grpc.AgentRequest;
4-
5-
import javax.validation.constraints.Min;
64
import javax.validation.constraints.NotEmpty;
7-
import javax.validation.constraints.NotNull;
85

6+
/*
7+
* Use this class when you need to update agent's attributes.
8+
* To add new attributes to update, add it to the class. Actually only ip is permitted.
9+
* */
910
public class AgentRequestVM {
1011
@NotEmpty
1112
private String ip;
1213
@NotEmpty
1314
private String hostname;
14-
private String os;
15-
private String platform;
16-
private String version;
17-
@NotEmpty
18-
private String mac;
19-
private String osMajorVersion;
20-
private String osMinorVersion;
21-
private String aliases;
22-
private String addresses;
23-
@NotEmpty
24-
private String agentKey;
25-
@Min(1)
26-
private int id;
2715

2816

2917
public AgentRequestVM() {}
@@ -32,14 +20,6 @@ public AgentRequest getAgentRequest() {
3220
return AgentRequest.newBuilder()
3321
.setIp(this.ip)
3422
.setHostname(this.hostname)
35-
.setOs(this.os)
36-
.setPlatform(this.platform)
37-
.setVersion(this.version)
38-
.setMac(this.mac)
39-
.setOsMajorVersion(this.osMajorVersion)
40-
.setOsMinorVersion(this.osMinorVersion)
41-
.setAliases(this.aliases)
42-
.setAddresses(this.addresses)
4323
.build();
4424
}
4525

@@ -58,84 +38,4 @@ public String getHostname() {
5838
public void setHostname(String hostname) {
5939
this.hostname = hostname;
6040
}
61-
62-
public String getOs() {
63-
return os;
64-
}
65-
66-
public void setOs(String os) {
67-
this.os = os;
68-
}
69-
70-
public String getPlatform() {
71-
return platform;
72-
}
73-
74-
public void setPlatform(String platform) {
75-
this.platform = platform;
76-
}
77-
78-
public String getVersion() {
79-
return version;
80-
}
81-
82-
public void setVersion(String version) {
83-
this.version = version;
84-
}
85-
86-
public String getMac() {
87-
return mac;
88-
}
89-
90-
public void setMac(String mac) {
91-
this.mac = mac;
92-
}
93-
94-
public String getOsMajorVersion() {
95-
return osMajorVersion;
96-
}
97-
98-
public void setOsMajorVersion(String osMajorVersion) {
99-
this.osMajorVersion = osMajorVersion;
100-
}
101-
102-
public String getOsMinorVersion() {
103-
return osMinorVersion;
104-
}
105-
106-
public void setOsMinorVersion(String osMinorVersion) {
107-
this.osMinorVersion = osMinorVersion;
108-
}
109-
110-
public String getAliases() {
111-
return aliases;
112-
}
113-
114-
public void setAliases(String aliases) {
115-
this.aliases = aliases;
116-
}
117-
118-
public String getAddresses() {
119-
return addresses;
120-
}
121-
122-
public void setAddresses(String addresses) {
123-
this.addresses = addresses;
124-
}
125-
126-
public String getAgentKey() {
127-
return agentKey;
128-
}
129-
130-
public void setAgentKey(String agentKey) {
131-
this.agentKey = agentKey;
132-
}
133-
134-
public int getId() {
135-
return id;
136-
}
137-
138-
public void setId(int id) {
139-
this.id = id;
140-
}
14141
}

correlation/cache/operators.go

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ import (
1212

1313
func inCIDR(addr, network string) (bool, error) {
1414
_, subnet, err := net.ParseCIDR(network)
15-
if err == nil {
16-
ip := net.ParseIP(addr)
17-
if ip != nil {
18-
if subnet.Contains(ip) {
19-
return true, nil
20-
}
21-
}
15+
if err != nil {
16+
return false, fmt.Errorf("invalid CIDR")
17+
}
18+
ip := net.ParseIP(addr)
19+
if ip == nil {
2220
return false, fmt.Errorf("invalid IP address")
2321
}
24-
return false, err
22+
return subnet.Contains(ip), nil
2523
}
2624

2725
func equal(val1, val2 string) bool {
@@ -54,25 +52,25 @@ func endWith(str, suff string) bool {
5452
return strings.HasSuffix(str, suff)
5553
}
5654

57-
func expresion(exp, str string) (bool, error) {
55+
func expression(exp, str string) (bool, error) {
5856
re, err := regexp.Compile(exp)
59-
if err == nil {
60-
if re.MatchString(str) {
61-
return true, nil
62-
}
57+
if err != nil {
58+
return false, err
6359
}
64-
return false, err
60+
return re.MatchString(str), nil
6561
}
6662

6763
func parseFloats(val1, val2 string) (float64, float64, error) {
68-
f1, err1 := strconv.ParseFloat(val1, 64)
69-
if err1 != nil {
70-
return 0, 0, err1
64+
f1, err := strconv.ParseFloat(val1, 64)
65+
if err != nil {
66+
return 0, 0, err
7167
}
72-
f2, err2 := strconv.ParseFloat(val2, 64)
73-
if err2 != nil {
74-
return 0, 0, err2
68+
69+
f2, err := strconv.ParseFloat(val2, 64)
70+
if err != nil {
71+
return 0, 0, err
7572
}
73+
7674
return f1, f2, nil
7775
}
7876

@@ -105,17 +103,17 @@ func compare(operator, val1, val2 string) bool {
105103
case "not end with":
106104
return !endWith(val1, val2)
107105
case "regexp":
108-
matched, err := expresion(val2, val1)
106+
matched, err := expression(val2, val1)
109107
if err != nil {
110108
return false
111109
}
112110
return matched
113111
case "not regexp":
114-
matched, err := expresion(val2, val1)
112+
matched, err := expression(val2, val1)
115113
if err != nil {
116114
return false
117115
}
118-
return matched
116+
return !matched
119117
case "<":
120118
f1, f2, err := parseFloats(val1, val2)
121119
if err != nil {
@@ -144,24 +142,24 @@ func compare(operator, val1, val2 string) bool {
144142
return true
145143
case "in cidr":
146144
matched, err := inCIDR(val1, val2)
147-
if err == nil {
148-
return matched
145+
if err != nil {
146+
return false
149147
}
150-
return false
148+
return matched
151149
case "not in cidr":
152150
matched, err := inCIDR(val1, val2)
153-
if err == nil {
154-
return !matched
151+
if err != nil {
152+
return false
155153
}
156-
return false
154+
return !matched
157155
default:
158156
return false
159157
}
160158
}
161159

162160
func evalElement(elem, field, operator, value string) bool {
163-
if gjson.Get(elem, field).Exists() {
164-
return compare(operator, gjson.Get(elem, field).String(), value)
161+
if elem := gjson.Get(elem, field); elem.Exists() {
162+
return compare(operator, elem.String(), value)
165163
} else if operator == "not exist" {
166164
return true
167165
}

correlation/config.yml.prod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
rulesFolder: /app/rulesets/
2-
geoipFolder: /app/geosets/
32
elasticsearch: "http://ELASTICSEARCH_HOST:ELASTICSEARCH_PORT"
43
postgresql:
54
server: POSTGRESQL_HOST

correlation/go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/utmstack/UTMStack/correlation
22

3-
go 1.22.0
4-
5-
toolchain go1.23.5
3+
go 1.23
64

75
require (
86
github.com/fsnotify/fsnotify v1.8.0
@@ -20,7 +18,7 @@ require (
2018

2119
require (
2220
github.com/KyleBanks/depth v1.2.1 // indirect
23-
github.com/bytedance/sonic v1.12.8 // indirect
21+
github.com/bytedance/sonic v1.12.9 // indirect
2422
github.com/bytedance/sonic/loader v0.2.3 // indirect
2523
github.com/cloudwego/base64x v0.1.5 // indirect
2624
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
@@ -32,7 +30,7 @@ require (
3230
github.com/go-openapi/swag v0.23.0 // indirect
3331
github.com/go-playground/locales v0.14.1 // indirect
3432
github.com/go-playground/universal-translator v0.18.1 // indirect
35-
github.com/go-playground/validator/v10 v10.24.0 // indirect
33+
github.com/go-playground/validator/v10 v10.25.0 // indirect
3634
github.com/goccy/go-json v0.10.5 // indirect
3735
github.com/google/go-querystring v1.1.0 // indirect
3836
github.com/josharian/intern v1.0.0 // indirect

0 commit comments

Comments
 (0)