@@ -566,6 +566,56 @@ touch "$EXECUTED_FILE"
566566 }
567567 })
568568
569+ t .Run ("network diagnostics allow configured endpoints for unmapped resources" , func (t * testing.T ) {
570+ stubNetworkDiagnostics (
571+ t ,
572+ func (ctx context.Context , host string ) ([]string , error ) {
573+ return []string {"10.0.0.10" }, nil
574+ },
575+ func (ctx context.Context , endpoint networkDiagnosticEndpoint ) (tlsProbeResult , error ) {
576+ if endpoint .Host != "vpce-123.example.eu-west-1.vpce.amazonaws.com" {
577+ t .Fatalf ("unexpected endpoint host: %s" , endpoint .Host )
578+ }
579+ return tlsProbeResult {RemoteAddr : "10.0.0.10:443" , TLSVersion : "TLS1.3" }, nil
580+ },
581+ )
582+
583+ script := `#!/bin/sh
584+ set -eu
585+ out=""
586+ while [ "$#" -gt 0 ]; do
587+ if [ "$1" = "-s" ]; then
588+ out="$2"
589+ shift 2
590+ continue
591+ fi
592+ shift
593+ done
594+ mkdir -p "$out/test-policy"
595+ printf '[]' > "$out/test-policy/resources.json"
596+ `
597+ binary := writeExecutableScript (t , script )
598+ executor := & CommandCustodianExecutor {Logger : hclog .NewNullLogger ()}
599+
600+ result := executor .Execute (context .Background (), CustodianExecutionRequest {
601+ BinaryPath : binary ,
602+ Check : CustodianCheck {
603+ Name : "test-policy" ,
604+ Resource : "aws.future-resource" ,
605+ Provider : "aws" ,
606+ RawPolicy : map [string ]interface {}{"name" : "test-policy" , "resource" : "aws.future-resource" },
607+ },
608+ Timeout : 5 * time .Second ,
609+ OutputDir : filepath .Join (t .TempDir (), "out" ),
610+ NetworkDiagnostics : true ,
611+ NetworkDiagnosticEndpoints : []string {"vpce-123.example.eu-west-1.vpce.amazonaws.com" },
612+ })
613+
614+ if result .Err != nil {
615+ t .Fatalf ("expected successful execution, got error: %v" , result .Err )
616+ }
617+ })
618+
569619 t .Run ("passes debug and verbose args" , func (t * testing.T ) {
570620 argsFile := filepath .Join (t .TempDir (), "args.txt" )
571621 t .Setenv ("ARGS_FILE" , argsFile )
@@ -755,6 +805,45 @@ exit 3
755805 }
756806 })
757807
808+ t .Run ("does not read custodian log artifacts on success by default" , func (t * testing.T ) {
809+ script := `#!/bin/sh
810+ set -eu
811+ out=""
812+ while [ "$#" -gt 0 ]; do
813+ if [ "$1" = "-s" ]; then
814+ out="$2"
815+ shift 2
816+ continue
817+ fi
818+ shift
819+ done
820+ mkdir -p "$out/test-policy/us-east-1/test-policy"
821+ printf 'success log detail\n' > "$out/test-policy/us-east-1/test-policy/custodian-run.log"
822+ printf '[]' > "$out/test-policy/resources.json"
823+ `
824+ binary := writeExecutableScript (t , script )
825+ executor := & CommandCustodianExecutor {Logger : hclog .NewNullLogger ()}
826+
827+ result := executor .Execute (context .Background (), CustodianExecutionRequest {
828+ BinaryPath : binary ,
829+ Check : CustodianCheck {
830+ Name : "test-policy" ,
831+ Resource : "aws.backup-vault" ,
832+ Provider : "aws" ,
833+ RawPolicy : map [string ]interface {}{"name" : "test-policy" , "resource" : "aws.backup-vault" },
834+ },
835+ Timeout : 5 * time .Second ,
836+ OutputDir : filepath .Join (t .TempDir (), "out" ),
837+ })
838+
839+ if result .Err != nil {
840+ t .Fatalf ("expected successful execution, got error: %v" , result .Err )
841+ }
842+ if len (result .LogPaths ) != 0 {
843+ t .Fatalf ("expected successful execution not to walk log artifacts by default, got %#v" , result .LogPaths )
844+ }
845+ })
846+
758847 t .Run ("strips plugin-only policy fields before custodian execution" , func (t * testing.T ) {
759848 script := `#!/bin/sh
760849set -eu
@@ -891,6 +980,15 @@ func TestDiagnosticHelpers(t *testing.T) {
891980 }
892981 })
893982
983+ t .Run ("uses strict vpc endpoint suffix classification" , func (t * testing.T ) {
984+ if got := networkDiagnosticEndpointSource ("evil.vpce.amazonaws.com.attacker.com" ); got != "configured" {
985+ t .Fatalf ("expected attacker suffix not to be classified as vpc endpoint, got %s" , got )
986+ }
987+ if got := networkDiagnosticEndpointSource ("vpce-123.backup.eu-west-1.vpce.amazonaws.com" ); got != "aws-vpc-endpoint" {
988+ t .Fatalf ("expected vpc endpoint classification, got %s" , got )
989+ }
990+ })
991+
894992 t .Run ("rejects invalid configured endpoint ports" , func (t * testing.T ) {
895993 _ , _ , err := awsDiagnosticEndpointsForCheck ("aws.backup-vault" , nil , []string {"vpce-123.backup.eu-west-1.vpce.amazonaws.com:not-a-port" })
896994 if err == nil {
@@ -908,6 +1006,19 @@ func TestDiagnosticHelpers(t *testing.T) {
9081006 }
9091007 })
9101008
1009+ t .Run ("allows configured endpoints for unknown resource types" , func (t * testing.T ) {
1010+ endpoints , known , err := awsDiagnosticEndpointsForCheck ("aws.not-yet-mapped" , []string {"eu-west-1" }, []string {"vpce-123.example.eu-west-1.vpce.amazonaws.com" })
1011+ if err != nil {
1012+ t .Fatalf ("unexpected endpoint parse error: %v" , err )
1013+ }
1014+ if known {
1015+ t .Fatalf ("expected resource to remain unknown" )
1016+ }
1017+ if len (endpoints ) != 1 || endpoints [0 ].Host != "vpce-123.example.eu-west-1.vpce.amazonaws.com" {
1018+ t .Fatalf ("expected configured endpoint for unknown resource, got %#v" , endpoints )
1019+ }
1020+ })
1021+
9111022 t .Run ("maps known policy resource services" , func (t * testing.T ) {
9121023 resources := []string {
9131024 "aws.app-elb" ,
@@ -955,6 +1066,10 @@ func TestDiagnosticHelpers(t *testing.T) {
9551066 if got != "127.0.0.1:443" {
9561067 t .Fatalf ("unexpected decoded address: %s" , got )
9571068 }
1069+ got = decodeProcNetAddress ("00000000000000000000000001000000:01BB" , true )
1070+ if got != "[::1]:443" {
1071+ t .Fatalf ("unexpected decoded IPv6 address: %s" , got )
1072+ }
9581073 })
9591074
9601075 t .Run ("upserts environment values" , func (t * testing.T ) {
0 commit comments