Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 43 additions & 44 deletions lib/utilities/serverAccessLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,62 +411,61 @@ function logServerAccess(req, res) {
pid: process.pid,

// Analytics
action: params.analyticsAction === undefined ? null : params.analyticsAction,
accountName: params.analyticsAccountName === undefined ? null : params.analyticsAccountName,
accountDisplayName: authInfo ? authInfo.getAccountDisplayName() : null,
userName: params.analyticsUserName === undefined ? null : params.analyticsUserName,
clientPort: req.socket.remotePort === undefined ? null : req.socket.remotePort,
httpMethod: req.method === undefined ? null : req.method,
bytesDeleted: params.analyticsBytesDeleted === undefined ? null : params.analyticsBytesDeleted,
bytesReceived: req.parsedContentLength === undefined ? null : req.parsedContentLength,
bodyLength: req.headers['content-length'] === undefined ? null : parseInt(req.headers['content-length'], 10),
contentLength: req.parsedContentLength === undefined ? null : req.parsedContentLength,
action: params.analyticsAction ?? undefined,
accountName: params.analyticsAccountName ?? undefined,
userName: params.analyticsUserName ?? undefined,
httpMethod: req.method ?? undefined,
bytesDeleted: params.analyticsBytesDeleted ?? undefined,
bytesReceived: req.parsedContentLength ?? undefined,
bodyLength: req.headers['content-length'] !== undefined
? parseInt(req.headers['content-length'], 10)
: undefined,
contentLength: req.parsedContentLength ?? undefined,
// eslint-disable-next-line camelcase
elapsed_ms: calculateElapsedMS(params.startTime, params.onCloseEndTime),
httpURL: req.url === undefined ? null : req.url,
elapsed_ms: calculateElapsedMS(params.startTime, params.onCloseEndTime) ?? undefined,

// AWS access server logs fields https://docs.aws.amazon.com/AmazonS3/latest/userguide/LogFormat.html
startTime: timestampToDateTime643(params.startTimeUnixMS), // AWS "Time" field
requester: getRequester(authInfo),
startTime: timestampToDateTime643(params.startTimeUnixMS) ?? undefined, // AWS "Time" field
requester: getRequester(authInfo) ?? undefined,
operation: getOperation(req),
requestURI: getURI(req),
errorCode: errorCode === undefined ? null : errorCode,
objectSize: getObjectSize(req, res),
totalTime: calculateTotalTime(params.startTime, params.onFinishEndTime),
turnAroundTime: calculateTurnAroundTime(params.startTurnAroundTime, endTurnAroundTime),
referer: req.headers.referer === undefined ? null : req.headers.referer,
userAgent: req.headers['user-agent'] === undefined ? null : req.headers['user-agent'],
versionID: !req.query ? null : req.query.versionId === undefined ? null : req.query.versionId,
signatureVersion: authInfo ? authInfo.getAuthVersion() : null,
cipherSuite: req.socket.encrypted ? req.socket.getCipher()['standardName'] : null,
authenticationType: authInfo ? authInfo.getAuthType() : null,
hostHeader: req.headers.host === undefined ? null : req.headers.host,
tlsVersion: req.socket.encrypted ? req.socket.getCipher()['version'] : null,
aclRequired: null, // TODO: CLDSRV-774
// hostID: null, // NOT IMPLEMENTED
// accessPointARN: null, // NOT IMPLEMENTED
requestURI: getURI(req) ?? undefined,
errorCode: errorCode ?? undefined,
objectSize: getObjectSize(req, res) ?? undefined,
totalTime: calculateTotalTime(params.startTime, params.onFinishEndTime) ?? undefined,
turnAroundTime: calculateTurnAroundTime(params.startTurnAroundTime, endTurnAroundTime) ?? undefined,
referer: req.headers.referer ?? undefined,
userAgent: req.headers['user-agent'] ?? undefined,
versionID: req.query?.versionId ?? undefined,
signatureVersion: authInfo?.getAuthVersion() ?? undefined,
cipherSuite: req.socket.encrypted ? req.socket.getCipher()['standardName'] : undefined,
authenticationType: authInfo?.getAuthType() ?? undefined,
hostHeader: req.headers.host ?? undefined,
tlsVersion: req.socket.encrypted ? req.socket.getCipher()['version'] : undefined,
aclRequired: undefined, // TODO: CLDSRV-774
// hostID: undefined, // NOT IMPLEMENTED
// accessPointARN: undefined, // NOT IMPLEMENTED

// Shared between AWS access server logs and Analytics logs
bucketOwner: params.bucketOwner === undefined ? null : params.bucketOwner,
bucketName: params.bucketName === undefined ? null : params.bucketName, // AWS "Bucket" field
bucketOwner: params.bucketOwner ?? undefined,
bucketName: params.bucketName ?? undefined, // AWS "Bucket" field
// eslint-disable-next-line camelcase
req_id: requestID === undefined ? null : requestID, // AWS "Request ID" field
bytesSent: getBytesSent(res, bytesSent),
clientIP: getRemoteIPFromRequest(req), // AWS 'Remote IP' field
httpCode: res.statusCode === undefined ? null : res.statusCode, // AWS "HTTP Status" field
objectKey: params.objectKey === undefined ? null : params.objectKey, // AWS "Key" field
req_id: requestID ?? undefined, // AWS "Request ID" field
bytesSent: getBytesSent(res, bytesSent) ?? undefined,
clientIP: getRemoteIPFromRequest(req) ?? undefined, // AWS 'Remote IP' field
httpCode: res.statusCode ?? undefined, // AWS "HTTP Status" field
objectKey: params.objectKey ?? undefined, // AWS "Key" field

// Scality server access logs extra fields
logFormatVersion: SERVER_ACCESS_LOG_FORMAT_VERSION,
loggingEnabled: params.enabled,
loggingTargetBucket: params.loggingEnabled ? params.loggingEnabled.TargetBucket : null,
loggingTargetPrefix: params.loggingEnabled ? params.loggingEnabled.TargetPrefix : null,
awsAccessKeyID: authInfo ? authInfo.getAccessKey() : null,
raftSessionID: params.raftSessionID === undefined ? null : params.raftSessionID,
loggingEnabled: params.enabled ?? undefined,
loggingTargetBucket: params.loggingEnabled?.TargetBucket ?? undefined,
loggingTargetPrefix: params.loggingEnabled?.TargetPrefix ?? undefined,
awsAccessKeyID: authInfo?.getAccessKey() ?? undefined,
raftSessionID: params.raftSessionID ?? undefined,

// Rate Limiting fields (only present when rate limited)
rateLimited: params.rateLimited,
rateLimitSource: params.rateLimitSource,
rateLimited: params.rateLimited ?? undefined,
rateLimitSource: params.rateLimitSource ?? undefined,
})}\n`);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenko/cloudserver",
"version": "9.2.13",
"version": "9.2.14",
"description": "Zenko CloudServer, an open-source Node.js implementation of a server handling the Amazon S3 protocol",
"main": "index.js",
"engines": {
Expand Down
55 changes: 5 additions & 50 deletions schema/server_access_log.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,10 @@
"description": "Requester account display name.",
"type": ["string", "null"]
},
"accountDisplayName": {
"description": "Requester account display name.",
"type": ["string", "null"]
},
"userName": {
"description": "Requester IAM display name, or null if the requester is not an IAM user.",
"type": ["string", "null"]
},
"clientPort": {
"description": "Requester remote connection port.",
"type": "integer",
"maximum": 65535,
"minimum": 1
},
"httpMethod": {
"description": "Request HTTP method.",
"type": "string",
Expand Down Expand Up @@ -71,10 +61,6 @@
"type": "number",
"minimum": 0
},
"httpURL": {
"description": "Request URL string. This contains only the URL that is present in the actual HTTP request.",
"type": "string"
},
"startTime": {
"description": "Timestamp formatted as: 'seconds.milliseconds', recorded when the server first routes the request. Represents the AWS server access log 'Time' field. String type compatible with Clickhouse DateTime64(3) type.",
"type": "string"
Expand Down Expand Up @@ -211,47 +197,16 @@
"time",
"hostname",
"pid",
"action",
"accountName",
"accountDisplayName",
"userName",
"clientPort",
"operation",
"logFormatVersion",
"httpMethod",
"bytesDeleted",
"bytesReceived",
"bodyLength",
"contentLength",
"elapsed_ms",
"httpURL",
"startTime",
"requester",
"operation",
"requestURI",
"errorCode",
"objectSize",
"elapsed_ms",
"totalTime",
"turnAroundTime",
"referer",
"userAgent",
"versionID",
"signatureVersion",
"cipherSuite",
"authenticationType",
"requestURI",
"hostHeader",
"tlsVersion",
"aclRequired",
"bucketOwner",
"bucketName",
"req_id",
"bytesSent",
"clientIP",
"httpCode",
"objectKey",
"logFormatVersion",
"loggingEnabled",
"loggingTargetBucket",
"loggingTargetPrefix",
"awsAccessKeyID",
"raftSessionID"
"loggingEnabled"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ describe('Server Access Logs - File Output', async () => {
// 'pid': '', // UNKNOWN
'action': 'REQUIRED', // DYNAMIC
'accountName': 'Bart', // STATIC
'accountDisplayName': 'Bart', // STATIC
'userName': null, // TODO: Add test with IAM user to get a non null userName.
// 'clientPort': '', // UNKNOWN
'httpMethod': 'REQUIRED', // DYNAMIC
Expand Down Expand Up @@ -2642,6 +2641,12 @@ describe('Server Access Logs - File Output', async () => {

const properties = operation.expected[operationIdx];
for (const [key, val] of Object.entries(properties)) {
if (val === null) {
// Verify that null fields are omitted (not present in log)
assert.strictEqual(key in logEntries[logEntryIdx], false,
`Field ${key} should be omitted when null, action ${properties.action}`);
continue;
}
assert.strictEqual(logEntries[logEntryIdx][key], val,
`Invalid value for ${key}, action ${properties.action}`);
}
Expand Down
Loading
Loading