Add blacklisting of fingerprinters
This commit is contained in:
parent
3f7c278908
commit
b603bb007e
|
@ -720,6 +720,9 @@ func (c *Client) reservePorts() {
|
|||
func (c *Client) fingerprint() error {
|
||||
whitelist := c.config.ReadStringListToMap("fingerprint.whitelist")
|
||||
whitelistEnabled := len(whitelist) > 0
|
||||
blacklist := c.config.ReadStringListToMap("fingerprint.blacklist")
|
||||
blacklistEnabled := len(blacklist) > 0
|
||||
|
||||
c.logger.Printf("[DEBUG] client: built-in fingerprints: %v", fingerprint.BuiltinFingerprints())
|
||||
|
||||
var applied []string
|
||||
|
@ -730,6 +733,11 @@ func (c *Client) fingerprint() error {
|
|||
skipped = append(skipped, name)
|
||||
continue
|
||||
}
|
||||
// Skip modules that are in the blacklist if it is enabled.
|
||||
if _, ok := blacklist[name]; blacklistEnabled && ok {
|
||||
skipped = append(skipped, name)
|
||||
continue
|
||||
}
|
||||
f, err := fingerprint.NewFingerprint(name, c.logger)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -754,7 +762,7 @@ func (c *Client) fingerprint() error {
|
|||
}
|
||||
c.logger.Printf("[DEBUG] client: applied fingerprints %v", applied)
|
||||
if len(skipped) != 0 {
|
||||
c.logger.Printf("[DEBUG] client: fingerprint modules skipped due to whitelist: %v", skipped)
|
||||
c.logger.Printf("[DEBUG] client: fingerprint modules skipped due to white/blacklist: %v", skipped)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -216,6 +216,23 @@ func TestClient_Fingerprint_InWhitelist(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestClient_Fingerprint_InBlacklist(t *testing.T) {
|
||||
c := testClient(t, func(c *config.Config) {
|
||||
if c.Options == nil {
|
||||
c.Options = make(map[string]string)
|
||||
}
|
||||
|
||||
// Weird spacing to test trimming. Blacklist cpu.
|
||||
c.Options["fingerprint.blacklist"] = " cpu "
|
||||
})
|
||||
defer c.Shutdown()
|
||||
|
||||
node := c.Node()
|
||||
if node.Attributes["cpu.frequency"] != "" {
|
||||
t.Fatalf("cpu fingerprint module loaded despite blacklisting")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_Fingerprint_OutOfWhitelist(t *testing.T) {
|
||||
c := testClient(t, func(c *config.Config) {
|
||||
if c.Options == nil {
|
||||
|
@ -232,6 +249,35 @@ func TestClient_Fingerprint_OutOfWhitelist(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestClient_Fingerprint_WhitelistBlacklistCombination(t *testing.T) {
|
||||
c := testClient(t, func(c *config.Config) {
|
||||
if c.Options == nil {
|
||||
c.Options = make(map[string]string)
|
||||
}
|
||||
|
||||
// With both white- and blacklist, should return the set difference of modules (arch, cpu)
|
||||
c.Options["fingerprint.whitelist"] = "arch,memory,cpu"
|
||||
c.Options["fingerprint.blacklist"] = "memory,nomad"
|
||||
})
|
||||
defer c.Shutdown()
|
||||
|
||||
node := c.Node()
|
||||
// Check expected modules are present
|
||||
if node.Attributes["cpu.frequency"] == "" {
|
||||
t.Fatalf("missing cpu fingerprint module")
|
||||
}
|
||||
if node.Attributes["arch"] == "" {
|
||||
t.Fatalf("missing arch fingerprint module")
|
||||
}
|
||||
// Check remainder _not_ present
|
||||
if node.Attributes["memory.totalbytes"] != "" {
|
||||
t.Fatalf("found memory fingerprint module")
|
||||
}
|
||||
if node.Attributes["nomad.version"] != "" {
|
||||
t.Fatalf("found nomad fingerprint module")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_Drivers(t *testing.T) {
|
||||
c := testClient(t, nil)
|
||||
defer c.Shutdown()
|
||||
|
|
|
@ -213,6 +213,18 @@ see the [drivers documentation](/docs/drivers/index.html).
|
|||
}
|
||||
```
|
||||
|
||||
- `"fingerprint.blacklist"` `(string: "")` - Specifies a comma-separated list of
|
||||
blacklisted fingerprinters. If specified, any fingerprinters in the blacklist
|
||||
will be disabled. If the blacklist is empty, all fingerprinters are used.
|
||||
|
||||
```hcl
|
||||
client {
|
||||
options = {
|
||||
"fingerprint.blacklist" = "network"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### `reserved` Parameters
|
||||
|
||||
- `cpu` `(int: 0)` - Specifies the amount of CPU to reserve, in MHz.
|
||||
|
|
Loading…
Reference in New Issue