From 8fb98dca37904cdc7fe0923b768e8a0540aa747c Mon Sep 17 00:00:00 2001 From: Nikita Pivkin Date: Thu, 18 Jan 2024 23:42:46 +0700 Subject: [PATCH 1/2] fix(iam): pass all document metadata fields to rego --- pkg/providers/aws/iam/iam.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/providers/aws/iam/iam.go b/pkg/providers/aws/iam/iam.go index 8d3783488..7fff5cb28 100755 --- a/pkg/providers/aws/iam/iam.go +++ b/pkg/providers/aws/iam/iam.go @@ -36,15 +36,23 @@ type Document struct { func (d Document) ToRego() interface{} { m := d.Metadata doc, _ := d.Parsed.MarshalJSON() - return map[string]interface{}{ - "filepath": m.Range().GetFilename(), - "startline": m.Range().GetStartLine(), - "endline": m.Range().GetEndLine(), - "managed": m.IsManaged(), - "explicit": m.IsExplicit(), - "value": string(doc), - "fskey": defsecTypes.CreateFSKey(m.Range().GetFS()), + input := map[string]interface{}{ + "filepath": m.Range().GetFilename(), + "startline": m.Range().GetStartLine(), + "endline": m.Range().GetEndLine(), + "managed": m.IsManaged(), + "explicit": m.IsExplicit(), + "value": string(doc), + "sourceprefix": m.Range().GetSourcePrefix(), + "fskey": defsecTypes.CreateFSKey(m.Range().GetFS()), + "resource": m.Reference(), } + + if m.Parent() != nil { + input["parent"] = m.Parent().ToRego() + } + + return input } type Group struct { From 06ff1b1748309242eef6f125170acc5f37af32c8 Mon Sep 17 00:00:00 2001 From: Nikita Pivkin Date: Thu, 18 Jan 2024 23:46:27 +0700 Subject: [PATCH 2/2] chore: update schema --- pkg/rego/schemas/cloud.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/rego/schemas/cloud.json b/pkg/rego/schemas/cloud.json index 2ebadef6f..e593c6b26 100644 --- a/pkg/rego/schemas/cloud.json +++ b/pkg/rego/schemas/cloud.json @@ -2159,6 +2159,12 @@ "managed": { "type": "boolean" }, + "resource": { + "type": "string" + }, + "sourceprefix": { + "type": "string" + }, "startline": { "type": "integer" },