diff --git a/service/kas/access/rewrap.go b/service/kas/access/rewrap.go index 1193d8009c..57f0770e2c 100644 --- a/service/kas/access/rewrap.go +++ b/service/kas/access/rewrap.go @@ -83,6 +83,9 @@ type kaoResult struct { // Optional: Present for EC wrapped responses EphemeralPublicKey []byte RequiredObligations []string + + // Only populated for Nano auditing, since policy is encrypted + KeyID string } // From policy ID to KAO ID to result @@ -800,6 +803,7 @@ func (p *Provider) tdf3Rewrap(ctx context.Context, requests []*kaspb.UnsignedRew TDFFormat: "tdf3", Algorithm: req.GetAlgorithm(), PolicyBinding: policyBinding, + KeyID: kao.GetKeyAccessObject().GetKid(), } if !access { @@ -901,6 +905,7 @@ func (p *Provider) nanoTDFRewrap(ctx context.Context, requests []*kaspb.Unsigned IsSuccess: access, TDFFormat: "Nano", Algorithm: req.GetAlgorithm(), + KeyID: kaoInfo.KeyID, } if !access { @@ -992,8 +997,9 @@ func (p *Provider) verifyNanoRewrapRequests(ctx context.Context, req *kaspb.Unsi return nil, results } results[kao.GetKeyAccessObjectId()] = kaoResult{ - ID: kao.GetKeyAccessObjectId(), - DEK: symmetricKey, + ID: kao.GetKeyAccessObjectId(), + DEK: symmetricKey, + KeyID: kid, } return policy, results } diff --git a/service/logger/audit/logger_test.go b/service/logger/audit/logger_test.go index e2164fec66..1e847453ff 100644 --- a/service/logger/audit/logger_test.go +++ b/service/logger/audit/logger_test.go @@ -14,6 +14,36 @@ import ( "github.com/opentdf/platform/protocol/go/authorization" ) +// Params +var rewrapAttrs = []string{ + "https://example1.com", + "https://example2.com", +} + +const rewrapAttrsJSON = `["https://example1.com", "https://example2.com"]` + +var rewrapParams = RewrapAuditEventParams{ + Policy: KasPolicy{ + UUID: uuid.New(), + Body: KasPolicyBody{ + DataAttributes: []KasAttribute{ + {URI: rewrapAttrs[0]}, + {URI: rewrapAttrs[1]}, + }, + }, + }, + TDFFormat: "test-tdf-format", + Algorithm: "test-algorithm", + PolicyBinding: "test-policy-binding", + KeyID: "r1", +} + +var policyCRUDParams = PolicyEventParams{ + ActionType: ActionTypeUpdate, + ObjectID: "test-object-id", + ObjectType: ObjectTypeKeyObject, +} + func createTestLogger() (*Logger, *bytes.Buffer) { var buf bytes.Buffer @@ -66,29 +96,6 @@ func extractLogEntry(t *testing.T, logBuffer *bytes.Buffer) (logEntryStructure, return entry, entryTime } -// Params - -var rewrapParams = RewrapAuditEventParams{ - Policy: KasPolicy{ - UUID: uuid.New(), - Body: KasPolicyBody{ - DataAttributes: []KasAttribute{ - {URI: "https://example1.com"}, - {URI: "https://example2.com"}, - }, - }, - }, - TDFFormat: "test-tdf-format", - Algorithm: "test-algorithm", - PolicyBinding: "test-policy-binding", -} - -var policyCRUDParams = PolicyEventParams{ - ActionType: ActionTypeUpdate, - ObjectID: "test-object-id", - ObjectType: ObjectTypeKeyObject, -} - func TestAuditRewrapSuccess(t *testing.T) { l, buf := createTestLogger() @@ -104,7 +111,7 @@ func TestAuditRewrapSuccess(t *testing.T) { "name": "", "attributes": { "assertions": [], - "attrs": [], + "attrs": %s, "permissions": [] } }, @@ -118,7 +125,7 @@ func TestAuditRewrapSuccess(t *testing.T) { }, "eventMetaData": { "algorithm": "%s", - "keyID": "", + "keyID": "%s", "policyBinding": "%s", "tdfFormat": "%s" }, @@ -134,8 +141,10 @@ func TestAuditRewrapSuccess(t *testing.T) { } `, rewrapParams.Policy.UUID.String(), + rewrapAttrsJSON, TestActorID, rewrapParams.Algorithm, + rewrapParams.KeyID, rewrapParams.PolicyBinding, rewrapParams.TDFFormat, TestUserAgent, @@ -168,7 +177,7 @@ func TestAuditRewrapFailure(t *testing.T) { "name": "", "attributes": { "assertions": [], - "attrs": [], + "attrs": %s, "permissions": [] } }, @@ -182,7 +191,7 @@ func TestAuditRewrapFailure(t *testing.T) { }, "eventMetaData": { "algorithm": "%s", - "keyID": "", + "keyID": "%s", "policyBinding": "%s", "tdfFormat": "%s" }, @@ -198,8 +207,10 @@ func TestAuditRewrapFailure(t *testing.T) { } `, rewrapParams.Policy.UUID.String(), + rewrapAttrsJSON, TestActorID, rewrapParams.Algorithm, + rewrapParams.KeyID, rewrapParams.PolicyBinding, rewrapParams.TDFFormat, TestUserAgent, diff --git a/service/logger/audit/rewrap.go b/service/logger/audit/rewrap.go index 77dba335ba..d689ddb5ed 100644 --- a/service/logger/audit/rewrap.go +++ b/service/logger/audit/rewrap.go @@ -25,6 +25,7 @@ type RewrapAuditEventParams struct { TDFFormat string Algorithm string PolicyBinding string + KeyID string } func CreateRewrapAuditEvent(ctx context.Context, params RewrapAuditEventParams) (*EventObject, error) { @@ -36,14 +37,19 @@ func CreateRewrapAuditEvent(ctx context.Context, params RewrapAuditEventParams) auditEventActionResult = ActionResultSuccess } + attrFQNS := make([]string, len(params.Policy.Body.DataAttributes)) + for i, attr := range params.Policy.Body.DataAttributes { + attrFQNS[i] = attr.URI + } + return &EventObject{ Object: auditEventObject{ Type: ObjectTypeKeyObject, ID: params.Policy.UUID.String(), Attributes: eventObjectAttributes{ - Assertions: []string{}, - Attrs: []string{}, - Permissions: []string{}, + Assertions: []string{}, // Assertions aren't passed in the rewrap policy body + Attrs: attrFQNS, + Permissions: []string{}, // Currently always empty }, }, Action: eventAction{ @@ -55,7 +61,7 @@ func CreateRewrapAuditEvent(ctx context.Context, params RewrapAuditEventParams) Attributes: make([]any, 0), }, EventMetaData: auditEventMetadata{ - "keyID": "", // TODO: keyID once implemented + "keyID": params.KeyID, "policyBinding": params.PolicyBinding, "tdfFormat": params.TDFFormat, "algorithm": params.Algorithm, diff --git a/service/logger/audit/rewrap_test.go b/service/logger/audit/rewrap_test.go index 5dae8c7a5d..231dec0d23 100644 --- a/service/logger/audit/rewrap_test.go +++ b/service/logger/audit/rewrap_test.go @@ -8,12 +8,18 @@ import ( ) func TestCreateRewrapAuditEventHappyPath(t *testing.T) { + attrs := []string{ + "https://example1.com", + "https://example2.com", + } + keyID := "r1" + kasPolicy := KasPolicy{ UUID: uuid.New(), Body: KasPolicyBody{ DataAttributes: []KasAttribute{ - {URI: "https://example1.com"}, - {URI: "https://example2.com"}, + {URI: attrs[0]}, + {URI: attrs[1]}, }, Dissem: []string{"dissem1", "dissem2"}, }, @@ -25,6 +31,7 @@ func TestCreateRewrapAuditEventHappyPath(t *testing.T) { TDFFormat: TestTDFFormat, Algorithm: TestAlgorithm, PolicyBinding: TestPolicyBinding, + KeyID: keyID, } event, err := CreateRewrapAuditEvent(createTestContext(), params) @@ -37,7 +44,7 @@ func TestCreateRewrapAuditEventHappyPath(t *testing.T) { ID: kasPolicy.UUID.String(), Attributes: eventObjectAttributes{ Assertions: []string{}, - Attrs: []string{}, + Attrs: attrs, Permissions: []string{}, }, } @@ -62,7 +69,7 @@ func TestCreateRewrapAuditEventHappyPath(t *testing.T) { } expectedEventMetaData := auditEventMetadata{ - "keyID": "", + "keyID": keyID, "policyBinding": TestPolicyBinding, "tdfFormat": TestTDFFormat, "algorithm": TestAlgorithm,