Skip to content

Commit 657da20

Browse files
committed
Use SDK examples for continuous export setup
1 parent 9775538 commit 657da20

1 file changed

Lines changed: 61 additions & 21 deletions

File tree

info/audit-logs.mdx

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Continuous export writes new audit log events to an S3 bucket that you control.
209209

210210
### Set up a destination
211211

212-
You can use the CLI, the SDK resource (`kernel.auditLogs.exportDestinations` in TypeScript or `client.audit_logs.export_destinations` in Python), or the HTTP endpoints below. All destination requests require an organization-level credential.
212+
You can use the SDK resource (`kernel.auditLogs.exportDestinations` in TypeScript, `client.audit_logs.export_destinations` in Python, or `client.AuditLogs.ExportDestinations` in Go), the [CLI](/reference/cli/audit-logs#kernel-audit-logs-export), or the HTTP endpoints below. All destination requests require an organization-level credential.
213213

214214
| Operation | HTTP endpoint |
215215
|-----------|---------------|
@@ -222,22 +222,13 @@ You can use the CLI, the SDK resource (`kernel.auditLogs.exportDestinations` in
222222

223223
For HTTP, send `type: "s3"`, `format: "jsonl.gz"`, `region`, `bucket`, `prefix`, and `role_arn` in the create body; add `kms_key_id` only when using SSE-KMS. After testing, activate with `PATCH /audit-logs/export/destinations/{id}` and `{"status":"active"}`.
224224

225-
The CLI is the primary walkthrough. The equivalent SDK create and activation calls are shown in the setup steps.
225+
The setup steps below use the SDKs. For the CLI walkthrough, see the [CLI reference](/reference/cli/audit-logs#kernel-audit-logs-export).
226226

227227
#### 1. Create a paused destination
228228

229229
Create the destination with the customer role ARN. The create response contains the destination `id`, the Kernel role ARN that must be trusted (`kernel_role_arn`), and the unique STS external ID (`external_id`). Save all three values. The `external_id` is not your organization ID and is not interchangeable with an external ID from another destination.
230230

231-
```bash
232-
kernel audit-logs export create \
233-
--region us-east-1 \
234-
--bucket customer-audit-logs \
235-
--prefix audit-logs \
236-
--role-arn arn:aws:iam::123456789012:role/customer-audit-log-export \
237-
--output json
238-
```
239-
240-
The command always creates an S3 destination in `jsonl.gz` format with `status: "paused"`. If you use KMS, add `--kms-key-id` with a key ID, alias, or ARN in the destination region.
231+
Every destination is an S3 destination in `jsonl.gz` format and starts with `status: "paused"`. If you use KMS, set `kms_key_id` to a key ID, alias, or ARN in the destination region.
241232

242233
<CodeGroup>
243234
```typescript TypeScript
@@ -282,6 +273,41 @@ print(destination.id)
282273
print(destination.kernel_role_arn)
283274
print(destination.external_id)
284275
```
276+
277+
```go Go
278+
package main
279+
280+
import (
281+
"context"
282+
"fmt"
283+
284+
"github.com/kernel/kernel-go-sdk"
285+
)
286+
287+
func main() {
288+
ctx := context.Background()
289+
client := kernel.NewClient()
290+
291+
destination, err := client.AuditLogs.ExportDestinations.New(ctx, kernel.AuditLogExportDestinationNewParams{
292+
CreateAuditLogExportDestinationRequest: kernel.CreateAuditLogExportDestinationRequestParam{
293+
Type: kernel.CreateAuditLogExportDestinationRequestTypeS3,
294+
Format: kernel.CreateAuditLogExportDestinationRequestFormatJSONLGz,
295+
Region: "us-east-1",
296+
Bucket: "customer-audit-logs",
297+
Prefix: "audit-logs",
298+
RoleArn: "arn:aws:iam::123456789012:role/customer-audit-log-export",
299+
// KmsKeyID: kernel.String("arn:aws:kms:us-east-1:123456789012:key/11111111-2222-3333-4444-555555555555"),
300+
},
301+
})
302+
if err != nil {
303+
panic(err)
304+
}
305+
306+
fmt.Println(destination.ID)
307+
fmt.Println(destination.KernelRoleArn)
308+
fmt.Println(destination.ExternalID)
309+
}
310+
```
285311
</CodeGroup>
286312

287313
#### 2. Configure the IAM trust policy
@@ -344,15 +370,9 @@ When KMS is configured, the KMS key policy must also allow the customer role to
344370

345371
#### 4. Test and activate
346372

347-
The test endpoint assumes the customer role, writes a temporary gzip probe, and attempts to delete it. The probe uses the same request metadata as a real delivery: a SHA-256 checksum, `Content-Type: application/gzip`, and SSE-KMS when configured. Run the test before changing the destination to active:
348-
349-
```bash
350-
set -e
351-
kernel audit-logs export test dest_01hxxxxxxxxxxxxxxxxxxxxxxxx --output json
352-
kernel audit-logs export resume dest_01hxxxxxxxxxxxxxxxxxxxxxxxx --output json
353-
```
373+
The test endpoint assumes the customer role, writes a temporary gzip probe, and attempts to delete it. The probe uses the same request metadata as a real delivery: a SHA-256 checksum, `Content-Type: application/gzip`, and SSE-KMS when configured. Run the test before changing the destination to active.
354374

355-
A successful test returns `stage: "complete"`. A failed test identifies `assume_role` or `put_object` and returns `assume_role_failed` or `put_object_failed`. Do not resume until the test succeeds.
375+
A successful test returns `stage: "complete"`. A failed test identifies `assume_role` or `put_object` and returns `assume_role_failed` or `put_object_failed`. Do not activate the destination until the test succeeds.
356376

357377
<CodeGroup>
358378
```typescript TypeScript
@@ -378,6 +398,26 @@ active = client.audit_logs.export_destinations.update(
378398
)
379399
print(active.status) # active
380400
```
401+
402+
```go Go
403+
test, err := client.AuditLogs.ExportDestinations.Test(ctx, destination.ID)
404+
if err != nil {
405+
panic(err)
406+
}
407+
if !test.Success {
408+
panic(fmt.Sprintf("export test failed at %s", test.Stage))
409+
}
410+
411+
active, err := client.AuditLogs.ExportDestinations.Update(ctx, destination.ID, kernel.AuditLogExportDestinationUpdateParams{
412+
UpdateAuditLogExportDestinationRequest: kernel.UpdateAuditLogExportDestinationRequestParam{
413+
Status: kernel.UpdateAuditLogExportDestinationRequestStatusActive,
414+
},
415+
})
416+
if err != nil {
417+
panic(err)
418+
}
419+
fmt.Println(active.Status) // active
420+
```
381421
</CodeGroup>
382422

383423
Activation starts delivery at the activation time. It does not backfill events recorded before activation.
@@ -402,7 +442,7 @@ For example, a destination with prefix `audit-logs` writes under `audit-logs/des
402442

403443
### Monitor delivery
404444

405-
Use `kernel audit-logs export get <id>` or `list`, the SDK retrieve/list methods, or the HTTP GET endpoints to inspect the destination and its delivery health. The health fields are:
445+
Use the SDK retrieve and list methods, the [CLI](/reference/cli/audit-logs#kernel-audit-logs-export), or the HTTP GET endpoints to inspect the destination and its delivery health. The health fields are:
406446

407447
| Field | Meaning |
408448
|-------|---------|

0 commit comments

Comments
 (0)