mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
› Tenant ID: fails on headless Linux (containers, VMs, CI) because no D-Bus Secret Service is available and the keychain resolver refuses to construct. Add an explicit --insecure-file-store flag that enables dry's plaintext file fallback (~/.config/safedep/creds.json, mode 0600) for writing. Reading is fallback-enabled unconditionally in the credential resolver chain, logout and setup info, so stored file credentials resolve with no extra flags and logout can always clear them. On systems with a working keychain the file provider is never constructed.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package cloud
|
|
|
|
import (
|
|
"github.com/safedep/dry/cloud"
|
|
"github.com/safedep/dry/log"
|
|
"github.com/safedep/dry/usefulerror"
|
|
"github.com/safedep/pmg/errcodes"
|
|
"github.com/safedep/pmg/internal/ui"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newLogoutCommand() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "logout",
|
|
Short: "Clear stored SafeDep Cloud credentials",
|
|
RunE: runLogout,
|
|
}
|
|
}
|
|
|
|
func runLogout(cmd *cobra.Command, args []string) error {
|
|
store, err := cloud.NewKeychainCredentialStore(cloud.WithInsecureFileFallback())
|
|
if err != nil {
|
|
ui.ErrorExit(usefulerror.NewUsefulError().
|
|
Wrap(err).
|
|
WithCode(errcodes.Lifecycle).
|
|
WithHumanError("Failed to initialize credential store").
|
|
WithHelp("Your system may not support secure credential storage"))
|
|
}
|
|
defer func() {
|
|
if err := store.Close(); err != nil {
|
|
log.Warnf("failed to close credential store: %v", err)
|
|
}
|
|
}()
|
|
|
|
if err := store.Clear(); err != nil {
|
|
ui.ErrorExit(usefulerror.NewUsefulError().
|
|
Wrap(err).
|
|
WithCode(errcodes.Lifecycle).
|
|
WithHumanError("Failed to clear credentials"))
|
|
}
|
|
|
|
ui.Successf("Credentials cleared from keychain")
|
|
return nil
|
|
}
|