From: qinruyao (@qinruyao) <noreply+qinruyao@github.com>
To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>
Subject: Re: [pgbackrest/pgbackrest] PR #2896: Support encryption context for S3 server-side encryption using KMS.
Date: Fri, 20 Nov 2026 00:52:34 +0000
Message-ID: <gh-pgbackrest-pgbackrest-2896-c7026856542@github.com> (raw)
In-Reply-To: <gh-pgbackrest-pgbackrest-2896@github.com>
References: <gh-pgbackrest-pgbackrest-2896@github.com>
> I made a few changes (see commit history). The important ones are:
>
> * Rename the option.
> * Include header only for writable storage.
>
> Just checking -- you have tested this against real S3? Even if you have, would be good to do one final test before this gets committed.
@dwsteele Thanks so much for the careful review and updates! Yes, I've verified the new changes with expected test result - see the test cases and logs below. Let me know if you have any other questions.
**1. run patched pgbackrest with encryption context configured (after the KMS key creation and policy setup)**
**Test result:** backup succeeded, and aws cloudtrail event (attached below) confirmed the correct encryption context were used.
**2. run patched pgbackrest with the same key without s3-kms-context (and one wrong kms context entry) configured on the same cluster**
**Test result:** backup failed access denied error which is expected
```
AccessDenied: no identity-based policy allows the kms:Decrypt action
backup command end: aborted with exception [039]
```
**3. run not patched pgbackrest with the same key on a different cluster**
**Test result:** backup failed with AccessDenied error.
```
AccessDenied: User:
arn:aws:sts::083332610557:assumed-role/s3-operations/pgBackRest
is not authorized to perform: kms:GenerateDataKey
on resource:
arn:aws:kms::key/keyid, because no resource-based policy allows the kms:GenerateDataKey action
```
**redacted Aws cloudtrail event**
```
{
"eventVersion": "1.11",
"userIdentity": {
"type": "AWSAccount",
"principalId": ":pgBackRest",
"accountId": "",
"invokedBy": "fas.s3.amazonaws.com"
},
"eventSource": "kms.amazonaws.com",
"eventName": "Decrypt",
"awsRegion": "-2",
"sourceIPAddress": ".s3.amazonaws.com",
"userAgent": ".s3.amazonaws.com",
"requestParameters": {
"encryptionAlgorithm": "SYMMETRIC_DEFAULT",
**"encryptionContext": {
"tenant_id": "tenant-01",
"cluster_id": "pg-prod-01",**
"aws:s3:arn": "arn:aws:s3:::backups-bzt9/pgbackrest/postgres-operator/s3kmsctx-1119/repo2/backup/db/20261120-000445F/backup.manifest.copy"
}
},
"responseElements": null,
"additionalEventData": {
"keyMaterialId": ""
},
"requestID": "ecb7b0fa-e0a7-4785-9822-f10a902f7737",
"eventID": "cf39a620-b67b-39f0-81d3-3ce756d4fc79",
"readOnly": true,
"resources": [
{
"accountId": "",
"type": "AWS::KMS::Key",
"ARN": "arn:aws:kms:ap-southeast-2::key/07fe82be"
}
],
"eventType": "AwsApiCall",
"managementEvent": true,
"recipientAccountId": "",
"sharedEventID": "9a4",
"eventCategory": "Management"
}