-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathsecrets.go
More file actions
101 lines (82 loc) · 2.46 KB
/
secrets.go
File metadata and controls
101 lines (82 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright IBM Corp. 2015, 2025
// SPDX-License-Identifier: BUSL-1.1
package fingerprint
import (
"context"
"os"
"path/filepath"
"strings"
"time"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/commonplugins"
"github.com/hashicorp/nomad/helper"
)
type SecretsPluginFingerprint struct {
logger hclog.Logger
}
func NewPluginsSecretsFingerprint(logger hclog.Logger) Fingerprint {
return &SecretsPluginFingerprint{
logger: logger.Named("secrets_plugins"),
}
}
func (s *SecretsPluginFingerprint) Fingerprint(request *FingerprintRequest, response *FingerprintResponse) error {
// Add builtin secrets providers
defer func() {
response.AddAttribute("plugins.secrets.nomad.version", "1.0.0")
response.AddAttribute("plugins.secrets.vault.version", "1.0.0")
}()
response.Detected = true
pluginDir := request.Config.CommonPluginDir
if pluginDir == "" {
return nil
}
secretsDir := filepath.Join(pluginDir, commonplugins.SecretsPluginDir)
files, err := helper.FindExecutableFiles(secretsDir)
if err != nil {
if os.IsNotExist(err) {
s.logger.Trace("secrets plugin dir does not exist", "dir", secretsDir)
} else {
s.logger.Warn("error finding secrets plugins", "dir", secretsDir, "error", err)
}
return nil // don't halt agent start
}
// map of plugin names to fingerprinted versions
plugins := map[string]string{}
for name := range files {
name = strings.TrimSuffix(name, ".exe")
plug, err := commonplugins.NewExternalSecretsPlugin(request.Config.CommonPluginDir, name)
if err != nil {
return err
}
fprint, err := plug.Fingerprint(context.Background())
if err != nil {
s.logger.Error("secrets plugin failed fingerprint", "plugin", name, "error", err)
continue
}
if fprint.Version == nil || fprint.Type == nil {
continue
}
if *fprint.Type != "secrets" {
continue
}
plugins[name] = fprint.Version.Original()
}
// if this was a reload, wipe what was there before
for k := range request.Node.Attributes {
if strings.HasPrefix(k, "plugins.secrets.") {
response.RemoveAttribute(k)
}
}
// set the attribute(s)
for plugin, version := range plugins {
s.logger.Debug("detected plugin", "plugin_id", plugin, "version", version)
response.AddAttribute("plugins.secrets."+plugin+".version", version)
}
return nil
}
func (s *SecretsPluginFingerprint) Periodic() (bool, time.Duration) {
return false, 0
}
func (s *SecretsPluginFingerprint) Reload() {
// secrets plugins are re-detected on agent reload
}