Skip to content

Commit 4ee0528

Browse files
armruGabriFedi97mnencia
authored
feat: support DefaultAzureCredential authentication (#9468)
Adds support for the DefaultAzureCredential authentication mechanism Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Gabriele Fedi <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Co-authored-by: Gabriele Fedi <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]>
1 parent a2aba21 commit 4ee0528

7 files changed

Lines changed: 48 additions & 16 deletions

File tree

‎.wordlist-en-custom.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ DatabaseReclaimRetain
128128
DatabaseRoleRef
129129
DatabaseSpec
130130
DatabaseStatus
131+
DefaultAzureCredential
131132
DemotionToken
132133
DeploymentStrategy
133134
DevOps

‎api/v1/backup_types.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ type BarmanCredentials = barmanApi.BarmanCredentials
6161

6262
// AzureCredentials is the type for the credentials to be used to upload
6363
// files to Azure Blob Storage. The connection string contains every needed
64-
// information. If the connection string is not specified, we'll need the
65-
// storage account name and also one (and only one) of:
64+
// information. If the connection string is not specified, one (and only one)
65+
// of the following authentication methods must be specified:
6666
//
67-
// - storageKey
68-
// - storageSasToken
67+
// - storageKey (requires storageAccount)
68+
// - storageSasToken (requires storageAccount)
69+
// - inheritFromAzureAD (inheriting credentials from the pod environment)
70+
// - useDefaultAzureCredentials (using the default Azure authentication flow)
6971
//
70-
// - inheriting the credentials from the pod environment by setting inheritFromAzureAD to true
7172
// +kubebuilder:object:generate:=false
7273
type AzureCredentials = barmanApi.AzureCredentials
7374

‎config/crd/bases/postgresql.cnpg.io_backups.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ spec:
214214
- key
215215
- name
216216
type: object
217+
useDefaultAzureCredentials:
218+
description: |-
219+
Use the default Azure authentication flow, which includes DefaultAzureCredential.
220+
This allows authentication using environment variables and managed identities.
221+
type: boolean
217222
type: object
218223
backupId:
219224
description: The ID of the Barman backup

‎config/crd/bases/postgresql.cnpg.io_clusters.yaml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,11 @@ spec:
11161116
- key
11171117
- name
11181118
type: object
1119+
useDefaultAzureCredentials:
1120+
description: |-
1121+
Use the default Azure authentication flow, which includes DefaultAzureCredential.
1122+
This allows authentication using environment variables and managed identities.
1123+
type: boolean
11191124
type: object
11201125
data:
11211126
description: |-
@@ -2703,6 +2708,11 @@ spec:
27032708
- key
27042709
- name
27052710
type: object
2711+
useDefaultAzureCredentials:
2712+
description: |-
2713+
Use the default Azure authentication flow, which includes DefaultAzureCredential.
2714+
This allows authentication using environment variables and managed identities.
2715+
type: boolean
27062716
type: object
27072717
data:
27082718
description: |-

‎docs/src/appendixes/object_stores.md‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,15 @@ spec:
195195
[Azure Blob Storage](https://azure.microsoft.com/en-us/services/storage/blobs/) is the
196196
object storage service provided by Microsoft.
197197

198-
In order to access your storage account for backup and recovery of
199-
CloudNativePG managed databases, you will need one of the following
200-
combinations of credentials:
198+
CloudNativePG supports the following authentication methods for Azure Blob Storage:
201199

202200
- [Connection String](https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string#configure-a-connection-string-for-an-azure-storage-account)
203-
- Storage account name and [Storage account access key](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage)
204-
- Storage account name and [Storage account SAS Token](https://docs.microsoft.com/en-us/azure/storage/blobs/sas-service-create)
205-
- Storage account name and [Azure AD Workload Identity](https://azure.github.io/azure-workload-identity/docs/introduction.html)
206-
properly configured.
201+
- Storage Account Name + [Storage Account Access Key](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage)
202+
- Storage Account Name + [Storage Account SAS Token](https://docs.microsoft.com/en-us/azure/storage/blobs/sas-service-create)
203+
- [Azure AD Managed Identity](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview)
204+
- [Default Azure Credentials](https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python)
207205

208-
Using **Azure AD Workload Identity**, you can avoid saving the credentials into a Kubernetes Secret,
206+
Using **Azure AD Managed Identity**, you can avoid saving the credentials into a Kubernetes Secret,
209207
and have a Cluster configuration adding the `inheritFromAzureAD` as follows:
210208

211209
```yaml
@@ -220,6 +218,23 @@ spec:
220218
inheritFromAzureAD: true
221219
```
222220

221+
Alternatively, you can use the **Default Azure Credentials** authentication mechanism, which provides
222+
a seamless authentication experience by supporting multiple authentication methods including environment
223+
variables, managed identities, and Azure CLI credentials. Add the `useDefaultAzureCredentials` flag
224+
as follows:
225+
226+
```yaml
227+
apiVersion: postgresql.cnpg.io/v1
228+
kind: Cluster
229+
[...]
230+
spec:
231+
backup:
232+
barmanObjectStore:
233+
destinationPath: "<destination path here>"
234+
azureCredentials:
235+
useDefaultAzureCredentials: true
236+
```
237+
223238
On the other side, using both **Storage account access key** or **Storage account SAS Token**,
224239
the credentials need to be stored inside a Kubernetes Secret, adding data entries only when
225240
needed. The following command performs that:

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/avast/retry-go/v5 v5.0.0
1212
github.com/blang/semver v3.5.1+incompatible
1313
github.com/cheynewallace/tabby v1.1.1
14-
github.com/cloudnative-pg/barman-cloud v0.4.1-0.20251230211524-20b7e0e10b0f
14+
github.com/cloudnative-pg/barman-cloud v0.4.1-0.20260108104508-ced266c145f5
1515
github.com/cloudnative-pg/cnpg-i v0.3.1
1616
github.com/cloudnative-pg/machinery v0.3.3
1717
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
2020
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
2121
github.com/cheynewallace/tabby v1.1.1 h1:JvUR8waht4Y0S3JF17G6Vhyt+FRhnqVCkk8l4YrOU54=
2222
github.com/cheynewallace/tabby v1.1.1/go.mod h1:Pba/6cUL8uYqvOc9RkyvFbHGrQ9wShyrn6/S/1OYVys=
23-
github.com/cloudnative-pg/barman-cloud v0.4.1-0.20251230211524-20b7e0e10b0f h1:4/PwIQOwQSTIxuncGRn3pX2V9CRwl7zJNXOVWOMSCCU=
24-
github.com/cloudnative-pg/barman-cloud v0.4.1-0.20251230211524-20b7e0e10b0f/go.mod h1:qD0NtJOllNQbRB0MaleuHsZjFYaXtXfdg0HbFTbuHn0=
23+
github.com/cloudnative-pg/barman-cloud v0.4.1-0.20260108104508-ced266c145f5 h1:wPB7VTNgTv6t9sl4QYOBakmVTqHnOdKUht7Q3aL+uns=
24+
github.com/cloudnative-pg/barman-cloud v0.4.1-0.20260108104508-ced266c145f5/go.mod h1:qD0NtJOllNQbRB0MaleuHsZjFYaXtXfdg0HbFTbuHn0=
2525
github.com/cloudnative-pg/cnpg-i v0.3.1 h1:fKj8NoToWI11HUL2UWYJBpkVzmaTvbs3kDMo7wQF8RU=
2626
github.com/cloudnative-pg/cnpg-i v0.3.1/go.mod h1:glRDiJLJY51FY8ScJIv/OkaGJxFnojJkkNAqSy5XC6s=
2727
github.com/cloudnative-pg/machinery v0.3.3 h1:CaqXqLTJH9RrVv3R/YU0NmFaI/F18HLg2JfH3mQLcDk=

0 commit comments

Comments
 (0)