mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
podsecurity: distinguish between audit and audit violation annotations
This commit is contained in:
parent
4a79488ac2
commit
65f88c675c
@ -446,7 +446,7 @@ func (a *Admission) EvaluatePod(ctx context.Context, nsPolicy api.Policy, nsPoli
|
|||||||
|
|
||||||
// TODO: reuse previous evaluation if audit level+version is the same as enforce level+version
|
// TODO: reuse previous evaluation if audit level+version is the same as enforce level+version
|
||||||
if result := policy.AggregateCheckResults(a.Evaluator.EvaluatePod(nsPolicy.Audit, podMetadata, podSpec)); !result.Allowed {
|
if result := policy.AggregateCheckResults(a.Evaluator.EvaluatePod(nsPolicy.Audit, podMetadata, podSpec)); !result.Allowed {
|
||||||
auditAnnotations["audit"] = fmt.Sprintf(
|
auditAnnotations[api.AuditViolationsAnnotationKey] = fmt.Sprintf(
|
||||||
"would violate PodSecurity %q: %s",
|
"would violate PodSecurity %q: %s",
|
||||||
nsPolicy.Audit.String(),
|
nsPolicy.Audit.String(),
|
||||||
result.ForbiddenDetail(),
|
result.ForbiddenDetail(),
|
||||||
|
@ -650,7 +650,7 @@ func TestValidatePodController(t *testing.T) {
|
|||||||
newObject: &badDeploy,
|
newObject: &badDeploy,
|
||||||
gvk: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"},
|
gvk: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"},
|
||||||
gvr: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"},
|
gvr: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"},
|
||||||
expectAuditAnnotations: map[string]string{"audit": "would violate PodSecurity \"baseline:latest\": forbidden sysctls (unknown)"},
|
expectAuditAnnotations: map[string]string{"audit-violations": "would violate PodSecurity \"baseline:latest\": forbidden sysctls (unknown)"},
|
||||||
expectWarnings: []string{"would violate PodSecurity \"baseline:latest\": forbidden sysctls (unknown)"},
|
expectWarnings: []string{"would violate PodSecurity \"baseline:latest\": forbidden sysctls (unknown)"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -659,7 +659,7 @@ func TestValidatePodController(t *testing.T) {
|
|||||||
oldObject: &goodDeploy,
|
oldObject: &goodDeploy,
|
||||||
gvk: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"},
|
gvk: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"},
|
||||||
gvr: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"},
|
gvr: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"},
|
||||||
expectAuditAnnotations: map[string]string{"audit": "would violate PodSecurity \"baseline:latest\": forbidden sysctls (unknown)"},
|
expectAuditAnnotations: map[string]string{"audit-violations": "would violate PodSecurity \"baseline:latest\": forbidden sysctls (unknown)"},
|
||||||
expectWarnings: []string{"would violate PodSecurity \"baseline:latest\": forbidden sysctls (unknown)"},
|
expectWarnings: []string{"would violate PodSecurity \"baseline:latest\": forbidden sysctls (unknown)"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -45,4 +45,5 @@ const (
|
|||||||
WarnVersionLabel = labelPrefix + "warn-version"
|
WarnVersionLabel = labelPrefix + "warn-version"
|
||||||
|
|
||||||
ExemptionReasonAnnotationKey = "exempt"
|
ExemptionReasonAnnotationKey = "exempt"
|
||||||
|
AuditViolationsAnnotationKey = "audit-violations"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user