-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RW-13914][RW-13916][risk=no] Handle vwb egress alert (1st part) (#8990)
* draft * add tests * fix test * fix test * fix test * fix test * fix test * fix test * fix test * fix test
- Loading branch information
Showing
21 changed files
with
661 additions
and
74 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
api/db/changelog/db.changelog-246-add-vwb-egress-event-columns.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> | ||
<changeSet author="yonghao" id="db.changelog-246-add-is-vwb-egress-event-column"> | ||
<addColumn tableName="egress_event"> | ||
<column name="vwb_workspace_id" type="varchar(80)" /> | ||
<column name="vwb_vm_name" type="varchar(80)" /> | ||
<column name="gcp_project_id" type="varchar(80)" /> | ||
<column name="vwb_incident_count" type="bigint" /> | ||
<column name="vwb_egress_event_id" type="varchar(80)" /> | ||
</addColumn> | ||
</changeSet> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
api/src/main/java/org/pmiops/workbench/api/CloudTaskEgressController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
package org.pmiops.workbench.api; | ||
|
||
import static org.pmiops.workbench.exfiltration.ExfiltrationUtils.EGRESS_SUMOLOGIC_SERVICE_QUALIFIER; | ||
import static org.pmiops.workbench.exfiltration.ExfiltrationUtils.EGRESS_VWB_SERVICE_QUALIFIER; | ||
|
||
import org.pmiops.workbench.exfiltration.EgressRemediationService; | ||
import org.pmiops.workbench.model.ProcessEgressEventRequest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class CloudTaskEgressController implements CloudTaskEgressApiDelegate { | ||
|
||
@Autowired | ||
@Qualifier(EGRESS_SUMOLOGIC_SERVICE_QUALIFIER) | ||
private EgressRemediationService egressRemediationService; | ||
private final EgressRemediationService sumologicEgressRemediationService; | ||
private final EgressRemediationService vwbEgressRemediationService; | ||
|
||
public CloudTaskEgressController( | ||
@Qualifier(EGRESS_SUMOLOGIC_SERVICE_QUALIFIER) | ||
EgressRemediationService sumologicEgressRemediationService, | ||
@Qualifier(EGRESS_VWB_SERVICE_QUALIFIER) | ||
EgressRemediationService vwbEgressRemediationService) { | ||
this.sumologicEgressRemediationService = sumologicEgressRemediationService; | ||
this.vwbEgressRemediationService = vwbEgressRemediationService; | ||
} | ||
|
||
@Override | ||
public ResponseEntity<Void> processEgressEvent(ProcessEgressEventRequest request) { | ||
egressRemediationService.remediateEgressEvent(request.getEventId()); | ||
if (request.isIsVwbEgressEvent()) { | ||
vwbEgressRemediationService.remediateEgressEvent(request.getEventId()); | ||
} else { | ||
sumologicEgressRemediationService.remediateEgressEvent(request.getEventId()); | ||
} | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
api/src/main/java/org/pmiops/workbench/api/VwbEgressAdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,52 @@ | ||
package org.pmiops.workbench.api; | ||
|
||
import jakarta.inject.Provider; | ||
import java.util.logging.Logger; | ||
import org.pmiops.workbench.config.WorkbenchConfig; | ||
import org.pmiops.workbench.db.model.DbUser; | ||
import org.pmiops.workbench.exceptions.ForbiddenException; | ||
import org.pmiops.workbench.exceptions.UnauthorizedException; | ||
import org.pmiops.workbench.exfiltration.EgressEventService; | ||
import org.pmiops.workbench.model.VwbEgressEventRequest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class VwbEgressAdminController implements VwbEgressAdminApiDelegate { | ||
private static final Logger log = Logger.getLogger(NotebooksController.class.getName()); | ||
private final EgressEventService egressEventService; | ||
|
||
private final Provider<WorkbenchConfig> workbenchConfigProvider; | ||
|
||
private final Provider<DbUser> userProvider; | ||
|
||
@Autowired | ||
public VwbEgressAdminController( | ||
EgressEventService egressEventService, | ||
Provider<WorkbenchConfig> workbenchConfigProvider, | ||
Provider<DbUser> userProvider) { | ||
this.egressEventService = egressEventService; | ||
this.workbenchConfigProvider = workbenchConfigProvider; | ||
this.userProvider = userProvider; | ||
} | ||
|
||
@Override | ||
public ResponseEntity<Void> createVwbEgressEvent(VwbEgressEventRequest body) { | ||
if (!workbenchConfigProvider.get().featureFlags.enableVWBEgressMonitor) { | ||
throw new ForbiddenException("VWB Egress Monitor is disabled"); | ||
} | ||
if (!workbenchConfigProvider | ||
.get() | ||
.vwb | ||
.exfilManagerServiceAccount | ||
.equals(userProvider.get().getUsername())) { | ||
throw new UnauthorizedException( | ||
String.format( | ||
"User %s is not authorized to create VwbEgressEvent", | ||
userProvider.get().getUsername())); | ||
} | ||
egressEventService.handleVwbEvent(body); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
api/src/main/java/org/pmiops/workbench/exfiltration/EgressEventService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package org.pmiops.workbench.exfiltration; | ||
|
||
import org.pmiops.workbench.model.SumologicEgressEvent; | ||
import org.pmiops.workbench.model.VwbEgressEventRequest; | ||
|
||
public interface EgressEventService { | ||
void handleEvent(SumologicEgressEvent egressEvent); | ||
|
||
void handleVwbEvent(VwbEgressEventRequest egressEvent); | ||
} |
Oops, something went wrong.