natrontech / pbs-exporter

A prometheus exporter for Proxmox Backup Server
GNU General Public License v3.0
17 stars 6 forks source link

Add secrets file support for docker #9

Closed ChrisFromCnC closed 5 months ago

ChrisFromCnC commented 7 months ago

I propose to add support to dockerfile secrets for PBS_USERNAME, PBS_API_TOKEN_NAME and PBS_API_TOKEN.

Idea is to move secrets outside of docker-compose file for instance for security purpose.

As example a docker-compose file can be created like this: proxmoxbackup: image: ghcr.io/natrontech/pbs-exporter:0.1.5 container_name: proxmoxbackup restart: always secrets:

secrets: proxmoxbackup-username: file: "./.secrets/proxmoxbackup_username.secret" proxmoxbackup-api-token-name: file: "./.secrets/proxmoxbackup_api_token_name.secret" proxmoxbackup-api-token: file: "./.secrets/proxmoxbackup_api_token.secret"

All secrets are now stored in a folder .secrets.

Convention naming for secrets in docker is to add _FILE to regular environnement variable. In our case we need to manage PBS_USERNAME_FILE, PBS_API_TOKEN_NAME_FILE and PBS_API_TOKEN_FILE env variables.

I just adapt the main.go to read the new env variable for the secret file name and read the first line from the file.

Sorry I cannot add a file here so I post a diff of main

diff --git a/main.go b/main.go index 1e6686d..cd8cd88 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main

import (

+func ReadSecretFile(secretfilename string) string {

janfuhrer commented 5 months ago

Hi @ChrisFromCnC

Thanks for opening the issue. It sounds reasonable to me to add this functionality as long as both methods work (with and without docker secrets).

Feel free to open a PR with your changes and we will test and verify your implementation.

janfuhrer commented 5 months ago

implemented in #11 released in 0.3.0

Thanks again @ChrisFromCnC !