Commit Graph

2581 Commits

Author SHA1 Message Date
Nick Bozhenko 641d16178f Modernize Makefile and update .gitignore
- Replace old Makefile with modernized version featuring:
  * Better organization with grouped targets (Development, Build, Testing, etc.)
  * Colored output for improved readability
  * Enhanced help system with target descriptions
  * Cross-platform build support (Linux, macOS, Windows, multiple architectures)
  * Modern development tools (golangci-lint v1.64.5, air for hot reload, swag)
  * Improved testing targets with coverage reporting
  * Docker support targets
  * Dependency management utilities
  * CI/CD pipeline support

- Update .gitignore to exclude:
  * Coverage reports (*.out, *_coverage.html)
  * Build artifacts (aptly-binary, aptly-test)
  * Downloaded archives (*.tar.gz)
  * Test output files (test_results.log)
  * Python virtual environments (venv/, system/venv/)
  * act configuration files (.actrc)
  * Backup files (*.backup, *.bak)
  * Temporary directories (coverage/, scripts/)

The new Makefile maintains backward compatibility with all existing targets while adding many quality-of-life improvements for developers.
2025-07-10 12:14:57 -04:00
Nick Bozhenko 40ba104838 Add comprehensive CI/CD improvements and test coverage
This commit introduces major enhancements to the CI/CD pipeline and testing infrastructure:

CI/CD Improvements:
- Consolidated modern and legacy CI workflows into a single comprehensive pipeline
- Removed all publishing functionality from CI (no longer needed)
- Added 8 new advanced testing jobs for pull requests:
  * advanced-coverage: Detailed coverage analysis with base branch comparison
  * performance-profile: CPU and memory profiling with benchmarks
  * fuzz-test: Automated fuzz testing for supported packages
  * deep-analysis: Multiple static analysis tools (shadow, ineffassign, gosec, staticcheck)
  * mutation-test: Tests effectiveness of test suite on changed files
  * dependency-audit: Security vulnerabilities and outdated dependency checks
  * stress-test: Race detection with 100 iterations and parallel testing
  * test-report-summary: Aggregates all reports into a single PR comment
- Enabled RUN_LONG_TESTS by default for thorough testing
- Added automatic PR comment generation with all test results

Testing Infrastructure:
- Added comprehensive test files across all packages to improve coverage
- Implemented unit tests for previously untested packages
- Added race condition tests for concurrent operations
- Created integration tests for API endpoints
- Added storage backend tests (etcd, goleveldb)
- Implemented command-line interface tests

Local Testing Support:
- Added act configuration for testing GitHub Actions locally
- Created docker-compose.ci.yml for full CI environment simulation
- Updated CONTRIBUTING.md with detailed local testing instructions

Documentation Updates:
- Added comprehensive CI documentation to CONTRIBUTING.md
- Removed obsolete references to Travis CI
- Updated Go version requirements to 1.24
- Added act usage instructions and examples

Other Improvements:
- Updated .gitignore to exclude coverage reports and build artifacts
- Added test-act.yml workflow for testing act functionality
- Created CI_SUMMARY.md documenting all CI capabilities

These changes transform aptly's CI from a basic testing pipeline into a comprehensive quality assurance system that provides immediate feedback on code quality, performance, security, and test effectiveness.
2025-07-10 12:00:54 -04:00
Nick Bozhenko cd30723750 feat: upgrade Go version and improve build system
- Upgrade Go version from 1.22 to 1.24 for better performance and security
- Add comprehensive golangci-lint configuration with:
  - Enable additional linters: bodyclose, dupl, exportloopref, gocognit, gocritic, gosec, prealloc
  - Configure complexity thresholds (cyclomatic: 15, cognitive: 20)
  - Set up security scanning with gosec
  - Add code quality rules with revive
  - Exclude test files from certain strict checks
- Update dependencies to latest stable versions:
  - aws-sdk-go-v2: various components updated
  - Azure SDK: updated to v1.18.0 for azcore
  - etcd client: remains at v3.6.1 for stability
  - prometheus client: updated to v1.22.0
  - zerolog: updated to v1.34.0
- Enhance logging utilities:
  - Add GetLogLevelOrDebug function for flexible log level configuration
  - Support "warning" as alias for "warn" level
  - Improve error handling for invalid log levels

These changes improve code quality checks, leverage latest Go features,
and ensure dependencies are up-to-date with security patches.
2025-07-10 10:21:48 -04:00
Nick Bozhenko f7b4df2f32 Add comprehensive test coverage for utils package improvements
This commit adds extensive test coverage for the recent improvements to the utils
package, achieving 91.5% coverage (up from 76.8%). The tests ensure the reliability
and correctness of critical utility functions.

## Test Files Added

### utils/config_accessor_test.go
Tests for the new safe accessor methods that prevent concurrent map access:
- TestGetFileSystemPublishRoots: Verifies safe copying of FileSystemPublishRoots map
- TestGetS3PublishRoots: Tests S3 publish roots accessor with nil map handling
- TestGetSwiftPublishRoots: Tests Swift publish roots accessor
- TestGetAzurePublishRoots: Tests Azure publish roots accessor
- All tests verify that modifications to returned maps don't affect the original

### utils/sanitize_test.go
Comprehensive tests for the SanitizePath security function:
- TestSanitizePath: Tests various path sanitization scenarios including:
  - Path traversal attempts (../)
  - Absolute paths (leading /)
  - Shell expansion attempts ($, `)
  - Environment variable references
  - Command injection attempts
- TestSanitizePathSecurity: Focused security tests for malicious inputs
- Ensures dangerous patterns are properly removed

### utils/checksum_extra_test.go
Tests for additional utility functions:
- TestComplete: Verifies ChecksumInfo.Complete() correctly identifies when all
  checksums (MD5, SHA1, SHA256, SHA512) are present
- TestSaveConfigRaw: Tests configuration file saving with error handling
- TestPackagePoolStorageUnmarshalJSON: Tests JSON unmarshaling for different
  storage types (Azure, Local, S3, Swift)

## Test Characteristics

1. **Comprehensive Coverage**: Tests cover both normal operation and edge cases
2. **Security Focus**: Special attention to security-sensitive functions
3. **Error Handling**: Tests verify proper error handling and edge cases
4. **Concurrency Safety**: Tests ensure thread-safe operations for shared data
5. **Real-world Scenarios**: Test cases based on actual usage patterns

## Testing Approach

All tests use the gopkg.in/check.v1 framework for consistency with the existing
codebase. Tests are designed to be:
- Fast: No external dependencies or network calls
- Deterministic: No random failures or timing dependencies
- Isolated: Each test is independent and can run in any order
- Clear: Test names and assertions clearly indicate what is being tested

These tests provide confidence that the recent race condition fixes and
improvements work correctly and don't introduce regressions.
2025-07-10 10:12:43 -04:00
Nick Bozhenko 463c34a38e Fix race conditions and improve etcd timeout handling
This commit addresses several critical race conditions and improves the reliability
of etcd operations through better timeout and retry handling.

## Race Condition Fixes

1. **Task Resource Management Bug**
   - Fixed incorrect variable usage in task/list.go:78
   - Was using completed task's resources instead of idle task's resources
   - This caused resource conflicts and potential deadlocks

2. **Database Channel Initialization**
   - Added sync.Once pattern to ensure thread-safe channel initialization
   - Prevents panic from concurrent access during startup
   - Created initDBRequests() function for safe initialization

3. **Published Storage Double-Checked Locking**
   - Implemented double-checked locking pattern in GetPublishedStorage
   - Reduces lock contention while preventing concurrent initialization
   - Improves performance for frequently accessed storage

4. **File Operation Synchronization**
   - Created FileLockRegistry in utils/filelock.go
   - Prevents concurrent file operations (create, rename, delete, link)
   - Implements deadlock prevention for multi-file operations
   - Critical for preventing file corruption during parallel publishes

5. **WaitGroup Miscount Prevention**
   - Added defer pattern to ensure Done() is always called
   - Protects against panics during task execution
   - Prevents "negative WaitGroup counter" errors

## etcd Improvements

1. **Timeout Protection**
   - Replaced global context.TODO() with per-operation timeout contexts
   - Default timeout: 60 seconds (configurable)
   - Prevents indefinite hangs when etcd is unresponsive

2. **Environment Variable Configuration**
   - APTLY_ETCD_TIMEOUT: Operation timeout (default: 60s)
   - APTLY_ETCD_DIAL_TIMEOUT: Connection timeout (default: 60s)
   - APTLY_ETCD_KEEPALIVE: Keep-alive timeout (default: 7200s)
   - APTLY_ETCD_MAX_MSG_SIZE: Max message size (default: 50MB)

3. **Retry Logic for Read Operations**
   - Get operations retry up to 3 times with exponential backoff
   - Only retries on temporary/network errors
   - Improves reliability without risking data inconsistency

4. **Enhanced Error Logging**
   - All etcd errors now logged with operation context
   - Replaces silent failures with actionable error messages
   - Improves debugging and monitoring capabilities

5. **Increased Message Size Limits**
   - Default increased from 10MB to 50MB
   - Configurable via environment variable
   - Prevents "message too large" errors for large operations

## Testing

- Added comprehensive tests for etcd timeout functionality
- Tests verify context timeout, retry logic, and configuration
- All existing tests pass with the new implementation

## Documentation

- Updated README.rst with etcd configuration section
- Documented all environment variables and their defaults
- Added examples and feature descriptions

These changes significantly improve the reliability and debuggability of aptly
when using etcd as the database backend, while also fixing critical race
conditions that could cause data corruption or service crashes.
2025-07-10 10:05:49 -04:00
Nick Bozhenko 660cee2ce3 Fix concurrent map access race conditions in config publish roots
This commit addresses critical race conditions that were causing "map write failed"
errors and pod crashes in production environments. The issue occurred when multiple
goroutines accessed shared configuration maps simultaneously without proper synchronization.

Root Cause:
The global utils.Config structure contains several maps (FileSystemPublishRoots,
S3PublishRoots, SwiftPublishRoots, AzurePublishRoots) that were being accessed
directly by concurrent HTTP handlers. While context.Config() uses a mutex, it
returns a pointer to the global config, leaving subsequent map access unprotected.

Changes Made:

1. Added safe accessor methods in utils/config.go:
   - GetFileSystemPublishRoots() - returns defensive copy of map
   - GetS3PublishRoots() - returns defensive copy of map
   - GetSwiftPublishRoots() - returns defensive copy of map
   - GetAzurePublishRoots() - returns defensive copy of map

2. Updated API handlers to use safe accessors:
   - api/s3.go: apiS3List() now uses GetS3PublishRoots()
   - api/router.go: reposListInAPIMode() now uses GetFileSystemPublishRoots()

3. Updated context package storage initialization:
   - context/context.go: GetPublishedStorage() now uses safe accessors for all
     storage type configurations (filesystem, s3, swift, azure)

Impact:
- Eliminates "concurrent map writes" panics that were causing service instability
- Prevents pod crashes and restarts in Kubernetes environments
- Ensures thread-safe access to configuration maps during concurrent API requests
- Minimal performance overhead (microseconds) from creating map copies

The fix is backward compatible and requires no configuration changes. The defensive
copying approach ensures that even if config maps are modified after initialization
(which shouldn't happen in production), concurrent readers remain safe.

This addresses the production issues observed in lf-aptly-* pods where multiple
parallel publish requests or API calls were triggering race conditions.
2025-07-10 01:35:09 -04:00
André Roth 4675589cf6 Merge pull request #1460 from aptly-dev/dependabot/pip/system/requests-2.32.4
build(deps): bump requests from 2.28.2 to 2.32.4 in /system
2025-06-21 15:40:30 +02:00
dependabot[bot] 32f03bfd62 build(deps): bump requests from 2.28.2 to 2.32.4 in /system
Bumps [requests](https://github.com/psf/requests) from 2.28.2 to 2.32.4.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.28.2...v2.32.4)

---
updated-dependencies:
- dependency-name: requests
  dependency-version: 2.32.4
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-10 03:23:26 +00:00
André Roth d1bfd29dfd Merge pull request #1458 from aptly-dev/release/1.6.2
Release 1.6.2
v1.6.2
2025-06-09 18:12:35 +02:00
André Roth 27ec594606 update releasing.md 2025-06-09 14:38:53 +02:00
André Roth f652a522fd update changelog for 1.6.2 2025-06-09 14:38:53 +02:00
André Roth a794e87490 Merge pull request #1456 from aptly-dev/doc/gpg-api
doc: add swagger doc for /api/gpg/key
tests: use faketime for expired keys/signatures
2025-06-09 13:40:54 +02:00
André Roth 5b04d4fbe1 system-tests: abort on failure 2025-06-09 13:17:54 +02:00
André Roth 1566e193f6 system-test: enable faketime optionally per test 2025-06-09 13:17:54 +02:00
André Roth 601c8e9d52 tests: use faketime to prevent expired signing keys 2025-06-08 20:05:49 +02:00
André Roth 8e5707dbcc unit-tests: allow running individual tests 2025-06-08 15:00:16 +02:00
André Roth ad4d0c7b96 doc: add swagger doc for /api/gpg/key
- cleanup swagger validation errors
2025-06-08 14:24:27 +02:00
André Roth a11e004943 Merge pull request #1452 from boxjan/master
bash-completion: include global options in aptly command completions
2025-05-25 22:54:45 +02:00
boxjan f605d86a4e bash-completion: include global options in aptly command completions 2025-05-06 10:11:46 +00:00
André Roth f8bde63081 Merge pull request #1443 from aptly-dev/dependabot/go_modules/golang.org/x/net-0.38.0
Bump golang.org/x/net from 0.33.0 to 0.38.0
2025-05-01 12:17:14 +02:00
dependabot[bot] 887ce71005 Bump golang.org/x/net from 0.33.0 to 0.38.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.33.0 to 0.38.0.
- [Commits](https://github.com/golang/net/compare/v0.33.0...v0.38.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.38.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-01 09:14:39 +00:00
André Roth 87233ceafe Merge pull request #1441 from aptly-dev/dependabot/go_modules/golang.org/x/crypto-0.35.0
Bump golang.org/x/crypto from 0.31.0 to 0.35.0
2025-05-01 11:13:30 +02:00
André Roth 27c15680e8 Merge pull request #1445 from silkeh/fix-db-references
Remove corrupt package references in `db recover`
2025-05-01 10:27:42 +02:00
dependabot[bot] cb72e2d70f Bump golang.org/x/crypto from 0.31.0 to 0.35.0
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.31.0 to 0.35.0.
- [Commits](https://github.com/golang/crypto/compare/v0.31.0...v0.35.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-version: 0.35.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-01 08:15:38 +00:00
André Roth 2cafbc8484 Merge pull request #1439 from aptly-dev/feature/go-1.24
go: use version 1.24
2025-05-01 10:14:27 +02:00
Silke Hofstra 6dbb28b2b8 Add myself to authors 2025-04-30 12:21:34 +02:00
Silke Hofstra d8a4a28259 Remove corrupt package references in db recover
When aptly crashes it is possible to get a corrupt database with a dangling key reference.
This results in an error with 'key not found', eg:

    ERROR: unable to load package Pall example-package 1.2.3 778cf6f877bf6e2d: key not found

This change makes `db recover` fix this situation by removing the dangling references.
2025-04-30 12:21:34 +02:00
André Roth 9a217171c8 go: mod tidy 2025-04-26 13:35:49 +02:00
André Roth c67cafcf94 Makefile: allow no cache docker build 2025-04-26 13:31:16 +02:00
André Roth f7057a9517 go1.24: fix lint, unit and system tests
- development env: base on debian trixie with go1.24
- lint: run with default config
- fix lint errors
- fix unit tests
- fix system test
2025-04-26 13:29:50 +02:00
André Roth ae5379d84a go: use version 1.24 2025-04-25 14:20:13 +02:00
André Roth c05068c2e8 Merge pull request #1440 from aptly-dev/bugfix/issue-1435-fix-s3-upload-unchanged-package
Fix upload of unchanged packages in S3 on source update of published repository
2025-04-25 13:21:10 +02:00
André Roth 22bc2f9d0f system-tests: improve sorted compare
sort both aptly output and gold file. output original output for
debugging on failure.

* Makefile: enable CAPTURE=1 env variable for capturing gold files
* docker-system-test: use AWS env vars for S3 tests
* fix system tests timing issue with order of gpg logs in publish tests
2025-04-25 00:51:59 +02:00
André Roth c07bf2b108 s3: add debug logs for commands
* initialize zerolog for commands
* Change default log format: remote colors and timestamp
2025-04-24 12:13:38 +02:00
André Roth e447fc0f1e ci: keep CI artifacts for 7 days 2025-04-21 12:01:39 +02:00
André Roth e062df68c5 go1.23: update golangci-lint version
and fix warnings.
2025-04-20 20:32:55 +02:00
André Roth 664a5cd675 go1.23: fix system test 2025-04-20 11:57:42 +02:00
André Roth 9ef217b351 ci: use go 1.23 compatible with gocovmerge 2025-04-20 11:38:33 +02:00
Christoph Fiehe 67bd15487d Fixes Issue#1435.
Signed-off-by: Christoph Fiehe <christoph.fiehe@eurodata.de>
2025-04-14 13:39:45 +02:00
André Roth ab18da351d ci: add release notes
and update Releasing.md
v1.6.1
2025-02-15 22:25:56 +01:00
André Roth 1abb735bfa Merge pull request #1430 from aptly-dev/release/1.6.1
Release/1.6.1
2025-02-15 19:10:42 +01:00
André Roth 9397d8ab36 add releasing doc 2025-02-15 16:23:53 +01:00
André Roth 82300d6944 update changelog 2025-02-15 16:17:37 +01:00
André Roth cf3841e35c Merge pull request #1425 from aptly-dev/fix/debian-compliance
postrm: remove aptly-api user and home directory on purge
2025-01-24 00:49:15 +01:00
Sébastien Delafond 1a0bffdc51 postrm: remove aptly-api user and home directory on purge 2025-01-22 21:48:02 +01:00
André Roth 666b5c9700 Merge pull request #1422 from aptly-dev/fix/empty-mirror-snapshot
Allow snapshotting empty mirrors
2025-01-13 12:36:01 +01:00
André Roth 2eabc6045f go mod tidy 2025-01-12 00:05:00 +01:00
André Roth cc32e79f2a Merge pull request #1423 from mikelolasagasti/google-uuid
Switch to google/uuid module
2025-01-11 23:56:23 +01:00
Mikel Olasagasti Uranga 7074fc8856 Switch to google/uuid module
Current used github.com/pborman/uuid hasn't seen any updates in years.

Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
2025-01-11 23:18:50 +01:00
André Roth a7d85e5905 Merge pull request #1187 from aptly-dev/dependabot/go_modules/github.com/gin-gonic/gin-1.9.1
Bump github.com/gin-gonic/gin from 1.7.7 to 1.9.1
2025-01-11 22:15:59 +01:00