This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
139 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"gopkg.in/yaml.v2" | ||
"sigs.k8s.io/multi-tenancy/benchmarks/kubectl-mtb/test/util" | ||
) | ||
|
||
const ( | ||
// Location of the config files | ||
embedFolder string = "./test/benchmarks/" | ||
) | ||
|
||
// Structure of yaml (Used for README generation) | ||
type Doc struct { | ||
ID string `yaml:"id"` | ||
Title string `yaml:"title"` | ||
BenchmarkType string `yaml:"benchmarkType"` | ||
Category string `yaml:"category"` | ||
Description string `yaml:"description"` | ||
Remediation string `yaml:"remediation"` | ||
ProfileLevel int `yaml:"profileLevel"` | ||
} | ||
|
||
// README template | ||
const templ = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>README</title> | ||
</head> | ||
<body> | ||
<h2> {{.Title}} [{{.ID}}] </h2> | ||
<p> | ||
<b> Profile Applicability: </b> {{.ProfileLevel}} <br> | ||
<b> Type: </b> {{.BenchmarkType}} <br> | ||
<b> Category: </b> {{.Category}} <br> | ||
<b> Description: </b> {{.Description}} <br> | ||
<b> Remediation: </b> {{.Remediation}} <br> | ||
</p> | ||
</body> | ||
</html> | ||
` | ||
|
||
func main() { | ||
|
||
err := filepath.Walk(embedFolder, func(path string, info os.FileInfo, err error) error { | ||
if info.IsDir() { | ||
// Skip directories | ||
log.Println(path, "is a directory, skipping...") | ||
return nil | ||
} else { | ||
|
||
extension := filepath.Ext(path) | ||
|
||
if extension == ".yml" || extension == ".yaml" { | ||
b, err := ioutil.ReadFile(path) | ||
util.CheckError(err) | ||
d := Doc{} | ||
err = yaml.Unmarshal(b, &d) | ||
util.CheckError(err) | ||
t := template.New("README template") | ||
t, err = t.Parse(templ) | ||
|
||
// Get directory of the config file | ||
dirPath := util.GetDirectory(path, "/") | ||
|
||
//Check if Path exists | ||
_, err = util.Exists(dirPath) | ||
util.CheckError(err) | ||
|
||
f, err := os.Create(dirPath + "/README.md") | ||
util.CheckError(err) | ||
|
||
// Write the output to the README file | ||
err = t.Execute(f, d) | ||
util.CheckError(err) | ||
if err == nil { | ||
fmt.Println("README.md generated successfully") | ||
} | ||
|
||
err = f.Close() | ||
util.CheckError(err) | ||
|
||
} | ||
} | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
log.Fatal("Error walking through embed directory:", err) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 18 additions & 7 deletions
25
benchmarks/kubectl-mtb/test/benchmarks/block_privileged_containers/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
<p>id: MTB-PL1-BC-CPI-5 | ||
title: Block privileged containers | ||
benchmarkType: Behavioral Check | ||
category: Control Plane Isolation | ||
description: By default a container is not allowed to access any devices on the host, but a “privileged” container can access all devices on the host. A process within a privileged container can also get unrestricted host access. Hence, tenants should not be allowed to run privileged containers. | ||
remediation: Define a <code>PodSecurityPolicy</code> with <code>privileged</code> set to <code>false</code> and map the policy to each tenant’s namespace, or use a policy engine such as <a href="https://github.com/open-policy-agent/gatekeeper">OPA/Gatekeeper</a> or <a href="https://kyverno.io">Kyverno</a> to prevent tenants from running privileged containers. | ||
profileLevel: 1</p> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>README</title> | ||
</head> | ||
<body> | ||
<h2> Block privileged containers [MTB-PL1-BC-CPI-5] </h2> | ||
<p> | ||
<b> Profile Applicability: </b> 1 <br> | ||
<b> Type: </b> Behavioral Check <br> | ||
<b> Category: </b> Control Plane Isolation <br> | ||
<b> Description: </b> By default a container is not allowed to access any devices on the host, but a “privileged” container can access all devices on the host. A process within a privileged container can also get unrestricted host access. Hence, tenants should not be allowed to run privileged containers. <br> | ||
<b> Remediation: </b> Define a `PodSecurityPolicy` with `privileged` set to `false` and map the policy to each tenant's namespace, or use a policy engine such as [OPA/Gatekeeper](https://github.com/open-policy-agent/gatekeeper) or [Kyverno](https://kyverno.io) to prevent tenants from running privileged containers. <br> | ||
</p> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters