github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/fingerprint/landlock.go (about) 1 package fingerprint 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/go-hclog" 7 "github.com/shoenig/go-landlock" 8 ) 9 10 const ( 11 landlockKey = "kernel.landlock" 12 ) 13 14 // LandlockFingerprint is used to fingerprint the kernel landlock feature. 15 type LandlockFingerprint struct { 16 StaticFingerprinter 17 logger hclog.Logger 18 detector func() (int, error) 19 } 20 21 func NewLandlockFingerprint(logger hclog.Logger) Fingerprint { 22 return &LandlockFingerprint{ 23 logger: logger.Named("landlock"), 24 detector: landlock.Detect, 25 } 26 } 27 28 func (f *LandlockFingerprint) Fingerprint(_ *FingerprintRequest, resp *FingerprintResponse) error { 29 version, err := f.detector() 30 if err != nil { 31 f.logger.Warn("failed to fingerprint kernel landlock feature", "error", err) 32 version = 0 33 } 34 switch version { 35 case 0: 36 // do not set any attribute 37 default: 38 v := fmt.Sprintf("v%d", version) 39 resp.AddAttribute(landlockKey, v) 40 } 41 return nil 42 }