-
Notifications
You must be signed in to change notification settings - Fork 145
run CI for #8079 #8211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
n1ru4l
wants to merge
3
commits into
main
Choose a base branch
from
s3-iam-auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
run CI for #8079 #8211
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| 'hive': minor | ||
| --- | ||
|
|
||
| Added opt-in AWS IAM authentication for S3 connections. When IAM is enabled, services authenticate | ||
| to S3 using short-lived SigV4 pre-signed tokens instead of static passwords, since S3 connections | ||
| are HTTP requests a new token will be generate for each call. | ||
|
|
||
| ### New environment variables | ||
|
|
||
| | Variable | Service | Description | | ||
| | ----------------------------------- | ------- | --------------------------------------------------------- | | ||
| | `S3_AWS_IAM_AUTH_ENABLED` | server | Set to `1` to enable IAM authentication for S3. | | ||
| | `S3_MIRROR_AWS_IAM_AUTH_ENABLED` | server | Set to `1` to enable IAM authentication for S3 Mirror. | | ||
| | `S3_AUDIT_LOG_AWS_IAM_AUTH_ENABLED` | server | Set to `1` to enable IAM authentication for S3 Audit Log. | | ||
|
|
||
| ### To enable | ||
|
|
||
| - `S3_*_AWS_IAM_AUTH_ENABLED=1`. | ||
| - `S3_BUCKET_NAME` set to the AWS S3 bucket. | ||
| - `S3_ENDPOINT` set with the S3 endpoint with the AWS Region (i.e. https://s3.us-east-1.amazonaws.com) | ||
|
|
||
| When `CDN_API=1` is set on the server, the CDN artifact handler also uses IAM-authenticated S3 clients. | ||
| Adds support for S3 Audit Logs exported to AWS S3. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
packages/services/api/src/modules/audit-logs/providers/audit-logs-manager.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { AwsClient, type S3CredentialProvider } from '../../cdn/providers/aws'; | ||
| import { AuditLogManager, AuditLogS3Config } from './audit-logs-manager'; | ||
|
|
||
| vi.mock('@hive/workflows/kit', () => ({ TaskScheduler: class {} })); | ||
| vi.mock('@hive/workflows/tasks/audit-log-export', () => ({ AuditLogExportTask: {} })); | ||
| vi.mock('@sentry/node', () => ({ captureException: vi.fn() })); | ||
| vi.mock('../../operations/providers/clickhouse-client', () => ({ | ||
| ClickHouse: class {}, | ||
| sql: (strings: TemplateStringsArray, ...values: any[]) => ({ strings, values }), | ||
| })); | ||
| vi.mock('./audit-log-recorder', () => ({ | ||
| formatToClickhouseDateTime: (d: Date) => d.toISOString(), | ||
| })); | ||
| vi.mock('./audit-logs-types', () => ({ | ||
| AuditLogClickhouseArrayModel: { parse: (v: any) => v }, | ||
| })); | ||
|
|
||
| function fakeCredentialProvider(keyId: string): S3CredentialProvider { | ||
| return { | ||
| getCredentials: async () => ({ accessKeyId: keyId, secretAccessKey: `${keyId}-secret` }), | ||
| }; | ||
| } | ||
|
|
||
| function createAuditLogManager(fetchImpl: (...args: any[]) => any) { | ||
| const credentialProvider = fakeCredentialProvider('test-key'); | ||
| const client = new AwsClient({ credentialProvider, service: 's3' }); | ||
| const fetchSpy = vi.spyOn(client, 'fetch').mockImplementation(fetchImpl as any); | ||
|
|
||
| const s3Config = new AuditLogS3Config(client, 'https://s3.example.com', 'audit-bucket'); | ||
|
|
||
| const mockSession = { | ||
| assertPerformAction: vi.fn().mockResolvedValue(undefined), | ||
| getViewer: vi.fn().mockResolvedValue({ email: 'user@example.com' }), | ||
| }; | ||
| const mockClickHouse = { | ||
| query: vi.fn().mockResolvedValue({ | ||
| data: [ | ||
| { | ||
| id: '1', | ||
| timestamp: '2026-01-15', | ||
| organizationId: 'org-1', | ||
| eventAction: 'login', | ||
| userId: 'u1', | ||
| userEmail: 'u@x.com', | ||
| accessTokenId: null, | ||
| metadata: '{}', | ||
| }, | ||
| ], | ||
| }), | ||
| }; | ||
| const mockLogger = { child: () => mockLogger, info: vi.fn(), error: vi.fn() } as any; | ||
| const mockTaskScheduler = { scheduleTask: vi.fn().mockResolvedValue(undefined) }; | ||
| const mockStorage = { | ||
| getOrganization: vi.fn().mockResolvedValue({ name: 'TestOrg', id: 'org-1' }), | ||
| }; | ||
|
|
||
| return { | ||
| manager: new AuditLogManager( | ||
| mockLogger, | ||
| mockClickHouse as any, | ||
| s3Config, | ||
| mockTaskScheduler as any, | ||
| mockSession as any, | ||
| mockStorage as any, | ||
| ), | ||
| fetchSpy, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Guards against regression where the S3 PUT upload was missing | ||
| * `aws: { signQuery: true }`, causing the `got` library to receive | ||
| * auth headers it can't handle - resulting in silent upload failures. | ||
| */ | ||
| describe('AuditLogManager S3 upload uses signQuery', () => { | ||
| it('PUT upload includes aws.signQuery: true', async () => { | ||
| const { manager, fetchSpy } = createAuditLogManager( | ||
| vi.fn().mockResolvedValue({ ok: true, url: 'https://s3.example.com/key' }), | ||
| ); | ||
|
|
||
| await manager.exportAndSendEmail('org-1', { | ||
| startDate: new Date('2026-01-01'), | ||
| endDate: new Date('2026-01-31'), | ||
| }); | ||
|
|
||
| const putCall = fetchSpy.mock.calls[0]; | ||
| expect(putCall[1]).toEqual( | ||
| expect.objectContaining({ | ||
| method: 'PUT', | ||
| aws: expect.objectContaining({ signQuery: true }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('GET presigned URL includes aws.signQuery: true', async () => { | ||
| const { manager, fetchSpy } = createAuditLogManager( | ||
| vi.fn().mockResolvedValue({ ok: true, url: 'https://s3.example.com/key' }), | ||
| ); | ||
|
|
||
| await manager.exportAndSendEmail('org-1', { | ||
| startDate: new Date('2026-01-01'), | ||
| endDate: new Date('2026-01-31'), | ||
| }); | ||
|
|
||
| const getCall = fetchSpy.mock.calls[1]; | ||
| expect(getCall[1]).toEqual( | ||
| expect.objectContaining({ | ||
| method: 'GET', | ||
| aws: expect.objectContaining({ signQuery: true }), | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar typo: "will be generate" should be "will be generated".