Skip to content

Commit

Permalink
Report AWS operations with service identity (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
orishavit authored Dec 16, 2024
1 parent 31229a3 commit 43dbc5b
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 26 deletions.
62 changes: 59 additions & 3 deletions src/mapper/pkg/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/mapper/pkg/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 24 additions & 15 deletions src/mapper/pkg/resolvers/schema.helpers.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,33 +249,42 @@ func (r *Resolver) handleDNSCaptureResultsAsExternalTraffic(_ context.Context, d
// ReportAWSOperation is the resolver for the reportAWSOperation field.
func (r *Resolver) handleAWSOperationReport(ctx context.Context, operation model.AWSOperationResults) error {
for _, op := range operation {
logrus.Debugf("Received AWS operation: %+v", op)
srcPod, err := r.kubeFinder.ResolveIPToPod(ctx, op.SrcIP)
var serviceIdentity model.OtterizeServiceIdentity

if err != nil {
logrus.Errorf("could not resolve %s to pod: %s", op.SrcIP, err.Error())
continue
}
if op.Client != nil {
serviceIdentity.Name = op.Client.Name
serviceIdentity.Namespace = op.Client.Namespace
} else if op.SrcIP != nil {
srcPod, err := r.kubeFinder.ResolveIPToPod(ctx, *op.SrcIP)

serviceId, err := r.serviceIdResolver.ResolvePodToServiceIdentity(ctx, srcPod)
if err != nil {
logrus.Errorf("could not resolve IP %s to pod: %s", *op.SrcIP, err.Error())
continue
}

if err != nil {
logrus.Errorf("could not resolve pod %s to identity: %s", srcPod.Name, err.Error())
serviceId, err := r.serviceIdResolver.ResolvePodToServiceIdentity(ctx, srcPod)

if err != nil {
logrus.Errorf("could not resolve pod %s to identity: %s", srcPod.Name, err.Error())
continue
}

serviceIdentity.Name = serviceId.Name
serviceIdentity.Namespace = srcPod.Namespace
} else {
logrus.Error("Invalid AWS operation report: both srcIP and client are nil")
continue
}

r.awsIntentsHolder.AddIntent(awsintentsholder.AWSIntent{
Client: model.OtterizeServiceIdentity{
Name: serviceId.Name,
Namespace: srcPod.Namespace,
},
Client: serviceIdentity,
Actions: op.Actions,
ARN: op.Resource,
})

logrus.
WithField("client", serviceId.Name).
WithField("namespace", srcPod.Namespace).
WithField("clientName", serviceIdentity.Name).
WithField("clientNamespace", serviceIdentity.Namespace).
WithField("actions", op.Actions).
WithField("arn", op.Resource).
Debug("Discovered AWS intent")
Expand Down
23 changes: 19 additions & 4 deletions src/mapperclient/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/mappergraphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,16 @@ input IstioConnectionResults {
results: [IstioConnection!]!
}

input NamespacedName {
name: String!
namespace: String!
}

input AWSOperation {
resource: String!
actions: [String!]!
srcIp: String!
srcIp: String
client: NamespacedName
}

input ServerFilter {
Expand Down

0 comments on commit 43dbc5b

Please sign in to comment.