Skip to content

Replace plain-text secrets with DPAPI-encrypted vault#137

Open
innovara wants to merge 4 commits into
kmwoley:mainfrom
innovara:secrets-vault
Open

Replace plain-text secrets with DPAPI-encrypted vault#137
innovara wants to merge 4 commits into
kmwoley:mainfrom
innovara:secrets-vault

Conversation

@innovara

Copy link
Copy Markdown
Contributor

Summary: replaces the secrets.ps1 file with a Windows Data Protection API (DPAPI) vault to prevent storing repository credentials in plain text.

Changes:

  • VaultManager.ps1: a utility to create an encrypted secrets.vault file locked to the SYSTEM account.
  • System-Context Init: moves repository initialization in install.ps1 to a SYSTEM task to verify the account can unlock the vault and reach the repository before setup completes.
  • Credential retrieval: updates backup.ps1 to pull secrets from the vault, with a fallback for existing secrets.ps1 files.
  • Config separation: moves non-sensitive variables like Repository URL and SMTP settings to config_sample.ps1.

This PR supersedes #113

Introduces a DPAPI-backed vault system to replace plain-text secret
storage. This ensures that sensitive environment variables are only
accessible to the NT AUTHORITY\SYSTEM account.

Key features:
- Administrative requirement: must be run with elevated privileges to
  manage the scheduled tasks and system directories.
- Dual-mode execution: supports interactive standalone creation or
  orchestrated secret export via dot-sourcing.
- Secure encryption: utilizes DPAPI via SecureString and Clixml to lock
  credentials to the SYSTEM account's identity.
- Interactive creation: provides a standalone CLI flow to collect
  passwords securely without echoing them to the console.
- Automatic backups: detects existing vault files and creates
  timestamped backups before generating new ones.

Signed-off-by: Manuel Fombuena <mfombuena@innovara.tech>
Updates the installation process to prioritize the new VaultManager system
while maintaining backward compatibility for legacy plain-text secrets.

Key features:
- Secure credential integration: implements a workflow to create a
  DPAPI-encrypted vault if no credentials are found in the environment.
- Identity-consistent initialization: performs repository initialization
  via a temporary SYSTEM task to ensure credentials and permissions are
  correctly configured for the background service account.
- Legacy support: honors existing secrets.ps1 configurations for users
  who have manually opted for plain-text secret storage.
- Robust state detection: introduces a repository check (cat config)
  to verify access to existing repositories during installation.
- Enhanced logging: captures restic initialization output to dedicated
  log files to assist with troubleshooting permission or network issues.
- Fast-fail logic: adds explicit checks for required configuration files
  to prevent incomplete installations.

Signed-off-by: Manuel Fombuena <mfombuena@innovara.tech>
Relocates the repository URL and SMTP settings from the secrets sample
to the config sample. This ensures these parameters remain available
for users who use the new vault system instead of a secrets.ps1 file.

Signed-off-by: Manuel Fombuena <mfombuena@innovara.tech>
Updates the main backup script to load credentials from the secure vault.
If a vault is present, it uses the VaultManager to export secrets to the
environment; otherwise, it falls back to the legacy secrets.ps1 file.

Key features:
- Secure secret loading: prioritizes the DPAPI-encrypted vault for
  retrieving the restic password and other sensitive keys.
- Email credential mapping: specifically handles the extraction of the
  email password from the vault to maintain notification functionality.
- Conditional fallback: maintains support for the legacy plain-text
  secrets file if no vault is detected.

Signed-off-by: Manuel Fombuena <mfombuena@innovara.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant