Skip to content

Commit c05cf38

Browse files
committed
update
1 parent 8257459 commit c05cf38

File tree

27 files changed

+353
-60
lines changed

27 files changed

+353
-60
lines changed

.local.env

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.178
2-
SENTRIUS_SSH_VERSION=1.1.33
3-
SENTRIUS_KEYCLOAK_VERSION=1.1.46
4-
SENTRIUS_AGENT_VERSION=1.1.33
5-
SENTRIUS_AI_AGENT_VERSION=1.1.60
6-
LLMPROXY_VERSION=1.0.43
7-
LAUNCHER_VERSION=1.0.50
8-
AGENTPROXY_VERSION=1.0.63
1+
SENTRIUS_VERSION=1.1.188
2+
SENTRIUS_SSH_VERSION=1.1.35
3+
SENTRIUS_KEYCLOAK_VERSION=1.1.47
4+
SENTRIUS_AGENT_VERSION=1.1.34
5+
SENTRIUS_AI_AGENT_VERSION=1.1.63
6+
LLMPROXY_VERSION=1.0.46
7+
LAUNCHER_VERSION=1.0.51
8+
AGENTPROXY_VERSION=1.0.66

.local.env.bak

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.178
2-
SENTRIUS_SSH_VERSION=1.1.33
3-
SENTRIUS_KEYCLOAK_VERSION=1.1.46
4-
SENTRIUS_AGENT_VERSION=1.1.33
5-
SENTRIUS_AI_AGENT_VERSION=1.1.60
6-
LLMPROXY_VERSION=1.0.43
7-
LAUNCHER_VERSION=1.0.50
8-
AGENTPROXY_VERSION=1.0.63
1+
SENTRIUS_VERSION=1.1.188
2+
SENTRIUS_SSH_VERSION=1.1.35
3+
SENTRIUS_KEYCLOAK_VERSION=1.1.47
4+
SENTRIUS_AGENT_VERSION=1.1.34
5+
SENTRIUS_AI_AGENT_VERSION=1.1.63
6+
LLMPROXY_VERSION=1.0.46
7+
LAUNCHER_VERSION=1.0.51
8+
AGENTPROXY_VERSION=1.0.66

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/agents/AgentVerb.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.sentrius.agent.analysis.agents.agents;
22

33
import java.lang.reflect.Method;
4+
import java.util.List;
5+
import io.sentrius.sso.core.dto.capabilities.ParameterDescriptor;
46
import io.sentrius.sso.core.model.verbs.DefaultInterpreter;
57
import io.sentrius.sso.core.model.verbs.InputInterpreterIfc;
68
import io.sentrius.sso.core.model.verbs.OutputInterpreterIfc;
@@ -13,6 +15,8 @@ public class AgentVerb {
1315
private String name;
1416
private String description;
1517
private Method method;
18+
private List<ParameterDescriptor> paramDescriptions;
19+
private boolean isAiCallable = true;
1620
@Builder.Default
1721
private boolean requiresTokenManagement = false;
1822
@Builder.Default

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/agents/ChatAgent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public void onApplicationEvent(final ApplicationReadyEvent event) {
7979

8080
verbRegistry.scanClasspath();
8181

82+
8283
var keyPair = agentKeyService.getKeyPair();
8384

8485
try {

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/agents/RegisteredAgent.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5+
import java.util.UUID;
56
import java.util.concurrent.TimeUnit;
67
import com.fasterxml.jackson.databind.node.ArrayNode;
78
import io.sentrius.agent.analysis.agents.verbs.AgentVerbs;
9+
import io.sentrius.agent.analysis.api.AgentKeyService;
10+
import io.sentrius.agent.config.AgentConfigOptions;
811
import io.sentrius.sso.core.dto.ztat.AgentExecution;
912
import io.sentrius.sso.core.dto.ztat.ZtatRequestDTO;
1013
import io.sentrius.sso.core.exceptions.ZtatException;
@@ -14,6 +17,7 @@
1417
import io.sentrius.sso.core.services.agents.AgentExecutionService;
1518
import io.sentrius.sso.core.services.agents.ZeroTrustClientService;
1619
import io.sentrius.sso.core.dto.UserDTO;
20+
import io.sentrius.sso.core.services.security.KeycloakService;
1721
import io.sentrius.sso.core.utils.JsonUtil;
1822
import jakarta.annotation.PreDestroy;
1923
import lombok.RequiredArgsConstructor;
@@ -35,6 +39,9 @@ public class RegisteredAgent implements ApplicationListener<ApplicationReadyEven
3539
final VerbRegistry verbRegistry;
3640
final AgentVerbs agentVerbs;
3741
final AgentExecutionService agentExecutionService;
42+
final AgentConfigOptions agentConfigOptions;
43+
final AgentKeyService agentKeyService;
44+
private final KeycloakService keycloakService;
3845

3946
private volatile boolean running = true;
4047
private Thread workerThread;
@@ -74,6 +81,8 @@ public void onApplicationEvent(final ApplicationReadyEvent event) {
7481
.username(zeroTrustClientService.getUsername())
7582
.build();
7683
var execution = agentExecutionService.getAgentExecution(user);
84+
85+
var keyPair = agentKeyService.getKeyPair();
7786
try {
7887
agentClientService.heartbeat(execution, execution.getUser().getUsername());
7988
} catch (ZtatException e) {
@@ -93,6 +102,32 @@ public void onApplicationEvent(final ApplicationReadyEvent event) {
93102

94103
log.error(e.getMessage());
95104
log.info("Registering v1.0.2 agent failed. Retrying in 10 seconds...");
105+
106+
try {
107+
var agentName = agentConfigOptions.getNamePrefix() + "-" + UUID.randomUUID().toString();
108+
var base64PublicKey = agentKeyService.getBase64PublicKey(keyPair.getPublic());
109+
var agentRegistrationDTO = agentClientService.bootstrap(
110+
agentName, base64PublicKey
111+
, keyPair.getPublic().getAlgorithm()
112+
);
113+
114+
var encryptedSecret = agentRegistrationDTO.getClientSecret();
115+
var decryptedSecret = agentKeyService.
116+
decryptWithPrivateKey(encryptedSecret, keyPair.getPrivate());
117+
keycloakService.createKeycloakClient(
118+
agentName,
119+
decryptedSecret
120+
);
121+
122+
final UserDTO newUserDTO = UserDTO.builder()
123+
.username(zeroTrustClientService.getUsername())
124+
.build();
125+
execution = agentExecutionService.getAgentExecution(newUserDTO);
126+
} catch (Exception e1) {
127+
log.error("Failed to bootstrap agent", e1);
128+
} catch (ZtatException ex) {
129+
log.error("Failed to bootstrap agent", ex);
130+
}
96131
try {
97132
Thread.sleep(10_000);
98133
} catch (InterruptedException ex) {

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/agents/VerbRegistry.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.github.classgraph.ClassGraph;
44
import io.github.classgraph.ScanResult;
55
import io.sentrius.sso.core.dto.capabilities.EndpointDescriptor;
6+
import io.sentrius.agent.discovery.AgentEndpointDiscoveryService;
67
import io.sentrius.sso.core.dto.ztat.AgentExecution;
78
import io.sentrius.sso.core.dto.ztat.ZtatRequestDTO;
89
import io.sentrius.sso.core.exceptions.ZtatException;
@@ -39,6 +40,8 @@ public class VerbRegistry {
3940
private final Map<String, AgentVerb> verbs = new HashMap<>();
4041
private final Map<String, Object> instances = new HashMap<>();
4142

43+
private final AgentEndpointDiscoveryService agentEndpointDiscoveryService;
44+
4245
public void scanClasspath() {
4346
// Scan the classpath for classes with the @Verb annotation
4447
synchronized (this) {
@@ -173,7 +176,7 @@ public VerbResponse execute(AgentExecution agentExecution, VerbResponse priorRes
173176
public Map<String, AgentVerb> getVerbs() {
174177
return new HashMap<>(verbs);
175178
}
176-
179+
177180
/**
178181
* Gets endpoint descriptors for all registered verbs.
179182
* This provides integration with the centralized endpoint scanning system.

ai-agent/src/main/java/io/sentrius/agent/config/AgentConfigOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentrius.agent.config;
22

3+
import java.util.List;
34
import lombok.Getter;
45
import lombok.Setter;
56
import lombok.extern.slf4j.Slf4j;
@@ -14,4 +15,5 @@ public class AgentConfigOptions {
1415

1516
private String namePrefix;
1617
private String type;
18+
private List<String> endpoints;
1719
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package io.sentrius.agent.discovery;
2+
3+
import io.sentrius.agent.analysis.agents.agents.AgentVerb;
4+
import io.sentrius.agent.config.AgentConfigOptions;
5+
import io.sentrius.sso.core.dto.capabilities.EndpointDescriptor;
6+
import io.sentrius.sso.core.dto.ztat.AgentExecution;
7+
import io.sentrius.sso.core.exceptions.ZtatException;
8+
import io.sentrius.sso.core.model.verbs.DefaultInterpreter;
9+
import io.sentrius.sso.core.services.agents.ZeroTrustClientService;
10+
import lombok.RequiredArgsConstructor;
11+
import lombok.extern.slf4j.Slf4j;
12+
import org.springframework.http.ResponseEntity;
13+
import org.springframework.stereotype.Service;
14+
import org.springframework.web.client.RestTemplate;
15+
16+
import java.util.*;
17+
import java.util.stream.Collectors;
18+
19+
@Slf4j
20+
@Service
21+
@RequiredArgsConstructor
22+
public class AgentEndpointDiscoveryService {
23+
24+
private final AgentConfigOptions agentConfigOptions;
25+
private final RestTemplate restTemplate = new RestTemplate();
26+
private final ZeroTrustClientService zeroTrustClientService;
27+
28+
// Simulated verb registry for example
29+
private final Map<String, AgentVerb> verbs = new HashMap<>();
30+
31+
public Map<String, AgentVerb> discoverEndpoints(AgentExecution agentExecution) {
32+
String discoveryUrl = agentConfigOptions.getEndpoints() + "?type=VERB";
33+
34+
log.info("Querying discovery endpoint: {}", discoveryUrl);
35+
36+
try {
37+
38+
List<EndpointDescriptor> descriptors = zeroTrustClientService.callGetOnApi(agentExecution, discoveryUrl);
39+
if (descriptors == null || descriptors.isEmpty()) {
40+
log.info("No endpoints discovered from capabilities API");
41+
return verbs;
42+
}
43+
44+
List<EndpointDescriptor> verbEndpoints = descriptors.stream()
45+
.filter(d -> "VERB".equalsIgnoreCase(d.getType()))
46+
.toList();
47+
48+
log.info("Discovered {} VERB endpoints", verbEndpoints.size());
49+
50+
for (EndpointDescriptor endpoint : verbEndpoints) {
51+
if (!verbs.containsKey(endpoint.getName())) {
52+
log.warn("Discovered verb '{}' not registered in agent", endpoint.getName());
53+
// You could also register it here dynamically if desired
54+
verbs.put(endpoint.getName(), convertToVerbDefinition(endpoint));
55+
}
56+
}
57+
58+
} catch (Exception e) {
59+
log.error("Failed to discover endpoints: {}", e.getMessage(), e);
60+
} catch (ZtatException e) {
61+
throw new RuntimeException(e);
62+
}
63+
return verbs;
64+
}
65+
66+
private AgentVerb convertToVerbDefinition(EndpointDescriptor descriptor) {
67+
return AgentVerb.builder()
68+
.name(descriptor.getName())
69+
.description(descriptor.getDescription())
70+
.returnType(descriptor.getReturnType() != null ? descriptor.getReturnType() : String.class)
71+
.requiresTokenManagement(descriptor.isRequiresTokenManagement())
72+
.outputInterpreter(DefaultInterpreter.class) // You can enhance this later if `metadata` has interpreter info
73+
.inputInterpreter(DefaultInterpreter.class)
74+
.paramDescriptions(descriptor.getParameters())
75+
.isAiCallable(true) // Assume everything from the API is callable
76+
.build();
77+
}
78+
}

api/src/main/java/io/sentrius/sso/config/AppConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ public class AppConfig {
1212
// Your configuration beans
1313
@Value("${agentproxy.externalUrl:}") // Defaults to empty string if not set
1414
private String agentProxyExternalUrl;
15+
16+
@Value("${sentrius.agent.register.bootstrap.allow:false}")
17+
private boolean allowRegistration;
18+
19+
@Value("${sentrius.agent.bootstrap.policy:default-policy.yaml}")
20+
private String defaultPolicyFile;
21+
22+
@Value("${sentrius.agent.launcher.service:http://sentrius-launcherservice:8080/}")
23+
private String sentriusLauncherService;
1524
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public ResponseEntity<?> requestRegistration(
151151
@RequestHeader("Authorization") String token,
152152
HttpServletRequest request, HttpServletResponse response) throws SQLException, GeneralSecurityException {
153153

154-
String compactJwt = token.startsWith("Bearer ") ? token.substring(7) : token;
154+
String compactJwt = token.startsWith("Beaer ") ? token.substring(7) : token;
155155

156156

157157
if (!keycloakService.validateJwt(compactJwt)) {

0 commit comments

Comments
 (0)