Skip to content

Commit 82226d3

Browse files
committed
address comments
1 parent b24a8a4 commit 82226d3

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ The `DN_TEMPLATE` supports the following placeholders:
8787

8888
You can track runtime risks through annotations. Add the annotation `github.com/runtime-risks`, with a comma-separated list of supported runtime risk values. Annotations are aggregated from the pod and its owner reference objects.
8989

90-
Currently supported runtime risks:
91-
- `critical-resource`
92-
- `lateral-movement`
93-
- `internet-exposed`
94-
- `sensitive-data`
90+
Currently supported runtime risks can be found in the [Create Deployment Record API docs](https://docs.github.com/en/rest/orgs/artifact-metadata?apiVersion=2022-11-28#create-an-artifact-deployment-record). Invalid runtime risk values will be ignored.
9591

9692

9793
## Kubernetes Deployment
@@ -101,7 +97,7 @@ which includes:
10197

10298
- **Namespace**: `deployment-tracker`
10399
- **ServiceAccount**: Identity for the controller pod
104-
- **ClusterRole**: Minimal permissions (`get`, `list`, `watch` on pods)
100+
- **ClusterRole**: Minimal permissions (`get`, `list`, `watch` on pods; `get` on other supported objects)
105101
- **ClusterRoleBinding**: Binds the ServiceAccount to the ClusterRole
106102
- **Deployment**: Runs the controller with security hardening
107103

pkg/deploymentrecord/record.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package deploymentrecord
22

3-
import "strings"
3+
import (
4+
"log/slog"
5+
"strings"
6+
)
47

58
// Status constants for deployment records.
69
const (
@@ -19,6 +22,14 @@ const (
1922
SensitiveData RuntimeRisk = "sensitive-data"
2023
)
2124

25+
// Map of valid runtime risks.
26+
var validRuntimeRisks = map[RuntimeRisk]bool{
27+
CriticalResource: true,
28+
InternetExposed: true,
29+
LateralMovement: true,
30+
SensitiveData: true,
31+
}
32+
2233
// DeploymentRecord represents a deployment event record.
2334
type DeploymentRecord struct {
2435
Name string `json:"name"`
@@ -59,11 +70,10 @@ func NewDeploymentRecord(name, digest, version, logicalEnv, physicalEnv,
5970
// ValidateRuntimeRisk confirms if string is a valid runtime risk,
6071
// then returns the canonical runtime risk constant if valid, empty string otherwise.
6172
func ValidateRuntimeRisk(risk string) RuntimeRisk {
62-
r := RuntimeRisk(strings.TrimSpace(risk))
63-
switch r {
64-
case CriticalResource, InternetExposed, LateralMovement, SensitiveData:
65-
return r
66-
default:
73+
r := RuntimeRisk(strings.ToLower(strings.TrimSpace(risk)))
74+
if !validRuntimeRisks[r] {
75+
slog.Debug("Invalid runtime risk", "risk", risk)
6776
return ""
6877
}
78+
return r
6979
}

0 commit comments

Comments
 (0)