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 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #809 from Divya063/readme_render
Added README generator
- Loading branch information
Showing
7 changed files
with
160 additions
and
1 deletion.
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,95 @@ | ||
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() { | ||
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
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
18 changes: 18 additions & 0 deletions
18
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
<!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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func Exists(path string) (bool, error) { | ||
|
||
_, err := os.Stat(path) | ||
fmt.Println(err) | ||
if err == nil { | ||
return true, nil | ||
} | ||
|
||
return false, err | ||
|
||
} | ||
|
||
func GetDirectory(path string, delimiter string) string { | ||
|
||
dir := strings.Split(path, delimiter) | ||
dir = dir[0 : len(dir)-1] | ||
dirPath := strings.Join(dir[:], "/") | ||
|
||
return dirPath | ||
} | ||
|
||
func CheckError(err error) { | ||
if err != nil { | ||
fmt.Println("Fatal error ", err.Error()) | ||
os.Exit(1) | ||
} | ||
} |