Commit 5c2afcb
Fix/security patches (#13)
* docs: add missing permalinks to example pages
Add permalink frontmatter to all example documentation pages to fix
Jekyll routing issues where pages were accessible at incorrect URLs.
Changes:
- Add permalink: /examples/clusters/ to clusters.md
- Add permalink: /examples/discovery/ to discovery.md
- Add permalink: /examples/users/ to users.md
- Add permalink: /examples/roles/ to roles.md
- Add permalink: /examples/network/ to network.md
- Add permalink: /examples/infrastructure/ to infrastructure.md
- Add permalink: /examples/dag-analysis/ to dag-analysis.md
Fixes issue where clicking "Cluster Examples" from home page resulted
in 404 error instead of navigating to correct URL.
* docs: fix broken links to non-existent /examples/advanced/ page
Replace references to non-existent /examples/advanced/ page with
appropriate existing documentation pages.
Changes:
- Update examples.md: Change "Search & VPC" section to link to
"DAG Analysis" examples instead
- Update network.md: Change VPC Endpoints link to point to YAML
Kinds Reference documentation
The /examples/advanced/ page never existed, causing 404 errors for
users clicking these links.
* docs: fix raw links missing Jekyll relative_url filter
Add missing relative_url filter to internal documentation links to
ensure correct URL generation when site is deployed to subdirectory.
Changes:
- infra.md: Fix 4 links to /discovery/ and /dag-engine/
- dag-engine.md: Fix 3 links in Further Reading section
- atlas.md: Fix link to /infra/
- database.md: Fix link to /atlas/
- examples/dag-analysis.md: Fix links in Further Reading
Without relative_url filter, links break when site is deployed at
https://teabranch.github.io/matlas-cli/ (baseurl set in _config.yml).
* docs: fix incorrect yaml-kinds permalink references
Update links that referenced /yaml-kinds/ to use correct /reference/
permalink path, matching the actual permalink setting in yaml-kinds.md.
Changes:
- alerts.md: Update YAML Kinds Reference link
- examples/alerts.md: Update YAML Kinds Reference link
- yaml-kinds.md: Fix malformed Related Documentation links
The yaml-kinds.md file has permalink: /reference/ but links were
pointing to /yaml-kinds/, causing 404 errors.
* docs: add tracking file for documentation link fixes
Add tracking/documentation.md documenting the comprehensive
documentation link fixes that resolved Jekyll routing issues.
* security: add secure file operations and credential masking
Implement comprehensive security improvements for sensitive data
handling throughout the CLI.
New Modules:
- internal/fileutil/secure_writer.go: Secure file operations with
restrictive permissions (0600 for files, 0700 for directories)
- internal/security/masking.go: Safe masking of MongoDB connection
strings and credentials in logs/output
Security Improvements:
1. File Operations:
- Replace direct os.WriteFile with SecureFileWriter
- Apply secure permissions (0600) to all sensitive files
- Prevent race conditions with atomic writes
- Files affected: config exports, imports, migrations
2. Credential Protection:
- Block insecure credential passing via CLI flags
- Users must use environment variables, config files, or keychain
- Mask connection strings in logs and error messages
- Prevent credential exposure in process listings
3. Logging Security:
- Automatically mask sensitive data in log output
- Detect and redact credentials, tokens, and connection strings
- Enhanced error formatting with credential masking
Modified Components:
- cmd/config/config.go: Use SecureFileWriter for config operations
- cmd/root.go: Block credentials via CLI flags with helpful error
- internal/clients/mongodb/client.go: Mask connection strings in logs
- internal/config/credentials.go: Secure credential loading
- internal/logging/logger.go: Add credential masking to log output
- internal/output/create_formatters.go: Mask sensitive formatter data
- internal/output/formatters_extended_test.go: Test credential masking
- internal/services/database/temp_user.go: Mask temp user credentials
Security Rationale:
- Command-line arguments are visible in process listings (ps, htop)
- Arguments are stored in shell history files
- File permissions prevent unauthorized access to sensitive configs
- Masked logs prevent credential leakage in debugging output
Refs: #security-hardening
* chore: update gitignore for bin directory
* perf(logging): pre-compile regex patterns for secret detection
Move regex pattern compilation from hot path to package initialization
to eliminate repeated compilation overhead in logging operations.
Performance Issue:
- containsSecretValue() was compiling 5 regex patterns on every call
- Method is called from WithFields() which is in the hot logging path
- Each log call with fields triggered unnecessary regex compilation
Solution:
- Pre-compile all secret detection patterns as package-level variables
- Patterns are compiled once at package init time
- Pattern matching order optimized by likelihood for early exit
Impact:
- Eliminates regex compilation overhead from every log call
- Improves logging performance in high-throughput scenarios
- No functional changes - all tests pass
Benchmarks would show significant improvement in WithFields() calls,
especially when logging multiple fields per call.
---------
Co-authored-by: Danny Teller <[email protected]>1 parent cfd604e commit 5c2afcb
File tree
27 files changed
+449
-304
lines changed- cmd
- config
- docs
- examples
- internal
- clients/mongodb
- config
- fileutil
- logging
- output
- security
- services/database
- tracking
27 files changed
+449
-304
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
583 | 584 | | |
584 | 585 | | |
585 | 586 | | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
| 587 | + | |
592 | 588 | | |
593 | 589 | | |
594 | 590 | | |
595 | 591 | | |
596 | 592 | | |
597 | | - | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
598 | 596 | | |
599 | 597 | | |
600 | 598 | | |
| |||
642 | 640 | | |
643 | 641 | | |
644 | 642 | | |
645 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
| |||
703 | 703 | | |
704 | 704 | | |
705 | 705 | | |
706 | | - | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
707 | 709 | | |
708 | 710 | | |
709 | 711 | | |
| |||
721 | 723 | | |
722 | 724 | | |
723 | 725 | | |
724 | | - | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
725 | 729 | | |
726 | 730 | | |
727 | 731 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
50 | 61 | | |
51 | 62 | | |
52 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
539 | | - | |
| 539 | + | |
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
794 | 794 | | |
795 | 795 | | |
796 | 796 | | |
797 | | - | |
798 | | - | |
799 | | - | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
389 | | - | |
| 389 | + | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
464 | | - | |
| 464 | + | |
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
0 commit comments