Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers/osinfo: add security lockdown type detection #103

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions helpers/osinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,47 @@ func FtraceEnabled() (bool, error) {
}
return b[0] == '1', nil
}

type LockdownMode int32

func (l LockdownMode) String() string {
return lockdownModeToString[l]
}

const (
NOVALUE LockdownMode = iota
NONE
INTEGRITY
CONFIDENTIALITY
)

var stringToLockdownMode = map[string]LockdownMode{
"none": NONE,
"integrity": INTEGRITY,
"confidentiality": CONFIDENTIALITY,
}

var lockdownModeToString = map[LockdownMode]string{
NONE: "none",
INTEGRITY: "integrity",
CONFIDENTIALITY: "confidentiality",
}

func Lockdown() (LockdownMode, error) {
LockdownFile := "/sys/kernel/security/lockdown"
data, err := os.ReadFile(LockdownFile)
if err != nil {
return NOVALUE, err
}

dataString := string(data[:])

for lockString, lockMode := range stringToLockdownMode {
rafaeldtinoco marked this conversation as resolved.
Show resolved Hide resolved
tempString := fmt.Sprintf("[%s]", lockString)
if strings.Contains(dataString, tempString) {
return lockMode, nil
}
}

return NOVALUE, fmt.Errorf("could not get lockdown mode")
}