Skip to content

Commit 5bf2cf8

Browse files
committed
Add proxy
1 parent 01c7233 commit 5bf2cf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+7462
-27
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
SENTRIUS_VERSION=1.1.27
1+
SENTRIUS_VERSION=1.1.35
22
SENTRIUS_SSH_VERSION=1.1.1
33
SENTRIUS_KEYCLOAK_VERSION=1.1.3
44
SENTRIUS_AGENT_VERSION=1.1.1
5-
SENTRIUS_AI_AGENT_VERSION=1.1.7
5+
SENTRIUS_AI_AGENT_VERSION=1.1.11

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ analytics/target/**
4242
analytics/target/
4343
dataplane/target/**
4444
dataplane/target/
45+
openai-proxy/target/**
46+
openai-proxy/target/
4547
node/*
4648
node_modules/*
4749
api/node_modules/*

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public class RegisteredAgent implements ApplicationListener<ApplicationReadyEven
2222
@Override
2323
public void onApplicationEvent(final ApplicationReadyEvent event) {
2424

25-
26-
2725
// get username from token
2826
UserDTO user = UserDTO.builder()
2927
.username(zeroTrustClientService.getUsername())
@@ -35,8 +33,8 @@ public void onApplicationEvent(final ApplicationReadyEvent event) {
3533
log.info("Registering v1.0.2 agent...");
3634

3735
// register
38-
zeroTrustClientService.requestZtatToken(user, command);
39-
log.info("Registered agent is running");
36+
var register = zeroTrustClientService.registerAgent(user);
37+
log.info("Registered agent is running {} ", register);
4038
return;
4139
}
4240

ai-agent/src/main/java/io/sentrius/agent/services/ZeroTrustClientService.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ public String getUsername() {
3333
}
3434

3535

36+
/**
37+
* Request a Zero Trust Access Token (ZTAT) using Keycloak JWT and `ZtatRequestDTO`
38+
*/
39+
public String registerAgent(UserDTO user) {
40+
String keycloakJwt = getKeycloakToken();
41+
42+
HttpHeaders headers = new HttpHeaders();
43+
headers.setContentType(MediaType.APPLICATION_JSON);
44+
headers.setBearerAuth(keycloakJwt);
45+
46+
HttpEntity<ZtatRequestDTO> requestEntity = new HttpEntity<>(headers);
47+
48+
String url = agentApiUrl + "/api/v1/agent/register";
49+
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
50+
51+
if (response.getStatusCode() == HttpStatus.OK) {
52+
return response.getBody(); // This is the ZTAT (JWT or opaque token)
53+
} else {
54+
throw new RuntimeException("Failed to obtain ZTAT: " + response.getStatusCode());
55+
}
56+
}
57+
3658
/**
3759
* Request a Zero Trust Access Token (ZTAT) using Keycloak JWT and `ZtatRequestDTO`
3860
*/

ai-agent/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ spring.servlet.multipart.max-request-size=10MB
4747
server.error.whitelabel.enabled=false
4848

4949

50-
50+
server.port=8083
5151
keycloak.realm=sentrius
5252
keycloak.base-url=${KEYCLOAK_BASE_URL:http://localhost:8180}
5353
spring.security.oauth2.client.registration.keycloak.client-id=java-agents

api/dynamic.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ enableInternalAudit=true
2323
twopartyapproval.require.explanation.LOCKING_SYSTEMS=false
2424
canApproveOwnJITs=false
2525
allowUploadSystemConfiguration = true
26-
yamlConfigurationPath=/mnt/ExtraDrive/repos/Sentrius/docker/sentrius/demoInstaller.yml
26+
yamlConfigurationPath=/mnt/ExtraDrive/repos/Sentrius/docker/sentrius/demoInstaller.yml
27+
# defines the policy mapping for the java agents
28+
agents.trust.policy.mapping.1=java-agents:/mnt/ExtraDrive/repos/Sentrius/docker/sentrius/java-agents.yaml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.sentrius.sso.config;
2+
3+
public class ApiPaths {
4+
public static final String API_V1 = "/api/v1";
5+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package io.sentrius.sso.controllers.api;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
5+
import io.sentrius.sso.core.annotations.LimitAccess;
6+
import io.sentrius.sso.core.model.security.enums.ApplicationAccessEnum;
7+
import io.sentrius.sso.core.services.ATPLPolicyService;
8+
import io.sentrius.sso.core.model.ATPLPolicyEntity;
9+
import io.sentrius.sso.core.trust.ATPLPolicy;
10+
import lombok.RequiredArgsConstructor;
11+
import lombok.extern.slf4j.Slf4j;
12+
import org.springframework.http.ResponseEntity;
13+
import org.springframework.http.HttpStatus;
14+
import org.springframework.web.bind.annotation.*;
15+
16+
import java.util.List;
17+
18+
@RestController
19+
@RequestMapping("/api/v1/policies")
20+
@RequiredArgsConstructor
21+
@Slf4j
22+
public class ATPLPolicyController {
23+
24+
private final ATPLPolicyService policyService;
25+
private final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
26+
27+
@PostMapping(consumes = {"application/x-yaml", "application/yaml", "text/yaml", "application/json"})
28+
public ResponseEntity<?> uploadPolicy(@RequestBody String rawPolicy) {
29+
try {
30+
ATPLPolicy policy = yamlMapper.readValue(rawPolicy, ATPLPolicy.class);
31+
32+
// Optional: Do deeper schema validation or approval here
33+
if (policy.getPolicyId() == null || policy.getVersion() == null) {
34+
return ResponseEntity.badRequest().body("Missing required fields: policy_id and version.");
35+
}
36+
37+
policyService.savePolicy(policy);
38+
return ResponseEntity.status(HttpStatus.CREATED).body("Policy uploaded successfully.");
39+
40+
} catch (Exception e) {
41+
log.error("Invalid policy submission", e);
42+
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
43+
.body("Invalid policy format: " + e.getMessage());
44+
}
45+
}
46+
47+
@GetMapping
48+
@LimitAccess(applicationAccess = {ApplicationAccessEnum.CAN_MANAGE_APPLICATION})
49+
public ResponseEntity<List<ATPLPolicyEntity>> listPolicies() {
50+
return ResponseEntity.ok(policyService.findAll());
51+
}
52+
53+
@GetMapping("/{policyId}")
54+
@LimitAccess(applicationAccess = {ApplicationAccessEnum.CAN_MANAGE_APPLICATION})
55+
public ResponseEntity<?> getPolicy(@PathVariable String policyId) {
56+
ATPLPolicy policy = policyService.getPolicy(policyId);
57+
if (policy == null) {
58+
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Policy not found.");
59+
}
60+
return ResponseEntity.ok(policy);
61+
}
62+
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import java.sql.SQLException;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.UUID;
78
import java.util.stream.Collectors;
9+
import io.sentrius.sso.config.ApiPaths;
810
import io.sentrius.sso.core.annotations.LimitAccess;
911
import io.sentrius.sso.core.config.SystemOptions;
1012
import io.sentrius.sso.core.controllers.BaseController;
@@ -42,7 +44,7 @@
4244

4345
@Slf4j
4446
@RestController
45-
@RequestMapping("/api/v1/agent")
47+
@RequestMapping(ApiPaths.API_V1 + "/agent")
4648
public class AgentApiController extends BaseController {
4749
private final AuditService auditService;
4850
final CryptoService cryptoService;
@@ -93,10 +95,18 @@ public ResponseEntity<?> requestRegistration(
9395
// Extract agent identity from the JWT
9496
String agentId = keycloakService.extractAgentId(compactJwt);
9597

96-
log.info("Received registration request from agent: {}", agentId);
98+
if (null == operatingUser) {
99+
log.warn("No operating user found for agent: {}", agentId);
100+
var username = keycloakService.extractUsername(compactJwt);
101+
operatingUser = userService.getUserWithDetails(username);
102+
103+
}
104+
105+
log.info("Received registration request from agent: {} {}", agentId, operatingUser);
97106
// Store the request in the database
98107
var ztatRequest = ztatService.createAgentRequest(agentId, "registration", "register",
99-
ZeroTrustAccessTokenReason.builder().build(), operatingUser);
108+
ZeroTrustAccessTokenReason.builder().commandNeed("registration call").reasonIdentifier(UUID.randomUUID().toString()).build(),
109+
operatingUser);
100110
ztatRequest = ztrService.addJITRequest(ztatRequest);
101111

102112
// Approve the request if the agent has an active policy ( and it is known and allowed ).

api/src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,5 @@ spring.security.oauth2.client.provider.keycloak.issuer-uri=${KEYCLOAK_BASE_URL:h
7676

7777
management.endpoints.web.exposure.include=health
7878
management.endpoint.health.show-details=always
79-
8079
### change for production environments
8180
https.required=${HTTP_REQUIRED:true}

0 commit comments

Comments
 (0)