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
11 changes: 10 additions & 1 deletion .github/workflows/test-go-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ jobs:
if [[ "${{ inputs.suite }}" == "main" ]]; then
echo "CI_TEST_PKG=main" >> $GITHUB_ENV
echo "NEED_DOCKER=1" >> $GITHUB_ENV
echo "DOCKER_COMMAND=${{ env.DOCKER_COMMAND }} localstack" >> $GITHUB_ENV
echo "DOCKER_COMMAND=${{ env.DOCKER_COMMAND }} localstack azurite" >> $GITHUB_ENV
echo "AZURE_STORAGE_TEST=1" >> $GITHUB_ENV
elif [[ "${{ inputs.suite }}" == "fast" ]]; then
# DO NOT add any dependencies in this test suite.
echo "CI_TEST_PKG=${{ inputs.suite }}" >> $GITHUB_ENV
Expand Down Expand Up @@ -254,6 +255,14 @@ jobs:
echo "Waiting for LocalStack..."
timeout 60 bash -c 'until curl -sf http://localhost:4566/_localstack/health; do sleep 2; done'
echo "LocalStack is ready"

- name: Wait for Azurite
if: ${{ env.NEED_DOCKER && contains(env.DOCKER_COMMAND, 'azurite') }}
run: |
echo "Waiting for Azurite..."
# Azurite has no health endpoint; omitting -f means any HTTP response (even 400) counts as "up".
timeout 60 bash -c 'until curl -s -o /dev/null http://127.0.0.1:10000/devstoreaccount1; do sleep 2; done'
echo "Azurite is ready"

- name: Generate test schema
if: ${{ env.GENERATE_TEST_SCHEMA }}
Expand Down
1 change: 1 addition & 0 deletions changes/azure-blob-storage-software-installers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added Azure Blob Storage support (via new `FLEET_CLOUD_STORAGE_AZURE_FILES_*` environment variables) as an alternative to S3 for storing software installers, bootstrap packages, software title icons, and org logos.
238 changes: 157 additions & 81 deletions cmd/fleet/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
configpkg "github.com/fleetdm/fleet/v4/server/config"
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
licensectx "github.com/fleetdm/fleet/v4/server/contexts/license"
"github.com/fleetdm/fleet/v4/server/datastore/azure"
"github.com/fleetdm/fleet/v4/server/datastore/cached_mysql"
"github.com/fleetdm/fleet/v4/server/datastore/failing"
"github.com/fleetdm/fleet/v4/server/datastore/filesystem"
Expand Down Expand Up @@ -543,7 +544,11 @@ func runServeCmd(cmd *cobra.Command, configManager configpkg.Manager, debug, dev
initFatal(err, "initializing ee android service")
}

orgLogoStore := initOrgLogoStore(ctx, config.S3, mds, logger)
// Must run before initOrgLogoStore, which picks the object store backend regardless of license tier.
config.ValidateSoftwareInstallersBackend(initFatal)
softwareInstallersBackend, _ := config.SoftwareInstallersBackend()

orgLogoStore := initOrgLogoStore(ctx, softwareInstallersBackend, config.S3, config.CloudStorage.Azure, mds, logger)

svc, err = service.NewService(
ctx,
Expand Down Expand Up @@ -589,84 +594,19 @@ func runServeCmd(cmd *cobra.Command, configManager configpkg.Manager, debug, dev
if license.IsPremium() {
hydrantService := est.NewService(est.WithLogger(logger))
profileMatcher := apple_mdm.NewProfileMatcher(redisPool)
if config.S3.SoftwareInstallersBucket != "" {
if config.S3.BucketsAndPrefixesMatch() {
logger.WarnContext(ctx,
"the S3 buckets and prefixes for carves and software installers appear to be identical, this can cause issues")
}
// Extract the CloudFront URL signer before creating the S3 stores.
config.S3.ValidateCloudFrontURL(initFatal)
config.S3.ValidateSoftwareInstallersSignedURL(initFatal)
if config.S3.SoftwareInstallersCloudFrontURLSigningPrivateKey != "" {
// Strip newlines from private key
signingPrivateKey := strings.ReplaceAll(config.S3.SoftwareInstallersCloudFrontURLSigningPrivateKey, "\\n", "\n")
privateKey, err := cryptoutil.ParsePrivateKey([]byte(signingPrivateKey),
"CloudFront URL signing private key")
if err != nil {
initFatal(err, "parsing CloudFront URL signing private key")
}
var ok bool
config.S3.SoftwareInstallersCloudFrontSigner, ok = privateKey.(crypto.Signer)
if !ok {
initFatal(errors.New("CloudFront URL signing private key is not a crypto.Signer"),
"parsing CloudFront URL signing private key")
}
}
store, err := s3.NewSoftwareInstallerStore(config.S3)
if err != nil {
initFatal(err, "initializing S3 software installer store")
}
softwareInstallStore = store
logger.InfoContext(ctx, "using S3 software installer store", "bucket", config.S3.SoftwareInstallersBucket)

bstore, err := s3.NewBootstrapPackageStore(config.S3)
if err != nil {
initFatal(err, "initializing S3 bootstrap package store")
}
bootstrapPackageStore = bstore
logger.InfoContext(ctx, "using S3 bootstrap package store", "bucket", config.S3.SoftwareInstallersBucket)

softwareTitleIconStore, err = s3.NewSoftwareTitleIconStore(config.S3)
if err != nil {
initFatal(err, "initializing S3 software title icon store")
}
logger.InfoContext(ctx, "using S3 software title icon store", "bucket", config.S3.SoftwareInstallersBucket)

stagedUploadStore, err = s3.NewStagedUploadStore(config.S3)
if err != nil {
initFatal(err, "initializing S3 staged upload store")
}
} else {
installerDir := os.TempDir()
if dir := os.Getenv("FLEET_SOFTWARE_INSTALLER_STORE_DIR"); dir != "" {
installerDir = dir
}
store, err := filesystem.NewSoftwareInstallerStore(installerDir)
if err != nil {
logger.ErrorContext(ctx, "failed to configure local filesystem software installer store", "err", err)
softwareInstallStore = failing.NewFailingSoftwareInstallerStore()
} else {
softwareInstallStore = store
logger.InfoContext(ctx,
"using local filesystem software installer store, this is not suitable for multi-container deployments", "directory",
installerDir)
}

iconDir := os.TempDir()
if dir := os.Getenv("FLEET_SOFTWARE_TITLE_ICON_STORE_DIR"); dir != "" {
iconDir = dir
}
iconStore, err := filesystem.NewSoftwareTitleIconStore(iconDir)
if err != nil {
logger.ErrorContext(ctx, "failed to configure local filesystem software title icon store", "err", err)
softwareTitleIconStore = failing.NewFailingSoftwareTitleIconStore()
} else {
softwareTitleIconStore = iconStore
logger.WarnContext(ctx,
"using local filesystem software title icon store, this is not suitable for production use", "directory",
iconDir)
}
var stores softwareInstallerStores
switch softwareInstallersBackend {
case configpkg.StorageBackendAzure:
stores = newAzureSoftwareInstallerStores(ctx, config.CloudStorage.Azure, logger)
case configpkg.StorageBackendS3:
stores = newS3SoftwareInstallerStores(ctx, &config, logger)
default:
stores = newFilesystemSoftwareInstallerStores(ctx, logger)
}
softwareInstallStore = stores.installer
bootstrapPackageStore = stores.bootstrap
softwareTitleIconStore = stores.icon
stagedUploadStore = stores.stagedUpload

distributedLock = redis_lock.NewLock(redisPool)
svc, err = eeservice.NewService(
Expand Down Expand Up @@ -1320,10 +1260,18 @@ func createChartBoundedContext(dbConns *common_mysql.DBConnections, svc fleet.Se
}

// initOrgLogoStore builds the OrgLogoStore implementation appropriate for the deployment:
// - S3 when a software installers bucket is configured (shared bucket, distinct prefix)
// - the configured object store backend (S3 or Azure Blob) when one is selected for the software installers group
// - otherwise a database-backed store, so custom org logos work without object storage or a writable filesystem.
func initOrgLogoStore(ctx context.Context, s3Config configpkg.S3Config, ds *mysql.Datastore, logger *slog.Logger) fleet.OrgLogoStore {
if s3Config.SoftwareInstallersBucket != "" {
func initOrgLogoStore(ctx context.Context, backend configpkg.StorageBackend, s3Config configpkg.S3Config, azureConfig configpkg.AzureConfig, ds *mysql.Datastore, logger *slog.Logger) fleet.OrgLogoStore {
switch backend {
case configpkg.StorageBackendAzure:
store, err := azure.NewOrgLogoStore(azureConfig)
if err != nil {
initFatal(err, "initializing Azure Blob org logo store")
}
logger.InfoContext(ctx, "using Azure Blob org logo store", "container", azureConfig.SoftwareInstallersContainer)
return store
case configpkg.StorageBackendS3:
store, err := s3.NewOrgLogoStore(s3Config)
if err != nil {
initFatal(err, "initializing S3 org logo store")
Expand All @@ -1335,6 +1283,134 @@ func initOrgLogoStore(ctx context.Context, s3Config configpkg.S3Config, ds *mysq
return ds.NewOrgLogoStore()
}

// softwareInstallerStores groups the stores backing the software installers
// group for a given storage backend. Stores a backend doesn't support are nil.
type softwareInstallerStores struct {
installer fleet.SoftwareInstallerStore
bootstrap fleet.MDMBootstrapPackageStore
icon fleet.SoftwareTitleIconStore
stagedUpload fleet.StagedUploadStore
}

func newAzureSoftwareInstallerStores(ctx context.Context, cfg configpkg.AzureConfig, logger *slog.Logger) softwareInstallerStores {
var stores softwareInstallerStores

installer, err := azure.NewSoftwareInstallerStore(cfg)
if err != nil {
initFatal(err, "initializing Azure Blob software installer store")
}
stores.installer = installer
logger.InfoContext(ctx, "using Azure Blob software installer store", "container", cfg.SoftwareInstallersContainer)

bstore, err := azure.NewBootstrapPackageStore(cfg)
if err != nil {
initFatal(err, "initializing Azure Blob bootstrap package store")
}
stores.bootstrap = bstore
logger.InfoContext(ctx, "using Azure Blob bootstrap package store", "container", cfg.SoftwareInstallersContainer)

stores.icon, err = azure.NewSoftwareTitleIconStore(cfg)
if err != nil {
initFatal(err, "initializing Azure Blob software title icon store")
}
logger.InfoContext(ctx, "using Azure Blob software title icon store", "container", cfg.SoftwareInstallersContainer)

return stores
}

// newS3SoftwareInstallerStores also stores the parsed CloudFront URL signer in
// the provided config, as the service layer reads it from there.
func newS3SoftwareInstallerStores(ctx context.Context, config *configpkg.FleetConfig, logger *slog.Logger) softwareInstallerStores {
var stores softwareInstallerStores

if config.S3.BucketsAndPrefixesMatch() {
logger.WarnContext(ctx,
"the S3 buckets and prefixes for carves and software installers appear to be identical, this can cause issues")
}
// Extract the CloudFront URL signer before creating the S3 stores.
config.S3.ValidateCloudFrontURL(initFatal)
config.S3.ValidateSoftwareInstallersSignedURL(initFatal)
if config.S3.SoftwareInstallersCloudFrontURLSigningPrivateKey != "" {
// Strip newlines from private key
signingPrivateKey := strings.ReplaceAll(config.S3.SoftwareInstallersCloudFrontURLSigningPrivateKey, "\\n", "\n")
privateKey, err := cryptoutil.ParsePrivateKey([]byte(signingPrivateKey),
"CloudFront URL signing private key")
if err != nil {
initFatal(err, "parsing CloudFront URL signing private key")
}
var ok bool
config.S3.SoftwareInstallersCloudFrontSigner, ok = privateKey.(crypto.Signer)
if !ok {
initFatal(errors.New("CloudFront URL signing private key is not a crypto.Signer"),
"parsing CloudFront URL signing private key")
}
}
installer, err := s3.NewSoftwareInstallerStore(config.S3)
if err != nil {
initFatal(err, "initializing S3 software installer store")
}
stores.installer = installer
logger.InfoContext(ctx, "using S3 software installer store", "bucket", config.S3.SoftwareInstallersBucket)

bstore, err := s3.NewBootstrapPackageStore(config.S3)
if err != nil {
initFatal(err, "initializing S3 bootstrap package store")
}
stores.bootstrap = bstore
logger.InfoContext(ctx, "using S3 bootstrap package store", "bucket", config.S3.SoftwareInstallersBucket)

stores.icon, err = s3.NewSoftwareTitleIconStore(config.S3)
if err != nil {
initFatal(err, "initializing S3 software title icon store")
}
logger.InfoContext(ctx, "using S3 software title icon store", "bucket", config.S3.SoftwareInstallersBucket)

stores.stagedUpload, err = s3.NewStagedUploadStore(config.S3)
if err != nil {
initFatal(err, "initializing S3 staged upload store")
}

return stores
}

// newFilesystemSoftwareInstallerStores is the fallback when no object store is
// configured. It is not suitable for multi-container deployments.
func newFilesystemSoftwareInstallerStores(ctx context.Context, logger *slog.Logger) softwareInstallerStores {
var stores softwareInstallerStores

installerDir := os.TempDir()
if dir := os.Getenv("FLEET_SOFTWARE_INSTALLER_STORE_DIR"); dir != "" {
installerDir = dir
}
store, err := filesystem.NewSoftwareInstallerStore(installerDir)
if err != nil {
logger.ErrorContext(ctx, "failed to configure local filesystem software installer store", "err", err)
stores.installer = failing.NewFailingSoftwareInstallerStore()
} else {
stores.installer = store
logger.InfoContext(ctx,
"using local filesystem software installer store, this is not suitable for multi-container deployments", "directory",
installerDir)
}

iconDir := os.TempDir()
if dir := os.Getenv("FLEET_SOFTWARE_TITLE_ICON_STORE_DIR"); dir != "" {
iconDir = dir
}
iconStore, err := filesystem.NewSoftwareTitleIconStore(iconDir)
if err != nil {
logger.ErrorContext(ctx, "failed to configure local filesystem software title icon store", "err", err)
stores.icon = failing.NewFailingSoftwareTitleIconStore()
} else {
stores.icon = iconStore
logger.WarnContext(ctx,
"using local filesystem software title icon store, this is not suitable for production use", "directory",
iconDir)
}

return stores
}

func createActivityBoundedContext(svc fleet.Service, ds fleet.Datastore, dbConns *common_mysql.DBConnections, logger *slog.Logger) (activity_api.Service, endpointer.HandlerRoutesFunc) {
legacyAuthorizer, err := authz.NewAuthorizer()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/fleet/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,6 @@ func TestInitOrgLogoStore(t *testing.T) {
// the database-backed implementation. NewOrgLogoStore does no DB work at
// construction, so a zero-value Datastore is enough to verify selection.
ds := &mysql.Datastore{}
store := initOrgLogoStore(t.Context(), config.S3Config{}, ds, logger)
store := initOrgLogoStore(t.Context(), config.StorageBackendLocal, config.S3Config{}, config.AzureConfig{}, ds, logger)
require.IsType(t, ds.NewOrgLogoStore(), store)
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ services:
volumes:
- data-s3:/data:rw

# Azurite emulator for Azure Blob Storage (software installers/bootstrap packages/icons/org logos)
azurite:
image: mcr.microsoft.com/azure-storage/azurite:3.35.0
command: ["azurite-blob", "--blobHost", "0.0.0.0", "--blobPort", "10000", "--skipApiVersionCheck"]
ports:
- "127.0.0.1:${FLEET_AZURITE_PORT:-10000}:10000"
volumes:
- data-azurite:/data:rw

volumes:
mysql-persistent-volume:
data-s3:
data-azurite:
2 changes: 1 addition & 1 deletion ee/server/service/in_house_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (svc *Service) GetInHouseAppManifest(ctx context.Context, titleID uint, tok
appConfig.MDMUrl(), titleID, token,
)

if svc.config.S3.SoftwareInstallersCloudFrontSigner != nil || svc.config.S3.SoftwareInstallersSignedURL {
if svc.config.SoftwareInstallersSignedURLEnabled() {
signedURL, err := svc.softwareInstallStore.Sign(ctx, meta.StorageID, fleet.InHouseAppSignedURLExpiry)
if err != nil {
// We log the error and continue to send the Fleet server URL for the in-house app
Expand Down
4 changes: 2 additions & 2 deletions ee/server/service/software_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,8 @@ func (svc *Service) GetSoftwareInstallDetails(ctx context.Context, installUUID s
return nil, err
}

// Sign the download URL when CloudFront signing (premium-only) or GCS presigning is configured.
if svc.config.S3.SoftwareInstallersCloudFrontSigner != nil || svc.config.S3.SoftwareInstallersSignedURL {
// Sign the download URL when CloudFront signing (premium-only), GCS presigning or Azure SAS signing is configured.
if svc.config.SoftwareInstallersSignedURLEnabled() {
// Sign the URL for the installer
installerURL, err := svc.getSoftwareInstallURL(ctx, details.InstallerID)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions ee/server/service/software_installers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ func TestGetInHouseAppManifest(t *testing.T) {
require.ErrorAs(t, err, &permErr)

signer, _ := rsa.GenerateKey(rand.Reader, 2048)
svc.config.S3.SoftwareInstallersBucket = "test-bucket"
svc.config.S3.SoftwareInstallersCloudFrontSigner = signer
signerURL := "https://example.cloudfront.net"

Expand Down
Loading
Loading