Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ permissions:

env:
NFPM_VERSION: 'v2.35.3'
GOPROXY: "direct"
GOPROXY: "https://${{ secrets.ARTIFACTORY_USER }}:${{ secrets.ARTIFACTORY_TOKEN }}@azr.artifactory.f5net.com/artifactory/api/go/f5-nginx-go-dev"

jobs:
proxy-sanity-check:
Expand Down
18 changes: 16 additions & 2 deletions internal/file/file_manager_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
return model.Error, errors.New("fileOverview is nil")
}

// check if any file in request is outside the allowed directories
allowedErr := fms.checkAllowedDirectory(fileOverview.GetFiles())
if allowedErr != nil {
return model.Error, allowedErr
Expand Down Expand Up @@ -355,18 +356,28 @@ func (fms *FileManagerService) DetermineFileActions(
// if file is in manifestFiles but not in modified files, file has been deleted
// copy contents, set file action
for fileName, manifestFile := range filesMap {
_, exists := modifiedFiles[fileName]
_, existsInReq := modifiedFiles[fileName]

// allowed directories may have been updated since manifest file was written
// if file is outside allowed directories skip deletion and return error
if !fms.agentConfig.IsDirectoryAllowed(fileName) {
return nil, fmt.Errorf("error deleting file %s: file not in allowed directories", fileName)
}

// if file is unmanaged skip deletion
if manifestFile.GetUnmanaged() {
slog.DebugContext(ctx, "Skipping unmanaged file deletion", "file_name", fileName)
continue
}

// if file doesn't exist on disk skip deletion
if _, err := os.Stat(fileName); os.IsNotExist(err) {
slog.DebugContext(ctx, "File already deleted, skipping", "file", fileName)
continue
}

if !exists {
// go ahead and delete the file
if !existsInReq {
fileDiff[fileName] = &model.FileCache{
File: manifestFile,
Action: model.Delete,
Expand All @@ -382,6 +393,7 @@ func (fms *FileManagerService) DetermineFileActions(

// if file is unmanaged, action is set to unchanged so file is skipped when performing actions
if modifiedFile.File.GetUnmanaged() {
slog.DebugContext(ctx, "Skipping unmanaged file updates", "file_name", fileName)
continue
}
// if file doesn't exist in the current files, file has been added
Expand Down Expand Up @@ -729,6 +741,7 @@ func (fms *FileManagerService) convertToManifestFile(file *mpi.File, referenced
Size: file.GetFileMeta().GetSize(),
Hash: file.GetFileMeta().GetHash(),
Referenced: referenced,
Unmanaged: file.GetUnmanaged(),
},
}
}
Expand All @@ -750,6 +763,7 @@ func (fms *FileManagerService) convertToFile(manifestFile *model.ManifestFile) *
Hash: manifestFile.ManifestFileMeta.Hash,
Size: manifestFile.ManifestFileMeta.Size,
},
Unmanaged: manifestFile.ManifestFileMeta.Unmanaged,
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type ManifestFileMeta struct {
Size int64 `json:"size"`
// File referenced in the NGINX config
Referenced bool `json:"referenced"`
// File is not managed by the agent
Unmanaged bool `json:"unmanaged"`
}
type ConfigApplyMessage struct {
Error error
Expand Down
Loading