-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #371 from guardian/aa-wazuh-singleton
feat: make Wazuh access security group a singleton
- Loading branch information
Showing
6 changed files
with
80 additions
and
94 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./base"; | ||
export * from "./wazuh"; |
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,39 @@ | ||
import "@aws-cdk/assert/jest"; | ||
import { Vpc } from "@aws-cdk/aws-ec2"; | ||
import { Stack } from "@aws-cdk/core"; | ||
import { simpleGuStackForTesting } from "../../../utils/test"; | ||
import { GuWazuhAccess } from "./wazuh"; | ||
|
||
describe("The GuWazuhAccess class", () => { | ||
const vpc = Vpc.fromVpcAttributes(new Stack(), "VPC", { | ||
vpcId: "test", | ||
availabilityZones: [""], | ||
publicSubnetIds: [""], | ||
}); | ||
|
||
it("sets props as expected", () => { | ||
const stack = simpleGuStackForTesting(); | ||
|
||
GuWazuhAccess.getInstance(stack, vpc); | ||
|
||
expect(stack).toHaveResource("AWS::EC2::SecurityGroup", { | ||
GroupDescription: "Wazuh agent registration and event logging", | ||
SecurityGroupEgress: [ | ||
{ | ||
CidrIp: "0.0.0.0/0", | ||
Description: "Wazuh event logging", | ||
FromPort: 1514, | ||
IpProtocol: "tcp", | ||
ToPort: 1514, | ||
}, | ||
{ | ||
CidrIp: "0.0.0.0/0", | ||
Description: "Wazuh agent registration", | ||
FromPort: 1515, | ||
IpProtocol: "tcp", | ||
ToPort: 1515, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
import type { IVpc } from "@aws-cdk/aws-ec2"; | ||
import { Peer } from "@aws-cdk/aws-ec2"; | ||
import type { GuStack } from "../../core"; | ||
import { GuSecurityGroup } from "./base"; | ||
|
||
export class GuWazuhAccess extends GuSecurityGroup { | ||
private static instance: GuWazuhAccess | undefined; | ||
|
||
private constructor(scope: GuStack, vpc: IVpc) { | ||
super(scope, "WazuhSecurityGroup", { | ||
vpc, | ||
description: "Wazuh agent registration and event logging", | ||
overrideId: true, | ||
allowAllOutbound: false, | ||
egresses: [ | ||
{ range: Peer.anyIpv4(), port: 1514, description: "Wazuh event logging" }, | ||
{ range: Peer.anyIpv4(), port: 1515, description: "Wazuh agent registration" }, | ||
], | ||
}); | ||
} | ||
|
||
public static getInstance(stack: GuStack, vpc: IVpc): GuWazuhAccess { | ||
// Resources can only live in the same App so return a new instance where necessary. | ||
// See https://github.com/aws/aws-cdk/blob/0ea4b19afd639541e5f1d7c1783032ee480c307e/packages/%40aws-cdk/core/lib/private/refs.ts#L47-L50 | ||
const isSameStack = this.instance?.node.root === stack.node.root; | ||
|
||
if (!this.instance || !isSameStack) { | ||
this.instance = new GuWazuhAccess(stack, vpc); | ||
} | ||
|
||
return this.instance; | ||
} | ||
} |
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