Skip to content
Open
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
1 change: 1 addition & 0 deletions containers/Dockerfile.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN go mod download
COPY ../cmd/manager/main.go cmd/manager/main.go
COPY ../api/ api/
COPY ../internal/ internal/
COPY ../pkg/ pkg/

ENV GOCACHE=/root/.cache/go-build
ENV GOMODCACHE=/go/pkg/mod
Expand Down
1 change: 1 addition & 0 deletions containers/Dockerfile.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ENV GOMODCACHE=/go/pkg/mod
COPY ../cmd/manager/main.go cmd/manager/main.go
COPY ../api/ api/
COPY ../internal/ internal/
COPY ../pkg/ pkg/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
15 changes: 15 additions & 0 deletions internal/cnpgi/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ SPDX-License-Identifier: Apache-2.0
package common

import (
"context"
"fmt"
"path"
"strings"

barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
"github.com/cloudnative-pg/barman-cloud/pkg/command"

apiv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
pluginmetadata "github.com/cloudnative-pg/plugin-barman-cloud/pkg/metadata"
)

// TODO: refactor.
Expand Down Expand Up @@ -97,3 +101,14 @@ func MergeEnv(env []string, incomingEnv []string) []string {
func BuildCertificateFilePath(objectStoreName string) string {
return path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName)
}

// ContextWithProviderOptions enriches the context with cloud service provider specific options
// based on the ObjectStore resource
func ContextWithProviderOptions(ctx context.Context, objectStore apiv1.ObjectStore) context.Context {
if objectStore.GetAnnotations()[pluginmetadata.UseDefaultAzureCredentialAnnotationName] ==
pluginmetadata.UseDefaultAzureCredentialTrueValue {
return command.ContextWithDefaultAzureCredentials(ctx, true)
}

return ctx
}
2 changes: 2 additions & 0 deletions internal/cnpgi/common/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func (w WALServiceImplementation) Archive(
return nil, err
}

ctx = ContextWithProviderOptions(ctx, objectStore)

envArchive, err := barmanCredentials.EnvSetCloudCredentialsAndCertificates(
ctx,
w.Client,
Expand Down
2 changes: 2 additions & 0 deletions internal/cnpgi/instance/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func (b BackupServiceImplementation) Backup(
return nil, err
}

ctx = common.ContextWithProviderOptions(ctx, objectStore)

if err := fileutils.EnsureDirectoryExists(postgres.BackupTemporaryDirectory); err != nil {
contextLogger.Error(err, "Cannot create backup temporary directory", "err", err)
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions internal/cnpgi/instance/retention.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (c *CatalogMaintenanceRunnable) cycle(ctx context.Context) (time.Duration,
return 0, err
}

ctx = common.ContextWithProviderOptions(ctx, barmanObjectStore)

if err := c.maintenance(ctx, &cluster, &barmanObjectStore); err != nil {
return 0, err
}
Expand Down
4 changes: 3 additions & 1 deletion internal/cnpgi/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (impl JobHookImpl) Restore(
}

if err := impl.checkBackupDestination(
ctx,
common.ContextWithProviderOptions(ctx, targetObjectStore),
configuration.Cluster,
&targetObjectStore.Spec.Configuration,
targetObjectStore.Name,
Expand All @@ -118,6 +118,8 @@ func (impl JobHookImpl) Restore(
}
}

ctx = common.ContextWithProviderOptions(ctx, recoveryObjectStore)

// Detect the backup to recover
backup, env, err := loadBackupObjectFromExternalCluster(
ctx,
Expand Down
2 changes: 2 additions & 0 deletions pkg/metadata/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package metadata provides metadata utilities for the Barman Cloud plugin
package metadata
15 changes: 15 additions & 0 deletions pkg/metadata/labels_annotations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package metadata

// MetadataNamespace is the namespace used for the Barman Cloud plugin metadata
const MetadataNamespace = "barmancloud.cnpg.io"

const (
// UseDefaultAzureCredentialAnnotationName is an annotation that can be set
// on an ObjectStore resource to enable the authentication to Azure via DefaultAzureCredential.
// This is meant to be used with inheritFromAzureAD enabled.
UseDefaultAzureCredentialAnnotationName = MetadataNamespace + "/useDefaultAzureCredential"

// UseDefaultAzureCredentialTrueValue is the value for the annotation
// barmancloud.cnpg.io/useDefaultAzureCredential to enable the DefaultAzureCredentials auth mechanism.
UseDefaultAzureCredentialTrueValue = "true"
)
22 changes: 22 additions & 0 deletions web/docs/object_stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ Barman Cloud supports the following authentication methods:
- Storage Account Name + [Access Key](https://learn.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage)
- Storage Account Name + [SAS Token](https://learn.microsoft.com/en-us/azure/storage/blobs/sas-service-create)
- [Azure AD Workload Identity](https://azure.github.io/azure-workload-identity/docs/introduction.html)
- [DefaultAzureCredential](https://learn.microsoft.com/en-us/azure/developer/go/sdk/authentication/credential-chains#defaultazurecredential-overview)

### Azure AD Workload Identity

Expand All @@ -252,6 +253,27 @@ spec:
[...]
```

### DefaultAzureCredential

To authenticate using `DefaultAzureCredential`, set the annotation
`barmancloud.cnpg.io/useDefaultAzureCredential="true"` on the ObjectStore in
conjunction with the `.spec.configuration.inheritFromAzureAD` option:

```yaml
apiVersion: barmancloud.cnpg.io/v1
kind: ObjectStore
metadata:
name: azure-store
annotations:
barmancloud.cnpg.io/useDefaultAzureCredential: "true"
spec:
configuration:
destinationPath: "<destination path here>"
azureCredentials:
inheritFromAzureAD: true
[...]
```

### Access Key, SAS Token, or Connection String

Store credentials in a Kubernetes secret:
Expand Down