Skip to content

Commit 505e51e

Browse files
lpcoxCopilot
andauthored
feat: include api-proxy token logs in firewall audit artifact (#1549)
Move api-proxy logs from a sibling directory of proxyLogsDir to a subdirectory inside it. When --proxy-logs-dir is set (e.g., by gh-aw to /tmp/gh-aw/sandbox/firewall/logs), the api-proxy logs now land at .../logs/api-proxy-logs/ instead of .../api-proxy-logs/. This means the existing firewall-audit-logs artifact upload automatically captures token-usage.jsonl without any workflow changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 850e7a0 commit 505e51e

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/docker-manager.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ describe('docker-manager', () => {
17591759
expect(squid.volumes).toContain('/tmp/awf-test/squid-logs:/var/log/squid:rw');
17601760
});
17611761

1762-
it('should use sibling api-proxy-logs directory when proxyLogsDir is specified', () => {
1762+
it('should use api-proxy-logs subdirectory inside proxyLogsDir when specified', () => {
17631763
const config: WrapperConfig = {
17641764
...mockConfig,
17651765
proxyLogsDir: '/custom/proxy/logs',
@@ -1772,7 +1772,7 @@ describe('docker-manager', () => {
17721772
});
17731773
const apiProxy = result.services['api-proxy'];
17741774

1775-
expect(apiProxy.volumes).toContain('/custom/proxy/api-proxy-logs:/var/log/api-proxy:rw');
1775+
expect(apiProxy.volumes).toContain('/custom/proxy/logs/api-proxy-logs:/var/log/api-proxy:rw');
17761776
});
17771777

17781778
it('should use workDir/api-proxy-logs when proxyLogsDir is not specified', () => {
@@ -2711,7 +2711,7 @@ describe('docker-manager', () => {
27112711
expect(fs.existsSync(proxyLogsDir)).toBe(true);
27122712
});
27132713

2714-
it('should create api-proxy-logs sibling directory when proxyLogsDir is specified', async () => {
2714+
it('should create api-proxy-logs subdirectory inside proxyLogsDir when specified', async () => {
27152715
const proxyLogsDir = path.join(testDir, 'custom-proxy-logs');
27162716
const config: WrapperConfig = {
27172717
allowedDomains: ['github.com'],
@@ -2728,8 +2728,8 @@ describe('docker-manager', () => {
27282728
// May fail after writing configs
27292729
}
27302730

2731-
// Verify api-proxy-logs sibling directory was created
2732-
const apiProxyLogsDir = path.join(testDir, 'api-proxy-logs');
2731+
// Verify api-proxy-logs subdirectory was created inside proxyLogsDir
2732+
const apiProxyLogsDir = path.join(proxyLogsDir, 'api-proxy-logs');
27332733
expect(fs.existsSync(apiProxyLogsDir)).toBe(true);
27342734
});
27352735

@@ -3253,11 +3253,11 @@ describe('docker-manager', () => {
32533253
}
32543254
});
32553255

3256-
it('should chmod api-proxy-logs sibling when proxyLogsDir is specified', async () => {
3256+
it('should chmod api-proxy-logs subdirectory when proxyLogsDir is specified', async () => {
32573257
// proxyLogsDir must be OUTSIDE workDir since cleanup deletes workDir
32583258
const externalDir = fs.mkdtempSync(path.join(os.tmpdir(), 'awf-proxy-logs-test-'));
32593259
const proxyLogsDir = path.join(externalDir, 'proxy-logs');
3260-
const apiProxyLogsDir = path.join(externalDir, 'api-proxy-logs');
3260+
const apiProxyLogsDir = path.join(proxyLogsDir, 'api-proxy-logs');
32613261
fs.mkdirSync(proxyLogsDir, { recursive: true });
32623262
fs.mkdirSync(apiProxyLogsDir, { recursive: true });
32633263
fs.writeFileSync(path.join(proxyLogsDir, 'access.log'), 'proxy log content');
@@ -3266,7 +3266,7 @@ describe('docker-manager', () => {
32663266
try {
32673267
await cleanup(testDir, false, proxyLogsDir);
32683268

3269-
// Verify chmod was called on both proxyLogsDir and api-proxy-logs sibling
3269+
// Verify chmod was called on both proxyLogsDir and api-proxy-logs subdirectory
32703270
expect(mockExecaSync).toHaveBeenCalledWith('chmod', ['-R', 'a+rX', proxyLogsDir]);
32713271
expect(mockExecaSync).toHaveBeenCalledWith('chmod', ['-R', 'a+rX', apiProxyLogsDir]);
32723272
} finally {

src/docker-manager.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,11 @@ export function generateDockerCompose(
366366
// Squid logs path: use proxyLogsDir if specified (direct write), otherwise workDir/squid-logs
367367
const squidLogsPath = config.proxyLogsDir || `${config.workDir}/squid-logs`;
368368

369-
// API proxy logs path: if proxyLogsDir is specified, write to sibling directory
369+
// API proxy logs path: if proxyLogsDir is specified, write inside it as a subdirectory
370+
// so that token-usage.jsonl is included in the firewall-audit-logs artifact automatically.
370371
// Otherwise, write to workDir/api-proxy-logs (will be moved to /tmp after cleanup)
371372
const apiProxyLogsPath = config.proxyLogsDir
372-
? path.join(path.dirname(config.proxyLogsDir), 'api-proxy-logs')
373+
? path.join(config.proxyLogsDir, 'api-proxy-logs')
373374
: path.join(config.workDir, 'api-proxy-logs');
374375

375376
// Build Squid volumes list
@@ -1598,11 +1599,12 @@ export async function writeConfigs(config: WrapperConfig): Promise<void> {
15981599
logger.debug(`Squid logs directory created at: ${squidLogsDir}`);
15991600

16001601
// Create api-proxy logs directory for persistence
1601-
// If proxyLogsDir is specified, write to sibling directory (timeout-safe)
1602+
// If proxyLogsDir is specified, write inside it as a subdirectory (timeout-safe,
1603+
// and included in the firewall-audit-logs artifact upload automatically)
16021604
// Otherwise, write to workDir/api-proxy-logs (will be moved to /tmp after cleanup)
16031605
// Note: API proxy runs as user 'apiproxy' (non-root)
16041606
const apiProxyLogsDir = config.proxyLogsDir
1605-
? path.join(path.dirname(config.proxyLogsDir), 'api-proxy-logs')
1607+
? path.join(config.proxyLogsDir, 'api-proxy-logs')
16061608
: path.join(config.workDir, 'api-proxy-logs');
16071609
if (!fs.existsSync(apiProxyLogsDir)) {
16081610
fs.mkdirSync(apiProxyLogsDir, { recursive: true, mode: 0o777 });
@@ -2146,9 +2148,9 @@ export async function cleanup(workDir: string, keepFiles: boolean, proxyLogsDir?
21462148

21472149
// Preserve api-proxy logs before cleanup
21482150
if (proxyLogsDir) {
2149-
// Logs were written directly to sibling of proxyLogsDir during runtime (timeout-safe)
2151+
// Logs were written inside proxyLogsDir/api-proxy-logs during runtime (timeout-safe)
21502152
// Just fix permissions so they're readable
2151-
const apiProxyLogsDir = path.join(path.dirname(proxyLogsDir), 'api-proxy-logs');
2153+
const apiProxyLogsDir = path.join(proxyLogsDir, 'api-proxy-logs');
21522154
if (fs.existsSync(apiProxyLogsDir)) {
21532155
try {
21542156
execa.sync('chmod', ['-R', 'a+rX', apiProxyLogsDir]);

0 commit comments

Comments
 (0)